]>
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. * |
bdcd2b92 | 4 | * Copyright (C) 2004-2012 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e 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> |
dea3101e | 27 | |
91886523 | 28 | #include <scsi/scsi.h> |
dea3101e JB |
29 | #include <scsi/scsi_cmnd.h> |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_host.h> | |
f888ba3c | 32 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 33 | #include <scsi/fc/fc_fs.h> |
0d878419 | 34 | #include <linux/aer.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e JB |
37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e JB |
41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_crtn.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_compat.h" | |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
04c68496 | 48 | #include "lpfc_vport.h" |
dea3101e JB |
49 | |
50 | /* There are only four IOCB completion types. */ | |
51 | typedef enum _lpfc_iocb_type { | |
52 | LPFC_UNKNOWN_IOCB, | |
53 | LPFC_UNSOL_IOCB, | |
54 | LPFC_SOL_IOCB, | |
55 | LPFC_ABORT_IOCB | |
56 | } lpfc_iocb_type; | |
57 | ||
4f774513 JS |
58 | |
59 | /* Provide function prototypes local to this module. */ | |
60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
61 | uint32_t); | |
62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
63 | uint8_t *, uint32_t *); |
64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
65 | struct lpfc_iocbq *); | |
6669f9bb JS |
66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
67 | struct hbq_dmabuf *); | |
0558056c JS |
68 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
69 | struct lpfc_cqe *); | |
8a9d2e80 JS |
70 | static int lpfc_sli4_post_els_sgl_list(struct lpfc_hba *, struct list_head *, |
71 | int); | |
0558056c | 72 | |
4f774513 JS |
73 | static IOCB_t * |
74 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
75 | { | |
76 | return &iocbq->iocb; | |
77 | } | |
78 | ||
79 | /** | |
80 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
81 | * @q: The Work Queue to operate on. | |
82 | * @wqe: The work Queue Entry to put on the Work queue. | |
83 | * | |
84 | * This routine will copy the contents of @wqe to the next available entry on | |
85 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
86 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
87 | * successful. If no entries are available on @q then this function will return | |
88 | * -ENOMEM. | |
89 | * The caller is expected to hold the hbalock when calling this routine. | |
90 | **/ | |
91 | static uint32_t | |
92 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
93 | { | |
2e90f4b5 | 94 | union lpfc_wqe *temp_wqe; |
4f774513 JS |
95 | struct lpfc_register doorbell; |
96 | uint32_t host_index; | |
027140ea | 97 | uint32_t idx; |
4f774513 | 98 | |
2e90f4b5 JS |
99 | /* sanity check on queue memory */ |
100 | if (unlikely(!q)) | |
101 | return -ENOMEM; | |
102 | temp_wqe = q->qe[q->host_index].wqe; | |
103 | ||
4f774513 | 104 | /* If the host has not yet processed the next entry then we are done */ |
027140ea JS |
105 | idx = ((q->host_index + 1) % q->entry_count); |
106 | if (idx == q->hba_index) { | |
b84daac9 | 107 | q->WQ_overflow++; |
4f774513 | 108 | return -ENOMEM; |
b84daac9 JS |
109 | } |
110 | q->WQ_posted++; | |
4f774513 | 111 | /* set consumption flag every once in a while */ |
ff78d8f9 | 112 | if (!((q->host_index + 1) % q->entry_repost)) |
f0d9bccc | 113 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
fedd3b7b JS |
114 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
115 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
4f774513 JS |
116 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
117 | ||
118 | /* Update the host index before invoking device */ | |
119 | host_index = q->host_index; | |
027140ea JS |
120 | |
121 | q->host_index = idx; | |
4f774513 JS |
122 | |
123 | /* Ring Doorbell */ | |
124 | doorbell.word0 = 0; | |
125 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); | |
126 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); | |
127 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); | |
128 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); | |
4f774513 JS |
129 | |
130 | return 0; | |
131 | } | |
132 | ||
133 | /** | |
134 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
135 | * @q: The Work Queue to operate on. | |
136 | * @index: The index to advance the hba index to. | |
137 | * | |
138 | * This routine will update the HBA index of a queue to reflect consumption of | |
139 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
140 | * an entry the host calls this function to update the queue's internal | |
141 | * pointers. This routine returns the number of entries that were consumed by | |
142 | * the HBA. | |
143 | **/ | |
144 | static uint32_t | |
145 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
146 | { | |
147 | uint32_t released = 0; | |
148 | ||
2e90f4b5 JS |
149 | /* sanity check on queue memory */ |
150 | if (unlikely(!q)) | |
151 | return 0; | |
152 | ||
4f774513 JS |
153 | if (q->hba_index == index) |
154 | return 0; | |
155 | do { | |
156 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
157 | released++; | |
158 | } while (q->hba_index != index); | |
159 | return released; | |
160 | } | |
161 | ||
162 | /** | |
163 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
164 | * @q: The Mailbox Queue to operate on. | |
165 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
166 | * | |
167 | * This routine will copy the contents of @mqe to the next available entry on | |
168 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
169 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
170 | * successful. If no entries are available on @q then this function will return | |
171 | * -ENOMEM. | |
172 | * The caller is expected to hold the hbalock when calling this routine. | |
173 | **/ | |
174 | static uint32_t | |
175 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
176 | { | |
2e90f4b5 | 177 | struct lpfc_mqe *temp_mqe; |
4f774513 JS |
178 | struct lpfc_register doorbell; |
179 | uint32_t host_index; | |
180 | ||
2e90f4b5 JS |
181 | /* sanity check on queue memory */ |
182 | if (unlikely(!q)) | |
183 | return -ENOMEM; | |
184 | temp_mqe = q->qe[q->host_index].mqe; | |
185 | ||
4f774513 JS |
186 | /* If the host has not yet processed the next entry then we are done */ |
187 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
188 | return -ENOMEM; | |
189 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | |
190 | /* Save off the mailbox pointer for completion */ | |
191 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
192 | ||
193 | /* Update the host index before invoking device */ | |
194 | host_index = q->host_index; | |
195 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
196 | ||
197 | /* Ring Doorbell */ | |
198 | doorbell.word0 = 0; | |
199 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
200 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
201 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
4f774513 JS |
202 | return 0; |
203 | } | |
204 | ||
205 | /** | |
206 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
207 | * @q: The Mailbox Queue to operate on. | |
208 | * | |
209 | * This routine will update the HBA index of a queue to reflect consumption of | |
210 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
211 | * an entry the host calls this function to update the queue's internal | |
212 | * pointers. This routine returns the number of entries that were consumed by | |
213 | * the HBA. | |
214 | **/ | |
215 | static uint32_t | |
216 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
217 | { | |
2e90f4b5 JS |
218 | /* sanity check on queue memory */ |
219 | if (unlikely(!q)) | |
220 | return 0; | |
221 | ||
4f774513 JS |
222 | /* Clear the mailbox pointer for completion */ |
223 | q->phba->mbox = NULL; | |
224 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
225 | return 1; | |
226 | } | |
227 | ||
228 | /** | |
229 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
230 | * @q: The Event Queue to get the first valid EQE from | |
231 | * | |
232 | * This routine will get the first valid Event Queue Entry from @q, update | |
233 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
234 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
235 | * processed, but not popped back to the HBA then this routine will return NULL. | |
236 | **/ | |
237 | static struct lpfc_eqe * | |
238 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
239 | { | |
2e90f4b5 | 240 | struct lpfc_eqe *eqe; |
027140ea | 241 | uint32_t idx; |
2e90f4b5 JS |
242 | |
243 | /* sanity check on queue memory */ | |
244 | if (unlikely(!q)) | |
245 | return NULL; | |
246 | eqe = q->qe[q->hba_index].eqe; | |
4f774513 JS |
247 | |
248 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 249 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
250 | return NULL; |
251 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
252 | idx = ((q->hba_index + 1) % q->entry_count); |
253 | if (idx == q->host_index) | |
4f774513 JS |
254 | return NULL; |
255 | ||
027140ea | 256 | q->hba_index = idx; |
4f774513 JS |
257 | return eqe; |
258 | } | |
259 | ||
260 | /** | |
261 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
262 | * @q: The Event Queue that the host has completed processing for. | |
263 | * @arm: Indicates whether the host wants to arms this CQ. | |
264 | * | |
265 | * This routine will mark all Event Queue Entries on @q, from the last | |
266 | * known completed entry to the last entry that was processed, as completed | |
267 | * by clearing the valid bit for each completion queue entry. Then it will | |
268 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
269 | * The internal host index in the @q will be updated by this routine to indicate | |
270 | * that the host has finished processing the entries. The @arm parameter | |
271 | * indicates that the queue should be rearmed when ringing the doorbell. | |
272 | * | |
273 | * This function will return the number of EQEs that were popped. | |
274 | **/ | |
275 | uint32_t | |
276 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
277 | { | |
278 | uint32_t released = 0; | |
279 | struct lpfc_eqe *temp_eqe; | |
280 | struct lpfc_register doorbell; | |
281 | ||
2e90f4b5 JS |
282 | /* sanity check on queue memory */ |
283 | if (unlikely(!q)) | |
284 | return 0; | |
285 | ||
4f774513 JS |
286 | /* while there are valid entries */ |
287 | while (q->hba_index != q->host_index) { | |
288 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 289 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
290 | released++; |
291 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
292 | } | |
293 | if (unlikely(released == 0 && !arm)) | |
294 | return 0; | |
295 | ||
296 | /* ring doorbell for number popped */ | |
297 | doorbell.word0 = 0; | |
298 | if (arm) { | |
299 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
300 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
301 | } | |
302 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
303 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
6b5151fd JS |
304 | bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell, |
305 | (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT)); | |
306 | bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id); | |
4f774513 | 307 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
a747c9ce JS |
308 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
309 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
310 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
311 | return released; |
312 | } | |
313 | ||
314 | /** | |
315 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
316 | * @q: The Completion Queue to get the first valid CQE from | |
317 | * | |
318 | * This routine will get the first valid Completion Queue Entry from @q, update | |
319 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
320 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
321 | * processed, but not popped back to the HBA then this routine will return NULL. | |
322 | **/ | |
323 | static struct lpfc_cqe * | |
324 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
325 | { | |
326 | struct lpfc_cqe *cqe; | |
027140ea | 327 | uint32_t idx; |
4f774513 | 328 | |
2e90f4b5 JS |
329 | /* sanity check on queue memory */ |
330 | if (unlikely(!q)) | |
331 | return NULL; | |
332 | ||
4f774513 | 333 | /* If the next CQE is not valid then we are done */ |
cb5172ea | 334 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
335 | return NULL; |
336 | /* If the host has not yet processed the next entry then we are done */ | |
027140ea JS |
337 | idx = ((q->hba_index + 1) % q->entry_count); |
338 | if (idx == q->host_index) | |
4f774513 JS |
339 | return NULL; |
340 | ||
341 | cqe = q->qe[q->hba_index].cqe; | |
027140ea | 342 | q->hba_index = idx; |
4f774513 JS |
343 | return cqe; |
344 | } | |
345 | ||
346 | /** | |
347 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
348 | * @q: The Completion Queue that the host has completed processing for. | |
349 | * @arm: Indicates whether the host wants to arms this CQ. | |
350 | * | |
351 | * This routine will mark all Completion queue entries on @q, from the last | |
352 | * known completed entry to the last entry that was processed, as completed | |
353 | * by clearing the valid bit for each completion queue entry. Then it will | |
354 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
355 | * The internal host index in the @q will be updated by this routine to indicate | |
356 | * that the host has finished processing the entries. The @arm parameter | |
357 | * indicates that the queue should be rearmed when ringing the doorbell. | |
358 | * | |
359 | * This function will return the number of CQEs that were released. | |
360 | **/ | |
361 | uint32_t | |
362 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
363 | { | |
364 | uint32_t released = 0; | |
365 | struct lpfc_cqe *temp_qe; | |
366 | struct lpfc_register doorbell; | |
367 | ||
2e90f4b5 JS |
368 | /* sanity check on queue memory */ |
369 | if (unlikely(!q)) | |
370 | return 0; | |
4f774513 JS |
371 | /* while there are valid entries */ |
372 | while (q->hba_index != q->host_index) { | |
373 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 374 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
375 | released++; |
376 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
377 | } | |
378 | if (unlikely(released == 0 && !arm)) | |
379 | return 0; | |
380 | ||
381 | /* ring doorbell for number popped */ | |
382 | doorbell.word0 = 0; | |
383 | if (arm) | |
384 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
385 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
386 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
6b5151fd JS |
387 | bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell, |
388 | (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT)); | |
389 | bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id); | |
4f774513 JS |
390 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); |
391 | return released; | |
392 | } | |
393 | ||
394 | /** | |
395 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
396 | * @q: The Header Receive Queue to operate on. | |
397 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
398 | * | |
399 | * This routine will copy the contents of @wqe to the next available entry on | |
400 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
401 | * HBA to start processing the Receive Queue Entry. This function returns the | |
402 | * index that the rqe was copied to if successful. If no entries are available | |
403 | * on @q then this function will return -ENOMEM. | |
404 | * The caller is expected to hold the hbalock when calling this routine. | |
405 | **/ | |
406 | static int | |
407 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
408 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
409 | { | |
2e90f4b5 JS |
410 | struct lpfc_rqe *temp_hrqe; |
411 | struct lpfc_rqe *temp_drqe; | |
4f774513 JS |
412 | struct lpfc_register doorbell; |
413 | int put_index = hq->host_index; | |
414 | ||
2e90f4b5 JS |
415 | /* sanity check on queue memory */ |
416 | if (unlikely(!hq) || unlikely(!dq)) | |
417 | return -ENOMEM; | |
418 | temp_hrqe = hq->qe[hq->host_index].rqe; | |
419 | temp_drqe = dq->qe[dq->host_index].rqe; | |
420 | ||
4f774513 JS |
421 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) |
422 | return -EINVAL; | |
423 | if (hq->host_index != dq->host_index) | |
424 | return -EINVAL; | |
425 | /* If the host has not yet processed the next entry then we are done */ | |
426 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
427 | return -EBUSY; | |
428 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
429 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
430 | ||
431 | /* Update the host index to point to the next slot */ | |
432 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
433 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
434 | ||
435 | /* Ring The Header Receive Queue Doorbell */ | |
73d91e50 | 436 | if (!(hq->host_index % hq->entry_repost)) { |
4f774513 JS |
437 | doorbell.word0 = 0; |
438 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | |
73d91e50 | 439 | hq->entry_repost); |
4f774513 JS |
440 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); |
441 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); | |
442 | } | |
443 | return put_index; | |
444 | } | |
445 | ||
446 | /** | |
447 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
448 | * @q: The Header Receive Queue to operate on. | |
449 | * | |
450 | * This routine will update the HBA index of a queue to reflect consumption of | |
451 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
452 | * consumed an entry the host calls this function to update the queue's | |
453 | * internal pointers. This routine returns the number of entries that were | |
454 | * consumed by the HBA. | |
455 | **/ | |
456 | static uint32_t | |
457 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
458 | { | |
2e90f4b5 JS |
459 | /* sanity check on queue memory */ |
460 | if (unlikely(!hq) || unlikely(!dq)) | |
461 | return 0; | |
462 | ||
4f774513 JS |
463 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) |
464 | return 0; | |
465 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
466 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
467 | return 1; | |
468 | } | |
469 | ||
e59058c4 | 470 | /** |
3621a710 | 471 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
472 | * @phba: Pointer to HBA context object. |
473 | * @pring: Pointer to driver SLI ring object. | |
474 | * | |
475 | * This function returns pointer to next command iocb entry | |
476 | * in the command ring. The caller must hold hbalock to prevent | |
477 | * other threads consume the next command iocb. | |
478 | * SLI-2/SLI-3 provide different sized iocbs. | |
479 | **/ | |
ed957684 JS |
480 | static inline IOCB_t * |
481 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
482 | { | |
7e56aa25 JS |
483 | return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) + |
484 | pring->sli.sli3.cmdidx * phba->iocb_cmd_size); | |
ed957684 JS |
485 | } |
486 | ||
e59058c4 | 487 | /** |
3621a710 | 488 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
489 | * @phba: Pointer to HBA context object. |
490 | * @pring: Pointer to driver SLI ring object. | |
491 | * | |
492 | * This function returns pointer to next response iocb entry | |
493 | * in the response ring. The caller must hold hbalock to make sure | |
494 | * that no other thread consume the next response iocb. | |
495 | * SLI-2/SLI-3 provide different sized iocbs. | |
496 | **/ | |
ed957684 JS |
497 | static inline IOCB_t * |
498 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
499 | { | |
7e56aa25 JS |
500 | return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) + |
501 | pring->sli.sli3.rspidx * phba->iocb_rsp_size); | |
ed957684 JS |
502 | } |
503 | ||
e59058c4 | 504 | /** |
3621a710 | 505 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
506 | * @phba: Pointer to HBA context object. |
507 | * | |
508 | * This function is called with hbalock held. This function | |
509 | * allocates a new driver iocb object from the iocb pool. If the | |
510 | * allocation is successful, it returns pointer to the newly | |
511 | * allocated iocb object else it returns NULL. | |
512 | **/ | |
4f2e66c6 | 513 | struct lpfc_iocbq * |
2e0fef85 | 514 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) |
0bd4ca25 JSEC |
515 | { |
516 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
517 | struct lpfc_iocbq * iocbq = NULL; | |
518 | ||
519 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
2a9bf3d0 JS |
520 | if (iocbq) |
521 | phba->iocb_cnt++; | |
522 | if (phba->iocb_cnt > phba->iocb_max) | |
523 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
524 | return iocbq; |
525 | } | |
526 | ||
da0436e9 JS |
527 | /** |
528 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
529 | * @phba: Pointer to HBA context object. | |
530 | * @xritag: XRI value. | |
531 | * | |
532 | * This function clears the sglq pointer from the array of acive | |
533 | * sglq's. The xritag that is passed in is used to index into the | |
534 | * array. Before the xritag can be used it needs to be adjusted | |
535 | * by subtracting the xribase. | |
536 | * | |
537 | * Returns sglq ponter = success, NULL = Failure. | |
538 | **/ | |
539 | static struct lpfc_sglq * | |
540 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
541 | { | |
da0436e9 | 542 | struct lpfc_sglq *sglq; |
6d368e53 JS |
543 | |
544 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
545 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; | |
da0436e9 JS |
546 | return sglq; |
547 | } | |
548 | ||
549 | /** | |
550 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
551 | * @phba: Pointer to HBA context object. | |
552 | * @xritag: XRI value. | |
553 | * | |
554 | * This function returns the sglq pointer from the array of acive | |
555 | * sglq's. The xritag that is passed in is used to index into the | |
556 | * array. Before the xritag can be used it needs to be adjusted | |
557 | * by subtracting the xribase. | |
558 | * | |
559 | * Returns sglq ponter = success, NULL = Failure. | |
560 | **/ | |
0f65ff68 | 561 | struct lpfc_sglq * |
da0436e9 JS |
562 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
563 | { | |
da0436e9 | 564 | struct lpfc_sglq *sglq; |
6d368e53 JS |
565 | |
566 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
da0436e9 JS |
567 | return sglq; |
568 | } | |
569 | ||
19ca7609 | 570 | /** |
1151e3ec | 571 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
572 | * @phba: Pointer to HBA context object. |
573 | * @xritag: xri used in this exchange. | |
574 | * @rrq: The RRQ to be cleared. | |
575 | * | |
19ca7609 | 576 | **/ |
1151e3ec JS |
577 | void |
578 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
579 | uint16_t xritag, | |
580 | struct lpfc_node_rrq *rrq) | |
19ca7609 | 581 | { |
1151e3ec | 582 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 583 | |
1151e3ec JS |
584 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
585 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
586 | |
587 | /* The target DID could have been swapped (cable swap) | |
588 | * we should use the ndlp from the findnode if it is | |
589 | * available. | |
590 | */ | |
1151e3ec | 591 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
592 | ndlp = rrq->ndlp; |
593 | ||
1151e3ec JS |
594 | if (!ndlp) |
595 | goto out; | |
596 | ||
6d368e53 | 597 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
19ca7609 JS |
598 | rrq->send_rrq = 0; |
599 | rrq->xritag = 0; | |
600 | rrq->rrq_stop_time = 0; | |
601 | } | |
1151e3ec | 602 | out: |
19ca7609 JS |
603 | mempool_free(rrq, phba->rrq_pool); |
604 | } | |
605 | ||
606 | /** | |
607 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
608 | * @phba: Pointer to HBA context object. | |
609 | * | |
610 | * This function is called with hbalock held. This function | |
611 | * Checks if stop_time (ratov from setting rrq active) has | |
612 | * been reached, if it has and the send_rrq flag is set then | |
613 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
614 | * then it will just call the routine to clear the rrq and | |
615 | * free the rrq resource. | |
616 | * The timer is set to the next rrq that is going to expire before | |
617 | * leaving the routine. | |
618 | * | |
619 | **/ | |
620 | void | |
621 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
622 | { | |
623 | struct lpfc_node_rrq *rrq; | |
624 | struct lpfc_node_rrq *nextrrq; | |
625 | unsigned long next_time; | |
626 | unsigned long iflags; | |
1151e3ec | 627 | LIST_HEAD(send_rrq); |
19ca7609 JS |
628 | |
629 | spin_lock_irqsave(&phba->hbalock, iflags); | |
630 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
631 | next_time = jiffies + HZ * (phba->fc_ratov + 1); | |
632 | list_for_each_entry_safe(rrq, nextrrq, | |
1151e3ec JS |
633 | &phba->active_rrq_list, list) { |
634 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
635 | list_move(&rrq->list, &send_rrq); | |
636 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
637 | next_time = rrq->rrq_stop_time; |
638 | } | |
639 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
640 | if (!list_empty(&phba->active_rrq_list)) | |
641 | mod_timer(&phba->rrq_tmr, next_time); | |
1151e3ec JS |
642 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
643 | list_del(&rrq->list); | |
644 | if (!rrq->send_rrq) | |
645 | /* this call will free the rrq */ | |
646 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
647 | else if (lpfc_send_rrq(phba, rrq)) { | |
648 | /* if we send the rrq then the completion handler | |
649 | * will clear the bit in the xribitmap. | |
650 | */ | |
651 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
652 | rrq); | |
653 | } | |
654 | } | |
19ca7609 JS |
655 | } |
656 | ||
657 | /** | |
658 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
659 | * @vport: Pointer to vport context object. | |
660 | * @xri: The xri used in the exchange. | |
661 | * @did: The targets DID for this exchange. | |
662 | * | |
663 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
664 | * rrq = rrq for this xri and target. | |
665 | **/ | |
666 | struct lpfc_node_rrq * | |
667 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
668 | { | |
669 | struct lpfc_hba *phba = vport->phba; | |
670 | struct lpfc_node_rrq *rrq; | |
671 | struct lpfc_node_rrq *nextrrq; | |
672 | unsigned long iflags; | |
673 | ||
674 | if (phba->sli_rev != LPFC_SLI_REV4) | |
675 | return NULL; | |
676 | spin_lock_irqsave(&phba->hbalock, iflags); | |
677 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
678 | if (rrq->vport == vport && rrq->xritag == xri && | |
679 | rrq->nlp_DID == did){ | |
680 | list_del(&rrq->list); | |
681 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
682 | return rrq; | |
683 | } | |
684 | } | |
685 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
686 | return NULL; | |
687 | } | |
688 | ||
689 | /** | |
690 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
691 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
692 | * @ndlp: Pointer to the lpfc_node_list structure. |
693 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
694 | * phba->active_rrq_list and clear the rrq. | |
695 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
696 | **/ |
697 | void | |
1151e3ec | 698 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
699 | |
700 | { | |
701 | struct lpfc_hba *phba = vport->phba; | |
702 | struct lpfc_node_rrq *rrq; | |
703 | struct lpfc_node_rrq *nextrrq; | |
704 | unsigned long iflags; | |
1151e3ec | 705 | LIST_HEAD(rrq_list); |
19ca7609 JS |
706 | |
707 | if (phba->sli_rev != LPFC_SLI_REV4) | |
708 | return; | |
1151e3ec JS |
709 | if (!ndlp) { |
710 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
711 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 712 | } |
1151e3ec JS |
713 | spin_lock_irqsave(&phba->hbalock, iflags); |
714 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
715 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
716 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 717 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
718 | |
719 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
720 | list_del(&rrq->list); | |
721 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
722 | } | |
19ca7609 JS |
723 | } |
724 | ||
725 | /** | |
726 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. | |
727 | * @phba: Pointer to HBA context object. | |
728 | * | |
729 | * Remove all rrqs from the phba->active_rrq_list and free them by | |
730 | * calling __lpfc_clr_active_rrq | |
731 | * | |
732 | **/ | |
733 | void | |
734 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) | |
735 | { | |
736 | struct lpfc_node_rrq *rrq; | |
737 | struct lpfc_node_rrq *nextrrq; | |
738 | unsigned long next_time; | |
739 | unsigned long iflags; | |
1151e3ec | 740 | LIST_HEAD(rrq_list); |
19ca7609 JS |
741 | |
742 | if (phba->sli_rev != LPFC_SLI_REV4) | |
743 | return; | |
744 | spin_lock_irqsave(&phba->hbalock, iflags); | |
745 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
746 | next_time = jiffies + HZ * (phba->fc_ratov * 2); | |
1151e3ec JS |
747 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
748 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
749 | ||
750 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
19ca7609 | 751 | list_del(&rrq->list); |
1151e3ec | 752 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
19ca7609 | 753 | } |
19ca7609 JS |
754 | if (!list_empty(&phba->active_rrq_list)) |
755 | mod_timer(&phba->rrq_tmr, next_time); | |
756 | } | |
757 | ||
758 | ||
759 | /** | |
1151e3ec | 760 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
761 | * @phba: Pointer to HBA context object. |
762 | * @ndlp: Targets nodelist pointer for this exchange. | |
763 | * @xritag the xri in the bitmap to test. | |
764 | * | |
765 | * This function is called with hbalock held. This function | |
766 | * returns 0 = rrq not active for this xri | |
767 | * 1 = rrq is valid for this xri. | |
768 | **/ | |
1151e3ec JS |
769 | int |
770 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
771 | uint16_t xritag) |
772 | { | |
19ca7609 JS |
773 | if (!ndlp) |
774 | return 0; | |
6d368e53 | 775 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
19ca7609 JS |
776 | return 1; |
777 | else | |
778 | return 0; | |
779 | } | |
780 | ||
781 | /** | |
782 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
783 | * @phba: Pointer to HBA context object. | |
784 | * @ndlp: nodelist pointer for this target. | |
785 | * @xritag: xri used in this exchange. | |
786 | * @rxid: Remote Exchange ID. | |
787 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
788 | * | |
789 | * This function takes the hbalock. | |
790 | * The active bit is always set in the active rrq xri_bitmap even | |
791 | * if there is no slot avaiable for the other rrq information. | |
792 | * | |
793 | * returns 0 rrq actived for this xri | |
794 | * < 0 No memory or invalid ndlp. | |
795 | **/ | |
796 | int | |
797 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
b42c07c8 | 798 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) |
19ca7609 | 799 | { |
19ca7609 | 800 | unsigned long iflags; |
b42c07c8 JS |
801 | struct lpfc_node_rrq *rrq; |
802 | int empty; | |
803 | ||
804 | if (!ndlp) | |
805 | return -EINVAL; | |
806 | ||
807 | if (!phba->cfg_enable_rrq) | |
808 | return -EINVAL; | |
19ca7609 JS |
809 | |
810 | spin_lock_irqsave(&phba->hbalock, iflags); | |
b42c07c8 JS |
811 | if (phba->pport->load_flag & FC_UNLOADING) { |
812 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
813 | goto out; | |
814 | } | |
815 | ||
816 | /* | |
817 | * set the active bit even if there is no mem available. | |
818 | */ | |
819 | if (NLP_CHK_FREE_REQ(ndlp)) | |
820 | goto out; | |
821 | ||
822 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
823 | goto out; | |
824 | ||
825 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) | |
826 | goto out; | |
827 | ||
19ca7609 | 828 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
b42c07c8 JS |
829 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
830 | if (!rrq) { | |
831 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
832 | "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x" | |
833 | " DID:0x%x Send:%d\n", | |
834 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
835 | return -EINVAL; | |
836 | } | |
837 | rrq->send_rrq = send_rrq; | |
838 | rrq->xritag = xritag; | |
839 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); | |
840 | rrq->ndlp = ndlp; | |
841 | rrq->nlp_DID = ndlp->nlp_DID; | |
842 | rrq->vport = ndlp->vport; | |
843 | rrq->rxid = rxid; | |
844 | rrq->send_rrq = send_rrq; | |
845 | spin_lock_irqsave(&phba->hbalock, iflags); | |
846 | empty = list_empty(&phba->active_rrq_list); | |
847 | list_add_tail(&rrq->list, &phba->active_rrq_list); | |
848 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
849 | if (empty) | |
850 | lpfc_worker_wake_up(phba); | |
851 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
852 | return 0; | |
853 | out: | |
854 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
855 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
856 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
857 | " DID:0x%x Send:%d\n", | |
858 | xritag, rxid, ndlp->nlp_DID, send_rrq); | |
859 | return -EINVAL; | |
19ca7609 JS |
860 | } |
861 | ||
da0436e9 JS |
862 | /** |
863 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
864 | * @phba: Pointer to HBA context object. | |
19ca7609 | 865 | * @piocb: Pointer to the iocbq. |
da0436e9 JS |
866 | * |
867 | * This function is called with hbalock held. This function | |
6d368e53 | 868 | * gets a new driver sglq object from the sglq list. If the |
da0436e9 JS |
869 | * list is not empty then it is successful, it returns pointer to the newly |
870 | * allocated sglq object else it returns NULL. | |
871 | **/ | |
872 | static struct lpfc_sglq * | |
19ca7609 | 873 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
874 | { |
875 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
876 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 877 | struct lpfc_sglq *start_sglq = NULL; |
19ca7609 JS |
878 | struct lpfc_scsi_buf *lpfc_cmd; |
879 | struct lpfc_nodelist *ndlp; | |
880 | int found = 0; | |
881 | ||
882 | if (piocbq->iocb_flag & LPFC_IO_FCP) { | |
883 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
884 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 JS |
885 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
886 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
19ca7609 | 887 | ndlp = piocbq->context_un.ndlp; |
93d1379e JS |
888 | else if ((piocbq->iocb.ulpCommand == CMD_ELS_REQUEST64_CR) && |
889 | (piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
890 | ndlp = piocbq->context_un.ndlp; | |
19ca7609 JS |
891 | else |
892 | ndlp = piocbq->context1; | |
893 | ||
da0436e9 | 894 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
895 | start_sglq = sglq; |
896 | while (!found) { | |
897 | if (!sglq) | |
898 | return NULL; | |
ee0f4fe1 | 899 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_lxritag)) { |
19ca7609 JS |
900 | /* This xri has an rrq outstanding for this DID. |
901 | * put it back in the list and get another xri. | |
902 | */ | |
903 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
904 | sglq = NULL; | |
905 | list_remove_head(lpfc_sgl_list, sglq, | |
906 | struct lpfc_sglq, list); | |
907 | if (sglq == start_sglq) { | |
908 | sglq = NULL; | |
909 | break; | |
910 | } else | |
911 | continue; | |
912 | } | |
913 | sglq->ndlp = ndlp; | |
914 | found = 1; | |
6d368e53 | 915 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
19ca7609 JS |
916 | sglq->state = SGL_ALLOCATED; |
917 | } | |
da0436e9 JS |
918 | return sglq; |
919 | } | |
920 | ||
e59058c4 | 921 | /** |
3621a710 | 922 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
923 | * @phba: Pointer to HBA context object. |
924 | * | |
925 | * This function is called with no lock held. This function | |
926 | * allocates a new driver iocb object from the iocb pool. If the | |
927 | * allocation is successful, it returns pointer to the newly | |
928 | * allocated iocb object else it returns NULL. | |
929 | **/ | |
2e0fef85 JS |
930 | struct lpfc_iocbq * |
931 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
932 | { | |
933 | struct lpfc_iocbq * iocbq = NULL; | |
934 | unsigned long iflags; | |
935 | ||
936 | spin_lock_irqsave(&phba->hbalock, iflags); | |
937 | iocbq = __lpfc_sli_get_iocbq(phba); | |
938 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
939 | return iocbq; | |
940 | } | |
941 | ||
4f774513 JS |
942 | /** |
943 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
944 | * @phba: Pointer to HBA context object. | |
945 | * @iocbq: Pointer to driver iocb object. | |
946 | * | |
947 | * This function is called with hbalock held to release driver | |
948 | * iocb object to the iocb pool. The iotag in the iocb object | |
949 | * does not change for each use of the iocb object. This function | |
950 | * clears all other fields of the iocb object when it is freed. | |
951 | * The sqlq structure that holds the xritag and phys and virtual | |
952 | * mappings for the scatter gather list is retrieved from the | |
953 | * active array of sglq. The get of the sglq pointer also clears | |
954 | * the entry in the array. If the status of the IO indiactes that | |
955 | * this IO was aborted then the sglq entry it put on the | |
956 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
957 | * IO has good status or fails for any other reason then the sglq | |
958 | * entry is added to the free list (lpfc_sgl_list). | |
959 | **/ | |
960 | static void | |
961 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
962 | { | |
963 | struct lpfc_sglq *sglq; | |
964 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
965 | unsigned long iflag = 0; |
966 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
967 | |
968 | if (iocbq->sli4_xritag == NO_XRI) | |
969 | sglq = NULL; | |
970 | else | |
6d368e53 JS |
971 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
972 | ||
4f774513 | 973 | if (sglq) { |
0f65ff68 JS |
974 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
975 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
976 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
977 | iflag); | |
978 | list_add(&sglq->list, | |
979 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
980 | spin_unlock_irqrestore( | |
981 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
982 | } else { |
983 | sglq->state = SGL_FREED; | |
19ca7609 | 984 | sglq->ndlp = NULL; |
fedd3b7b JS |
985 | list_add_tail(&sglq->list, |
986 | &phba->sli4_hba.lpfc_sgl_list); | |
2a9bf3d0 JS |
987 | |
988 | /* Check if TXQ queue needs to be serviced */ | |
589a52d6 | 989 | if (pring->txq_cnt) |
2a9bf3d0 | 990 | lpfc_worker_wake_up(phba); |
0f65ff68 | 991 | } |
4f774513 JS |
992 | } |
993 | ||
994 | ||
995 | /* | |
996 | * Clean all volatile data fields, preserve iotag and node struct. | |
997 | */ | |
998 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
6d368e53 | 999 | iocbq->sli4_lxritag = NO_XRI; |
4f774513 JS |
1000 | iocbq->sli4_xritag = NO_XRI; |
1001 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
1002 | } | |
1003 | ||
2a9bf3d0 | 1004 | |
e59058c4 | 1005 | /** |
3772a991 | 1006 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
1007 | * @phba: Pointer to HBA context object. |
1008 | * @iocbq: Pointer to driver iocb object. | |
1009 | * | |
1010 | * This function is called with hbalock held to release driver | |
1011 | * iocb object to the iocb pool. The iotag in the iocb object | |
1012 | * does not change for each use of the iocb object. This function | |
1013 | * clears all other fields of the iocb object when it is freed. | |
1014 | **/ | |
a6ababd2 | 1015 | static void |
3772a991 | 1016 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1017 | { |
2e0fef85 | 1018 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
1019 | |
1020 | /* | |
1021 | * Clean all volatile data fields, preserve iotag and node struct. | |
1022 | */ | |
1023 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1024 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1025 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1026 | } | |
1027 | ||
3772a991 JS |
1028 | /** |
1029 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1030 | * @phba: Pointer to HBA context object. | |
1031 | * @iocbq: Pointer to driver iocb object. | |
1032 | * | |
1033 | * This function is called with hbalock held to release driver | |
1034 | * iocb object to the iocb pool. The iotag in the iocb object | |
1035 | * does not change for each use of the iocb object. This function | |
1036 | * clears all other fields of the iocb object when it is freed. | |
1037 | **/ | |
1038 | static void | |
1039 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1040 | { | |
1041 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1042 | phba->iocb_cnt--; |
3772a991 JS |
1043 | } |
1044 | ||
e59058c4 | 1045 | /** |
3621a710 | 1046 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1047 | * @phba: Pointer to HBA context object. |
1048 | * @iocbq: Pointer to driver iocb object. | |
1049 | * | |
1050 | * This function is called with no lock held to release the iocb to | |
1051 | * iocb pool. | |
1052 | **/ | |
2e0fef85 JS |
1053 | void |
1054 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1055 | { | |
1056 | unsigned long iflags; | |
1057 | ||
1058 | /* | |
1059 | * Clean all volatile data fields, preserve iotag and node struct. | |
1060 | */ | |
1061 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1062 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1063 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1064 | } | |
1065 | ||
a257bf90 JS |
1066 | /** |
1067 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1068 | * @phba: Pointer to HBA context object. | |
1069 | * @iocblist: List of IOCBs. | |
1070 | * @ulpstatus: ULP status in IOCB command field. | |
1071 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1072 | * | |
1073 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1074 | * on the list by invoking the complete callback function associated with the | |
1075 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1076 | * fields. | |
1077 | **/ | |
1078 | void | |
1079 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1080 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1081 | { | |
1082 | struct lpfc_iocbq *piocb; | |
1083 | ||
1084 | while (!list_empty(iocblist)) { | |
1085 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
1086 | ||
1087 | if (!piocb->iocb_cmpl) | |
1088 | lpfc_sli_release_iocbq(phba, piocb); | |
1089 | else { | |
1090 | piocb->iocb.ulpStatus = ulpstatus; | |
1091 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1092 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1093 | } | |
1094 | } | |
1095 | return; | |
1096 | } | |
1097 | ||
e59058c4 | 1098 | /** |
3621a710 JS |
1099 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1100 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1101 | * |
1102 | * This function is called by ring event handler function to get the iocb type. | |
1103 | * This function translates the iocb command to an iocb command type used to | |
1104 | * decide the final disposition of each completed IOCB. | |
1105 | * The function returns | |
1106 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1107 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1108 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1109 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1110 | * | |
1111 | * The caller is not required to hold any lock. | |
1112 | **/ | |
dea3101e JB |
1113 | static lpfc_iocb_type |
1114 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1115 | { | |
1116 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1117 | ||
1118 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1119 | return 0; | |
1120 | ||
1121 | switch (iocb_cmnd) { | |
1122 | case CMD_XMIT_SEQUENCE_CR: | |
1123 | case CMD_XMIT_SEQUENCE_CX: | |
1124 | case CMD_XMIT_BCAST_CN: | |
1125 | case CMD_XMIT_BCAST_CX: | |
1126 | case CMD_ELS_REQUEST_CR: | |
1127 | case CMD_ELS_REQUEST_CX: | |
1128 | case CMD_CREATE_XRI_CR: | |
1129 | case CMD_CREATE_XRI_CX: | |
1130 | case CMD_GET_RPI_CN: | |
1131 | case CMD_XMIT_ELS_RSP_CX: | |
1132 | case CMD_GET_RPI_CR: | |
1133 | case CMD_FCP_IWRITE_CR: | |
1134 | case CMD_FCP_IWRITE_CX: | |
1135 | case CMD_FCP_IREAD_CR: | |
1136 | case CMD_FCP_IREAD_CX: | |
1137 | case CMD_FCP_ICMND_CR: | |
1138 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1139 | case CMD_FCP_TSEND_CX: |
1140 | case CMD_FCP_TRSP_CX: | |
1141 | case CMD_FCP_TRECEIVE_CX: | |
1142 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
1143 | case CMD_ADAPTER_MSG: |
1144 | case CMD_ADAPTER_DUMP: | |
1145 | case CMD_XMIT_SEQUENCE64_CR: | |
1146 | case CMD_XMIT_SEQUENCE64_CX: | |
1147 | case CMD_XMIT_BCAST64_CN: | |
1148 | case CMD_XMIT_BCAST64_CX: | |
1149 | case CMD_ELS_REQUEST64_CR: | |
1150 | case CMD_ELS_REQUEST64_CX: | |
1151 | case CMD_FCP_IWRITE64_CR: | |
1152 | case CMD_FCP_IWRITE64_CX: | |
1153 | case CMD_FCP_IREAD64_CR: | |
1154 | case CMD_FCP_IREAD64_CX: | |
1155 | case CMD_FCP_ICMND64_CR: | |
1156 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1157 | case CMD_FCP_TSEND64_CX: |
1158 | case CMD_FCP_TRSP64_CX: | |
1159 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
1160 | case CMD_GEN_REQUEST64_CR: |
1161 | case CMD_GEN_REQUEST64_CX: | |
1162 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1163 | case DSSCMD_IWRITE64_CR: |
1164 | case DSSCMD_IWRITE64_CX: | |
1165 | case DSSCMD_IREAD64_CR: | |
1166 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
1167 | type = LPFC_SOL_IOCB; |
1168 | break; | |
1169 | case CMD_ABORT_XRI_CN: | |
1170 | case CMD_ABORT_XRI_CX: | |
1171 | case CMD_CLOSE_XRI_CN: | |
1172 | case CMD_CLOSE_XRI_CX: | |
1173 | case CMD_XRI_ABORTED_CX: | |
1174 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1175 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
1176 | type = LPFC_ABORT_IOCB; |
1177 | break; | |
1178 | case CMD_RCV_SEQUENCE_CX: | |
1179 | case CMD_RCV_ELS_REQ_CX: | |
1180 | case CMD_RCV_SEQUENCE64_CX: | |
1181 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1182 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1183 | case CMD_IOCB_RCV_SEQ64_CX: |
1184 | case CMD_IOCB_RCV_ELS64_CX: | |
1185 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1186 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
1187 | type = LPFC_UNSOL_IOCB; |
1188 | break; | |
3163f725 JS |
1189 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1190 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1191 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1192 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1193 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1194 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1195 | case CMD_IOCB_RET_HBQE64_CN: | |
1196 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1197 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1198 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1199 | case CMD_IOCB_LOGENTRY_CN: | |
1200 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1201 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1202 | __func__, iocb_cmnd); |
3163f725 JS |
1203 | type = LPFC_UNKNOWN_IOCB; |
1204 | break; | |
dea3101e JB |
1205 | default: |
1206 | type = LPFC_UNKNOWN_IOCB; | |
1207 | break; | |
1208 | } | |
1209 | ||
1210 | return type; | |
1211 | } | |
1212 | ||
e59058c4 | 1213 | /** |
3621a710 | 1214 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1215 | * @phba: Pointer to HBA context object. |
1216 | * | |
1217 | * This function is called from SLI initialization code | |
1218 | * to configure every ring of the HBA's SLI interface. The | |
1219 | * caller is not required to hold any lock. This function issues | |
1220 | * a config_ring mailbox command for each ring. | |
1221 | * This function returns zero if successful else returns a negative | |
1222 | * error code. | |
1223 | **/ | |
dea3101e | 1224 | static int |
ed957684 | 1225 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
1226 | { |
1227 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1228 | LPFC_MBOXQ_t *pmb; |
1229 | MAILBOX_t *pmbox; | |
1230 | int i, rc, ret = 0; | |
dea3101e | 1231 | |
ed957684 JS |
1232 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1233 | if (!pmb) | |
1234 | return -ENOMEM; | |
04c68496 | 1235 | pmbox = &pmb->u.mb; |
ed957684 | 1236 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1237 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
1238 | lpfc_config_ring(phba, i, pmb); |
1239 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1240 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1241 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1242 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
1243 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1244 | "ring %d\n", | |
e8b62011 JS |
1245 | rc, pmbox->mbxCommand, |
1246 | pmbox->mbxStatus, i); | |
2e0fef85 | 1247 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1248 | ret = -ENXIO; |
1249 | break; | |
dea3101e JB |
1250 | } |
1251 | } | |
ed957684 JS |
1252 | mempool_free(pmb, phba->mbox_mem_pool); |
1253 | return ret; | |
dea3101e JB |
1254 | } |
1255 | ||
e59058c4 | 1256 | /** |
3621a710 | 1257 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1258 | * @phba: Pointer to HBA context object. |
1259 | * @pring: Pointer to driver SLI ring object. | |
1260 | * @piocb: Pointer to the driver iocb object. | |
1261 | * | |
1262 | * This function is called with hbalock held. The function adds the | |
1263 | * new iocb to txcmplq of the given ring. This function always returns | |
1264 | * 0. If this function is called for ELS ring, this function checks if | |
1265 | * there is a vport associated with the ELS command. This function also | |
1266 | * starts els_tmofunc timer if this is an ELS command. | |
1267 | **/ | |
dea3101e | 1268 | static int |
2e0fef85 JS |
1269 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1270 | struct lpfc_iocbq *piocb) | |
dea3101e | 1271 | { |
dea3101e | 1272 | list_add_tail(&piocb->list, &pring->txcmplq); |
4f2e66c6 | 1273 | piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; |
dea3101e | 1274 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
1275 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
1276 | pring->txcmplq_max = pring->txcmplq_cnt; | |
1277 | ||
92d7f7b0 JS |
1278 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1279 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
1280 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
1281 | if (!piocb->vport) | |
1282 | BUG(); | |
1283 | else | |
1284 | mod_timer(&piocb->vport->els_tmofunc, | |
1285 | jiffies + HZ * (phba->fc_ratov << 1)); | |
1286 | } | |
1287 | ||
dea3101e | 1288 | |
2e0fef85 | 1289 | return 0; |
dea3101e JB |
1290 | } |
1291 | ||
e59058c4 | 1292 | /** |
3621a710 | 1293 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1294 | * @phba: Pointer to HBA context object. |
1295 | * @pring: Pointer to driver SLI ring object. | |
1296 | * | |
1297 | * This function is called with hbalock held to get next | |
1298 | * iocb in txq of the given ring. If there is any iocb in | |
1299 | * the txq, the function returns first iocb in the list after | |
1300 | * removing the iocb from the list, else it returns NULL. | |
1301 | **/ | |
2a9bf3d0 | 1302 | struct lpfc_iocbq * |
2e0fef85 | 1303 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1304 | { |
dea3101e JB |
1305 | struct lpfc_iocbq *cmd_iocb; |
1306 | ||
858c9f6c JS |
1307 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
1308 | if (cmd_iocb != NULL) | |
dea3101e | 1309 | pring->txq_cnt--; |
2e0fef85 | 1310 | return cmd_iocb; |
dea3101e JB |
1311 | } |
1312 | ||
e59058c4 | 1313 | /** |
3621a710 | 1314 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1315 | * @phba: Pointer to HBA context object. |
1316 | * @pring: Pointer to driver SLI ring object. | |
1317 | * | |
1318 | * This function is called with hbalock held and the caller must post the | |
1319 | * iocb without releasing the lock. If the caller releases the lock, | |
1320 | * iocb slot returned by the function is not guaranteed to be available. | |
1321 | * The function returns pointer to the next available iocb slot if there | |
1322 | * is available slot in the ring, else it returns NULL. | |
1323 | * If the get index of the ring is ahead of the put index, the function | |
1324 | * will post an error attention event to the worker thread to take the | |
1325 | * HBA to offline state. | |
1326 | **/ | |
dea3101e JB |
1327 | static IOCB_t * |
1328 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1329 | { | |
34b02dcd | 1330 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
7e56aa25 JS |
1331 | uint32_t max_cmd_idx = pring->sli.sli3.numCiocb; |
1332 | if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) && | |
1333 | (++pring->sli.sli3.next_cmdidx >= max_cmd_idx)) | |
1334 | pring->sli.sli3.next_cmdidx = 0; | |
dea3101e | 1335 | |
7e56aa25 JS |
1336 | if (unlikely(pring->sli.sli3.local_getidx == |
1337 | pring->sli.sli3.next_cmdidx)) { | |
dea3101e | 1338 | |
7e56aa25 | 1339 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e | 1340 | |
7e56aa25 | 1341 | if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) { |
dea3101e | 1342 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 1343 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1344 | "is bigger than cmd ring %d\n", |
e8b62011 | 1345 | pring->ringno, |
7e56aa25 JS |
1346 | pring->sli.sli3.local_getidx, |
1347 | max_cmd_idx); | |
dea3101e | 1348 | |
2e0fef85 | 1349 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1350 | /* |
1351 | * All error attention handlers are posted to | |
1352 | * worker thread | |
1353 | */ | |
1354 | phba->work_ha |= HA_ERATT; | |
1355 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1356 | |
5e9d9b82 | 1357 | lpfc_worker_wake_up(phba); |
dea3101e JB |
1358 | |
1359 | return NULL; | |
1360 | } | |
1361 | ||
7e56aa25 | 1362 | if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx) |
dea3101e JB |
1363 | return NULL; |
1364 | } | |
1365 | ||
ed957684 | 1366 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
1367 | } |
1368 | ||
e59058c4 | 1369 | /** |
3621a710 | 1370 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1371 | * @phba: Pointer to HBA context object. |
1372 | * @iocbq: Pointer to driver iocb object. | |
1373 | * | |
1374 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1375 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1376 | * array and assigns a new iotag. | |
1377 | * The function returns the allocated iotag if successful, else returns zero. | |
1378 | * Zero is not a valid iotag. | |
1379 | * The caller is not required to hold any lock. | |
1380 | **/ | |
604a3e30 | 1381 | uint16_t |
2e0fef85 | 1382 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1383 | { |
2e0fef85 JS |
1384 | struct lpfc_iocbq **new_arr; |
1385 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1386 | size_t new_len; |
1387 | struct lpfc_sli *psli = &phba->sli; | |
1388 | uint16_t iotag; | |
dea3101e | 1389 | |
2e0fef85 | 1390 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1391 | iotag = psli->last_iotag; |
1392 | if(++iotag < psli->iocbq_lookup_len) { | |
1393 | psli->last_iotag = iotag; | |
1394 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1395 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1396 | iocbq->iotag = iotag; |
1397 | return iotag; | |
2e0fef85 | 1398 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1399 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1400 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1401 | spin_unlock_irq(&phba->hbalock); |
1402 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1403 | GFP_KERNEL); |
1404 | if (new_arr) { | |
2e0fef85 | 1405 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1406 | old_arr = psli->iocbq_lookup; |
1407 | if (new_len <= psli->iocbq_lookup_len) { | |
1408 | /* highly unprobable case */ | |
1409 | kfree(new_arr); | |
1410 | iotag = psli->last_iotag; | |
1411 | if(++iotag < psli->iocbq_lookup_len) { | |
1412 | psli->last_iotag = iotag; | |
1413 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1414 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1415 | iocbq->iotag = iotag; |
1416 | return iotag; | |
1417 | } | |
2e0fef85 | 1418 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1419 | return 0; |
1420 | } | |
1421 | if (psli->iocbq_lookup) | |
1422 | memcpy(new_arr, old_arr, | |
1423 | ((psli->last_iotag + 1) * | |
311464ec | 1424 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1425 | psli->iocbq_lookup = new_arr; |
1426 | psli->iocbq_lookup_len = new_len; | |
1427 | psli->last_iotag = iotag; | |
1428 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1429 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1430 | iocbq->iotag = iotag; |
1431 | kfree(old_arr); | |
1432 | return iotag; | |
1433 | } | |
8f6d98d2 | 1434 | } else |
2e0fef85 | 1435 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1436 | |
bc73905a | 1437 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1438 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1439 | psli->last_iotag); | |
dea3101e | 1440 | |
604a3e30 | 1441 | return 0; |
dea3101e JB |
1442 | } |
1443 | ||
e59058c4 | 1444 | /** |
3621a710 | 1445 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1446 | * @phba: Pointer to HBA context object. |
1447 | * @pring: Pointer to driver SLI ring object. | |
1448 | * @iocb: Pointer to iocb slot in the ring. | |
1449 | * @nextiocb: Pointer to driver iocb object which need to be | |
1450 | * posted to firmware. | |
1451 | * | |
1452 | * This function is called with hbalock held to post a new iocb to | |
1453 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1454 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1455 | * a completion call back for this iocb else the function will free the | |
1456 | * iocb object. | |
1457 | **/ | |
dea3101e JB |
1458 | static void |
1459 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1460 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1461 | { | |
1462 | /* | |
604a3e30 | 1463 | * Set up an iotag |
dea3101e | 1464 | */ |
604a3e30 | 1465 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1466 | |
e2a0a9d6 | 1467 | |
a58cbd52 JS |
1468 | if (pring->ringno == LPFC_ELS_RING) { |
1469 | lpfc_debugfs_slow_ring_trc(phba, | |
1470 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1471 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1472 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1473 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1474 | } | |
1475 | ||
dea3101e JB |
1476 | /* |
1477 | * Issue iocb command to adapter | |
1478 | */ | |
92d7f7b0 | 1479 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1480 | wmb(); |
1481 | pring->stats.iocb_cmd++; | |
1482 | ||
1483 | /* | |
1484 | * If there is no completion routine to call, we can release the | |
1485 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1486 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1487 | */ | |
1488 | if (nextiocb->iocb_cmpl) | |
1489 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1490 | else |
2e0fef85 | 1491 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1492 | |
1493 | /* | |
1494 | * Let the HBA know what IOCB slot will be the next one the | |
1495 | * driver will put a command into. | |
1496 | */ | |
7e56aa25 JS |
1497 | pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx; |
1498 | writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); | |
dea3101e JB |
1499 | } |
1500 | ||
e59058c4 | 1501 | /** |
3621a710 | 1502 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1503 | * @phba: Pointer to HBA context object. |
1504 | * @pring: Pointer to driver SLI ring object. | |
1505 | * | |
1506 | * The caller is not required to hold any lock for calling this function. | |
1507 | * This function updates the chip attention bits for the ring to inform firmware | |
1508 | * that there are pending work to be done for this ring and requests an | |
1509 | * interrupt when there is space available in the ring. This function is | |
1510 | * called when the driver is unable to post more iocbs to the ring due | |
1511 | * to unavailability of space in the ring. | |
1512 | **/ | |
dea3101e | 1513 | static void |
2e0fef85 | 1514 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1515 | { |
1516 | int ringno = pring->ringno; | |
1517 | ||
1518 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1519 | ||
1520 | wmb(); | |
1521 | ||
1522 | /* | |
1523 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1524 | * The HBA will tell us when an IOCB entry is available. | |
1525 | */ | |
1526 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1527 | readl(phba->CAregaddr); /* flush */ | |
1528 | ||
1529 | pring->stats.iocb_cmd_full++; | |
1530 | } | |
1531 | ||
e59058c4 | 1532 | /** |
3621a710 | 1533 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1534 | * @phba: Pointer to HBA context object. |
1535 | * @pring: Pointer to driver SLI ring object. | |
1536 | * | |
1537 | * This function updates the chip attention register bit for the | |
1538 | * given ring to inform HBA that there is more work to be done | |
1539 | * in this ring. The caller is not required to hold any lock. | |
1540 | **/ | |
dea3101e | 1541 | static void |
2e0fef85 | 1542 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1543 | { |
1544 | int ringno = pring->ringno; | |
1545 | ||
1546 | /* | |
1547 | * Tell the HBA that there is work to do in this ring. | |
1548 | */ | |
34b02dcd JS |
1549 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1550 | wmb(); | |
1551 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1552 | readl(phba->CAregaddr); /* flush */ | |
1553 | } | |
dea3101e JB |
1554 | } |
1555 | ||
e59058c4 | 1556 | /** |
3621a710 | 1557 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1558 | * @phba: Pointer to HBA context object. |
1559 | * @pring: Pointer to driver SLI ring object. | |
1560 | * | |
1561 | * This function is called with hbalock held to post pending iocbs | |
1562 | * in the txq to the firmware. This function is called when driver | |
1563 | * detects space available in the ring. | |
1564 | **/ | |
dea3101e | 1565 | static void |
2e0fef85 | 1566 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1567 | { |
1568 | IOCB_t *iocb; | |
1569 | struct lpfc_iocbq *nextiocb; | |
1570 | ||
1571 | /* | |
1572 | * Check to see if: | |
1573 | * (a) there is anything on the txq to send | |
1574 | * (b) link is up | |
1575 | * (c) link attention events can be processed (fcp ring only) | |
1576 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1577 | */ | |
1578 | if (pring->txq_cnt && | |
2e0fef85 | 1579 | lpfc_is_link_up(phba) && |
dea3101e | 1580 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1581 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1582 | |
1583 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1584 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1585 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1586 | ||
1587 | if (iocb) | |
1588 | lpfc_sli_update_ring(phba, pring); | |
1589 | else | |
1590 | lpfc_sli_update_full_ring(phba, pring); | |
1591 | } | |
1592 | ||
1593 | return; | |
1594 | } | |
1595 | ||
e59058c4 | 1596 | /** |
3621a710 | 1597 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1598 | * @phba: Pointer to HBA context object. |
1599 | * @hbqno: HBQ number. | |
1600 | * | |
1601 | * This function is called with hbalock held to get the next | |
1602 | * available slot for the given HBQ. If there is free slot | |
1603 | * available for the HBQ it will return pointer to the next available | |
1604 | * HBQ entry else it will return NULL. | |
1605 | **/ | |
a6ababd2 | 1606 | static struct lpfc_hbq_entry * |
ed957684 JS |
1607 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1608 | { | |
1609 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1610 | ||
1611 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1612 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1613 | hbqp->next_hbqPutIdx = 0; | |
1614 | ||
1615 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1616 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1617 | uint32_t getidx = le32_to_cpu(raw_index); |
1618 | ||
1619 | hbqp->local_hbqGetIdx = getidx; | |
1620 | ||
1621 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1622 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1623 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1624 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1625 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1626 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1627 | hbqp->entry_count); |
1628 | ||
1629 | phba->link_state = LPFC_HBA_ERROR; | |
1630 | return NULL; | |
1631 | } | |
1632 | ||
1633 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1634 | return NULL; | |
1635 | } | |
1636 | ||
51ef4c26 JS |
1637 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1638 | hbqp->hbqPutIdx; | |
ed957684 JS |
1639 | } |
1640 | ||
e59058c4 | 1641 | /** |
3621a710 | 1642 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1643 | * @phba: Pointer to HBA context object. |
1644 | * | |
1645 | * This function is called with no lock held to free all the | |
1646 | * hbq buffers while uninitializing the SLI interface. It also | |
1647 | * frees the HBQ buffers returned by the firmware but not yet | |
1648 | * processed by the upper layers. | |
1649 | **/ | |
ed957684 JS |
1650 | void |
1651 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1652 | { | |
92d7f7b0 JS |
1653 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1654 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1655 | unsigned long flags; |
51ef4c26 | 1656 | int i, hbq_count; |
3163f725 | 1657 | uint32_t hbqno; |
ed957684 | 1658 | |
51ef4c26 | 1659 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1660 | /* Return all memory used by all HBQs */ |
3163f725 | 1661 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1662 | for (i = 0; i < hbq_count; ++i) { |
1663 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1664 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1665 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1666 | list_del(&hbq_buf->dbuf.list); | |
1667 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1668 | } | |
a8adb832 | 1669 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1670 | } |
3163f725 | 1671 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1672 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1673 | list) { | |
3163f725 JS |
1674 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1675 | list_del(&hbq_buf->dbuf.list); | |
1676 | if (hbq_buf->tag == -1) { | |
1677 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1678 | (phba, hbq_buf); | |
1679 | } else { | |
1680 | hbqno = hbq_buf->tag >> 16; | |
1681 | if (hbqno >= LPFC_MAX_HBQS) | |
1682 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1683 | (phba, hbq_buf); | |
1684 | else | |
1685 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1686 | hbq_buf); | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | /* Mark the HBQs not in use */ | |
1691 | phba->hbq_in_use = 0; | |
1692 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1693 | } |
1694 | ||
e59058c4 | 1695 | /** |
3621a710 | 1696 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1697 | * @phba: Pointer to HBA context object. |
1698 | * @hbqno: HBQ number. | |
1699 | * @hbq_buf: Pointer to HBQ buffer. | |
1700 | * | |
1701 | * This function is called with the hbalock held to post a | |
1702 | * hbq buffer to the firmware. If the function finds an empty | |
1703 | * slot in the HBQ, it will post the buffer. The function will return | |
1704 | * pointer to the hbq entry if it successfully post the buffer | |
1705 | * else it will return NULL. | |
1706 | **/ | |
3772a991 | 1707 | static int |
ed957684 | 1708 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1709 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1710 | { |
1711 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1712 | } | |
1713 | ||
1714 | /** | |
1715 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1716 | * @phba: Pointer to HBA context object. | |
1717 | * @hbqno: HBQ number. | |
1718 | * @hbq_buf: Pointer to HBQ buffer. | |
1719 | * | |
1720 | * This function is called with the hbalock held to post a hbq buffer to the | |
1721 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1722 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1723 | * it successfully post the buffer else it will return an error. | |
1724 | **/ | |
1725 | static int | |
1726 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1727 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1728 | { |
1729 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1730 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1731 | |
1732 | /* Get next HBQ entry slot to use */ | |
1733 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1734 | if (hbqe) { | |
1735 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1736 | ||
92d7f7b0 JS |
1737 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1738 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1739 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1740 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1741 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1742 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1743 | /* Sync SLIM */ | |
ed957684 JS |
1744 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1745 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1746 | /* flush */ |
ed957684 | 1747 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1748 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1749 | return 0; |
1750 | } else | |
1751 | return -ENOMEM; | |
ed957684 JS |
1752 | } |
1753 | ||
4f774513 JS |
1754 | /** |
1755 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1756 | * @phba: Pointer to HBA context object. | |
1757 | * @hbqno: HBQ number. | |
1758 | * @hbq_buf: Pointer to HBQ buffer. | |
1759 | * | |
1760 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1761 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1762 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1763 | **/ | |
1764 | static int | |
1765 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1766 | struct hbq_dmabuf *hbq_buf) | |
1767 | { | |
1768 | int rc; | |
1769 | struct lpfc_rqe hrqe; | |
1770 | struct lpfc_rqe drqe; | |
1771 | ||
1772 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1773 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1774 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1775 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1776 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1777 | &hrqe, &drqe); | |
1778 | if (rc < 0) | |
1779 | return rc; | |
1780 | hbq_buf->tag = rc; | |
1781 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1782 | return 0; | |
1783 | } | |
1784 | ||
e59058c4 | 1785 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1786 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1787 | .rn = 1, | |
def9c7a9 | 1788 | .entry_count = 256, |
92d7f7b0 JS |
1789 | .mask_count = 0, |
1790 | .profile = 0, | |
51ef4c26 | 1791 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1792 | .buffer_count = 0, |
a257bf90 JS |
1793 | .init_count = 40, |
1794 | .add_count = 40, | |
92d7f7b0 | 1795 | }; |
ed957684 | 1796 | |
e59058c4 | 1797 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1798 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1799 | .rn = 1, | |
1800 | .entry_count = 200, | |
1801 | .mask_count = 0, | |
1802 | .profile = 0, | |
1803 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1804 | .buffer_count = 0, | |
1805 | .init_count = 0, | |
1806 | .add_count = 5, | |
1807 | }; | |
1808 | ||
e59058c4 | 1809 | /* Array of HBQs */ |
78b2d852 | 1810 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1811 | &lpfc_els_hbq, |
51ef4c26 | 1812 | &lpfc_extra_hbq, |
92d7f7b0 | 1813 | }; |
ed957684 | 1814 | |
e59058c4 | 1815 | /** |
3621a710 | 1816 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1817 | * @phba: Pointer to HBA context object. |
1818 | * @hbqno: HBQ number. | |
1819 | * @count: Number of HBQ buffers to be posted. | |
1820 | * | |
d7c255b2 JS |
1821 | * This function is called with no lock held to post more hbq buffers to the |
1822 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1823 | * posted. | |
e59058c4 | 1824 | **/ |
311464ec | 1825 | static int |
92d7f7b0 | 1826 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1827 | { |
d7c255b2 | 1828 | uint32_t i, posted = 0; |
3163f725 | 1829 | unsigned long flags; |
92d7f7b0 | 1830 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1831 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1832 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1833 | return 0; |
51ef4c26 | 1834 | |
d7c255b2 JS |
1835 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1836 | lpfc_hbq_defs[hbqno]->entry_count) | |
1837 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1838 | phba->hbqs[hbqno].buffer_count; | |
1839 | if (!count) | |
1840 | return 0; | |
1841 | /* Allocate HBQ entries */ | |
1842 | for (i = 0; i < count; i++) { | |
1843 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1844 | if (!hbq_buffer) | |
1845 | break; | |
1846 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1847 | } | |
3163f725 JS |
1848 | /* Check whether HBQ is still in use */ |
1849 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1850 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1851 | goto err; |
1852 | while (!list_empty(&hbq_buf_list)) { | |
1853 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1854 | dbuf.list); | |
1855 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1856 | (hbqno << 16)); | |
3772a991 | 1857 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1858 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1859 | posted++; |
1860 | } else | |
51ef4c26 | 1861 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1862 | } |
3163f725 | 1863 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1864 | return posted; |
1865 | err: | |
eafe1df9 | 1866 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1867 | while (!list_empty(&hbq_buf_list)) { |
1868 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1869 | dbuf.list); | |
1870 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1871 | } | |
1872 | return 0; | |
ed957684 JS |
1873 | } |
1874 | ||
e59058c4 | 1875 | /** |
3621a710 | 1876 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1877 | * @phba: Pointer to HBA context object. |
1878 | * @qno: HBQ number. | |
1879 | * | |
1880 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1881 | * is called with no lock held. The function returns the number of HBQ entries |
1882 | * successfully allocated. | |
e59058c4 | 1883 | **/ |
92d7f7b0 JS |
1884 | int |
1885 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1886 | { |
def9c7a9 JS |
1887 | if (phba->sli_rev == LPFC_SLI_REV4) |
1888 | return 0; | |
1889 | else | |
1890 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1891 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1892 | } |
ed957684 | 1893 | |
e59058c4 | 1894 | /** |
3621a710 | 1895 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1896 | * @phba: Pointer to HBA context object. |
1897 | * @qno: HBQ queue number. | |
1898 | * | |
1899 | * This function is called from SLI initialization code path with | |
1900 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1901 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1902 | **/ |
a6ababd2 | 1903 | static int |
92d7f7b0 JS |
1904 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1905 | { | |
def9c7a9 JS |
1906 | if (phba->sli_rev == LPFC_SLI_REV4) |
1907 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
73d91e50 | 1908 | lpfc_hbq_defs[qno]->entry_count); |
def9c7a9 JS |
1909 | else |
1910 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1911 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1912 | } |
1913 | ||
3772a991 JS |
1914 | /** |
1915 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1916 | * @phba: Pointer to HBA context object. | |
1917 | * @hbqno: HBQ number. | |
1918 | * | |
1919 | * This function removes the first hbq buffer on an hbq list and returns a | |
1920 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1921 | **/ | |
1922 | static struct hbq_dmabuf * | |
1923 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1924 | { | |
1925 | struct lpfc_dmabuf *d_buf; | |
1926 | ||
1927 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1928 | if (!d_buf) | |
1929 | return NULL; | |
1930 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1931 | } | |
1932 | ||
e59058c4 | 1933 | /** |
3621a710 | 1934 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1935 | * @phba: Pointer to HBA context object. |
1936 | * @tag: Tag of the hbq buffer. | |
1937 | * | |
1938 | * This function is called with hbalock held. This function searches | |
1939 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1940 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1941 | * it returns NULL. | |
1942 | **/ | |
a6ababd2 | 1943 | static struct hbq_dmabuf * |
92d7f7b0 | 1944 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1945 | { |
92d7f7b0 JS |
1946 | struct lpfc_dmabuf *d_buf; |
1947 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1948 | uint32_t hbqno; |
1949 | ||
1950 | hbqno = tag >> 16; | |
a0a74e45 | 1951 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1952 | return NULL; |
ed957684 | 1953 | |
3772a991 | 1954 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1955 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1956 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1957 | if (hbq_buf->tag == tag) { |
3772a991 | 1958 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1959 | return hbq_buf; |
ed957684 JS |
1960 | } |
1961 | } | |
3772a991 | 1962 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1963 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1964 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1965 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1966 | return NULL; |
ed957684 JS |
1967 | } |
1968 | ||
e59058c4 | 1969 | /** |
3621a710 | 1970 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1971 | * @phba: Pointer to HBA context object. |
1972 | * @hbq_buffer: Pointer to HBQ buffer. | |
1973 | * | |
1974 | * This function is called with hbalock. This function gives back | |
1975 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1976 | * post the buffer, it will free the buffer. | |
1977 | **/ | |
ed957684 | 1978 | void |
51ef4c26 | 1979 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
1980 | { |
1981 | uint32_t hbqno; | |
1982 | ||
51ef4c26 JS |
1983 | if (hbq_buffer) { |
1984 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 1985 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 1986 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
1987 | } |
1988 | } | |
1989 | ||
e59058c4 | 1990 | /** |
3621a710 | 1991 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
1992 | * @mbxCommand: mailbox command code. |
1993 | * | |
1994 | * This function is called by the mailbox event handler function to verify | |
1995 | * that the completed mailbox command is a legitimate mailbox command. If the | |
1996 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
1997 | * and the mailbox event handler will take the HBA offline. | |
1998 | **/ | |
dea3101e JB |
1999 | static int |
2000 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
2001 | { | |
2002 | uint8_t ret; | |
2003 | ||
2004 | switch (mbxCommand) { | |
2005 | case MBX_LOAD_SM: | |
2006 | case MBX_READ_NV: | |
2007 | case MBX_WRITE_NV: | |
a8adb832 | 2008 | case MBX_WRITE_VPARMS: |
dea3101e JB |
2009 | case MBX_RUN_BIU_DIAG: |
2010 | case MBX_INIT_LINK: | |
2011 | case MBX_DOWN_LINK: | |
2012 | case MBX_CONFIG_LINK: | |
2013 | case MBX_CONFIG_RING: | |
2014 | case MBX_RESET_RING: | |
2015 | case MBX_READ_CONFIG: | |
2016 | case MBX_READ_RCONFIG: | |
2017 | case MBX_READ_SPARM: | |
2018 | case MBX_READ_STATUS: | |
2019 | case MBX_READ_RPI: | |
2020 | case MBX_READ_XRI: | |
2021 | case MBX_READ_REV: | |
2022 | case MBX_READ_LNK_STAT: | |
2023 | case MBX_REG_LOGIN: | |
2024 | case MBX_UNREG_LOGIN: | |
dea3101e JB |
2025 | case MBX_CLEAR_LA: |
2026 | case MBX_DUMP_MEMORY: | |
2027 | case MBX_DUMP_CONTEXT: | |
2028 | case MBX_RUN_DIAGS: | |
2029 | case MBX_RESTART: | |
2030 | case MBX_UPDATE_CFG: | |
2031 | case MBX_DOWN_LOAD: | |
2032 | case MBX_DEL_LD_ENTRY: | |
2033 | case MBX_RUN_PROGRAM: | |
2034 | case MBX_SET_MASK: | |
09372820 | 2035 | case MBX_SET_VARIABLE: |
dea3101e | 2036 | case MBX_UNREG_D_ID: |
41415862 | 2037 | case MBX_KILL_BOARD: |
dea3101e | 2038 | case MBX_CONFIG_FARP: |
41415862 | 2039 | case MBX_BEACON: |
dea3101e JB |
2040 | case MBX_LOAD_AREA: |
2041 | case MBX_RUN_BIU_DIAG64: | |
2042 | case MBX_CONFIG_PORT: | |
2043 | case MBX_READ_SPARM64: | |
2044 | case MBX_READ_RPI64: | |
2045 | case MBX_REG_LOGIN64: | |
76a95d75 | 2046 | case MBX_READ_TOPOLOGY: |
09372820 | 2047 | case MBX_WRITE_WWN: |
dea3101e JB |
2048 | case MBX_SET_DEBUG: |
2049 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2050 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2051 | case MBX_REG_VPI: |
2052 | case MBX_UNREG_VPI: | |
858c9f6c | 2053 | case MBX_HEARTBEAT: |
84774a4d JS |
2054 | case MBX_PORT_CAPABILITIES: |
2055 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2056 | case MBX_SLI4_CONFIG: |
2057 | case MBX_SLI4_REQ_FTRS: | |
2058 | case MBX_REG_FCFI: | |
2059 | case MBX_UNREG_FCFI: | |
2060 | case MBX_REG_VFI: | |
2061 | case MBX_UNREG_VFI: | |
2062 | case MBX_INIT_VPI: | |
2063 | case MBX_INIT_VFI: | |
2064 | case MBX_RESUME_RPI: | |
c7495937 JS |
2065 | case MBX_READ_EVENT_LOG_STATUS: |
2066 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2067 | case MBX_SECURITY_MGMT: |
2068 | case MBX_AUTH_PORT: | |
dea3101e JB |
2069 | ret = mbxCommand; |
2070 | break; | |
2071 | default: | |
2072 | ret = MBX_SHUTDOWN; | |
2073 | break; | |
2074 | } | |
2e0fef85 | 2075 | return ret; |
dea3101e | 2076 | } |
e59058c4 JS |
2077 | |
2078 | /** | |
3621a710 | 2079 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2080 | * @phba: Pointer to HBA context object. |
2081 | * @pmboxq: Pointer to mailbox command. | |
2082 | * | |
2083 | * This is completion handler function for mailbox commands issued from | |
2084 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2085 | * mailbox event handler function with no lock held. This function | |
2086 | * will wake up thread waiting on the wait queue pointed by context1 | |
2087 | * of the mailbox. | |
2088 | **/ | |
04c68496 | 2089 | void |
2e0fef85 | 2090 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
2091 | { |
2092 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2093 | unsigned long drvr_flag; |
dea3101e JB |
2094 | |
2095 | /* | |
2096 | * If pdone_q is empty, the driver thread gave up waiting and | |
2097 | * continued running. | |
2098 | */ | |
7054a606 | 2099 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2100 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
2101 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2102 | if (pdone_q) | |
2103 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2104 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
2105 | return; |
2106 | } | |
2107 | ||
e59058c4 JS |
2108 | |
2109 | /** | |
3621a710 | 2110 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2111 | * @phba: Pointer to HBA context object. |
2112 | * @pmb: Pointer to mailbox object. | |
2113 | * | |
2114 | * This function is the default mailbox completion handler. It | |
2115 | * frees the memory resources associated with the completed mailbox | |
2116 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2117 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2118 | **/ | |
dea3101e | 2119 | void |
2e0fef85 | 2120 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2121 | { |
d439d286 | 2122 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2123 | struct lpfc_dmabuf *mp; |
d439d286 | 2124 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2125 | struct Scsi_Host *shost; |
04c68496 | 2126 | uint16_t rpi, vpi; |
7054a606 JS |
2127 | int rc; |
2128 | ||
dea3101e | 2129 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2130 | |
dea3101e JB |
2131 | if (mp) { |
2132 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2133 | kfree(mp); | |
2134 | } | |
7054a606 JS |
2135 | |
2136 | /* | |
2137 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2138 | * is in re-discovery driver need to cleanup the RPI. | |
2139 | */ | |
2e0fef85 | 2140 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2141 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2142 | !pmb->u.mb.mbxStatus) { | |
2143 | rpi = pmb->u.mb.un.varWords[0]; | |
6d368e53 | 2144 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
04c68496 | 2145 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
92d7f7b0 | 2146 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2147 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2148 | if (rc != MBX_NOT_FINISHED) | |
2149 | return; | |
2150 | } | |
2151 | ||
695a814e JS |
2152 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2153 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2154 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2155 | shost = lpfc_shost_from_vport(vport); |
2156 | spin_lock_irq(shost->host_lock); | |
2157 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2158 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2159 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2160 | } |
2161 | ||
d439d286 JS |
2162 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2163 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2164 | lpfc_nlp_put(ndlp); | |
2165 | pmb->context2 = NULL; | |
2166 | } | |
2167 | ||
dcf2a4e0 JS |
2168 | /* Check security permission status on INIT_LINK mailbox command */ |
2169 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2170 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2171 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2172 | "2860 SLI authentication is required " | |
2173 | "for INIT_LINK but has not done yet\n"); | |
2174 | ||
04c68496 JS |
2175 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2176 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2177 | else | |
2178 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e JB |
2179 | } |
2180 | ||
e59058c4 | 2181 | /** |
3621a710 | 2182 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2183 | * @phba: Pointer to HBA context object. |
2184 | * | |
2185 | * This function is called with no lock held. This function processes all | |
2186 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2187 | * service routine processes mailbox completion interrupt and adds completed | |
2188 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2189 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2190 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2191 | * function returns the mailbox commands to the upper layer by calling the | |
2192 | * completion handler function of each mailbox. | |
2193 | **/ | |
dea3101e | 2194 | int |
2e0fef85 | 2195 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2196 | { |
92d7f7b0 | 2197 | MAILBOX_t *pmbox; |
dea3101e | 2198 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2199 | int rc; |
2200 | LIST_HEAD(cmplq); | |
dea3101e JB |
2201 | |
2202 | phba->sli.slistat.mbox_event++; | |
2203 | ||
92d7f7b0 JS |
2204 | /* Get all completed mailboxe buffers into the cmplq */ |
2205 | spin_lock_irq(&phba->hbalock); | |
2206 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2207 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2208 | |
92d7f7b0 JS |
2209 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2210 | do { | |
2211 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2212 | if (pmb == NULL) | |
2213 | break; | |
2e0fef85 | 2214 | |
04c68496 | 2215 | pmbox = &pmb->u.mb; |
dea3101e | 2216 | |
858c9f6c JS |
2217 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2218 | if (pmb->vport) { | |
2219 | lpfc_debugfs_disc_trc(pmb->vport, | |
2220 | LPFC_DISC_TRC_MBOX_VPORT, | |
2221 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2222 | (uint32_t)pmbox->mbxCommand, | |
2223 | pmbox->un.varWords[0], | |
2224 | pmbox->un.varWords[1]); | |
2225 | } | |
2226 | else { | |
2227 | lpfc_debugfs_disc_trc(phba->pport, | |
2228 | LPFC_DISC_TRC_MBOX, | |
2229 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2230 | (uint32_t)pmbox->mbxCommand, | |
2231 | pmbox->un.varWords[0], | |
2232 | pmbox->un.varWords[1]); | |
2233 | } | |
2234 | } | |
2235 | ||
dea3101e JB |
2236 | /* |
2237 | * It is a fatal error if unknown mbox command completion. | |
2238 | */ | |
2239 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2240 | MBX_SHUTDOWN) { | |
af901ca1 | 2241 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2242 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2243 | "(%d):0323 Unknown Mailbox command " |
a183a15f | 2244 | "x%x (x%x/x%x) Cmpl\n", |
92d7f7b0 | 2245 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 | 2246 | pmbox->mbxCommand, |
a183a15f JS |
2247 | lpfc_sli_config_mbox_subsys_get(phba, |
2248 | pmb), | |
2249 | lpfc_sli_config_mbox_opcode_get(phba, | |
2250 | pmb)); | |
2e0fef85 | 2251 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2252 | phba->work_hs = HS_FFER3; |
2253 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2254 | continue; |
dea3101e JB |
2255 | } |
2256 | ||
dea3101e JB |
2257 | if (pmbox->mbxStatus) { |
2258 | phba->sli.slistat.mbox_stat_err++; | |
2259 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2260 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 | 2261 | lpfc_printf_log(phba, KERN_INFO, |
a183a15f JS |
2262 | LOG_MBOX | LOG_SLI, |
2263 | "(%d):0305 Mbox cmd cmpl " | |
2264 | "error - RETRYing Data: x%x " | |
2265 | "(x%x/x%x) x%x x%x x%x\n", | |
2266 | pmb->vport ? pmb->vport->vpi : 0, | |
2267 | pmbox->mbxCommand, | |
2268 | lpfc_sli_config_mbox_subsys_get(phba, | |
2269 | pmb), | |
2270 | lpfc_sli_config_mbox_opcode_get(phba, | |
2271 | pmb), | |
2272 | pmbox->mbxStatus, | |
2273 | pmbox->un.varWords[0], | |
2274 | pmb->vport->port_state); | |
dea3101e JB |
2275 | pmbox->mbxStatus = 0; |
2276 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2277 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2278 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2279 | continue; |
dea3101e JB |
2280 | } |
2281 | } | |
2282 | ||
2283 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2284 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
a183a15f | 2285 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
dea3101e | 2286 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2287 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2288 | pmbox->mbxCommand, |
a183a15f JS |
2289 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
2290 | lpfc_sli_config_mbox_opcode_get(phba, pmb), | |
dea3101e JB |
2291 | pmb->mbox_cmpl, |
2292 | *((uint32_t *) pmbox), | |
2293 | pmbox->un.varWords[0], | |
2294 | pmbox->un.varWords[1], | |
2295 | pmbox->un.varWords[2], | |
2296 | pmbox->un.varWords[3], | |
2297 | pmbox->un.varWords[4], | |
2298 | pmbox->un.varWords[5], | |
2299 | pmbox->un.varWords[6], | |
2300 | pmbox->un.varWords[7]); | |
2301 | ||
92d7f7b0 | 2302 | if (pmb->mbox_cmpl) |
dea3101e | 2303 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2304 | } while (1); |
2305 | return 0; | |
2306 | } | |
dea3101e | 2307 | |
e59058c4 | 2308 | /** |
3621a710 | 2309 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2310 | * @phba: Pointer to HBA context object. |
2311 | * @pring: Pointer to driver SLI ring object. | |
2312 | * @tag: buffer tag. | |
2313 | * | |
2314 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2315 | * is set in the tag the buffer is posted for a particular exchange, | |
2316 | * the function will return the buffer without replacing the buffer. | |
2317 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2318 | * returns the buffer and also posts another buffer to the firmware. | |
2319 | **/ | |
76bb24ef JS |
2320 | static struct lpfc_dmabuf * |
2321 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2322 | struct lpfc_sli_ring *pring, |
2323 | uint32_t tag) | |
76bb24ef | 2324 | { |
9f1e1b50 JS |
2325 | struct hbq_dmabuf *hbq_entry; |
2326 | ||
76bb24ef JS |
2327 | if (tag & QUE_BUFTAG_BIT) |
2328 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2329 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2330 | if (!hbq_entry) | |
2331 | return NULL; | |
2332 | return &hbq_entry->dbuf; | |
76bb24ef | 2333 | } |
57127f15 | 2334 | |
3772a991 JS |
2335 | /** |
2336 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2337 | * @phba: Pointer to HBA context object. | |
2338 | * @pring: Pointer to driver SLI ring object. | |
2339 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2340 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2341 | * @fch_type: the type for the first frame of the sequence. | |
2342 | * | |
2343 | * This function is called with no lock held. This function uses the r_ctl and | |
2344 | * type of the received sequence to find the correct callback function to call | |
2345 | * to process the sequence. | |
2346 | **/ | |
2347 | static int | |
2348 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2349 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2350 | uint32_t fch_type) | |
2351 | { | |
2352 | int i; | |
2353 | ||
2354 | /* unSolicited Responses */ | |
2355 | if (pring->prt[0].profile) { | |
2356 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2357 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2358 | saveq); | |
2359 | return 1; | |
2360 | } | |
2361 | /* We must search, based on rctl / type | |
2362 | for the right routine */ | |
2363 | for (i = 0; i < pring->num_mask; i++) { | |
2364 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2365 | (pring->prt[i].type == fch_type)) { | |
2366 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2367 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2368 | (phba, pring, saveq); | |
2369 | return 1; | |
2370 | } | |
2371 | } | |
2372 | return 0; | |
2373 | } | |
e59058c4 JS |
2374 | |
2375 | /** | |
3621a710 | 2376 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2377 | * @phba: Pointer to HBA context object. |
2378 | * @pring: Pointer to driver SLI ring object. | |
2379 | * @saveq: Pointer to the unsolicited iocb. | |
2380 | * | |
2381 | * This function is called with no lock held by the ring event handler | |
2382 | * when there is an unsolicited iocb posted to the response ring by the | |
2383 | * firmware. This function gets the buffer associated with the iocbs | |
2384 | * and calls the event handler for the ring. This function handles both | |
2385 | * qring buffers and hbq buffers. | |
2386 | * When the function returns 1 the caller can free the iocb object otherwise | |
2387 | * upper layer functions will free the iocb objects. | |
2388 | **/ | |
dea3101e JB |
2389 | static int |
2390 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2391 | struct lpfc_iocbq *saveq) | |
2392 | { | |
2393 | IOCB_t * irsp; | |
2394 | WORD5 * w5p; | |
2395 | uint32_t Rctl, Type; | |
3772a991 | 2396 | uint32_t match; |
76bb24ef | 2397 | struct lpfc_iocbq *iocbq; |
3163f725 | 2398 | struct lpfc_dmabuf *dmzbuf; |
dea3101e JB |
2399 | |
2400 | match = 0; | |
2401 | irsp = &(saveq->iocb); | |
57127f15 JS |
2402 | |
2403 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2404 | if (pring->lpfc_sli_rcv_async_status) | |
2405 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2406 | else | |
2407 | lpfc_printf_log(phba, | |
2408 | KERN_WARNING, | |
2409 | LOG_SLI, | |
2410 | "0316 Ring %d handler: unexpected " | |
2411 | "ASYNC_STATUS iocb received evt_code " | |
2412 | "0x%x\n", | |
2413 | pring->ringno, | |
2414 | irsp->un.asyncstat.evt_code); | |
2415 | return 1; | |
2416 | } | |
2417 | ||
3163f725 JS |
2418 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2419 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2420 | if (irsp->ulpBdeCount > 0) { | |
2421 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2422 | irsp->un.ulpWord[3]); | |
2423 | lpfc_in_buf_free(phba, dmzbuf); | |
2424 | } | |
2425 | ||
2426 | if (irsp->ulpBdeCount > 1) { | |
2427 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2428 | irsp->unsli3.sli3Words[3]); | |
2429 | lpfc_in_buf_free(phba, dmzbuf); | |
2430 | } | |
2431 | ||
2432 | if (irsp->ulpBdeCount > 2) { | |
2433 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2434 | irsp->unsli3.sli3Words[7]); | |
2435 | lpfc_in_buf_free(phba, dmzbuf); | |
2436 | } | |
2437 | ||
2438 | return 1; | |
2439 | } | |
2440 | ||
92d7f7b0 | 2441 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2442 | if (irsp->ulpBdeCount != 0) { |
2443 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2444 | irsp->un.ulpWord[3]); | |
2445 | if (!saveq->context2) | |
2446 | lpfc_printf_log(phba, | |
2447 | KERN_ERR, | |
2448 | LOG_SLI, | |
2449 | "0341 Ring %d Cannot find buffer for " | |
2450 | "an unsolicited iocb. tag 0x%x\n", | |
2451 | pring->ringno, | |
2452 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2453 | } |
2454 | if (irsp->ulpBdeCount == 2) { | |
2455 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2456 | irsp->unsli3.sli3Words[7]); | |
2457 | if (!saveq->context3) | |
2458 | lpfc_printf_log(phba, | |
2459 | KERN_ERR, | |
2460 | LOG_SLI, | |
2461 | "0342 Ring %d Cannot find buffer for an" | |
2462 | " unsolicited iocb. tag 0x%x\n", | |
2463 | pring->ringno, | |
2464 | irsp->unsli3.sli3Words[7]); | |
2465 | } | |
2466 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2467 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2468 | if (irsp->ulpBdeCount != 0) { |
2469 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2470 | irsp->un.ulpWord[3]); | |
9c2face6 | 2471 | if (!iocbq->context2) |
76bb24ef JS |
2472 | lpfc_printf_log(phba, |
2473 | KERN_ERR, | |
2474 | LOG_SLI, | |
2475 | "0343 Ring %d Cannot find " | |
2476 | "buffer for an unsolicited iocb" | |
2477 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2478 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2479 | } |
2480 | if (irsp->ulpBdeCount == 2) { | |
2481 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2482 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2483 | if (!iocbq->context3) |
76bb24ef JS |
2484 | lpfc_printf_log(phba, |
2485 | KERN_ERR, | |
2486 | LOG_SLI, | |
2487 | "0344 Ring %d Cannot find " | |
2488 | "buffer for an unsolicited " | |
2489 | "iocb. tag 0x%x\n", | |
2490 | pring->ringno, | |
2491 | irsp->unsli3.sli3Words[7]); | |
2492 | } | |
2493 | } | |
92d7f7b0 | 2494 | } |
9c2face6 JS |
2495 | if (irsp->ulpBdeCount != 0 && |
2496 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2497 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2498 | int found = 0; | |
2499 | ||
2500 | /* search continue save q for same XRI */ | |
2501 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
7851fe2c JS |
2502 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
2503 | saveq->iocb.unsli3.rcvsli3.ox_id) { | |
9c2face6 JS |
2504 | list_add_tail(&saveq->list, &iocbq->list); |
2505 | found = 1; | |
2506 | break; | |
2507 | } | |
2508 | } | |
2509 | if (!found) | |
2510 | list_add_tail(&saveq->clist, | |
2511 | &pring->iocb_continue_saveq); | |
2512 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2513 | list_del_init(&iocbq->clist); | |
2514 | saveq = iocbq; | |
2515 | irsp = &(saveq->iocb); | |
2516 | } else | |
2517 | return 0; | |
2518 | } | |
2519 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2520 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2521 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2522 | Rctl = FC_RCTL_ELS_REQ; |
2523 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2524 | } else { |
2525 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2526 | Rctl = w5p->hcsw.Rctl; | |
2527 | Type = w5p->hcsw.Type; | |
2528 | ||
2529 | /* Firmware Workaround */ | |
2530 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2531 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2532 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2533 | Rctl = FC_RCTL_ELS_REQ; |
2534 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2535 | w5p->hcsw.Rctl = Rctl; |
2536 | w5p->hcsw.Type = Type; | |
2537 | } | |
2538 | } | |
92d7f7b0 | 2539 | |
3772a991 | 2540 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2541 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2542 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2543 | "Type x%x received\n", |
e8b62011 | 2544 | pring->ringno, Rctl, Type); |
3772a991 | 2545 | |
92d7f7b0 | 2546 | return 1; |
dea3101e JB |
2547 | } |
2548 | ||
e59058c4 | 2549 | /** |
3621a710 | 2550 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2551 | * @phba: Pointer to HBA context object. |
2552 | * @pring: Pointer to driver SLI ring object. | |
2553 | * @prspiocb: Pointer to response iocb object. | |
2554 | * | |
2555 | * This function looks up the iocb_lookup table to get the command iocb | |
2556 | * corresponding to the given response iocb using the iotag of the | |
2557 | * response iocb. This function is called with the hbalock held. | |
2558 | * This function returns the command iocb object if it finds the command | |
2559 | * iocb else returns NULL. | |
2560 | **/ | |
dea3101e | 2561 | static struct lpfc_iocbq * |
2e0fef85 JS |
2562 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2563 | struct lpfc_sli_ring *pring, | |
2564 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2565 | { |
dea3101e JB |
2566 | struct lpfc_iocbq *cmd_iocb = NULL; |
2567 | uint16_t iotag; | |
2568 | ||
604a3e30 JB |
2569 | iotag = prspiocb->iocb.ulpIoTag; |
2570 | ||
2571 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2572 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2573 | list_del_init(&cmd_iocb->list); |
4f2e66c6 | 2574 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
2a9bf3d0 | 2575 | pring->txcmplq_cnt--; |
4f2e66c6 | 2576 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
2a9bf3d0 | 2577 | } |
604a3e30 | 2578 | return cmd_iocb; |
dea3101e JB |
2579 | } |
2580 | ||
dea3101e | 2581 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2582 | "0317 iotag x%x is out off " |
604a3e30 | 2583 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2584 | iotag, phba->sli.last_iotag, |
604a3e30 | 2585 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
2586 | return NULL; |
2587 | } | |
2588 | ||
3772a991 JS |
2589 | /** |
2590 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2591 | * @phba: Pointer to HBA context object. | |
2592 | * @pring: Pointer to driver SLI ring object. | |
2593 | * @iotag: IOCB tag. | |
2594 | * | |
2595 | * This function looks up the iocb_lookup table to get the command iocb | |
2596 | * corresponding to the given iotag. This function is called with the | |
2597 | * hbalock held. | |
2598 | * This function returns the command iocb object if it finds the command | |
2599 | * iocb else returns NULL. | |
2600 | **/ | |
2601 | static struct lpfc_iocbq * | |
2602 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2603 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2604 | { | |
2605 | struct lpfc_iocbq *cmd_iocb; | |
2606 | ||
2607 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2608 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
4f2e66c6 JS |
2609 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_TXCMPLQ) { |
2610 | /* remove from txcmpl queue list */ | |
2611 | list_del_init(&cmd_iocb->list); | |
2612 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; | |
2a9bf3d0 | 2613 | pring->txcmplq_cnt--; |
4f2e66c6 | 2614 | return cmd_iocb; |
2a9bf3d0 | 2615 | } |
3772a991 | 2616 | } |
3772a991 JS |
2617 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
2618 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2619 | iotag, phba->sli.last_iotag); | |
2620 | return NULL; | |
2621 | } | |
2622 | ||
e59058c4 | 2623 | /** |
3621a710 | 2624 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2625 | * @phba: Pointer to HBA context object. |
2626 | * @pring: Pointer to driver SLI ring object. | |
2627 | * @saveq: Pointer to the response iocb to be processed. | |
2628 | * | |
2629 | * This function is called by the ring event handler for non-fcp | |
2630 | * rings when there is a new response iocb in the response ring. | |
2631 | * The caller is not required to hold any locks. This function | |
2632 | * gets the command iocb associated with the response iocb and | |
2633 | * calls the completion handler for the command iocb. If there | |
2634 | * is no completion handler, the function will free the resources | |
2635 | * associated with command iocb. If the response iocb is for | |
2636 | * an already aborted command iocb, the status of the completion | |
2637 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2638 | * This function always returns 1. | |
2639 | **/ | |
dea3101e | 2640 | static int |
2e0fef85 | 2641 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
2642 | struct lpfc_iocbq *saveq) |
2643 | { | |
2e0fef85 | 2644 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
2645 | int rc = 1; |
2646 | unsigned long iflag; | |
2647 | ||
2648 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2649 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2650 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2651 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2652 | ||
dea3101e JB |
2653 | if (cmdiocbp) { |
2654 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2655 | /* |
2656 | * If an ELS command failed send an event to mgmt | |
2657 | * application. | |
2658 | */ | |
2659 | if (saveq->iocb.ulpStatus && | |
2660 | (pring->ringno == LPFC_ELS_RING) && | |
2661 | (cmdiocbp->iocb.ulpCommand == | |
2662 | CMD_ELS_REQUEST64_CR)) | |
2663 | lpfc_send_els_failure_event(phba, | |
2664 | cmdiocbp, saveq); | |
2665 | ||
dea3101e JB |
2666 | /* |
2667 | * Post all ELS completions to the worker thread. | |
2668 | * All other are passed to the completion callback. | |
2669 | */ | |
2670 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2671 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2672 | (cmdiocbp->iocb_flag & | |
2673 | LPFC_DRIVER_ABORTED)) { | |
2674 | spin_lock_irqsave(&phba->hbalock, | |
2675 | iflag); | |
07951076 JS |
2676 | cmdiocbp->iocb_flag &= |
2677 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2678 | spin_unlock_irqrestore(&phba->hbalock, |
2679 | iflag); | |
07951076 JS |
2680 | saveq->iocb.ulpStatus = |
2681 | IOSTAT_LOCAL_REJECT; | |
2682 | saveq->iocb.un.ulpWord[4] = | |
2683 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2684 | |
2685 | /* Firmware could still be in progress | |
2686 | * of DMAing payload, so don't free data | |
2687 | * buffer till after a hbeat. | |
2688 | */ | |
341af102 JS |
2689 | spin_lock_irqsave(&phba->hbalock, |
2690 | iflag); | |
0ff10d46 | 2691 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2692 | spin_unlock_irqrestore(&phba->hbalock, |
2693 | iflag); | |
2694 | } | |
0f65ff68 JS |
2695 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2696 | if (saveq->iocb_flag & | |
2697 | LPFC_EXCHANGE_BUSY) { | |
2698 | /* Set cmdiocb flag for the | |
2699 | * exchange busy so sgl (xri) | |
2700 | * will not be released until | |
2701 | * the abort xri is received | |
2702 | * from hba. | |
2703 | */ | |
2704 | spin_lock_irqsave( | |
2705 | &phba->hbalock, iflag); | |
2706 | cmdiocbp->iocb_flag |= | |
2707 | LPFC_EXCHANGE_BUSY; | |
2708 | spin_unlock_irqrestore( | |
2709 | &phba->hbalock, iflag); | |
2710 | } | |
2711 | if (cmdiocbp->iocb_flag & | |
2712 | LPFC_DRIVER_ABORTED) { | |
2713 | /* | |
2714 | * Clear LPFC_DRIVER_ABORTED | |
2715 | * bit in case it was driver | |
2716 | * initiated abort. | |
2717 | */ | |
2718 | spin_lock_irqsave( | |
2719 | &phba->hbalock, iflag); | |
2720 | cmdiocbp->iocb_flag &= | |
2721 | ~LPFC_DRIVER_ABORTED; | |
2722 | spin_unlock_irqrestore( | |
2723 | &phba->hbalock, iflag); | |
2724 | cmdiocbp->iocb.ulpStatus = | |
2725 | IOSTAT_LOCAL_REJECT; | |
2726 | cmdiocbp->iocb.un.ulpWord[4] = | |
2727 | IOERR_ABORT_REQUESTED; | |
2728 | /* | |
2729 | * For SLI4, irsiocb contains | |
2730 | * NO_XRI in sli_xritag, it | |
2731 | * shall not affect releasing | |
2732 | * sgl (xri) process. | |
2733 | */ | |
2734 | saveq->iocb.ulpStatus = | |
2735 | IOSTAT_LOCAL_REJECT; | |
2736 | saveq->iocb.un.ulpWord[4] = | |
2737 | IOERR_SLI_ABORTED; | |
2738 | spin_lock_irqsave( | |
2739 | &phba->hbalock, iflag); | |
2740 | saveq->iocb_flag |= | |
2741 | LPFC_DELAY_MEM_FREE; | |
2742 | spin_unlock_irqrestore( | |
2743 | &phba->hbalock, iflag); | |
2744 | } | |
07951076 | 2745 | } |
dea3101e | 2746 | } |
2e0fef85 | 2747 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2748 | } else |
2749 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
2750 | } else { |
2751 | /* | |
2752 | * Unknown initiating command based on the response iotag. | |
2753 | * This could be the case on the ELS ring because of | |
2754 | * lpfc_els_abort(). | |
2755 | */ | |
2756 | if (pring->ringno != LPFC_ELS_RING) { | |
2757 | /* | |
2758 | * Ring <ringno> handler: unexpected completion IoTag | |
2759 | * <IoTag> | |
2760 | */ | |
a257bf90 | 2761 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2762 | "0322 Ring %d handler: " |
2763 | "unexpected completion IoTag x%x " | |
2764 | "Data: x%x x%x x%x x%x\n", | |
2765 | pring->ringno, | |
2766 | saveq->iocb.ulpIoTag, | |
2767 | saveq->iocb.ulpStatus, | |
2768 | saveq->iocb.un.ulpWord[4], | |
2769 | saveq->iocb.ulpCommand, | |
2770 | saveq->iocb.ulpContext); | |
dea3101e JB |
2771 | } |
2772 | } | |
68876920 | 2773 | |
dea3101e JB |
2774 | return rc; |
2775 | } | |
2776 | ||
e59058c4 | 2777 | /** |
3621a710 | 2778 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2779 | * @phba: Pointer to HBA context object. |
2780 | * @pring: Pointer to driver SLI ring object. | |
2781 | * | |
2782 | * This function is called from the iocb ring event handlers when | |
2783 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2784 | * an error attention condition to the worker thread and the worker | |
2785 | * thread will transition the HBA to offline state. | |
2786 | **/ | |
2e0fef85 JS |
2787 | static void |
2788 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2789 | { |
34b02dcd | 2790 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2791 | /* |
025dfdaf | 2792 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2793 | * rsp ring <portRspMax> |
2794 | */ | |
2795 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2796 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2797 | "is bigger than rsp ring %d\n", |
e8b62011 | 2798 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
7e56aa25 | 2799 | pring->sli.sli3.numRiocb); |
875fbdfe | 2800 | |
2e0fef85 | 2801 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2802 | |
2803 | /* | |
2804 | * All error attention handlers are posted to | |
2805 | * worker thread | |
2806 | */ | |
2807 | phba->work_ha |= HA_ERATT; | |
2808 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2809 | |
5e9d9b82 | 2810 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2811 | |
2812 | return; | |
2813 | } | |
2814 | ||
9399627f | 2815 | /** |
3621a710 | 2816 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2817 | * @ptr: Pointer to address of HBA context object. |
2818 | * | |
2819 | * This function is invoked by the Error Attention polling timer when the | |
2820 | * timer times out. It will check the SLI Error Attention register for | |
2821 | * possible attention events. If so, it will post an Error Attention event | |
2822 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2823 | * Error Attention polling timer for the next poll. | |
2824 | **/ | |
2825 | void lpfc_poll_eratt(unsigned long ptr) | |
2826 | { | |
2827 | struct lpfc_hba *phba; | |
aa6fbb75 JS |
2828 | uint32_t eratt = 0, rem; |
2829 | uint64_t sli_intr, cnt; | |
9399627f JS |
2830 | |
2831 | phba = (struct lpfc_hba *)ptr; | |
2832 | ||
aa6fbb75 JS |
2833 | /* Here we will also keep track of interrupts per sec of the hba */ |
2834 | sli_intr = phba->sli.slistat.sli_intr; | |
2835 | ||
2836 | if (phba->sli.slistat.sli_prev_intr > sli_intr) | |
2837 | cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) + | |
2838 | sli_intr); | |
2839 | else | |
2840 | cnt = (sli_intr - phba->sli.slistat.sli_prev_intr); | |
2841 | ||
2842 | /* 64-bit integer division not supporte on 32-bit x86 - use do_div */ | |
2843 | rem = do_div(cnt, LPFC_ERATT_POLL_INTERVAL); | |
2844 | phba->sli.slistat.sli_ips = cnt; | |
2845 | ||
2846 | phba->sli.slistat.sli_prev_intr = sli_intr; | |
2847 | ||
9399627f JS |
2848 | /* Check chip HA register for error event */ |
2849 | eratt = lpfc_sli_check_eratt(phba); | |
2850 | ||
2851 | if (eratt) | |
2852 | /* Tell the worker thread there is work to do */ | |
2853 | lpfc_worker_wake_up(phba); | |
2854 | else | |
2855 | /* Restart the timer for next eratt poll */ | |
2856 | mod_timer(&phba->eratt_poll, jiffies + | |
2857 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2858 | return; | |
2859 | } | |
2860 | ||
875fbdfe | 2861 | |
e59058c4 | 2862 | /** |
3621a710 | 2863 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2864 | * @phba: Pointer to HBA context object. |
2865 | * @pring: Pointer to driver SLI ring object. | |
2866 | * @mask: Host attention register mask for this ring. | |
2867 | * | |
2868 | * This function is called from the interrupt context when there is a ring | |
2869 | * event for the fcp ring. The caller does not hold any lock. | |
2870 | * The function processes each response iocb in the response ring until it | |
25985edc | 2871 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2872 | * LE bit set. The function will call the completion handler of the command iocb |
2873 | * if the response iocb indicates a completion for a command iocb or it is | |
2874 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2875 | * function if this is an unsolicited iocb. | |
dea3101e | 2876 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2877 | * to check it explicitly. |
2878 | */ | |
2879 | int | |
2e0fef85 JS |
2880 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2881 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2882 | { |
34b02dcd | 2883 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2884 | IOCB_t *irsp = NULL; |
87f6eaff | 2885 | IOCB_t *entry = NULL; |
dea3101e JB |
2886 | struct lpfc_iocbq *cmdiocbq = NULL; |
2887 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
2888 | uint32_t status; |
2889 | uint32_t portRspPut, portRspMax; | |
2890 | int rc = 1; | |
2891 | lpfc_iocb_type type; | |
2892 | unsigned long iflag; | |
2893 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2894 | |
2e0fef85 | 2895 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2896 | pring->stats.iocb_event++; |
2897 | ||
dea3101e JB |
2898 | /* |
2899 | * The next available response entry should never exceed the maximum | |
2900 | * entries. If it does, treat it as an adapter hardware error. | |
2901 | */ | |
7e56aa25 | 2902 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e JB |
2903 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
2904 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2905 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2906 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2907 | return 1; |
2908 | } | |
45ed1190 JS |
2909 | if (phba->fcp_ring_in_use) { |
2910 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2911 | return 1; | |
2912 | } else | |
2913 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
2914 | |
2915 | rmb(); | |
7e56aa25 | 2916 | while (pring->sli.sli3.rspidx != portRspPut) { |
87f6eaff JSEC |
2917 | /* |
2918 | * Fetch an entry off the ring and copy it into a local data | |
2919 | * structure. The copy involves a byte-swap since the | |
2920 | * network byte order and pci byte orders are different. | |
2921 | */ | |
ed957684 | 2922 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2923 | phba->last_completion_time = jiffies; |
875fbdfe | 2924 | |
7e56aa25 JS |
2925 | if (++pring->sli.sli3.rspidx >= portRspMax) |
2926 | pring->sli.sli3.rspidx = 0; | |
875fbdfe | 2927 | |
87f6eaff JSEC |
2928 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2929 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2930 | phba->iocb_rsp_size); |
a4bc3379 | 2931 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2932 | irsp = &rspiocbq.iocb; |
2933 | ||
dea3101e JB |
2934 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2935 | pring->stats.iocb_rsp++; | |
2936 | rsp_cmpl++; | |
2937 | ||
2938 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2939 | /* |
2940 | * If resource errors reported from HBA, reduce | |
2941 | * queuedepths of the SCSI device. | |
2942 | */ | |
2943 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2944 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2945 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2946 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2947 | spin_lock_irqsave(&phba->hbalock, iflag); |
2948 | } | |
2949 | ||
dea3101e JB |
2950 | /* Rsp ring <ringno> error: IOCB */ |
2951 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2952 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2953 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2954 | pring->ringno, |
92d7f7b0 JS |
2955 | irsp->un.ulpWord[0], |
2956 | irsp->un.ulpWord[1], | |
2957 | irsp->un.ulpWord[2], | |
2958 | irsp->un.ulpWord[3], | |
2959 | irsp->un.ulpWord[4], | |
2960 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2961 | *(uint32_t *)&irsp->un1, |
2962 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
2963 | } |
2964 | ||
2965 | switch (type) { | |
2966 | case LPFC_ABORT_IOCB: | |
2967 | case LPFC_SOL_IOCB: | |
2968 | /* | |
2969 | * Idle exchange closed via ABTS from port. No iocb | |
2970 | * resources need to be recovered. | |
2971 | */ | |
2972 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2974 | "0333 IOCB cmd 0x%x" |
dca9479b | 2975 | " processed. Skipping" |
92d7f7b0 | 2976 | " completion\n", |
dca9479b | 2977 | irsp->ulpCommand); |
dea3101e JB |
2978 | break; |
2979 | } | |
2980 | ||
604a3e30 JB |
2981 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2982 | &rspiocbq); | |
0f65ff68 JS |
2983 | if (unlikely(!cmdiocbq)) |
2984 | break; | |
2985 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2986 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2987 | if (cmdiocbq->iocb_cmpl) { | |
2988 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2989 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2990 | &rspiocbq); | |
2991 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2992 | } | |
dea3101e | 2993 | break; |
a4bc3379 | 2994 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2995 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2996 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2997 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2998 | break; |
dea3101e JB |
2999 | default: |
3000 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3001 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3002 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3003 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
3004 | MAX_MSG_DATA); | |
898eb71c JP |
3005 | dev_warn(&((phba->pcidev)->dev), |
3006 | "lpfc%d: %s\n", | |
dea3101e JB |
3007 | phba->brd_no, adaptermsg); |
3008 | } else { | |
3009 | /* Unknown IOCB command */ | |
3010 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 3011 | "0334 Unknown IOCB command " |
92d7f7b0 | 3012 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 3013 | type, irsp->ulpCommand, |
92d7f7b0 JS |
3014 | irsp->ulpStatus, |
3015 | irsp->ulpIoTag, | |
3016 | irsp->ulpContext); | |
dea3101e JB |
3017 | } |
3018 | break; | |
3019 | } | |
3020 | ||
3021 | /* | |
3022 | * The response IOCB has been processed. Update the ring | |
3023 | * pointer in SLIM. If the port response put pointer has not | |
3024 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
3025 | * response put pointer. | |
3026 | */ | |
7e56aa25 JS |
3027 | writel(pring->sli.sli3.rspidx, |
3028 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3029 | |
7e56aa25 | 3030 | if (pring->sli.sli3.rspidx == portRspPut) |
dea3101e JB |
3031 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3032 | } | |
3033 | ||
3034 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
3035 | pring->stats.iocb_rsp_full++; | |
3036 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3037 | writel(status, phba->CAregaddr); | |
3038 | readl(phba->CAregaddr); | |
3039 | } | |
3040 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3041 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3042 | pring->stats.iocb_cmd_empty++; | |
3043 | ||
3044 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3045 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e JB |
3046 | lpfc_sli_resume_iocb(phba, pring); |
3047 | ||
3048 | if ((pring->lpfc_sli_cmd_available)) | |
3049 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3050 | ||
3051 | } | |
3052 | ||
45ed1190 | 3053 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3054 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3055 | return rc; |
3056 | } | |
3057 | ||
e59058c4 | 3058 | /** |
3772a991 JS |
3059 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3060 | * @phba: Pointer to HBA context object. | |
3061 | * @pring: Pointer to driver SLI ring object. | |
3062 | * @rspiocbp: Pointer to driver response IOCB object. | |
3063 | * | |
3064 | * This function is called from the worker thread when there is a slow-path | |
3065 | * response IOCB to process. This function chains all the response iocbs until | |
3066 | * seeing the iocb with the LE bit set. The function will call | |
3067 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3068 | * completion of a command iocb. The function will call the | |
3069 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3070 | * The function frees the resources or calls the completion handler if this | |
3071 | * iocb is an abort completion. The function returns NULL when the response | |
3072 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3073 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3074 | * response iocb passed in. | |
3075 | **/ | |
3076 | static struct lpfc_iocbq * | |
3077 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3078 | struct lpfc_iocbq *rspiocbp) | |
3079 | { | |
3080 | struct lpfc_iocbq *saveq; | |
3081 | struct lpfc_iocbq *cmdiocbp; | |
3082 | struct lpfc_iocbq *next_iocb; | |
3083 | IOCB_t *irsp = NULL; | |
3084 | uint32_t free_saveq; | |
3085 | uint8_t iocb_cmd_type; | |
3086 | lpfc_iocb_type type; | |
3087 | unsigned long iflag; | |
3088 | int rc; | |
3089 | ||
3090 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3091 | /* First add the response iocb to the countinueq list */ | |
3092 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3093 | pring->iocb_continueq_cnt++; | |
3094 | ||
70f23fd6 | 3095 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3096 | irsp = &rspiocbp->iocb; |
3097 | if (irsp->ulpLe) { | |
3098 | /* | |
3099 | * By default, the driver expects to free all resources | |
3100 | * associated with this iocb completion. | |
3101 | */ | |
3102 | free_saveq = 1; | |
3103 | saveq = list_get_first(&pring->iocb_continueq, | |
3104 | struct lpfc_iocbq, list); | |
3105 | irsp = &(saveq->iocb); | |
3106 | list_del_init(&pring->iocb_continueq); | |
3107 | pring->iocb_continueq_cnt = 0; | |
3108 | ||
3109 | pring->stats.iocb_rsp++; | |
3110 | ||
3111 | /* | |
3112 | * If resource errors reported from HBA, reduce | |
3113 | * queuedepths of the SCSI device. | |
3114 | */ | |
3115 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3116 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3117 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3118 | phba->lpfc_rampdown_queue_depth(phba); | |
3119 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3120 | } | |
3121 | ||
3122 | if (irsp->ulpStatus) { | |
3123 | /* Rsp ring <ringno> error: IOCB */ | |
3124 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3125 | "0328 Rsp Ring %d error: " | |
3126 | "IOCB Data: " | |
3127 | "x%x x%x x%x x%x " | |
3128 | "x%x x%x x%x x%x " | |
3129 | "x%x x%x x%x x%x " | |
3130 | "x%x x%x x%x x%x\n", | |
3131 | pring->ringno, | |
3132 | irsp->un.ulpWord[0], | |
3133 | irsp->un.ulpWord[1], | |
3134 | irsp->un.ulpWord[2], | |
3135 | irsp->un.ulpWord[3], | |
3136 | irsp->un.ulpWord[4], | |
3137 | irsp->un.ulpWord[5], | |
3138 | *(((uint32_t *) irsp) + 6), | |
3139 | *(((uint32_t *) irsp) + 7), | |
3140 | *(((uint32_t *) irsp) + 8), | |
3141 | *(((uint32_t *) irsp) + 9), | |
3142 | *(((uint32_t *) irsp) + 10), | |
3143 | *(((uint32_t *) irsp) + 11), | |
3144 | *(((uint32_t *) irsp) + 12), | |
3145 | *(((uint32_t *) irsp) + 13), | |
3146 | *(((uint32_t *) irsp) + 14), | |
3147 | *(((uint32_t *) irsp) + 15)); | |
3148 | } | |
3149 | ||
3150 | /* | |
3151 | * Fetch the IOCB command type and call the correct completion | |
3152 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3153 | * get freed back to the lpfc_iocb_list by the discovery | |
3154 | * kernel thread. | |
3155 | */ | |
3156 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3157 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3158 | switch (type) { | |
3159 | case LPFC_SOL_IOCB: | |
3160 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3161 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3162 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3163 | break; | |
3164 | ||
3165 | case LPFC_UNSOL_IOCB: | |
3166 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3167 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3168 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3169 | if (!rc) | |
3170 | free_saveq = 0; | |
3171 | break; | |
3172 | ||
3173 | case LPFC_ABORT_IOCB: | |
3174 | cmdiocbp = NULL; | |
3175 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3176 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3177 | saveq); | |
3178 | if (cmdiocbp) { | |
3179 | /* Call the specified completion routine */ | |
3180 | if (cmdiocbp->iocb_cmpl) { | |
3181 | spin_unlock_irqrestore(&phba->hbalock, | |
3182 | iflag); | |
3183 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3184 | saveq); | |
3185 | spin_lock_irqsave(&phba->hbalock, | |
3186 | iflag); | |
3187 | } else | |
3188 | __lpfc_sli_release_iocbq(phba, | |
3189 | cmdiocbp); | |
3190 | } | |
3191 | break; | |
3192 | ||
3193 | case LPFC_UNKNOWN_IOCB: | |
3194 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3195 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3196 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3197 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3198 | MAX_MSG_DATA); | |
3199 | dev_warn(&((phba->pcidev)->dev), | |
3200 | "lpfc%d: %s\n", | |
3201 | phba->brd_no, adaptermsg); | |
3202 | } else { | |
3203 | /* Unknown IOCB command */ | |
3204 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3205 | "0335 Unknown IOCB " | |
3206 | "command Data: x%x " | |
3207 | "x%x x%x x%x\n", | |
3208 | irsp->ulpCommand, | |
3209 | irsp->ulpStatus, | |
3210 | irsp->ulpIoTag, | |
3211 | irsp->ulpContext); | |
3212 | } | |
3213 | break; | |
3214 | } | |
3215 | ||
3216 | if (free_saveq) { | |
3217 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3218 | &saveq->list, list) { | |
3219 | list_del(&rspiocbp->list); | |
3220 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3221 | } | |
3222 | __lpfc_sli_release_iocbq(phba, saveq); | |
3223 | } | |
3224 | rspiocbp = NULL; | |
3225 | } | |
3226 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3227 | return rspiocbp; | |
3228 | } | |
3229 | ||
3230 | /** | |
3231 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3232 | * @phba: Pointer to HBA context object. |
3233 | * @pring: Pointer to driver SLI ring object. | |
3234 | * @mask: Host attention register mask for this ring. | |
3235 | * | |
3772a991 JS |
3236 | * This routine wraps the actual slow_ring event process routine from the |
3237 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3238 | **/ |
3772a991 | 3239 | void |
2e0fef85 JS |
3240 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3241 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3242 | { |
3243 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3244 | } | |
3245 | ||
3246 | /** | |
3247 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3248 | * @phba: Pointer to HBA context object. | |
3249 | * @pring: Pointer to driver SLI ring object. | |
3250 | * @mask: Host attention register mask for this ring. | |
3251 | * | |
3252 | * This function is called from the worker thread when there is a ring event | |
3253 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3254 | * remove each response iocb in the response ring and calls the handle | |
3255 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3256 | **/ | |
3257 | static void | |
3258 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3259 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3260 | { |
34b02dcd | 3261 | struct lpfc_pgp *pgp; |
dea3101e JB |
3262 | IOCB_t *entry; |
3263 | IOCB_t *irsp = NULL; | |
3264 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3265 | uint32_t portRspPut, portRspMax; |
dea3101e | 3266 | unsigned long iflag; |
3772a991 | 3267 | uint32_t status; |
dea3101e | 3268 | |
34b02dcd | 3269 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3270 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3271 | pring->stats.iocb_event++; |
3272 | ||
dea3101e JB |
3273 | /* |
3274 | * The next available response entry should never exceed the maximum | |
3275 | * entries. If it does, treat it as an adapter hardware error. | |
3276 | */ | |
7e56aa25 | 3277 | portRspMax = pring->sli.sli3.numRiocb; |
dea3101e JB |
3278 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3279 | if (portRspPut >= portRspMax) { | |
3280 | /* | |
025dfdaf | 3281 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
3282 | * rsp ring <portRspMax> |
3283 | */ | |
ed957684 | 3284 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3285 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3286 | "is bigger than rsp ring %d\n", |
e8b62011 | 3287 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3288 | |
2e0fef85 JS |
3289 | phba->link_state = LPFC_HBA_ERROR; |
3290 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
3291 | |
3292 | phba->work_hs = HS_FFER3; | |
3293 | lpfc_handle_eratt(phba); | |
3294 | ||
3772a991 | 3295 | return; |
dea3101e JB |
3296 | } |
3297 | ||
3298 | rmb(); | |
7e56aa25 | 3299 | while (pring->sli.sli3.rspidx != portRspPut) { |
dea3101e JB |
3300 | /* |
3301 | * Build a completion list and call the appropriate handler. | |
3302 | * The process is to get the next available response iocb, get | |
3303 | * a free iocb from the list, copy the response data into the | |
3304 | * free iocb, insert to the continuation list, and update the | |
3305 | * next response index to slim. This process makes response | |
3306 | * iocb's in the ring available to DMA as fast as possible but | |
3307 | * pays a penalty for a copy operation. Since the iocb is | |
3308 | * only 32 bytes, this penalty is considered small relative to | |
3309 | * the PCI reads for register values and a slim write. When | |
3310 | * the ulpLe field is set, the entire Command has been | |
3311 | * received. | |
3312 | */ | |
ed957684 JS |
3313 | entry = lpfc_resp_iocb(phba, pring); |
3314 | ||
858c9f6c | 3315 | phba->last_completion_time = jiffies; |
2e0fef85 | 3316 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
3317 | if (rspiocbp == NULL) { |
3318 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3319 | "completion.\n", __func__); |
dea3101e JB |
3320 | break; |
3321 | } | |
3322 | ||
ed957684 JS |
3323 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3324 | phba->iocb_rsp_size); | |
dea3101e JB |
3325 | irsp = &rspiocbp->iocb; |
3326 | ||
7e56aa25 JS |
3327 | if (++pring->sli.sli3.rspidx >= portRspMax) |
3328 | pring->sli.sli3.rspidx = 0; | |
dea3101e | 3329 | |
a58cbd52 JS |
3330 | if (pring->ringno == LPFC_ELS_RING) { |
3331 | lpfc_debugfs_slow_ring_trc(phba, | |
3332 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3333 | *(((uint32_t *) irsp) + 4), | |
3334 | *(((uint32_t *) irsp) + 6), | |
3335 | *(((uint32_t *) irsp) + 7)); | |
3336 | } | |
3337 | ||
7e56aa25 JS |
3338 | writel(pring->sli.sli3.rspidx, |
3339 | &phba->host_gp[pring->ringno].rspGetInx); | |
dea3101e | 3340 | |
3772a991 JS |
3341 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3342 | /* Handle the response IOCB */ | |
3343 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3344 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
3345 | |
3346 | /* | |
3347 | * If the port response put pointer has not been updated, sync | |
3348 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3349 | * response put pointer. | |
3350 | */ | |
7e56aa25 | 3351 | if (pring->sli.sli3.rspidx == portRspPut) { |
dea3101e JB |
3352 | portRspPut = le32_to_cpu(pgp->rspPutInx); |
3353 | } | |
7e56aa25 | 3354 | } /* while (pring->sli.sli3.rspidx != portRspPut) */ |
dea3101e | 3355 | |
92d7f7b0 | 3356 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
3357 | /* At least one response entry has been freed */ |
3358 | pring->stats.iocb_rsp_full++; | |
3359 | /* SET RxRE_RSP in Chip Att register */ | |
3360 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3361 | writel(status, phba->CAregaddr); | |
3362 | readl(phba->CAregaddr); /* flush */ | |
3363 | } | |
3364 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3365 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3366 | pring->stats.iocb_cmd_empty++; | |
3367 | ||
3368 | /* Force update of the local copy of cmdGetInx */ | |
7e56aa25 | 3369 | pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx); |
dea3101e JB |
3370 | lpfc_sli_resume_iocb(phba, pring); |
3371 | ||
3372 | if ((pring->lpfc_sli_cmd_available)) | |
3373 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3374 | ||
3375 | } | |
3376 | ||
2e0fef85 | 3377 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3378 | return; |
dea3101e JB |
3379 | } |
3380 | ||
4f774513 JS |
3381 | /** |
3382 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3383 | * @phba: Pointer to HBA context object. | |
3384 | * @pring: Pointer to driver SLI ring object. | |
3385 | * @mask: Host attention register mask for this ring. | |
3386 | * | |
3387 | * This function is called from the worker thread when there is a pending | |
3388 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3389 | * queue. The caller does not hold any lock. The function will remove each | |
3390 | * response iocb from the response worker queue and calls the handle | |
3391 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3392 | **/ | |
3393 | static void | |
3394 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3395 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3396 | { | |
3397 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3398 | struct hbq_dmabuf *dmabuf; |
3399 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3400 | unsigned long iflag; |
3401 | ||
45ed1190 JS |
3402 | spin_lock_irqsave(&phba->hbalock, iflag); |
3403 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3404 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3405 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3406 | /* Get the response iocb from the head of work queue */ |
3407 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3408 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3409 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3410 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3411 | |
3412 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3413 | case CQE_CODE_COMPL_WQE: | |
3414 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3415 | cq_event); | |
45ed1190 JS |
3416 | /* Translate ELS WCQE to response IOCBQ */ |
3417 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3418 | irspiocbq); | |
3419 | if (irspiocbq) | |
3420 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3421 | irspiocbq); | |
4d9ab994 JS |
3422 | break; |
3423 | case CQE_CODE_RECEIVE: | |
7851fe2c | 3424 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 JS |
3425 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
3426 | cq_event); | |
3427 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3428 | break; | |
3429 | default: | |
3430 | break; | |
3431 | } | |
4f774513 JS |
3432 | } |
3433 | } | |
3434 | ||
e59058c4 | 3435 | /** |
3621a710 | 3436 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3437 | * @phba: Pointer to HBA context object. |
3438 | * @pring: Pointer to driver SLI ring object. | |
3439 | * | |
3440 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3441 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3442 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3443 | * the return of this function. The caller is not required to hold any locks. | |
3444 | **/ | |
2e0fef85 | 3445 | void |
dea3101e JB |
3446 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3447 | { | |
2534ba75 | 3448 | LIST_HEAD(completions); |
dea3101e | 3449 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3450 | |
92d7f7b0 JS |
3451 | if (pring->ringno == LPFC_ELS_RING) { |
3452 | lpfc_fabric_abort_hba(phba); | |
3453 | } | |
3454 | ||
dea3101e JB |
3455 | /* Error everything on txq and txcmplq |
3456 | * First do the txq. | |
3457 | */ | |
2e0fef85 | 3458 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3459 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3460 | pring->txq_cnt = 0; |
dea3101e JB |
3461 | |
3462 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3463 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3464 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3465 | |
2e0fef85 | 3466 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3467 | |
a257bf90 JS |
3468 | /* Cancel all the IOCBs from the completions list */ |
3469 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3470 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3471 | } |
3472 | ||
a8e497d5 | 3473 | /** |
3621a710 | 3474 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3475 | * @phba: Pointer to HBA context object. |
3476 | * | |
3477 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3478 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3479 | * for all the iocb commands in txcmplq, they will just be returned with | |
3480 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3481 | * slot has been permanently disabled. | |
3482 | **/ | |
3483 | void | |
3484 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3485 | { | |
3486 | LIST_HEAD(txq); | |
3487 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3488 | struct lpfc_sli *psli = &phba->sli; |
3489 | struct lpfc_sli_ring *pring; | |
3490 | ||
3491 | /* Currently, only one fcp ring */ | |
3492 | pring = &psli->ring[psli->fcp_ring]; | |
3493 | ||
3494 | spin_lock_irq(&phba->hbalock); | |
3495 | /* Retrieve everything on txq */ | |
3496 | list_splice_init(&pring->txq, &txq); | |
3497 | pring->txq_cnt = 0; | |
3498 | ||
3499 | /* Retrieve everything on the txcmplq */ | |
3500 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3501 | pring->txcmplq_cnt = 0; | |
4f2e66c6 JS |
3502 | |
3503 | /* Indicate the I/O queues are flushed */ | |
3504 | phba->hba_flag |= HBA_FCP_IOQ_FLUSH; | |
a8e497d5 JS |
3505 | spin_unlock_irq(&phba->hbalock); |
3506 | ||
3507 | /* Flush the txq */ | |
a257bf90 JS |
3508 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3509 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3510 | |
3511 | /* Flush the txcmpq */ | |
a257bf90 JS |
3512 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3513 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3514 | } |
3515 | ||
e59058c4 | 3516 | /** |
3772a991 | 3517 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3518 | * @phba: Pointer to HBA context object. |
3519 | * @mask: Bit mask to be checked. | |
3520 | * | |
3521 | * This function reads the host status register and compares | |
3522 | * with the provided bit mask to check if HBA completed | |
3523 | * the restart. This function will wait in a loop for the | |
3524 | * HBA to complete restart. If the HBA does not restart within | |
3525 | * 15 iterations, the function will reset the HBA again. The | |
3526 | * function returns 1 when HBA fail to restart otherwise returns | |
3527 | * zero. | |
3528 | **/ | |
3772a991 JS |
3529 | static int |
3530 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3531 | { |
41415862 JW |
3532 | uint32_t status; |
3533 | int i = 0; | |
3534 | int retval = 0; | |
dea3101e | 3535 | |
41415862 | 3536 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3537 | if (lpfc_readl(phba->HSregaddr, &status)) |
3538 | return 1; | |
dea3101e | 3539 | |
41415862 JW |
3540 | /* |
3541 | * Check status register every 100ms for 5 retries, then every | |
3542 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3543 | * every 2.5 sec for 4. | |
3544 | * Break our of the loop if errors occurred during init. | |
3545 | */ | |
3546 | while (((status & mask) != mask) && | |
3547 | !(status & HS_FFERM) && | |
3548 | i++ < 20) { | |
dea3101e | 3549 | |
41415862 JW |
3550 | if (i <= 5) |
3551 | msleep(10); | |
3552 | else if (i <= 10) | |
3553 | msleep(500); | |
3554 | else | |
3555 | msleep(2500); | |
dea3101e | 3556 | |
41415862 | 3557 | if (i == 15) { |
2e0fef85 | 3558 | /* Do post */ |
92d7f7b0 | 3559 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3560 | lpfc_sli_brdrestart(phba); |
3561 | } | |
3562 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3563 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3564 | retval = 1; | |
3565 | break; | |
3566 | } | |
41415862 | 3567 | } |
dea3101e | 3568 | |
41415862 JW |
3569 | /* Check to see if any errors occurred during init */ |
3570 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3571 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3572 | "2751 Adapter failed to restart, " | |
3573 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3574 | status, | |
3575 | readl(phba->MBslimaddr + 0xa8), | |
3576 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3577 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3578 | retval = 1; |
dea3101e | 3579 | } |
dea3101e | 3580 | |
41415862 JW |
3581 | return retval; |
3582 | } | |
dea3101e | 3583 | |
da0436e9 JS |
3584 | /** |
3585 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3586 | * @phba: Pointer to HBA context object. | |
3587 | * @mask: Bit mask to be checked. | |
3588 | * | |
3589 | * This function checks the host status register to check if HBA is | |
3590 | * ready. This function will wait in a loop for the HBA to be ready | |
3591 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3592 | * function again. The function returns 1 when HBA fail to be ready | |
3593 | * otherwise returns zero. | |
3594 | **/ | |
3595 | static int | |
3596 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3597 | { | |
3598 | uint32_t status; | |
3599 | int retval = 0; | |
3600 | ||
3601 | /* Read the HBA Host Status Register */ | |
3602 | status = lpfc_sli4_post_status_check(phba); | |
3603 | ||
3604 | if (status) { | |
3605 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3606 | lpfc_sli_brdrestart(phba); | |
3607 | status = lpfc_sli4_post_status_check(phba); | |
3608 | } | |
3609 | ||
3610 | /* Check to see if any errors occurred during init */ | |
3611 | if (status) { | |
3612 | phba->link_state = LPFC_HBA_ERROR; | |
3613 | retval = 1; | |
3614 | } else | |
3615 | phba->sli4_hba.intr_enable = 0; | |
3616 | ||
3617 | return retval; | |
3618 | } | |
3619 | ||
3620 | /** | |
3621 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3622 | * @phba: Pointer to HBA context object. | |
3623 | * @mask: Bit mask to be checked. | |
3624 | * | |
3625 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3626 | * from the API jump table function pointer from the lpfc_hba struct. | |
3627 | **/ | |
3628 | int | |
3629 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3630 | { | |
3631 | return phba->lpfc_sli_brdready(phba, mask); | |
3632 | } | |
3633 | ||
9290831f JS |
3634 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3635 | ||
e59058c4 | 3636 | /** |
3621a710 | 3637 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3638 | * @phba: Pointer to HBA context object. |
3639 | * | |
1b51197d JS |
3640 | * This function is called before resetting an HBA. This function is called |
3641 | * with hbalock held and requests HBA to quiesce DMAs before a reset. | |
e59058c4 | 3642 | **/ |
2e0fef85 | 3643 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3644 | { |
65a29c16 JS |
3645 | uint32_t __iomem *resp_buf; |
3646 | uint32_t __iomem *mbox_buf; | |
9290831f | 3647 | volatile uint32_t mbox; |
9940b97b | 3648 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3649 | int i; |
3650 | uint8_t hdrtype; | |
3651 | ||
3652 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3653 | if (hdrtype != 0x80 || | |
3654 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3655 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3656 | return; | |
3657 | ||
3658 | /* | |
3659 | * Tell the other part of the chip to suspend temporarily all | |
3660 | * its DMA activity. | |
3661 | */ | |
65a29c16 | 3662 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3663 | |
3664 | /* Disable the error attention */ | |
9940b97b JS |
3665 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3666 | return; | |
9290831f JS |
3667 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3668 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3669 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3670 | |
9940b97b JS |
3671 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3672 | return; | |
3673 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3674 | /* Clear Chip error bit */ |
3675 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3676 | phba->pport->stopped = 1; |
9290831f JS |
3677 | } |
3678 | ||
3679 | mbox = 0; | |
3680 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3681 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3682 | ||
3683 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3684 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3685 | writel(mbox, mbox_buf); |
3686 | ||
9940b97b JS |
3687 | for (i = 0; i < 50; i++) { |
3688 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3689 | return; | |
3690 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3691 | mdelay(1); | |
3692 | else | |
3693 | break; | |
3694 | } | |
3695 | resp_data = 0; | |
3696 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3697 | return; | |
3698 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3699 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3700 | phba->pport->stopped) |
9290831f JS |
3701 | goto restore_hc; |
3702 | else | |
3703 | goto clear_errat; | |
3704 | } | |
3705 | ||
3706 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3707 | resp_data = 0; |
3708 | for (i = 0; i < 500; i++) { | |
3709 | if (lpfc_readl(resp_buf, &resp_data)) | |
3710 | return; | |
3711 | if (resp_data != mbox) | |
3712 | mdelay(1); | |
3713 | else | |
3714 | break; | |
3715 | } | |
9290831f JS |
3716 | |
3717 | clear_errat: | |
3718 | ||
9940b97b JS |
3719 | while (++i < 500) { |
3720 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3721 | return; | |
3722 | if (!(ha_copy & HA_ERATT)) | |
3723 | mdelay(1); | |
3724 | else | |
3725 | break; | |
3726 | } | |
9290831f JS |
3727 | |
3728 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3729 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3730 | phba->pport->stopped = 1; |
9290831f JS |
3731 | } |
3732 | ||
3733 | restore_hc: | |
2e0fef85 | 3734 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3735 | writel(hc_copy, phba->HCregaddr); |
3736 | readl(phba->HCregaddr); /* flush */ | |
3737 | } | |
3738 | ||
e59058c4 | 3739 | /** |
3621a710 | 3740 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3741 | * @phba: Pointer to HBA context object. |
3742 | * | |
3743 | * This function issues a kill_board mailbox command and waits for | |
3744 | * the error attention interrupt. This function is called for stopping | |
3745 | * the firmware processing. The caller is not required to hold any | |
3746 | * locks. This function calls lpfc_hba_down_post function to free | |
3747 | * any pending commands after the kill. The function will return 1 when it | |
3748 | * fails to kill the board else will return 0. | |
3749 | **/ | |
41415862 | 3750 | int |
2e0fef85 | 3751 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3752 | { |
3753 | struct lpfc_sli *psli; | |
3754 | LPFC_MBOXQ_t *pmb; | |
3755 | uint32_t status; | |
3756 | uint32_t ha_copy; | |
3757 | int retval; | |
3758 | int i = 0; | |
dea3101e | 3759 | |
41415862 | 3760 | psli = &phba->sli; |
dea3101e | 3761 | |
41415862 | 3762 | /* Kill HBA */ |
ed957684 | 3763 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3764 | "0329 Kill HBA Data: x%x x%x\n", |
3765 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3766 | |
98c9ea5c JS |
3767 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3768 | if (!pmb) | |
41415862 | 3769 | return 1; |
41415862 JW |
3770 | |
3771 | /* Disable the error attention */ | |
2e0fef85 | 3772 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3773 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3774 | spin_unlock_irq(&phba->hbalock); | |
3775 | mempool_free(pmb, phba->mbox_mem_pool); | |
3776 | return 1; | |
3777 | } | |
41415862 JW |
3778 | status &= ~HC_ERINT_ENA; |
3779 | writel(status, phba->HCregaddr); | |
3780 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3781 | phba->link_flag |= LS_IGNORE_ERATT; |
3782 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3783 | |
3784 | lpfc_kill_board(phba, pmb); | |
3785 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3786 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3787 | ||
3788 | if (retval != MBX_SUCCESS) { | |
3789 | if (retval != MBX_BUSY) | |
3790 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3791 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3792 | "2752 KILL_BOARD command failed retval %d\n", | |
3793 | retval); | |
2e0fef85 JS |
3794 | spin_lock_irq(&phba->hbalock); |
3795 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3796 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3797 | return 1; |
3798 | } | |
3799 | ||
f4b4c68f JS |
3800 | spin_lock_irq(&phba->hbalock); |
3801 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3802 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3803 | |
41415862 JW |
3804 | mempool_free(pmb, phba->mbox_mem_pool); |
3805 | ||
3806 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3807 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3808 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3809 | * board is now undefined. | |
3810 | */ | |
9940b97b JS |
3811 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3812 | return 1; | |
41415862 JW |
3813 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3814 | mdelay(100); | |
9940b97b JS |
3815 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3816 | return 1; | |
41415862 JW |
3817 | } |
3818 | ||
3819 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3820 | if (ha_copy & HA_ERATT) { |
3821 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3822 | phba->pport->stopped = 1; |
9290831f | 3823 | } |
2e0fef85 | 3824 | spin_lock_irq(&phba->hbalock); |
41415862 | 3825 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3826 | psli->mbox_active = NULL; |
2e0fef85 JS |
3827 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3828 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3829 | |
41415862 | 3830 | lpfc_hba_down_post(phba); |
2e0fef85 | 3831 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3832 | |
2e0fef85 | 3833 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
3834 | } |
3835 | ||
e59058c4 | 3836 | /** |
3772a991 | 3837 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3838 | * @phba: Pointer to HBA context object. |
3839 | * | |
3840 | * This function resets the HBA by writing HC_INITFF to the control | |
3841 | * register. After the HBA resets, this function resets all the iocb ring | |
3842 | * indices. This function disables PCI layer parity checking during | |
3843 | * the reset. | |
3844 | * This function returns 0 always. | |
3845 | * The caller is not required to hold any locks. | |
3846 | **/ | |
41415862 | 3847 | int |
2e0fef85 | 3848 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3849 | { |
41415862 | 3850 | struct lpfc_sli *psli; |
dea3101e | 3851 | struct lpfc_sli_ring *pring; |
41415862 | 3852 | uint16_t cfg_value; |
dea3101e | 3853 | int i; |
dea3101e | 3854 | |
41415862 | 3855 | psli = &phba->sli; |
dea3101e | 3856 | |
41415862 JW |
3857 | /* Reset HBA */ |
3858 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3859 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3860 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
3861 | |
3862 | /* perform board reset */ | |
3863 | phba->fc_eventTag = 0; | |
4d9ab994 | 3864 | phba->link_events = 0; |
2e0fef85 JS |
3865 | phba->pport->fc_myDID = 0; |
3866 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3867 | |
41415862 JW |
3868 | /* Turn off parity checking and serr during the physical reset */ |
3869 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3870 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3871 | (cfg_value & | |
3872 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3873 | ||
3772a991 JS |
3874 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3875 | ||
41415862 JW |
3876 | /* Now toggle INITFF bit in the Host Control Register */ |
3877 | writel(HC_INITFF, phba->HCregaddr); | |
3878 | mdelay(1); | |
3879 | readl(phba->HCregaddr); /* flush */ | |
3880 | writel(0, phba->HCregaddr); | |
3881 | readl(phba->HCregaddr); /* flush */ | |
3882 | ||
3883 | /* Restore PCI cmd register */ | |
3884 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
3885 | |
3886 | /* Initialize relevant SLI info */ | |
41415862 JW |
3887 | for (i = 0; i < psli->num_rings; i++) { |
3888 | pring = &psli->ring[i]; | |
dea3101e | 3889 | pring->flag = 0; |
7e56aa25 JS |
3890 | pring->sli.sli3.rspidx = 0; |
3891 | pring->sli.sli3.next_cmdidx = 0; | |
3892 | pring->sli.sli3.local_getidx = 0; | |
3893 | pring->sli.sli3.cmdidx = 0; | |
dea3101e JB |
3894 | pring->missbufcnt = 0; |
3895 | } | |
dea3101e | 3896 | |
2e0fef85 | 3897 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3898 | return 0; |
3899 | } | |
3900 | ||
e59058c4 | 3901 | /** |
da0436e9 JS |
3902 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3903 | * @phba: Pointer to HBA context object. | |
3904 | * | |
3905 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3906 | * checking during resets the device. The caller is not required to hold | |
3907 | * any locks. | |
3908 | * | |
3909 | * This function returns 0 always. | |
3910 | **/ | |
3911 | int | |
3912 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3913 | { | |
3914 | struct lpfc_sli *psli = &phba->sli; | |
3915 | uint16_t cfg_value; | |
27b01b82 | 3916 | int rc; |
da0436e9 JS |
3917 | |
3918 | /* Reset HBA */ | |
3919 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3920 | "0295 Reset HBA Data: x%x x%x\n", | |
3921 | phba->pport->port_state, psli->sli_flag); | |
3922 | ||
3923 | /* perform board reset */ | |
3924 | phba->fc_eventTag = 0; | |
4d9ab994 | 3925 | phba->link_events = 0; |
da0436e9 JS |
3926 | phba->pport->fc_myDID = 0; |
3927 | phba->pport->fc_prevDID = 0; | |
3928 | ||
da0436e9 JS |
3929 | spin_lock_irq(&phba->hbalock); |
3930 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3931 | phba->fcf.fcf_flag = 0; | |
da0436e9 JS |
3932 | spin_unlock_irq(&phba->hbalock); |
3933 | ||
3934 | /* Now physically reset the device */ | |
3935 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3936 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
3937 | |
3938 | /* Turn off parity checking and serr during the physical reset */ | |
3939 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3940 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
3941 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3942 | ||
da0436e9 | 3943 | /* Perform FCoE PCI function reset */ |
2e90f4b5 | 3944 | lpfc_sli4_queue_destroy(phba); |
27b01b82 | 3945 | rc = lpfc_pci_function_reset(phba); |
da0436e9 | 3946 | |
be858b65 JS |
3947 | /* Restore PCI cmd register */ |
3948 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
3949 | ||
27b01b82 | 3950 | return rc; |
da0436e9 JS |
3951 | } |
3952 | ||
3953 | /** | |
3954 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3955 | * @phba: Pointer to HBA context object. |
3956 | * | |
3957 | * This function is called in the SLI initialization code path to | |
3958 | * restart the HBA. The caller is not required to hold any lock. | |
3959 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3960 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3961 | * function to free any pending commands. The function enables | |
3962 | * POST only during the first initialization. The function returns zero. | |
3963 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3964 | * command before the return of this function. | |
3965 | **/ | |
da0436e9 JS |
3966 | static int |
3967 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3968 | { |
3969 | MAILBOX_t *mb; | |
3970 | struct lpfc_sli *psli; | |
41415862 JW |
3971 | volatile uint32_t word0; |
3972 | void __iomem *to_slim; | |
0d878419 | 3973 | uint32_t hba_aer_enabled; |
41415862 | 3974 | |
2e0fef85 | 3975 | spin_lock_irq(&phba->hbalock); |
41415862 | 3976 | |
0d878419 JS |
3977 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3978 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3979 | ||
41415862 JW |
3980 | psli = &phba->sli; |
3981 | ||
3982 | /* Restart HBA */ | |
3983 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3984 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3985 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3986 | |
3987 | word0 = 0; | |
3988 | mb = (MAILBOX_t *) &word0; | |
3989 | mb->mbxCommand = MBX_RESTART; | |
3990 | mb->mbxHc = 1; | |
3991 | ||
9290831f JS |
3992 | lpfc_reset_barrier(phba); |
3993 | ||
41415862 JW |
3994 | to_slim = phba->MBslimaddr; |
3995 | writel(*(uint32_t *) mb, to_slim); | |
3996 | readl(to_slim); /* flush */ | |
3997 | ||
3998 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3999 | if (phba->pport->port_state) |
41415862 | 4000 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 4001 | else |
41415862 | 4002 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 4003 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
4004 | writel(*(uint32_t *) mb, to_slim); |
4005 | readl(to_slim); /* flush */ | |
dea3101e | 4006 | |
41415862 | 4007 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
4008 | phba->pport->stopped = 0; |
4009 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 4010 | phba->hba_flag = 0; |
2e0fef85 | 4011 | spin_unlock_irq(&phba->hbalock); |
41415862 | 4012 | |
64ba8818 JS |
4013 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
4014 | psli->stats_start = get_seconds(); | |
4015 | ||
eaf15d5b JS |
4016 | /* Give the INITFF and Post time to settle. */ |
4017 | mdelay(100); | |
41415862 | 4018 | |
0d878419 JS |
4019 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4020 | if (hba_aer_enabled) | |
4021 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4022 | ||
41415862 | 4023 | lpfc_hba_down_post(phba); |
dea3101e JB |
4024 | |
4025 | return 0; | |
4026 | } | |
4027 | ||
da0436e9 JS |
4028 | /** |
4029 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
4030 | * @phba: Pointer to HBA context object. | |
4031 | * | |
4032 | * This function is called in the SLI initialization code path to restart | |
4033 | * a SLI4 HBA. The caller is not required to hold any lock. | |
4034 | * At the end of the function, it calls lpfc_hba_down_post function to | |
4035 | * free any pending commands. | |
4036 | **/ | |
4037 | static int | |
4038 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
4039 | { | |
4040 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 4041 | uint32_t hba_aer_enabled; |
27b01b82 | 4042 | int rc; |
da0436e9 JS |
4043 | |
4044 | /* Restart HBA */ | |
4045 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4046 | "0296 Restart HBA Data: x%x x%x\n", | |
4047 | phba->pport->port_state, psli->sli_flag); | |
4048 | ||
75baf696 JS |
4049 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4050 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4051 | ||
27b01b82 | 4052 | rc = lpfc_sli4_brdreset(phba); |
da0436e9 JS |
4053 | |
4054 | spin_lock_irq(&phba->hbalock); | |
4055 | phba->pport->stopped = 0; | |
4056 | phba->link_state = LPFC_INIT_START; | |
4057 | phba->hba_flag = 0; | |
4058 | spin_unlock_irq(&phba->hbalock); | |
4059 | ||
4060 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4061 | psli->stats_start = get_seconds(); | |
4062 | ||
75baf696 JS |
4063 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4064 | if (hba_aer_enabled) | |
4065 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4066 | ||
da0436e9 JS |
4067 | lpfc_hba_down_post(phba); |
4068 | ||
27b01b82 | 4069 | return rc; |
da0436e9 JS |
4070 | } |
4071 | ||
4072 | /** | |
4073 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4074 | * @phba: Pointer to HBA context object. | |
4075 | * | |
4076 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4077 | * API jump table function pointer from the lpfc_hba struct. | |
4078 | **/ | |
4079 | int | |
4080 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4081 | { | |
4082 | return phba->lpfc_sli_brdrestart(phba); | |
4083 | } | |
4084 | ||
e59058c4 | 4085 | /** |
3621a710 | 4086 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4087 | * @phba: Pointer to HBA context object. |
4088 | * | |
4089 | * This function is called after a HBA restart to wait for successful | |
4090 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4091 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4092 | * iteration, the function will restart the HBA again. The function returns | |
4093 | * zero if HBA successfully restarted else returns negative error code. | |
4094 | **/ | |
dea3101e JB |
4095 | static int |
4096 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4097 | { | |
4098 | uint32_t status, i = 0; | |
4099 | ||
4100 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4101 | if (lpfc_readl(phba->HSregaddr, &status)) |
4102 | return -EIO; | |
dea3101e JB |
4103 | |
4104 | /* Check status register to see what current state is */ | |
4105 | i = 0; | |
4106 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4107 | ||
dcf2a4e0 JS |
4108 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4109 | * retries, then every 1 sec for 50 retires for a total of | |
4110 | * ~60 seconds before reset the board again and check every | |
4111 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4112 | * board ready is required by the Falcon FIPS zeroization | |
4113 | * complete, and any reset the board in between shall cause | |
4114 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4115 | */ |
dcf2a4e0 | 4116 | if (i++ >= 200) { |
dea3101e JB |
4117 | /* Adapter failed to init, timeout, status reg |
4118 | <status> */ | |
ed957684 | 4119 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4120 | "0436 Adapter failed to init, " |
09372820 JS |
4121 | "timeout, status reg x%x, " |
4122 | "FW Data: A8 x%x AC x%x\n", status, | |
4123 | readl(phba->MBslimaddr + 0xa8), | |
4124 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4125 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4126 | return -ETIMEDOUT; |
4127 | } | |
4128 | ||
4129 | /* Check to see if any errors occurred during init */ | |
4130 | if (status & HS_FFERM) { | |
4131 | /* ERROR: During chipset initialization */ | |
4132 | /* Adapter failed to init, chipset, status reg | |
4133 | <status> */ | |
ed957684 | 4134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4135 | "0437 Adapter failed to init, " |
09372820 JS |
4136 | "chipset, status reg x%x, " |
4137 | "FW Data: A8 x%x AC x%x\n", status, | |
4138 | readl(phba->MBslimaddr + 0xa8), | |
4139 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4140 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4141 | return -EIO; |
4142 | } | |
4143 | ||
dcf2a4e0 | 4144 | if (i <= 10) |
dea3101e | 4145 | msleep(10); |
dcf2a4e0 JS |
4146 | else if (i <= 100) |
4147 | msleep(100); | |
4148 | else | |
4149 | msleep(1000); | |
dea3101e | 4150 | |
dcf2a4e0 JS |
4151 | if (i == 150) { |
4152 | /* Do post */ | |
92d7f7b0 | 4153 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4154 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4155 | } |
4156 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4157 | if (lpfc_readl(phba->HSregaddr, &status)) |
4158 | return -EIO; | |
dea3101e JB |
4159 | } |
4160 | ||
4161 | /* Check to see if any errors occurred during init */ | |
4162 | if (status & HS_FFERM) { | |
4163 | /* ERROR: During chipset initialization */ | |
4164 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4165 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4166 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4167 | "status reg x%x, " |
4168 | "FW Data: A8 x%x AC x%x\n", status, | |
4169 | readl(phba->MBslimaddr + 0xa8), | |
4170 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4171 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4172 | return -EIO; |
4173 | } | |
4174 | ||
4175 | /* Clear all interrupt enable conditions */ | |
4176 | writel(0, phba->HCregaddr); | |
4177 | readl(phba->HCregaddr); /* flush */ | |
4178 | ||
4179 | /* setup host attn register */ | |
4180 | writel(0xffffffff, phba->HAregaddr); | |
4181 | readl(phba->HAregaddr); /* flush */ | |
4182 | return 0; | |
4183 | } | |
4184 | ||
e59058c4 | 4185 | /** |
3621a710 | 4186 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4187 | * |
4188 | * This function calculates and returns the number of HBQs required to be | |
4189 | * configured. | |
4190 | **/ | |
78b2d852 | 4191 | int |
ed957684 JS |
4192 | lpfc_sli_hbq_count(void) |
4193 | { | |
92d7f7b0 | 4194 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4195 | } |
4196 | ||
e59058c4 | 4197 | /** |
3621a710 | 4198 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4199 | * |
4200 | * This function adds the number of hbq entries in every HBQ to get | |
4201 | * the total number of hbq entries required for the HBA and returns | |
4202 | * the total count. | |
4203 | **/ | |
ed957684 JS |
4204 | static int |
4205 | lpfc_sli_hbq_entry_count(void) | |
4206 | { | |
4207 | int hbq_count = lpfc_sli_hbq_count(); | |
4208 | int count = 0; | |
4209 | int i; | |
4210 | ||
4211 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4212 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4213 | return count; |
4214 | } | |
4215 | ||
e59058c4 | 4216 | /** |
3621a710 | 4217 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4218 | * |
4219 | * This function calculates amount of memory required for all hbq entries | |
4220 | * to be configured and returns the total memory required. | |
4221 | **/ | |
dea3101e | 4222 | int |
ed957684 JS |
4223 | lpfc_sli_hbq_size(void) |
4224 | { | |
4225 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4226 | } | |
4227 | ||
e59058c4 | 4228 | /** |
3621a710 | 4229 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4230 | * @phba: Pointer to HBA context object. |
4231 | * | |
4232 | * This function is called during the SLI initialization to configure | |
4233 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4234 | * required to hold any locks. This function will return zero if successful | |
4235 | * else it will return negative error code. | |
4236 | **/ | |
ed957684 JS |
4237 | static int |
4238 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4239 | { | |
4240 | int hbq_count = lpfc_sli_hbq_count(); | |
4241 | LPFC_MBOXQ_t *pmb; | |
4242 | MAILBOX_t *pmbox; | |
4243 | uint32_t hbqno; | |
4244 | uint32_t hbq_entry_index; | |
ed957684 | 4245 | |
92d7f7b0 JS |
4246 | /* Get a Mailbox buffer to setup mailbox |
4247 | * commands for HBA initialization | |
4248 | */ | |
ed957684 JS |
4249 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4250 | ||
4251 | if (!pmb) | |
4252 | return -ENOMEM; | |
4253 | ||
04c68496 | 4254 | pmbox = &pmb->u.mb; |
ed957684 JS |
4255 | |
4256 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4257 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4258 | phba->hbq_in_use = 1; |
ed957684 JS |
4259 | |
4260 | hbq_entry_index = 0; | |
4261 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4262 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4263 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4264 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4265 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4266 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4267 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4268 | hbq_entry_index, pmb); | |
ed957684 JS |
4269 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4270 | ||
4271 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4272 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4273 | mbxStatus <status>, ring <num> */ | |
4274 | ||
4275 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4276 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4277 | "1805 Adapter failed to init. " |
ed957684 | 4278 | "Data: x%x x%x x%x\n", |
e8b62011 | 4279 | pmbox->mbxCommand, |
ed957684 JS |
4280 | pmbox->mbxStatus, hbqno); |
4281 | ||
4282 | phba->link_state = LPFC_HBA_ERROR; | |
4283 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4284 | return -ENXIO; |
ed957684 JS |
4285 | } |
4286 | } | |
4287 | phba->hbq_count = hbq_count; | |
4288 | ||
ed957684 JS |
4289 | mempool_free(pmb, phba->mbox_mem_pool); |
4290 | ||
92d7f7b0 | 4291 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4292 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4293 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4294 | return 0; |
4295 | } | |
4296 | ||
4f774513 JS |
4297 | /** |
4298 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4299 | * @phba: Pointer to HBA context object. | |
4300 | * | |
4301 | * This function is called during the SLI initialization to configure | |
4302 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4303 | * required to hold any locks. This function will return zero if successful | |
4304 | * else it will return negative error code. | |
4305 | **/ | |
4306 | static int | |
4307 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4308 | { | |
4309 | phba->hbq_in_use = 1; | |
4310 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4311 | phba->hbq_count = 1; | |
4312 | /* Initially populate or replenish the HBQs */ | |
4313 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4314 | return 0; | |
4315 | } | |
4316 | ||
e59058c4 | 4317 | /** |
3621a710 | 4318 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4319 | * @phba: Pointer to HBA context object. |
4320 | * @sli_mode: sli mode - 2/3 | |
4321 | * | |
4322 | * This function is called by the sli intialization code path | |
4323 | * to issue config_port mailbox command. This function restarts the | |
4324 | * HBA firmware and issues a config_port mailbox command to configure | |
4325 | * the SLI interface in the sli mode specified by sli_mode | |
4326 | * variable. The caller is not required to hold any locks. | |
4327 | * The function returns 0 if successful, else returns negative error | |
4328 | * code. | |
4329 | **/ | |
9399627f JS |
4330 | int |
4331 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
4332 | { |
4333 | LPFC_MBOXQ_t *pmb; | |
4334 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4335 | ||
4336 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4337 | if (!pmb) { | |
2e0fef85 | 4338 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4339 | return -ENOMEM; |
4340 | } | |
4341 | ||
ed957684 | 4342 | phba->sli_rev = sli_mode; |
dea3101e | 4343 | while (resetcount < 2 && !done) { |
2e0fef85 | 4344 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4345 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4346 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4347 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4348 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4349 | rc = lpfc_sli_chipset_init(phba); |
4350 | if (rc) | |
4351 | break; | |
4352 | ||
2e0fef85 | 4353 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4354 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4355 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4356 | resetcount++; |
4357 | ||
ed957684 JS |
4358 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4359 | * value of 0 means the call was successful. Any other | |
4360 | * nonzero value is a failure, but if ERESTART is returned, | |
4361 | * the driver may reset the HBA and try again. | |
4362 | */ | |
dea3101e JB |
4363 | rc = lpfc_config_port_prep(phba); |
4364 | if (rc == -ERESTART) { | |
ed957684 | 4365 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4366 | continue; |
34b02dcd | 4367 | } else if (rc) |
dea3101e | 4368 | break; |
6d368e53 | 4369 | |
2e0fef85 | 4370 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
4371 | lpfc_config_port(phba, pmb); |
4372 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4373 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4374 | LPFC_SLI3_HBQ_ENABLED | | |
4375 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4376 | LPFC_SLI3_BG_ENABLED | |
4377 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4378 | if (rc != MBX_SUCCESS) { |
dea3101e | 4379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4380 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4381 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4382 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4383 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4384 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4385 | spin_unlock_irq(&phba->hbalock); |
4386 | rc = -ENXIO; | |
04c68496 JS |
4387 | } else { |
4388 | /* Allow asynchronous mailbox command to go through */ | |
4389 | spin_lock_irq(&phba->hbalock); | |
4390 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4391 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4392 | done = 1; |
cb69f7de JS |
4393 | |
4394 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && | |
4395 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) | |
4396 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4397 | "3110 Port did not grant ASABT\n"); | |
04c68496 | 4398 | } |
dea3101e | 4399 | } |
ed957684 JS |
4400 | if (!done) { |
4401 | rc = -EINVAL; | |
4402 | goto do_prep_failed; | |
4403 | } | |
04c68496 JS |
4404 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4405 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4406 | rc = -ENXIO; |
4407 | goto do_prep_failed; | |
4408 | } | |
04c68496 | 4409 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4410 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4411 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4412 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4413 | phba->max_vpi : phba->max_vports; | |
4414 | ||
34b02dcd JS |
4415 | } else |
4416 | phba->max_vpi = 0; | |
bc73905a JS |
4417 | phba->fips_level = 0; |
4418 | phba->fips_spec_rev = 0; | |
4419 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4420 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4421 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4422 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4423 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4424 | "2850 Security Crypto Active. FIPS x%d " | |
4425 | "(Spec Rev: x%d)", | |
4426 | phba->fips_level, phba->fips_spec_rev); | |
4427 | } | |
4428 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4430 | "2856 Config Port Security Crypto " | |
4431 | "Error: x%x ", | |
4432 | pmb->u.mb.un.varCfgPort.sec_err); | |
4433 | } | |
04c68496 | 4434 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4435 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4436 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4437 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4438 | |
4439 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4440 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4441 | |
4442 | if (phba->cfg_enable_bg) { | |
04c68496 | 4443 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4444 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4445 | else | |
4446 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4447 | "0443 Adapter did not grant " | |
4448 | "BlockGuard\n"); | |
4449 | } | |
34b02dcd | 4450 | } else { |
8f34f4ce | 4451 | phba->hbq_get = NULL; |
34b02dcd | 4452 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4453 | phba->max_vpi = 0; |
ed957684 | 4454 | } |
92d7f7b0 | 4455 | do_prep_failed: |
ed957684 JS |
4456 | mempool_free(pmb, phba->mbox_mem_pool); |
4457 | return rc; | |
4458 | } | |
4459 | ||
e59058c4 JS |
4460 | |
4461 | /** | |
3621a710 | 4462 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4463 | * @phba: Pointer to HBA context object. |
4464 | * | |
4465 | * This function is the main SLI intialization function. This function | |
4466 | * is called by the HBA intialization code, HBA reset code and HBA | |
4467 | * error attention handler code. Caller is not required to hold any | |
4468 | * locks. This function issues config_port mailbox command to configure | |
4469 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4470 | * calls the config_port_post function to issue init_link mailbox | |
4471 | * command and to start the discovery. The function will return zero | |
4472 | * if successful, else it will return negative error code. | |
4473 | **/ | |
ed957684 JS |
4474 | int |
4475 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4476 | { | |
4477 | uint32_t rc; | |
6d368e53 JS |
4478 | int mode = 3, i; |
4479 | int longs; | |
ed957684 JS |
4480 | |
4481 | switch (lpfc_sli_mode) { | |
4482 | case 2: | |
78b2d852 | 4483 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4485 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4486 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4487 | lpfc_sli_mode); |
92d7f7b0 JS |
4488 | break; |
4489 | } | |
ed957684 JS |
4490 | mode = 2; |
4491 | break; | |
4492 | case 0: | |
4493 | case 3: | |
4494 | break; | |
4495 | default: | |
92d7f7b0 | 4496 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4497 | "1819 Unrecognized lpfc_sli_mode " |
4498 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4499 | |
4500 | break; | |
4501 | } | |
4502 | ||
9399627f JS |
4503 | rc = lpfc_sli_config_port(phba, mode); |
4504 | ||
ed957684 | 4505 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4507 | "1820 Unable to select SLI-3. " |
4508 | "Not supported by adapter.\n"); | |
ed957684 | 4509 | if (rc && mode != 2) |
9399627f | 4510 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4511 | if (rc) |
dea3101e JB |
4512 | goto lpfc_sli_hba_setup_error; |
4513 | ||
0d878419 JS |
4514 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4515 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4516 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4517 | if (!rc) { | |
4518 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4519 | "2709 This device supports " | |
4520 | "Advanced Error Reporting (AER)\n"); | |
4521 | spin_lock_irq(&phba->hbalock); | |
4522 | phba->hba_flag |= HBA_AER_ENABLED; | |
4523 | spin_unlock_irq(&phba->hbalock); | |
4524 | } else { | |
4525 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4526 | "2708 This device does not support " | |
4527 | "Advanced Error Reporting (AER)\n"); | |
4528 | phba->cfg_aer_support = 0; | |
4529 | } | |
4530 | } | |
4531 | ||
ed957684 JS |
4532 | if (phba->sli_rev == 3) { |
4533 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4534 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4535 | } else { |
4536 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4537 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4538 | phba->sli3_options = 0; |
ed957684 JS |
4539 | } |
4540 | ||
4541 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4542 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4543 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4544 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
4545 | |
4546 | if (rc) | |
4547 | goto lpfc_sli_hba_setup_error; | |
4548 | ||
6d368e53 JS |
4549 | /* Initialize VPIs. */ |
4550 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
4551 | /* | |
4552 | * The VPI bitmask and physical ID array are allocated | |
4553 | * and initialized once only - at driver load. A port | |
4554 | * reset doesn't need to reinitialize this memory. | |
4555 | */ | |
4556 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
4557 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
4558 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4559 | GFP_KERNEL); | |
4560 | if (!phba->vpi_bmask) { | |
4561 | rc = -ENOMEM; | |
4562 | goto lpfc_sli_hba_setup_error; | |
4563 | } | |
4564 | ||
4565 | phba->vpi_ids = kzalloc( | |
4566 | (phba->max_vpi+1) * sizeof(uint16_t), | |
4567 | GFP_KERNEL); | |
4568 | if (!phba->vpi_ids) { | |
4569 | kfree(phba->vpi_bmask); | |
4570 | rc = -ENOMEM; | |
4571 | goto lpfc_sli_hba_setup_error; | |
4572 | } | |
4573 | for (i = 0; i < phba->max_vpi; i++) | |
4574 | phba->vpi_ids[i] = i; | |
4575 | } | |
4576 | } | |
4577 | ||
9399627f | 4578 | /* Init HBQs */ |
ed957684 JS |
4579 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4580 | rc = lpfc_sli_hbq_setup(phba); | |
4581 | if (rc) | |
4582 | goto lpfc_sli_hba_setup_error; | |
4583 | } | |
04c68496 | 4584 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4585 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4586 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4587 | |
4588 | rc = lpfc_config_port_post(phba); | |
4589 | if (rc) | |
4590 | goto lpfc_sli_hba_setup_error; | |
4591 | ||
ed957684 JS |
4592 | return rc; |
4593 | ||
92d7f7b0 | 4594 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4595 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4596 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4597 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
4598 | return rc; |
4599 | } | |
4600 | ||
e59058c4 | 4601 | /** |
da0436e9 JS |
4602 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4603 | * @phba: Pointer to HBA context object. | |
4604 | * @mboxq: mailbox pointer. | |
4605 | * This function issue a dump mailbox command to read config region | |
4606 | * 23 and parse the records in the region and populate driver | |
4607 | * data structure. | |
e59058c4 | 4608 | **/ |
da0436e9 | 4609 | static int |
ff78d8f9 | 4610 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
dea3101e | 4611 | { |
ff78d8f9 | 4612 | LPFC_MBOXQ_t *mboxq; |
da0436e9 JS |
4613 | struct lpfc_dmabuf *mp; |
4614 | struct lpfc_mqe *mqe; | |
4615 | uint32_t data_length; | |
4616 | int rc; | |
dea3101e | 4617 | |
da0436e9 JS |
4618 | /* Program the default value of vlan_id and fc_map */ |
4619 | phba->valid_vlan = 0; | |
4620 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4621 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4622 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4623 | |
ff78d8f9 JS |
4624 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4625 | if (!mboxq) | |
da0436e9 JS |
4626 | return -ENOMEM; |
4627 | ||
ff78d8f9 JS |
4628 | mqe = &mboxq->u.mqe; |
4629 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { | |
4630 | rc = -ENOMEM; | |
4631 | goto out_free_mboxq; | |
4632 | } | |
4633 | ||
da0436e9 JS |
4634 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
4635 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4636 | ||
4637 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4638 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4639 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4640 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4641 | "CQ: x%x x%x x%x x%x\n", | |
4642 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4643 | bf_get(lpfc_mqe_command, mqe), | |
4644 | bf_get(lpfc_mqe_status, mqe), | |
4645 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4646 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4647 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4648 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4649 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4650 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4651 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4652 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4653 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4654 | mboxq->mcqe.word0, | |
4655 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4656 | mboxq->mcqe.trailer); | |
4657 | ||
4658 | if (rc) { | |
4659 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4660 | kfree(mp); | |
ff78d8f9 JS |
4661 | rc = -EIO; |
4662 | goto out_free_mboxq; | |
da0436e9 JS |
4663 | } |
4664 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4665 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4666 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4667 | kfree(mp); | |
ff78d8f9 JS |
4668 | rc = -EIO; |
4669 | goto out_free_mboxq; | |
d11e31dd | 4670 | } |
dea3101e | 4671 | |
da0436e9 JS |
4672 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4673 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4674 | kfree(mp); | |
ff78d8f9 JS |
4675 | rc = 0; |
4676 | ||
4677 | out_free_mboxq: | |
4678 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4679 | return rc; | |
da0436e9 | 4680 | } |
e59058c4 JS |
4681 | |
4682 | /** | |
da0436e9 JS |
4683 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4684 | * @phba: pointer to lpfc hba data structure. | |
4685 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4686 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4687 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4688 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4689 | * |
da0436e9 JS |
4690 | * This routine executes a READ_REV SLI4 mailbox command. In |
4691 | * addition, this routine gets the port vpd data. | |
4692 | * | |
4693 | * Return codes | |
af901ca1 | 4694 | * 0 - successful |
d439d286 | 4695 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4696 | **/ |
da0436e9 JS |
4697 | static int |
4698 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4699 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4700 | { |
da0436e9 JS |
4701 | int rc = 0; |
4702 | uint32_t dma_size; | |
4703 | struct lpfc_dmabuf *dmabuf; | |
4704 | struct lpfc_mqe *mqe; | |
dea3101e | 4705 | |
da0436e9 JS |
4706 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4707 | if (!dmabuf) | |
4708 | return -ENOMEM; | |
4709 | ||
4710 | /* | |
4711 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4712 | * mailbox command. | |
a257bf90 | 4713 | */ |
da0436e9 JS |
4714 | dma_size = *vpd_size; |
4715 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4716 | dma_size, | |
4717 | &dmabuf->phys, | |
4718 | GFP_KERNEL); | |
4719 | if (!dmabuf->virt) { | |
4720 | kfree(dmabuf); | |
4721 | return -ENOMEM; | |
a257bf90 | 4722 | } |
da0436e9 | 4723 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4724 | |
da0436e9 JS |
4725 | /* |
4726 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4727 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4728 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4729 | */ |
da0436e9 JS |
4730 | lpfc_read_rev(phba, mboxq); |
4731 | mqe = &mboxq->u.mqe; | |
4732 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4733 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4734 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4735 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4736 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4737 | ||
4738 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4739 | if (rc) { | |
4740 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4741 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4742 | kfree(dmabuf); |
da0436e9 JS |
4743 | return -EIO; |
4744 | } | |
1dcb58e5 | 4745 | |
da0436e9 JS |
4746 | /* |
4747 | * The available vpd length cannot be bigger than the | |
4748 | * DMA buffer passed to the port. Catch the less than | |
4749 | * case and update the caller's size. | |
4750 | */ | |
4751 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4752 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4753 | |
d7c47992 JS |
4754 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4755 | ||
da0436e9 JS |
4756 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4757 | dmabuf->virt, dmabuf->phys); | |
4758 | kfree(dmabuf); | |
4759 | return 0; | |
dea3101e JB |
4760 | } |
4761 | ||
cd1c8301 JS |
4762 | /** |
4763 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name | |
4764 | * @phba: pointer to lpfc hba data structure. | |
4765 | * | |
4766 | * This routine retrieves SLI4 device physical port name this PCI function | |
4767 | * is attached to. | |
4768 | * | |
4769 | * Return codes | |
4770 | * 0 - sucessful | |
4771 | * otherwise - failed to retrieve physical port name | |
4772 | **/ | |
4773 | static int | |
4774 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) | |
4775 | { | |
4776 | LPFC_MBOXQ_t *mboxq; | |
cd1c8301 JS |
4777 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
4778 | struct lpfc_controller_attribute *cntl_attr; | |
4779 | struct lpfc_mbx_get_port_name *get_port_name; | |
4780 | void *virtaddr = NULL; | |
4781 | uint32_t alloclen, reqlen; | |
4782 | uint32_t shdr_status, shdr_add_status; | |
4783 | union lpfc_sli4_cfg_shdr *shdr; | |
4784 | char cport_name = 0; | |
4785 | int rc; | |
4786 | ||
4787 | /* We assume nothing at this point */ | |
4788 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; | |
4789 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; | |
4790 | ||
4791 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4792 | if (!mboxq) | |
4793 | return -ENOMEM; | |
cd1c8301 | 4794 | /* obtain link type and link number via READ_CONFIG */ |
ff78d8f9 JS |
4795 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
4796 | lpfc_sli4_read_config(phba); | |
4797 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) | |
4798 | goto retrieve_ppname; | |
cd1c8301 JS |
4799 | |
4800 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ | |
4801 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); | |
4802 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4803 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, | |
4804 | LPFC_SLI4_MBX_NEMBED); | |
4805 | if (alloclen < reqlen) { | |
4806 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4807 | "3084 Allocated DMA memory size (%d) is " | |
4808 | "less than the requested DMA memory size " | |
4809 | "(%d)\n", alloclen, reqlen); | |
4810 | rc = -ENOMEM; | |
4811 | goto out_free_mboxq; | |
4812 | } | |
4813 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4814 | virtaddr = mboxq->sge_array->addr[0]; | |
4815 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; | |
4816 | shdr = &mbx_cntl_attr->cfg_shdr; | |
4817 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4818 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4819 | if (shdr_status || shdr_add_status || rc) { | |
4820 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4821 | "3085 Mailbox x%x (x%x/x%x) failed, " | |
4822 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4823 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4824 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4825 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4826 | rc, shdr_status, shdr_add_status); | |
4827 | rc = -ENXIO; | |
4828 | goto out_free_mboxq; | |
4829 | } | |
4830 | cntl_attr = &mbx_cntl_attr->cntl_attr; | |
4831 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
4832 | phba->sli4_hba.lnk_info.lnk_tp = | |
4833 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); | |
4834 | phba->sli4_hba.lnk_info.lnk_no = | |
4835 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); | |
4836 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4837 | "3086 lnk_type:%d, lnk_numb:%d\n", | |
4838 | phba->sli4_hba.lnk_info.lnk_tp, | |
4839 | phba->sli4_hba.lnk_info.lnk_no); | |
4840 | ||
4841 | retrieve_ppname: | |
4842 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4843 | LPFC_MBOX_OPCODE_GET_PORT_NAME, | |
4844 | sizeof(struct lpfc_mbx_get_port_name) - | |
4845 | sizeof(struct lpfc_sli4_cfg_mhdr), | |
4846 | LPFC_SLI4_MBX_EMBED); | |
4847 | get_port_name = &mboxq->u.mqe.un.get_port_name; | |
4848 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; | |
4849 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); | |
4850 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, | |
4851 | phba->sli4_hba.lnk_info.lnk_tp); | |
4852 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4853 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4854 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4855 | if (shdr_status || shdr_add_status || rc) { | |
4856 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4857 | "3087 Mailbox x%x (x%x/x%x) failed: " | |
4858 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4859 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4860 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4861 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4862 | rc, shdr_status, shdr_add_status); | |
4863 | rc = -ENXIO; | |
4864 | goto out_free_mboxq; | |
4865 | } | |
4866 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
4867 | case LPFC_LINK_NUMBER_0: | |
4868 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, | |
4869 | &get_port_name->u.response); | |
4870 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4871 | break; | |
4872 | case LPFC_LINK_NUMBER_1: | |
4873 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, | |
4874 | &get_port_name->u.response); | |
4875 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4876 | break; | |
4877 | case LPFC_LINK_NUMBER_2: | |
4878 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, | |
4879 | &get_port_name->u.response); | |
4880 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4881 | break; | |
4882 | case LPFC_LINK_NUMBER_3: | |
4883 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, | |
4884 | &get_port_name->u.response); | |
4885 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4886 | break; | |
4887 | default: | |
4888 | break; | |
4889 | } | |
4890 | ||
4891 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { | |
4892 | phba->Port[0] = cport_name; | |
4893 | phba->Port[1] = '\0'; | |
4894 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4895 | "3091 SLI get port name: %s\n", phba->Port); | |
4896 | } | |
4897 | ||
4898 | out_free_mboxq: | |
4899 | if (rc != MBX_TIMEOUT) { | |
4900 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) | |
4901 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
4902 | else | |
4903 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4904 | } | |
4905 | return rc; | |
4906 | } | |
4907 | ||
e59058c4 | 4908 | /** |
da0436e9 JS |
4909 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4910 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4911 | * |
da0436e9 JS |
4912 | * This routine is called to explicitly arm the SLI4 device's completion and |
4913 | * event queues | |
4914 | **/ | |
4915 | static void | |
4916 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4917 | { | |
4918 | uint8_t fcp_eqidx; | |
4919 | ||
4920 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4921 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
0558056c | 4922 | fcp_eqidx = 0; |
2e90f4b5 | 4923 | if (phba->sli4_hba.fcp_cq) { |
67d12733 | 4924 | do { |
2e90f4b5 JS |
4925 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
4926 | LPFC_QUEUE_REARM); | |
67d12733 | 4927 | } while (++fcp_eqidx < phba->cfg_fcp_io_channel); |
2e90f4b5 | 4928 | } |
67d12733 JS |
4929 | if (phba->sli4_hba.hba_eq) { |
4930 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; | |
2e90f4b5 | 4931 | fcp_eqidx++) |
67d12733 | 4932 | lpfc_sli4_eq_release(phba->sli4_hba.hba_eq[fcp_eqidx], |
2e90f4b5 JS |
4933 | LPFC_QUEUE_REARM); |
4934 | } | |
da0436e9 JS |
4935 | } |
4936 | ||
6d368e53 JS |
4937 | /** |
4938 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
4939 | * @phba: Pointer to HBA context object. | |
4940 | * @type: The resource extent type. | |
b76f2dc9 JS |
4941 | * @extnt_count: buffer to hold port available extent count. |
4942 | * @extnt_size: buffer to hold element count per extent. | |
6d368e53 | 4943 | * |
b76f2dc9 JS |
4944 | * This function calls the port and retrievs the number of available |
4945 | * extents and their size for a particular extent type. | |
4946 | * | |
4947 | * Returns: 0 if successful. Nonzero otherwise. | |
6d368e53 | 4948 | **/ |
b76f2dc9 | 4949 | int |
6d368e53 JS |
4950 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
4951 | uint16_t *extnt_count, uint16_t *extnt_size) | |
4952 | { | |
4953 | int rc = 0; | |
4954 | uint32_t length; | |
4955 | uint32_t mbox_tmo; | |
4956 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
4957 | LPFC_MBOXQ_t *mbox; | |
4958 | ||
4959 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4960 | if (!mbox) | |
4961 | return -ENOMEM; | |
4962 | ||
4963 | /* Find out how many extents are available for this resource type */ | |
4964 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
4965 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
4966 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4967 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
4968 | length, LPFC_SLI4_MBX_EMBED); | |
4969 | ||
4970 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
4971 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
4972 | LPFC_SLI4_MBX_EMBED); | |
4973 | if (unlikely(rc)) { | |
4974 | rc = -EIO; | |
4975 | goto err_exit; | |
4976 | } | |
4977 | ||
4978 | if (!phba->sli4_hba.intr_enable) | |
4979 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
4980 | else { | |
a183a15f | 4981 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
4982 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
4983 | } | |
4984 | if (unlikely(rc)) { | |
4985 | rc = -EIO; | |
4986 | goto err_exit; | |
4987 | } | |
4988 | ||
4989 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
4990 | if (bf_get(lpfc_mbox_hdr_status, | |
4991 | &rsrc_info->header.cfg_shdr.response)) { | |
4992 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
4993 | "2930 Failed to get resource extents " | |
4994 | "Status 0x%x Add'l Status 0x%x\n", | |
4995 | bf_get(lpfc_mbox_hdr_status, | |
4996 | &rsrc_info->header.cfg_shdr.response), | |
4997 | bf_get(lpfc_mbox_hdr_add_status, | |
4998 | &rsrc_info->header.cfg_shdr.response)); | |
4999 | rc = -EIO; | |
5000 | goto err_exit; | |
5001 | } | |
5002 | ||
5003 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
5004 | &rsrc_info->u.rsp); | |
5005 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
5006 | &rsrc_info->u.rsp); | |
8a9d2e80 JS |
5007 | |
5008 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5009 | "3162 Retrieved extents type-%d from port: count:%d, " | |
5010 | "size:%d\n", type, *extnt_count, *extnt_size); | |
5011 | ||
5012 | err_exit: | |
6d368e53 JS |
5013 | mempool_free(mbox, phba->mbox_mem_pool); |
5014 | return rc; | |
5015 | } | |
5016 | ||
5017 | /** | |
5018 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
5019 | * @phba: Pointer to HBA context object. | |
5020 | * @type: The extent type to check. | |
5021 | * | |
5022 | * This function reads the current available extents from the port and checks | |
5023 | * if the extent count or extent size has changed since the last access. | |
5024 | * Callers use this routine post port reset to understand if there is a | |
5025 | * extent reprovisioning requirement. | |
5026 | * | |
5027 | * Returns: | |
5028 | * -Error: error indicates problem. | |
5029 | * 1: Extent count or size has changed. | |
5030 | * 0: No changes. | |
5031 | **/ | |
5032 | static int | |
5033 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
5034 | { | |
5035 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
5036 | uint16_t size_diff, rsrc_ext_size; | |
5037 | int rc = 0; | |
5038 | struct lpfc_rsrc_blks *rsrc_entry; | |
5039 | struct list_head *rsrc_blk_list = NULL; | |
5040 | ||
5041 | size_diff = 0; | |
5042 | curr_ext_cnt = 0; | |
5043 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5044 | &rsrc_ext_cnt, | |
5045 | &rsrc_ext_size); | |
5046 | if (unlikely(rc)) | |
5047 | return -EIO; | |
5048 | ||
5049 | switch (type) { | |
5050 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5051 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5052 | break; | |
5053 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5054 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
5055 | break; | |
5056 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5057 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5058 | break; | |
5059 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5060 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5061 | break; | |
5062 | default: | |
5063 | break; | |
5064 | } | |
5065 | ||
5066 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
5067 | curr_ext_cnt++; | |
5068 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
5069 | size_diff++; | |
5070 | } | |
5071 | ||
5072 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
5073 | rc = 1; | |
5074 | ||
5075 | return rc; | |
5076 | } | |
5077 | ||
5078 | /** | |
5079 | * lpfc_sli4_cfg_post_extnts - | |
5080 | * @phba: Pointer to HBA context object. | |
5081 | * @extnt_cnt - number of available extents. | |
5082 | * @type - the extent type (rpi, xri, vfi, vpi). | |
5083 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
5084 | * @mbox - pointer to the caller's allocated mailbox structure. | |
5085 | * | |
5086 | * This function executes the extents allocation request. It also | |
5087 | * takes care of the amount of memory needed to allocate or get the | |
5088 | * allocated extents. It is the caller's responsibility to evaluate | |
5089 | * the response. | |
5090 | * | |
5091 | * Returns: | |
5092 | * -Error: Error value describes the condition found. | |
5093 | * 0: if successful | |
5094 | **/ | |
5095 | static int | |
8a9d2e80 | 5096 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt, |
6d368e53 JS |
5097 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) |
5098 | { | |
5099 | int rc = 0; | |
5100 | uint32_t req_len; | |
5101 | uint32_t emb_len; | |
5102 | uint32_t alloc_len, mbox_tmo; | |
5103 | ||
5104 | /* Calculate the total requested length of the dma memory */ | |
8a9d2e80 | 5105 | req_len = extnt_cnt * sizeof(uint16_t); |
6d368e53 JS |
5106 | |
5107 | /* | |
5108 | * Calculate the size of an embedded mailbox. The uint32_t | |
5109 | * accounts for extents-specific word. | |
5110 | */ | |
5111 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5112 | sizeof(uint32_t); | |
5113 | ||
5114 | /* | |
5115 | * Presume the allocation and response will fit into an embedded | |
5116 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5117 | */ | |
5118 | *emb = LPFC_SLI4_MBX_EMBED; | |
5119 | if (req_len > emb_len) { | |
8a9d2e80 | 5120 | req_len = extnt_cnt * sizeof(uint16_t) + |
6d368e53 JS |
5121 | sizeof(union lpfc_sli4_cfg_shdr) + |
5122 | sizeof(uint32_t); | |
5123 | *emb = LPFC_SLI4_MBX_NEMBED; | |
5124 | } | |
5125 | ||
5126 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5127 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
5128 | req_len, *emb); | |
5129 | if (alloc_len < req_len) { | |
5130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
b76f2dc9 | 5131 | "2982 Allocated DMA memory size (x%x) is " |
6d368e53 JS |
5132 | "less than the requested DMA memory " |
5133 | "size (x%x)\n", alloc_len, req_len); | |
5134 | return -ENOMEM; | |
5135 | } | |
8a9d2e80 | 5136 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb); |
6d368e53 JS |
5137 | if (unlikely(rc)) |
5138 | return -EIO; | |
5139 | ||
5140 | if (!phba->sli4_hba.intr_enable) | |
5141 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5142 | else { | |
a183a15f | 5143 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5144 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5145 | } | |
5146 | ||
5147 | if (unlikely(rc)) | |
5148 | rc = -EIO; | |
5149 | return rc; | |
5150 | } | |
5151 | ||
5152 | /** | |
5153 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
5154 | * @phba: Pointer to HBA context object. | |
5155 | * @type: The resource extent type to allocate. | |
5156 | * | |
5157 | * This function allocates the number of elements for the specified | |
5158 | * resource type. | |
5159 | **/ | |
5160 | static int | |
5161 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5162 | { | |
5163 | bool emb = false; | |
5164 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
5165 | uint16_t rsrc_id, rsrc_start, j, k; | |
5166 | uint16_t *ids; | |
5167 | int i, rc; | |
5168 | unsigned long longs; | |
5169 | unsigned long *bmask; | |
5170 | struct lpfc_rsrc_blks *rsrc_blks; | |
5171 | LPFC_MBOXQ_t *mbox; | |
5172 | uint32_t length; | |
5173 | struct lpfc_id_range *id_array = NULL; | |
5174 | void *virtaddr = NULL; | |
5175 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5176 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5177 | struct list_head *ext_blk_list; | |
5178 | ||
5179 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5180 | &rsrc_cnt, | |
5181 | &rsrc_size); | |
5182 | if (unlikely(rc)) | |
5183 | return -EIO; | |
5184 | ||
5185 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
5186 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5187 | "3009 No available Resource Extents " | |
5188 | "for resource type 0x%x: Count: 0x%x, " | |
5189 | "Size 0x%x\n", type, rsrc_cnt, | |
5190 | rsrc_size); | |
5191 | return -ENOMEM; | |
5192 | } | |
5193 | ||
8a9d2e80 JS |
5194 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI, |
5195 | "2903 Post resource extents type-0x%x: " | |
5196 | "count:%d, size %d\n", type, rsrc_cnt, rsrc_size); | |
6d368e53 JS |
5197 | |
5198 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5199 | if (!mbox) | |
5200 | return -ENOMEM; | |
5201 | ||
8a9d2e80 | 5202 | rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox); |
6d368e53 JS |
5203 | if (unlikely(rc)) { |
5204 | rc = -EIO; | |
5205 | goto err_exit; | |
5206 | } | |
5207 | ||
5208 | /* | |
5209 | * Figure out where the response is located. Then get local pointers | |
5210 | * to the response data. The port does not guarantee to respond to | |
5211 | * all extents counts request so update the local variable with the | |
5212 | * allocated count from the port. | |
5213 | */ | |
5214 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5215 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5216 | id_array = &rsrc_ext->u.rsp.id[0]; | |
5217 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5218 | } else { | |
5219 | virtaddr = mbox->sge_array->addr[0]; | |
5220 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5221 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5222 | id_array = &n_rsrc->id; | |
5223 | } | |
5224 | ||
5225 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5226 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
5227 | ||
5228 | /* | |
5229 | * Based on the resource size and count, correct the base and max | |
5230 | * resource values. | |
5231 | */ | |
5232 | length = sizeof(struct lpfc_rsrc_blks); | |
5233 | switch (type) { | |
5234 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5235 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5236 | sizeof(unsigned long), | |
5237 | GFP_KERNEL); | |
5238 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5239 | rc = -ENOMEM; | |
5240 | goto err_exit; | |
5241 | } | |
5242 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * | |
5243 | sizeof(uint16_t), | |
5244 | GFP_KERNEL); | |
5245 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5246 | kfree(phba->sli4_hba.rpi_bmask); | |
5247 | rc = -ENOMEM; | |
5248 | goto err_exit; | |
5249 | } | |
5250 | ||
5251 | /* | |
5252 | * The next_rpi was initialized with the maximum available | |
5253 | * count but the port may allocate a smaller number. Catch | |
5254 | * that case and update the next_rpi. | |
5255 | */ | |
5256 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5257 | ||
5258 | /* Initialize local ptrs for common extent processing later. */ | |
5259 | bmask = phba->sli4_hba.rpi_bmask; | |
5260 | ids = phba->sli4_hba.rpi_ids; | |
5261 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5262 | break; | |
5263 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5264 | phba->vpi_bmask = kzalloc(longs * | |
5265 | sizeof(unsigned long), | |
5266 | GFP_KERNEL); | |
5267 | if (unlikely(!phba->vpi_bmask)) { | |
5268 | rc = -ENOMEM; | |
5269 | goto err_exit; | |
5270 | } | |
5271 | phba->vpi_ids = kzalloc(rsrc_id_cnt * | |
5272 | sizeof(uint16_t), | |
5273 | GFP_KERNEL); | |
5274 | if (unlikely(!phba->vpi_ids)) { | |
5275 | kfree(phba->vpi_bmask); | |
5276 | rc = -ENOMEM; | |
5277 | goto err_exit; | |
5278 | } | |
5279 | ||
5280 | /* Initialize local ptrs for common extent processing later. */ | |
5281 | bmask = phba->vpi_bmask; | |
5282 | ids = phba->vpi_ids; | |
5283 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5284 | break; | |
5285 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5286 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5287 | sizeof(unsigned long), | |
5288 | GFP_KERNEL); | |
5289 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5290 | rc = -ENOMEM; | |
5291 | goto err_exit; | |
5292 | } | |
8a9d2e80 | 5293 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5294 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * |
5295 | sizeof(uint16_t), | |
5296 | GFP_KERNEL); | |
5297 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5298 | kfree(phba->sli4_hba.xri_bmask); | |
5299 | rc = -ENOMEM; | |
5300 | goto err_exit; | |
5301 | } | |
5302 | ||
5303 | /* Initialize local ptrs for common extent processing later. */ | |
5304 | bmask = phba->sli4_hba.xri_bmask; | |
5305 | ids = phba->sli4_hba.xri_ids; | |
5306 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5307 | break; | |
5308 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5309 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5310 | sizeof(unsigned long), | |
5311 | GFP_KERNEL); | |
5312 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5313 | rc = -ENOMEM; | |
5314 | goto err_exit; | |
5315 | } | |
5316 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * | |
5317 | sizeof(uint16_t), | |
5318 | GFP_KERNEL); | |
5319 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5320 | kfree(phba->sli4_hba.vfi_bmask); | |
5321 | rc = -ENOMEM; | |
5322 | goto err_exit; | |
5323 | } | |
5324 | ||
5325 | /* Initialize local ptrs for common extent processing later. */ | |
5326 | bmask = phba->sli4_hba.vfi_bmask; | |
5327 | ids = phba->sli4_hba.vfi_ids; | |
5328 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5329 | break; | |
5330 | default: | |
5331 | /* Unsupported Opcode. Fail call. */ | |
5332 | id_array = NULL; | |
5333 | bmask = NULL; | |
5334 | ids = NULL; | |
5335 | ext_blk_list = NULL; | |
5336 | goto err_exit; | |
5337 | } | |
5338 | ||
5339 | /* | |
5340 | * Complete initializing the extent configuration with the | |
5341 | * allocated ids assigned to this function. The bitmask serves | |
5342 | * as an index into the array and manages the available ids. The | |
5343 | * array just stores the ids communicated to the port via the wqes. | |
5344 | */ | |
5345 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
5346 | if ((i % 2) == 0) | |
5347 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
5348 | &id_array[k]); | |
5349 | else | |
5350 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
5351 | &id_array[k]); | |
5352 | ||
5353 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
5354 | if (unlikely(!rsrc_blks)) { | |
5355 | rc = -ENOMEM; | |
5356 | kfree(bmask); | |
5357 | kfree(ids); | |
5358 | goto err_exit; | |
5359 | } | |
5360 | rsrc_blks->rsrc_start = rsrc_id; | |
5361 | rsrc_blks->rsrc_size = rsrc_size; | |
5362 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
5363 | rsrc_start = rsrc_id; | |
5364 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) | |
5365 | phba->sli4_hba.scsi_xri_start = rsrc_start + | |
5366 | lpfc_sli4_get_els_iocb_cnt(phba); | |
5367 | ||
5368 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
5369 | ids[j] = rsrc_id; | |
5370 | rsrc_id++; | |
5371 | j++; | |
5372 | } | |
5373 | /* Entire word processed. Get next word.*/ | |
5374 | if ((i % 2) == 1) | |
5375 | k++; | |
5376 | } | |
5377 | err_exit: | |
5378 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5379 | return rc; | |
5380 | } | |
5381 | ||
5382 | /** | |
5383 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
5384 | * @phba: Pointer to HBA context object. | |
5385 | * @type: the extent's type. | |
5386 | * | |
5387 | * This function deallocates all extents of a particular resource type. | |
5388 | * SLI4 does not allow for deallocating a particular extent range. It | |
5389 | * is the caller's responsibility to release all kernel memory resources. | |
5390 | **/ | |
5391 | static int | |
5392 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5393 | { | |
5394 | int rc; | |
5395 | uint32_t length, mbox_tmo = 0; | |
5396 | LPFC_MBOXQ_t *mbox; | |
5397 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
5398 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
5399 | ||
5400 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5401 | if (!mbox) | |
5402 | return -ENOMEM; | |
5403 | ||
5404 | /* | |
5405 | * This function sends an embedded mailbox because it only sends the | |
5406 | * the resource type. All extents of this type are released by the | |
5407 | * port. | |
5408 | */ | |
5409 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
5410 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5411 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5412 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
5413 | length, LPFC_SLI4_MBX_EMBED); | |
5414 | ||
5415 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
5416 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5417 | LPFC_SLI4_MBX_EMBED); | |
5418 | if (unlikely(rc)) { | |
5419 | rc = -EIO; | |
5420 | goto out_free_mbox; | |
5421 | } | |
5422 | if (!phba->sli4_hba.intr_enable) | |
5423 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5424 | else { | |
a183a15f | 5425 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5426 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5427 | } | |
5428 | if (unlikely(rc)) { | |
5429 | rc = -EIO; | |
5430 | goto out_free_mbox; | |
5431 | } | |
5432 | ||
5433 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
5434 | if (bf_get(lpfc_mbox_hdr_status, | |
5435 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
5436 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5437 | "2919 Failed to release resource extents " | |
5438 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
5439 | "Resource memory not released.\n", | |
5440 | type, | |
5441 | bf_get(lpfc_mbox_hdr_status, | |
5442 | &dealloc_rsrc->header.cfg_shdr.response), | |
5443 | bf_get(lpfc_mbox_hdr_add_status, | |
5444 | &dealloc_rsrc->header.cfg_shdr.response)); | |
5445 | rc = -EIO; | |
5446 | goto out_free_mbox; | |
5447 | } | |
5448 | ||
5449 | /* Release kernel memory resources for the specific type. */ | |
5450 | switch (type) { | |
5451 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5452 | kfree(phba->vpi_bmask); | |
5453 | kfree(phba->vpi_ids); | |
5454 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5455 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5456 | &phba->lpfc_vpi_blk_list, list) { | |
5457 | list_del_init(&rsrc_blk->list); | |
5458 | kfree(rsrc_blk); | |
5459 | } | |
5460 | break; | |
5461 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5462 | kfree(phba->sli4_hba.xri_bmask); | |
5463 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5464 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, |
5465 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
5466 | list_del_init(&rsrc_blk->list); | |
5467 | kfree(rsrc_blk); | |
5468 | } | |
5469 | break; | |
5470 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5471 | kfree(phba->sli4_hba.vfi_bmask); | |
5472 | kfree(phba->sli4_hba.vfi_ids); | |
5473 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5474 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5475 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
5476 | list_del_init(&rsrc_blk->list); | |
5477 | kfree(rsrc_blk); | |
5478 | } | |
5479 | break; | |
5480 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5481 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
5482 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5483 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
5484 | list_del_init(&rsrc_blk->list); | |
5485 | kfree(rsrc_blk); | |
5486 | } | |
5487 | break; | |
5488 | default: | |
5489 | break; | |
5490 | } | |
5491 | ||
5492 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5493 | ||
5494 | out_free_mbox: | |
5495 | mempool_free(mbox, phba->mbox_mem_pool); | |
5496 | return rc; | |
5497 | } | |
5498 | ||
5499 | /** | |
5500 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
5501 | * @phba: Pointer to HBA context object. | |
5502 | * | |
5503 | * This function allocates all SLI4 resource identifiers. | |
5504 | **/ | |
5505 | int | |
5506 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
5507 | { | |
5508 | int i, rc, error = 0; | |
5509 | uint16_t count, base; | |
5510 | unsigned long longs; | |
5511 | ||
ff78d8f9 JS |
5512 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5513 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6d368e53 JS |
5514 | if (phba->sli4_hba.extents_in_use) { |
5515 | /* | |
5516 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
5517 | * resource extent count must be read and allocated before | |
5518 | * provisioning the resource id arrays. | |
5519 | */ | |
5520 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5521 | LPFC_IDX_RSRC_RDY) { | |
5522 | /* | |
5523 | * Extent-based resources are set - the driver could | |
5524 | * be in a port reset. Figure out if any corrective | |
5525 | * actions need to be taken. | |
5526 | */ | |
5527 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5528 | LPFC_RSC_TYPE_FCOE_VFI); | |
5529 | if (rc != 0) | |
5530 | error++; | |
5531 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5532 | LPFC_RSC_TYPE_FCOE_VPI); | |
5533 | if (rc != 0) | |
5534 | error++; | |
5535 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5536 | LPFC_RSC_TYPE_FCOE_XRI); | |
5537 | if (rc != 0) | |
5538 | error++; | |
5539 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5540 | LPFC_RSC_TYPE_FCOE_RPI); | |
5541 | if (rc != 0) | |
5542 | error++; | |
5543 | ||
5544 | /* | |
5545 | * It's possible that the number of resources | |
5546 | * provided to this port instance changed between | |
5547 | * resets. Detect this condition and reallocate | |
5548 | * resources. Otherwise, there is no action. | |
5549 | */ | |
5550 | if (error) { | |
5551 | lpfc_printf_log(phba, KERN_INFO, | |
5552 | LOG_MBOX | LOG_INIT, | |
5553 | "2931 Detected extent resource " | |
5554 | "change. Reallocating all " | |
5555 | "extents.\n"); | |
5556 | rc = lpfc_sli4_dealloc_extent(phba, | |
5557 | LPFC_RSC_TYPE_FCOE_VFI); | |
5558 | rc = lpfc_sli4_dealloc_extent(phba, | |
5559 | LPFC_RSC_TYPE_FCOE_VPI); | |
5560 | rc = lpfc_sli4_dealloc_extent(phba, | |
5561 | LPFC_RSC_TYPE_FCOE_XRI); | |
5562 | rc = lpfc_sli4_dealloc_extent(phba, | |
5563 | LPFC_RSC_TYPE_FCOE_RPI); | |
5564 | } else | |
5565 | return 0; | |
5566 | } | |
5567 | ||
5568 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5569 | if (unlikely(rc)) | |
5570 | goto err_exit; | |
5571 | ||
5572 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5573 | if (unlikely(rc)) | |
5574 | goto err_exit; | |
5575 | ||
5576 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5577 | if (unlikely(rc)) | |
5578 | goto err_exit; | |
5579 | ||
5580 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5581 | if (unlikely(rc)) | |
5582 | goto err_exit; | |
5583 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5584 | LPFC_IDX_RSRC_RDY); | |
5585 | return rc; | |
5586 | } else { | |
5587 | /* | |
5588 | * The port does not support resource extents. The XRI, VPI, | |
5589 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
5590 | * Just allocate the bitmasks and provision the resource id | |
5591 | * arrays. If a port reset is active, the resources don't | |
5592 | * need any action - just exit. | |
5593 | */ | |
5594 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
ff78d8f9 JS |
5595 | LPFC_IDX_RSRC_RDY) { |
5596 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5597 | lpfc_sli4_remove_rpis(phba); | |
5598 | } | |
6d368e53 JS |
5599 | /* RPIs. */ |
5600 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
5601 | base = phba->sli4_hba.max_cfg_param.rpi_base; | |
5602 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5603 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5604 | sizeof(unsigned long), | |
5605 | GFP_KERNEL); | |
5606 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5607 | rc = -ENOMEM; | |
5608 | goto err_exit; | |
5609 | } | |
5610 | phba->sli4_hba.rpi_ids = kzalloc(count * | |
5611 | sizeof(uint16_t), | |
5612 | GFP_KERNEL); | |
5613 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5614 | rc = -ENOMEM; | |
5615 | goto free_rpi_bmask; | |
5616 | } | |
5617 | ||
5618 | for (i = 0; i < count; i++) | |
5619 | phba->sli4_hba.rpi_ids[i] = base + i; | |
5620 | ||
5621 | /* VPIs. */ | |
5622 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
5623 | base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5624 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5625 | phba->vpi_bmask = kzalloc(longs * | |
5626 | sizeof(unsigned long), | |
5627 | GFP_KERNEL); | |
5628 | if (unlikely(!phba->vpi_bmask)) { | |
5629 | rc = -ENOMEM; | |
5630 | goto free_rpi_ids; | |
5631 | } | |
5632 | phba->vpi_ids = kzalloc(count * | |
5633 | sizeof(uint16_t), | |
5634 | GFP_KERNEL); | |
5635 | if (unlikely(!phba->vpi_ids)) { | |
5636 | rc = -ENOMEM; | |
5637 | goto free_vpi_bmask; | |
5638 | } | |
5639 | ||
5640 | for (i = 0; i < count; i++) | |
5641 | phba->vpi_ids[i] = base + i; | |
5642 | ||
5643 | /* XRIs. */ | |
5644 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
5645 | base = phba->sli4_hba.max_cfg_param.xri_base; | |
5646 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5647 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5648 | sizeof(unsigned long), | |
5649 | GFP_KERNEL); | |
5650 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5651 | rc = -ENOMEM; | |
5652 | goto free_vpi_ids; | |
5653 | } | |
41899be7 | 5654 | phba->sli4_hba.max_cfg_param.xri_used = 0; |
6d368e53 JS |
5655 | phba->sli4_hba.xri_ids = kzalloc(count * |
5656 | sizeof(uint16_t), | |
5657 | GFP_KERNEL); | |
5658 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5659 | rc = -ENOMEM; | |
5660 | goto free_xri_bmask; | |
5661 | } | |
5662 | ||
5663 | for (i = 0; i < count; i++) | |
5664 | phba->sli4_hba.xri_ids[i] = base + i; | |
5665 | ||
5666 | /* VFIs. */ | |
5667 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
5668 | base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5669 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5670 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5671 | sizeof(unsigned long), | |
5672 | GFP_KERNEL); | |
5673 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5674 | rc = -ENOMEM; | |
5675 | goto free_xri_ids; | |
5676 | } | |
5677 | phba->sli4_hba.vfi_ids = kzalloc(count * | |
5678 | sizeof(uint16_t), | |
5679 | GFP_KERNEL); | |
5680 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5681 | rc = -ENOMEM; | |
5682 | goto free_vfi_bmask; | |
5683 | } | |
5684 | ||
5685 | for (i = 0; i < count; i++) | |
5686 | phba->sli4_hba.vfi_ids[i] = base + i; | |
5687 | ||
5688 | /* | |
5689 | * Mark all resources ready. An HBA reset doesn't need | |
5690 | * to reset the initialization. | |
5691 | */ | |
5692 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5693 | LPFC_IDX_RSRC_RDY); | |
5694 | return 0; | |
5695 | } | |
5696 | ||
5697 | free_vfi_bmask: | |
5698 | kfree(phba->sli4_hba.vfi_bmask); | |
5699 | free_xri_ids: | |
5700 | kfree(phba->sli4_hba.xri_ids); | |
5701 | free_xri_bmask: | |
5702 | kfree(phba->sli4_hba.xri_bmask); | |
5703 | free_vpi_ids: | |
5704 | kfree(phba->vpi_ids); | |
5705 | free_vpi_bmask: | |
5706 | kfree(phba->vpi_bmask); | |
5707 | free_rpi_ids: | |
5708 | kfree(phba->sli4_hba.rpi_ids); | |
5709 | free_rpi_bmask: | |
5710 | kfree(phba->sli4_hba.rpi_bmask); | |
5711 | err_exit: | |
5712 | return rc; | |
5713 | } | |
5714 | ||
5715 | /** | |
5716 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
5717 | * @phba: Pointer to HBA context object. | |
5718 | * | |
5719 | * This function allocates the number of elements for the specified | |
5720 | * resource type. | |
5721 | **/ | |
5722 | int | |
5723 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
5724 | { | |
5725 | if (phba->sli4_hba.extents_in_use) { | |
5726 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5727 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5728 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5729 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5730 | } else { | |
5731 | kfree(phba->vpi_bmask); | |
5732 | kfree(phba->vpi_ids); | |
5733 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5734 | kfree(phba->sli4_hba.xri_bmask); | |
5735 | kfree(phba->sli4_hba.xri_ids); | |
6d368e53 JS |
5736 | kfree(phba->sli4_hba.vfi_bmask); |
5737 | kfree(phba->sli4_hba.vfi_ids); | |
5738 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5739 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5740 | } | |
5741 | ||
5742 | return 0; | |
5743 | } | |
5744 | ||
b76f2dc9 JS |
5745 | /** |
5746 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. | |
5747 | * @phba: Pointer to HBA context object. | |
5748 | * @type: The resource extent type. | |
5749 | * @extnt_count: buffer to hold port extent count response | |
5750 | * @extnt_size: buffer to hold port extent size response. | |
5751 | * | |
5752 | * This function calls the port to read the host allocated extents | |
5753 | * for a particular type. | |
5754 | **/ | |
5755 | int | |
5756 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, | |
5757 | uint16_t *extnt_cnt, uint16_t *extnt_size) | |
5758 | { | |
5759 | bool emb; | |
5760 | int rc = 0; | |
5761 | uint16_t curr_blks = 0; | |
5762 | uint32_t req_len, emb_len; | |
5763 | uint32_t alloc_len, mbox_tmo; | |
5764 | struct list_head *blk_list_head; | |
5765 | struct lpfc_rsrc_blks *rsrc_blk; | |
5766 | LPFC_MBOXQ_t *mbox; | |
5767 | void *virtaddr = NULL; | |
5768 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5769 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5770 | union lpfc_sli4_cfg_shdr *shdr; | |
5771 | ||
5772 | switch (type) { | |
5773 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5774 | blk_list_head = &phba->lpfc_vpi_blk_list; | |
5775 | break; | |
5776 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5777 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; | |
5778 | break; | |
5779 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5780 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5781 | break; | |
5782 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5783 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5784 | break; | |
5785 | default: | |
5786 | return -EIO; | |
5787 | } | |
5788 | ||
5789 | /* Count the number of extents currently allocatd for this type. */ | |
5790 | list_for_each_entry(rsrc_blk, blk_list_head, list) { | |
5791 | if (curr_blks == 0) { | |
5792 | /* | |
5793 | * The GET_ALLOCATED mailbox does not return the size, | |
5794 | * just the count. The size should be just the size | |
5795 | * stored in the current allocated block and all sizes | |
5796 | * for an extent type are the same so set the return | |
5797 | * value now. | |
5798 | */ | |
5799 | *extnt_size = rsrc_blk->rsrc_size; | |
5800 | } | |
5801 | curr_blks++; | |
5802 | } | |
5803 | ||
5804 | /* Calculate the total requested length of the dma memory. */ | |
5805 | req_len = curr_blks * sizeof(uint16_t); | |
5806 | ||
5807 | /* | |
5808 | * Calculate the size of an embedded mailbox. The uint32_t | |
5809 | * accounts for extents-specific word. | |
5810 | */ | |
5811 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5812 | sizeof(uint32_t); | |
5813 | ||
5814 | /* | |
5815 | * Presume the allocation and response will fit into an embedded | |
5816 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5817 | */ | |
5818 | emb = LPFC_SLI4_MBX_EMBED; | |
5819 | req_len = emb_len; | |
5820 | if (req_len > emb_len) { | |
5821 | req_len = curr_blks * sizeof(uint16_t) + | |
5822 | sizeof(union lpfc_sli4_cfg_shdr) + | |
5823 | sizeof(uint32_t); | |
5824 | emb = LPFC_SLI4_MBX_NEMBED; | |
5825 | } | |
5826 | ||
5827 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5828 | if (!mbox) | |
5829 | return -ENOMEM; | |
5830 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); | |
5831 | ||
5832 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5833 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, | |
5834 | req_len, emb); | |
5835 | if (alloc_len < req_len) { | |
5836 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5837 | "2983 Allocated DMA memory size (x%x) is " | |
5838 | "less than the requested DMA memory " | |
5839 | "size (x%x)\n", alloc_len, req_len); | |
5840 | rc = -ENOMEM; | |
5841 | goto err_exit; | |
5842 | } | |
5843 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); | |
5844 | if (unlikely(rc)) { | |
5845 | rc = -EIO; | |
5846 | goto err_exit; | |
5847 | } | |
5848 | ||
5849 | if (!phba->sli4_hba.intr_enable) | |
5850 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5851 | else { | |
a183a15f | 5852 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
b76f2dc9 JS |
5853 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5854 | } | |
5855 | ||
5856 | if (unlikely(rc)) { | |
5857 | rc = -EIO; | |
5858 | goto err_exit; | |
5859 | } | |
5860 | ||
5861 | /* | |
5862 | * Figure out where the response is located. Then get local pointers | |
5863 | * to the response data. The port does not guarantee to respond to | |
5864 | * all extents counts request so update the local variable with the | |
5865 | * allocated count from the port. | |
5866 | */ | |
5867 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5868 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5869 | shdr = &rsrc_ext->header.cfg_shdr; | |
5870 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5871 | } else { | |
5872 | virtaddr = mbox->sge_array->addr[0]; | |
5873 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5874 | shdr = &n_rsrc->cfg_shdr; | |
5875 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5876 | } | |
5877 | ||
5878 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { | |
5879 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5880 | "2984 Failed to read allocated resources " | |
5881 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", | |
5882 | type, | |
5883 | bf_get(lpfc_mbox_hdr_status, &shdr->response), | |
5884 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); | |
5885 | rc = -EIO; | |
5886 | goto err_exit; | |
5887 | } | |
5888 | err_exit: | |
5889 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5890 | return rc; | |
5891 | } | |
5892 | ||
8a9d2e80 JS |
5893 | /** |
5894 | * lpfc_sli4_repost_els_sgl_list - Repsot the els buffers sgl pages as block | |
5895 | * @phba: pointer to lpfc hba data structure. | |
5896 | * | |
5897 | * This routine walks the list of els buffers that have been allocated and | |
5898 | * repost them to the port by using SGL block post. This is needed after a | |
5899 | * pci_function_reset/warm_start or start. It attempts to construct blocks | |
5900 | * of els buffer sgls which contains contiguous xris and uses the non-embedded | |
5901 | * SGL block post mailbox commands to post them to the port. For single els | |
5902 | * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post | |
5903 | * mailbox command for posting. | |
5904 | * | |
5905 | * Returns: 0 = success, non-zero failure. | |
5906 | **/ | |
5907 | static int | |
5908 | lpfc_sli4_repost_els_sgl_list(struct lpfc_hba *phba) | |
5909 | { | |
5910 | struct lpfc_sglq *sglq_entry = NULL; | |
5911 | struct lpfc_sglq *sglq_entry_next = NULL; | |
5912 | struct lpfc_sglq *sglq_entry_first = NULL; | |
5913 | int status, post_cnt = 0, num_posted = 0, block_cnt = 0; | |
5914 | int last_xritag = NO_XRI; | |
5915 | LIST_HEAD(prep_sgl_list); | |
5916 | LIST_HEAD(blck_sgl_list); | |
5917 | LIST_HEAD(allc_sgl_list); | |
5918 | LIST_HEAD(post_sgl_list); | |
5919 | LIST_HEAD(free_sgl_list); | |
5920 | ||
5921 | spin_lock(&phba->hbalock); | |
5922 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &allc_sgl_list); | |
5923 | spin_unlock(&phba->hbalock); | |
5924 | ||
5925 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, | |
5926 | &allc_sgl_list, list) { | |
5927 | list_del_init(&sglq_entry->list); | |
5928 | block_cnt++; | |
5929 | if ((last_xritag != NO_XRI) && | |
5930 | (sglq_entry->sli4_xritag != last_xritag + 1)) { | |
5931 | /* a hole in xri block, form a sgl posting block */ | |
5932 | list_splice_init(&prep_sgl_list, &blck_sgl_list); | |
5933 | post_cnt = block_cnt - 1; | |
5934 | /* prepare list for next posting block */ | |
5935 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
5936 | block_cnt = 1; | |
5937 | } else { | |
5938 | /* prepare list for next posting block */ | |
5939 | list_add_tail(&sglq_entry->list, &prep_sgl_list); | |
5940 | /* enough sgls for non-embed sgl mbox command */ | |
5941 | if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) { | |
5942 | list_splice_init(&prep_sgl_list, | |
5943 | &blck_sgl_list); | |
5944 | post_cnt = block_cnt; | |
5945 | block_cnt = 0; | |
5946 | } | |
5947 | } | |
5948 | num_posted++; | |
5949 | ||
5950 | /* keep track of last sgl's xritag */ | |
5951 | last_xritag = sglq_entry->sli4_xritag; | |
5952 | ||
5953 | /* end of repost sgl list condition for els buffers */ | |
5954 | if (num_posted == phba->sli4_hba.els_xri_cnt) { | |
5955 | if (post_cnt == 0) { | |
5956 | list_splice_init(&prep_sgl_list, | |
5957 | &blck_sgl_list); | |
5958 | post_cnt = block_cnt; | |
5959 | } else if (block_cnt == 1) { | |
5960 | status = lpfc_sli4_post_sgl(phba, | |
5961 | sglq_entry->phys, 0, | |
5962 | sglq_entry->sli4_xritag); | |
5963 | if (!status) { | |
5964 | /* successful, put sgl to posted list */ | |
5965 | list_add_tail(&sglq_entry->list, | |
5966 | &post_sgl_list); | |
5967 | } else { | |
5968 | /* Failure, put sgl to free list */ | |
5969 | lpfc_printf_log(phba, KERN_WARNING, | |
5970 | LOG_SLI, | |
5971 | "3159 Failed to post els " | |
5972 | "sgl, xritag:x%x\n", | |
5973 | sglq_entry->sli4_xritag); | |
5974 | list_add_tail(&sglq_entry->list, | |
5975 | &free_sgl_list); | |
5976 | spin_lock_irq(&phba->hbalock); | |
5977 | phba->sli4_hba.els_xri_cnt--; | |
5978 | spin_unlock_irq(&phba->hbalock); | |
5979 | } | |
5980 | } | |
5981 | } | |
5982 | ||
5983 | /* continue until a nembed page worth of sgls */ | |
5984 | if (post_cnt == 0) | |
5985 | continue; | |
5986 | ||
5987 | /* post the els buffer list sgls as a block */ | |
5988 | status = lpfc_sli4_post_els_sgl_list(phba, &blck_sgl_list, | |
5989 | post_cnt); | |
5990 | ||
5991 | if (!status) { | |
5992 | /* success, put sgl list to posted sgl list */ | |
5993 | list_splice_init(&blck_sgl_list, &post_sgl_list); | |
5994 | } else { | |
5995 | /* Failure, put sgl list to free sgl list */ | |
5996 | sglq_entry_first = list_first_entry(&blck_sgl_list, | |
5997 | struct lpfc_sglq, | |
5998 | list); | |
5999 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6000 | "3160 Failed to post els sgl-list, " | |
6001 | "xritag:x%x-x%x\n", | |
6002 | sglq_entry_first->sli4_xritag, | |
6003 | (sglq_entry_first->sli4_xritag + | |
6004 | post_cnt - 1)); | |
6005 | list_splice_init(&blck_sgl_list, &free_sgl_list); | |
6006 | spin_lock_irq(&phba->hbalock); | |
6007 | phba->sli4_hba.els_xri_cnt -= post_cnt; | |
6008 | spin_unlock_irq(&phba->hbalock); | |
6009 | } | |
6010 | ||
6011 | /* don't reset xirtag due to hole in xri block */ | |
6012 | if (block_cnt == 0) | |
6013 | last_xritag = NO_XRI; | |
6014 | ||
6015 | /* reset els sgl post count for next round of posting */ | |
6016 | post_cnt = 0; | |
6017 | } | |
6018 | ||
6019 | /* free the els sgls failed to post */ | |
6020 | lpfc_free_sgl_list(phba, &free_sgl_list); | |
6021 | ||
6022 | /* push els sgls posted to the availble list */ | |
6023 | if (!list_empty(&post_sgl_list)) { | |
6024 | spin_lock(&phba->hbalock); | |
6025 | list_splice_init(&post_sgl_list, | |
6026 | &phba->sli4_hba.lpfc_sgl_list); | |
6027 | spin_unlock(&phba->hbalock); | |
6028 | } else { | |
6029 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6030 | "3161 Failure to post els sgl to port.\n"); | |
6031 | return -EIO; | |
6032 | } | |
6033 | return 0; | |
6034 | } | |
6035 | ||
da0436e9 JS |
6036 | /** |
6037 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
6038 | * @phba: Pointer to HBA context object. | |
6039 | * | |
6040 | * This function is the main SLI4 device intialization PCI function. This | |
6041 | * function is called by the HBA intialization code, HBA reset code and | |
6042 | * HBA error attention handler code. Caller is not required to hold any | |
6043 | * locks. | |
6044 | **/ | |
6045 | int | |
6046 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
6047 | { | |
6048 | int rc; | |
6049 | LPFC_MBOXQ_t *mboxq; | |
6050 | struct lpfc_mqe *mqe; | |
6051 | uint8_t *vpd; | |
6052 | uint32_t vpd_size; | |
6053 | uint32_t ftr_rsp = 0; | |
6054 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
6055 | struct lpfc_vport *vport = phba->pport; | |
6056 | struct lpfc_dmabuf *mp; | |
6057 | ||
6058 | /* Perform a PCI function reset to start from clean */ | |
6059 | rc = lpfc_pci_function_reset(phba); | |
6060 | if (unlikely(rc)) | |
6061 | return -ENODEV; | |
6062 | ||
6063 | /* Check the HBA Host Status Register for readyness */ | |
6064 | rc = lpfc_sli4_post_status_check(phba); | |
6065 | if (unlikely(rc)) | |
6066 | return -ENODEV; | |
6067 | else { | |
6068 | spin_lock_irq(&phba->hbalock); | |
6069 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
6070 | spin_unlock_irq(&phba->hbalock); | |
6071 | } | |
6072 | ||
6073 | /* | |
6074 | * Allocate a single mailbox container for initializing the | |
6075 | * port. | |
6076 | */ | |
6077 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6078 | if (!mboxq) | |
6079 | return -ENOMEM; | |
6080 | ||
da0436e9 | 6081 | /* Issue READ_REV to collect vpd and FW information. */ |
49198b37 | 6082 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
6083 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
6084 | if (!vpd) { | |
6085 | rc = -ENOMEM; | |
6086 | goto out_free_mbox; | |
6087 | } | |
6088 | ||
6089 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
6090 | if (unlikely(rc)) { |
6091 | kfree(vpd); | |
6092 | goto out_free_mbox; | |
6093 | } | |
da0436e9 | 6094 | mqe = &mboxq->u.mqe; |
f1126688 JS |
6095 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
6096 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
6097 | phba->hba_flag |= HBA_FCOE_MODE; |
6098 | else | |
6099 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
6100 | |
6101 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
6102 | LPFC_DCBX_CEE_MODE) | |
6103 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
6104 | else | |
6105 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
6106 | ||
4f2e66c6 JS |
6107 | phba->hba_flag &= ~HBA_FCP_IOQ_FLUSH; |
6108 | ||
c31098ce | 6109 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
6110 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6111 | "0376 READ_REV Error. SLI Level %d " | |
6112 | "FCoE enabled %d\n", | |
76a95d75 | 6113 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 6114 | rc = -EIO; |
76a95d75 JS |
6115 | kfree(vpd); |
6116 | goto out_free_mbox; | |
da0436e9 | 6117 | } |
cd1c8301 | 6118 | |
ff78d8f9 JS |
6119 | /* |
6120 | * Continue initialization with default values even if driver failed | |
6121 | * to read FCoE param config regions, only read parameters if the | |
6122 | * board is FCoE | |
6123 | */ | |
6124 | if (phba->hba_flag & HBA_FCOE_MODE && | |
6125 | lpfc_sli4_read_fcoe_params(phba)) | |
6126 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, | |
6127 | "2570 Failed to read FCoE parameters\n"); | |
6128 | ||
cd1c8301 JS |
6129 | /* |
6130 | * Retrieve sli4 device physical port name, failure of doing it | |
6131 | * is considered as non-fatal. | |
6132 | */ | |
6133 | rc = lpfc_sli4_retrieve_pport_name(phba); | |
6134 | if (!rc) | |
6135 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6136 | "3080 Successful retrieving SLI4 device " | |
6137 | "physical port name: %s.\n", phba->Port); | |
6138 | ||
da0436e9 JS |
6139 | /* |
6140 | * Evaluate the read rev and vpd data. Populate the driver | |
6141 | * state with the results. If this routine fails, the failure | |
6142 | * is not fatal as the driver will use generic values. | |
6143 | */ | |
6144 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
6145 | if (unlikely(!rc)) { | |
6146 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6147 | "0377 Error %d parsing vpd. " | |
6148 | "Using defaults.\n", rc); | |
6149 | rc = 0; | |
6150 | } | |
76a95d75 | 6151 | kfree(vpd); |
da0436e9 | 6152 | |
f1126688 JS |
6153 | /* Save information as VPD data */ |
6154 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
6155 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
6156 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
6157 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
6158 | &mqe->un.read_rev); | |
6159 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
6160 | &mqe->un.read_rev); | |
6161 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
6162 | &mqe->un.read_rev); | |
6163 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
6164 | &mqe->un.read_rev); | |
6165 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
6166 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
6167 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
6168 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
6169 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
6170 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
6171 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6172 | "(%d):0380 READ_REV Status x%x " | |
6173 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
6174 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6175 | bf_get(lpfc_mqe_status, mqe), | |
6176 | phba->vpd.rev.opFwName, | |
6177 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
6178 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
6179 | |
6180 | /* | |
6181 | * Discover the port's supported feature set and match it against the | |
6182 | * hosts requests. | |
6183 | */ | |
6184 | lpfc_request_features(phba, mboxq); | |
6185 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6186 | if (unlikely(rc)) { | |
6187 | rc = -EIO; | |
76a95d75 | 6188 | goto out_free_mbox; |
da0436e9 JS |
6189 | } |
6190 | ||
6191 | /* | |
6192 | * The port must support FCP initiator mode as this is the | |
6193 | * only mode running in the host. | |
6194 | */ | |
6195 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
6196 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6197 | "0378 No support for fcpi mode.\n"); | |
6198 | ftr_rsp++; | |
6199 | } | |
fedd3b7b JS |
6200 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
6201 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
6202 | else | |
6203 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
6204 | /* |
6205 | * If the port cannot support the host's requested features | |
6206 | * then turn off the global config parameters to disable the | |
6207 | * feature in the driver. This is not a fatal error. | |
6208 | */ | |
bf08611b JS |
6209 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
6210 | if (phba->cfg_enable_bg) { | |
6211 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) | |
6212 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; | |
6213 | else | |
6214 | ftr_rsp++; | |
6215 | } | |
da0436e9 JS |
6216 | |
6217 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
6218 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6219 | ftr_rsp++; | |
6220 | ||
6221 | if (ftr_rsp) { | |
6222 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6223 | "0379 Feature Mismatch Data: x%08x %08x " | |
6224 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
6225 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
6226 | phba->cfg_enable_npiv, phba->max_vpi); | |
6227 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
6228 | phba->cfg_enable_bg = 0; | |
6229 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6230 | phba->cfg_enable_npiv = 0; | |
6231 | } | |
6232 | ||
6233 | /* These SLI3 features are assumed in SLI4 */ | |
6234 | spin_lock_irq(&phba->hbalock); | |
6235 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
6236 | spin_unlock_irq(&phba->hbalock); | |
6237 | ||
6d368e53 JS |
6238 | /* |
6239 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
6240 | * calls depends on these resources to complete port setup. | |
6241 | */ | |
6242 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
6243 | if (rc) { | |
6244 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6245 | "2920 Failed to alloc Resource IDs " | |
6246 | "rc = x%x\n", rc); | |
6247 | goto out_free_mbox; | |
6248 | } | |
6249 | ||
da0436e9 | 6250 | /* Read the port's service parameters. */ |
9f1177a3 JS |
6251 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
6252 | if (rc) { | |
6253 | phba->link_state = LPFC_HBA_ERROR; | |
6254 | rc = -ENOMEM; | |
76a95d75 | 6255 | goto out_free_mbox; |
9f1177a3 JS |
6256 | } |
6257 | ||
da0436e9 JS |
6258 | mboxq->vport = vport; |
6259 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6260 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
6261 | if (rc == MBX_SUCCESS) { | |
6262 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
6263 | rc = 0; | |
6264 | } | |
6265 | ||
6266 | /* | |
6267 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
6268 | * it to the mbuf pool. | |
6269 | */ | |
6270 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
6271 | kfree(mp); | |
6272 | mboxq->context1 = NULL; | |
6273 | if (unlikely(rc)) { | |
6274 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6275 | "0382 READ_SPARAM command failed " | |
6276 | "status %d, mbxStatus x%x\n", | |
6277 | rc, bf_get(lpfc_mqe_status, mqe)); | |
6278 | phba->link_state = LPFC_HBA_ERROR; | |
6279 | rc = -EIO; | |
76a95d75 | 6280 | goto out_free_mbox; |
da0436e9 JS |
6281 | } |
6282 | ||
0558056c | 6283 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
6284 | |
6285 | /* Update the fc_host data structures with new wwn. */ | |
6286 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
6287 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
6288 | ||
8a9d2e80 JS |
6289 | /* update host els and scsi xri-sgl sizes and mappings */ |
6290 | rc = lpfc_sli4_xri_sgl_update(phba); | |
6291 | if (unlikely(rc)) { | |
6292 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6293 | "1400 Failed to update xri-sgl size and " | |
6294 | "mapping: %d\n", rc); | |
6295 | goto out_free_mbox; | |
da0436e9 JS |
6296 | } |
6297 | ||
8a9d2e80 JS |
6298 | /* register the els sgl pool to the port */ |
6299 | rc = lpfc_sli4_repost_els_sgl_list(phba); | |
6300 | if (unlikely(rc)) { | |
6301 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6302 | "0582 Error %d during els sgl post " | |
6303 | "operation\n", rc); | |
6304 | rc = -ENODEV; | |
6305 | goto out_free_mbox; | |
6306 | } | |
6307 | ||
6308 | /* register the allocated scsi sgl pool to the port */ | |
da0436e9 JS |
6309 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); |
6310 | if (unlikely(rc)) { | |
6d368e53 | 6311 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6a9c52cf JS |
6312 | "0383 Error %d during scsi sgl post " |
6313 | "operation\n", rc); | |
da0436e9 JS |
6314 | /* Some Scsi buffers were moved to the abort scsi list */ |
6315 | /* A pci function reset will repost them */ | |
6316 | rc = -ENODEV; | |
76a95d75 | 6317 | goto out_free_mbox; |
da0436e9 JS |
6318 | } |
6319 | ||
6320 | /* Post the rpi header region to the device. */ | |
6321 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
6322 | if (unlikely(rc)) { | |
6323 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6324 | "0393 Error %d during rpi post operation\n", | |
6325 | rc); | |
6326 | rc = -ENODEV; | |
76a95d75 | 6327 | goto out_free_mbox; |
da0436e9 | 6328 | } |
97f2ecf1 | 6329 | lpfc_sli4_node_prep(phba); |
da0436e9 | 6330 | |
5350d872 JS |
6331 | /* Create all the SLI4 queues */ |
6332 | rc = lpfc_sli4_queue_create(phba); | |
6333 | if (rc) { | |
6334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6335 | "3089 Failed to allocate queues\n"); | |
6336 | rc = -ENODEV; | |
6337 | goto out_stop_timers; | |
6338 | } | |
da0436e9 JS |
6339 | /* Set up all the queues to the device */ |
6340 | rc = lpfc_sli4_queue_setup(phba); | |
6341 | if (unlikely(rc)) { | |
6342 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6343 | "0381 Error %d during queue setup.\n ", rc); | |
5350d872 | 6344 | goto out_destroy_queue; |
da0436e9 JS |
6345 | } |
6346 | ||
6347 | /* Arm the CQs and then EQs on device */ | |
6348 | lpfc_sli4_arm_cqeq_intr(phba); | |
6349 | ||
6350 | /* Indicate device interrupt mode */ | |
6351 | phba->sli4_hba.intr_enable = 1; | |
6352 | ||
6353 | /* Allow asynchronous mailbox command to go through */ | |
6354 | spin_lock_irq(&phba->hbalock); | |
6355 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6356 | spin_unlock_irq(&phba->hbalock); | |
6357 | ||
6358 | /* Post receive buffers to the device */ | |
6359 | lpfc_sli4_rb_setup(phba); | |
6360 | ||
fc2b989b JS |
6361 | /* Reset HBA FCF states after HBA reset */ |
6362 | phba->fcf.fcf_flag = 0; | |
6363 | phba->fcf.current_rec.flag = 0; | |
6364 | ||
da0436e9 | 6365 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
6366 | mod_timer(&vport->els_tmofunc, |
6367 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
6368 | |
6369 | /* Start heart beat timer */ | |
6370 | mod_timer(&phba->hb_tmofunc, | |
6371 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
6372 | phba->hb_outstanding = 0; | |
6373 | phba->last_completion_time = jiffies; | |
6374 | ||
6375 | /* Start error attention (ERATT) polling timer */ | |
6376 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
6377 | ||
75baf696 JS |
6378 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
6379 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
6380 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
6381 | if (!rc) { | |
6382 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6383 | "2829 This device supports " | |
6384 | "Advanced Error Reporting (AER)\n"); | |
6385 | spin_lock_irq(&phba->hbalock); | |
6386 | phba->hba_flag |= HBA_AER_ENABLED; | |
6387 | spin_unlock_irq(&phba->hbalock); | |
6388 | } else { | |
6389 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6390 | "2830 This device does not support " | |
6391 | "Advanced Error Reporting (AER)\n"); | |
6392 | phba->cfg_aer_support = 0; | |
6393 | } | |
0a96e975 | 6394 | rc = 0; |
75baf696 JS |
6395 | } |
6396 | ||
76a95d75 JS |
6397 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
6398 | /* | |
6399 | * The FC Port needs to register FCFI (index 0) | |
6400 | */ | |
6401 | lpfc_reg_fcfi(phba, mboxq); | |
6402 | mboxq->vport = phba->pport; | |
6403 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 6404 | if (rc != MBX_SUCCESS) |
76a95d75 | 6405 | goto out_unset_queue; |
9589b062 JS |
6406 | rc = 0; |
6407 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
6408 | &mboxq->u.mqe.un.reg_fcfi); | |
026abb87 JS |
6409 | |
6410 | /* Check if the port is configured to be disabled */ | |
6411 | lpfc_sli_read_link_ste(phba); | |
76a95d75 | 6412 | } |
026abb87 | 6413 | |
da0436e9 JS |
6414 | /* |
6415 | * The port is ready, set the host's link state to LINK_DOWN | |
6416 | * in preparation for link interrupts. | |
6417 | */ | |
da0436e9 JS |
6418 | spin_lock_irq(&phba->hbalock); |
6419 | phba->link_state = LPFC_LINK_DOWN; | |
6420 | spin_unlock_irq(&phba->hbalock); | |
026abb87 JS |
6421 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
6422 | (phba->hba_flag & LINK_DISABLED)) { | |
6423 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6424 | "3103 Adapter Link is disabled.\n"); | |
6425 | lpfc_down_link(phba, mboxq); | |
6426 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6427 | if (rc != MBX_SUCCESS) { | |
6428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6429 | "3104 Adapter failed to issue " | |
6430 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); | |
6431 | goto out_unset_queue; | |
6432 | } | |
6433 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { | |
1b51197d JS |
6434 | /* don't perform init_link on SLI4 FC port loopback test */ |
6435 | if (!(phba->link_flag & LS_LOOPBACK_MODE)) { | |
6436 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
6437 | if (rc) | |
6438 | goto out_unset_queue; | |
6439 | } | |
5350d872 JS |
6440 | } |
6441 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6442 | return rc; | |
76a95d75 | 6443 | out_unset_queue: |
da0436e9 | 6444 | /* Unset all the queues set up in this routine when error out */ |
5350d872 JS |
6445 | lpfc_sli4_queue_unset(phba); |
6446 | out_destroy_queue: | |
6447 | lpfc_sli4_queue_destroy(phba); | |
da0436e9 | 6448 | out_stop_timers: |
5350d872 | 6449 | lpfc_stop_hba_timers(phba); |
da0436e9 JS |
6450 | out_free_mbox: |
6451 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6452 | return rc; | |
6453 | } | |
6454 | ||
6455 | /** | |
6456 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
6457 | * @ptr: context object - pointer to hba structure. | |
6458 | * | |
6459 | * This is the callback function for mailbox timer. The mailbox | |
6460 | * timer is armed when a new mailbox command is issued and the timer | |
6461 | * is deleted when the mailbox complete. The function is called by | |
6462 | * the kernel timer code when a mailbox does not complete within | |
6463 | * expected time. This function wakes up the worker thread to | |
6464 | * process the mailbox timeout and returns. All the processing is | |
6465 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
6466 | **/ | |
6467 | void | |
6468 | lpfc_mbox_timeout(unsigned long ptr) | |
6469 | { | |
6470 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
6471 | unsigned long iflag; | |
6472 | uint32_t tmo_posted; | |
6473 | ||
6474 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
6475 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
6476 | if (!tmo_posted) | |
6477 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
6478 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
6479 | ||
6480 | if (!tmo_posted) | |
6481 | lpfc_worker_wake_up(phba); | |
6482 | return; | |
6483 | } | |
6484 | ||
6485 | ||
6486 | /** | |
6487 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
6488 | * @phba: Pointer to HBA context object. | |
6489 | * | |
6490 | * This function is called from worker thread when a mailbox command times out. | |
6491 | * The caller is not required to hold any locks. This function will reset the | |
6492 | * HBA and recover all the pending commands. | |
6493 | **/ | |
6494 | void | |
6495 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
6496 | { | |
6497 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 6498 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
6499 | struct lpfc_sli *psli = &phba->sli; |
6500 | struct lpfc_sli_ring *pring; | |
6501 | ||
6502 | /* Check the pmbox pointer first. There is a race condition | |
6503 | * between the mbox timeout handler getting executed in the | |
6504 | * worklist and the mailbox actually completing. When this | |
6505 | * race condition occurs, the mbox_active will be NULL. | |
6506 | */ | |
6507 | spin_lock_irq(&phba->hbalock); | |
6508 | if (pmbox == NULL) { | |
6509 | lpfc_printf_log(phba, KERN_WARNING, | |
6510 | LOG_MBOX | LOG_SLI, | |
6511 | "0353 Active Mailbox cleared - mailbox timeout " | |
6512 | "exiting\n"); | |
6513 | spin_unlock_irq(&phba->hbalock); | |
6514 | return; | |
6515 | } | |
6516 | ||
6517 | /* Mbox cmd <mbxCommand> timeout */ | |
6518 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6519 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
6520 | mb->mbxCommand, | |
6521 | phba->pport->port_state, | |
6522 | phba->sli.sli_flag, | |
6523 | phba->sli.mbox_active); | |
6524 | spin_unlock_irq(&phba->hbalock); | |
6525 | ||
6526 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
6527 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 6528 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
6529 | */ |
6530 | spin_lock_irq(&phba->pport->work_port_lock); | |
6531 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
6532 | spin_unlock_irq(&phba->pport->work_port_lock); | |
6533 | spin_lock_irq(&phba->hbalock); | |
6534 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 6535 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
6536 | spin_unlock_irq(&phba->hbalock); |
6537 | ||
6538 | pring = &psli->ring[psli->fcp_ring]; | |
6539 | lpfc_sli_abort_iocb_ring(phba, pring); | |
6540 | ||
6541 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6542 | "0345 Resetting board due to mailbox timeout\n"); | |
6543 | ||
6544 | /* Reset the HBA device */ | |
6545 | lpfc_reset_hba(phba); | |
6546 | } | |
6547 | ||
6548 | /** | |
6549 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
6550 | * @phba: Pointer to HBA context object. | |
6551 | * @pmbox: Pointer to mailbox object. | |
6552 | * @flag: Flag indicating how the mailbox need to be processed. | |
6553 | * | |
6554 | * This function is called by discovery code and HBA management code | |
6555 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
6556 | * function gets the hbalock to protect the data structures. | |
6557 | * The mailbox command can be submitted in polling mode, in which case | |
6558 | * this function will wait in a polling loop for the completion of the | |
6559 | * mailbox. | |
6560 | * If the mailbox is submitted in no_wait mode (not polling) the | |
6561 | * function will submit the command and returns immediately without waiting | |
6562 | * for the mailbox completion. The no_wait is supported only when HBA | |
6563 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
6564 | * The SLI interface allows only one mailbox pending at a time. If the | |
6565 | * mailbox is issued in polling mode and there is already a mailbox | |
6566 | * pending, then the function will return an error. If the mailbox is issued | |
6567 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
6568 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
6569 | * The sli layer owns the mailbox object until the completion of mailbox | |
6570 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
6571 | * return codes the caller owns the mailbox command after the return of | |
6572 | * the function. | |
e59058c4 | 6573 | **/ |
3772a991 JS |
6574 | static int |
6575 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
6576 | uint32_t flag) | |
dea3101e | 6577 | { |
dea3101e | 6578 | MAILBOX_t *mb; |
2e0fef85 | 6579 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6580 | uint32_t status, evtctr; |
9940b97b | 6581 | uint32_t ha_copy, hc_copy; |
dea3101e | 6582 | int i; |
09372820 | 6583 | unsigned long timeout; |
dea3101e | 6584 | unsigned long drvr_flag = 0; |
34b02dcd | 6585 | uint32_t word0, ldata; |
dea3101e | 6586 | void __iomem *to_slim; |
58da1ffb JS |
6587 | int processing_queue = 0; |
6588 | ||
6589 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6590 | if (!pmbox) { | |
8568a4d2 | 6591 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 6592 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
6593 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
6594 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6595 | return MBX_SUCCESS; | |
6596 | } | |
58da1ffb | 6597 | processing_queue = 1; |
58da1ffb JS |
6598 | pmbox = lpfc_mbox_get(phba); |
6599 | if (!pmbox) { | |
6600 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6601 | return MBX_SUCCESS; | |
6602 | } | |
6603 | } | |
dea3101e | 6604 | |
ed957684 | 6605 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 6606 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 6607 | if(!pmbox->vport) { |
58da1ffb | 6608 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 6609 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 6610 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 6611 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 6612 | pmbox->u.mb.mbxCommand); |
ed957684 | 6613 | dump_stack(); |
58da1ffb | 6614 | goto out_not_finished; |
ed957684 JS |
6615 | } |
6616 | } | |
6617 | ||
8d63f375 | 6618 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
6619 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
6620 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6621 | goto out_not_finished; | |
6622 | } | |
8d63f375 | 6623 | |
a257bf90 JS |
6624 | /* If HBA has a deferred error attention, fail the iocb. */ |
6625 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
6626 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6627 | goto out_not_finished; | |
6628 | } | |
6629 | ||
dea3101e | 6630 | psli = &phba->sli; |
92d7f7b0 | 6631 | |
3772a991 | 6632 | mb = &pmbox->u.mb; |
dea3101e JB |
6633 | status = MBX_SUCCESS; |
6634 | ||
2e0fef85 JS |
6635 | if (phba->link_state == LPFC_HBA_ERROR) { |
6636 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
6637 | |
6638 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6639 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6640 | "(%d):0311 Mailbox command x%x cannot " | |
6641 | "issue Data: x%x x%x\n", | |
6642 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6643 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 6644 | goto out_not_finished; |
41415862 JW |
6645 | } |
6646 | ||
9940b97b JS |
6647 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
6648 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || | |
6649 | !(hc_copy & HC_MBINT_ENA)) { | |
6650 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6651 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
6652 | "(%d):2528 Mailbox command x%x cannot " |
6653 | "issue Data: x%x x%x\n", | |
6654 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6655 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
6656 | goto out_not_finished; |
6657 | } | |
9290831f JS |
6658 | } |
6659 | ||
dea3101e JB |
6660 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
6661 | /* Polling for a mbox command when another one is already active | |
6662 | * is not allowed in SLI. Also, the driver must have established | |
6663 | * SLI2 mode to queue and process multiple mbox commands. | |
6664 | */ | |
6665 | ||
6666 | if (flag & MBX_POLL) { | |
2e0fef85 | 6667 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
6668 | |
6669 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6670 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6671 | "(%d):2529 Mailbox command x%x " | |
6672 | "cannot issue Data: x%x x%x\n", | |
6673 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6674 | pmbox->u.mb.mbxCommand, | |
6675 | psli->sli_flag, flag); | |
58da1ffb | 6676 | goto out_not_finished; |
dea3101e JB |
6677 | } |
6678 | ||
3772a991 | 6679 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 6680 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6681 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6682 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6683 | "(%d):2530 Mailbox command x%x " | |
6684 | "cannot issue Data: x%x x%x\n", | |
6685 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6686 | pmbox->u.mb.mbxCommand, | |
6687 | psli->sli_flag, flag); | |
58da1ffb | 6688 | goto out_not_finished; |
dea3101e JB |
6689 | } |
6690 | ||
dea3101e JB |
6691 | /* Another mailbox command is still being processed, queue this |
6692 | * command to be processed later. | |
6693 | */ | |
6694 | lpfc_mbox_put(phba, pmbox); | |
6695 | ||
6696 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 6697 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6698 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 6699 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
6700 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
6701 | mb->mbxCommand, phba->pport->port_state, | |
6702 | psli->sli_flag, flag); | |
dea3101e JB |
6703 | |
6704 | psli->slistat.mbox_busy++; | |
2e0fef85 | 6705 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6706 | |
858c9f6c JS |
6707 | if (pmbox->vport) { |
6708 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6709 | LPFC_DISC_TRC_MBOX_VPORT, | |
6710 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
6711 | (uint32_t)mb->mbxCommand, | |
6712 | mb->un.varWords[0], mb->un.varWords[1]); | |
6713 | } | |
6714 | else { | |
6715 | lpfc_debugfs_disc_trc(phba->pport, | |
6716 | LPFC_DISC_TRC_MBOX, | |
6717 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
6718 | (uint32_t)mb->mbxCommand, | |
6719 | mb->un.varWords[0], mb->un.varWords[1]); | |
6720 | } | |
6721 | ||
2e0fef85 | 6722 | return MBX_BUSY; |
dea3101e JB |
6723 | } |
6724 | ||
dea3101e JB |
6725 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
6726 | ||
6727 | /* If we are not polling, we MUST be in SLI2 mode */ | |
6728 | if (flag != MBX_POLL) { | |
3772a991 | 6729 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 6730 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 6731 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6732 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6733 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6734 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6735 | "(%d):2531 Mailbox command x%x " | |
6736 | "cannot issue Data: x%x x%x\n", | |
6737 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6738 | pmbox->u.mb.mbxCommand, | |
6739 | psli->sli_flag, flag); | |
58da1ffb | 6740 | goto out_not_finished; |
dea3101e JB |
6741 | } |
6742 | /* timeout active mbox command */ | |
a309a6b6 | 6743 | mod_timer(&psli->mbox_tmo, (jiffies + |
a183a15f | 6744 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
dea3101e JB |
6745 | } |
6746 | ||
6747 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 6748 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6749 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 6750 | "x%x\n", |
e8b62011 | 6751 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
6752 | mb->mbxCommand, phba->pport->port_state, |
6753 | psli->sli_flag, flag); | |
dea3101e | 6754 | |
858c9f6c JS |
6755 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
6756 | if (pmbox->vport) { | |
6757 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6758 | LPFC_DISC_TRC_MBOX_VPORT, | |
6759 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
6760 | (uint32_t)mb->mbxCommand, | |
6761 | mb->un.varWords[0], mb->un.varWords[1]); | |
6762 | } | |
6763 | else { | |
6764 | lpfc_debugfs_disc_trc(phba->pport, | |
6765 | LPFC_DISC_TRC_MBOX, | |
6766 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
6767 | (uint32_t)mb->mbxCommand, | |
6768 | mb->un.varWords[0], mb->un.varWords[1]); | |
6769 | } | |
6770 | } | |
6771 | ||
dea3101e JB |
6772 | psli->slistat.mbox_cmd++; |
6773 | evtctr = psli->slistat.mbox_event; | |
6774 | ||
6775 | /* next set own bit for the adapter and copy over command word */ | |
6776 | mb->mbxOwner = OWN_CHIP; | |
6777 | ||
3772a991 | 6778 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
6779 | /* Populate mbox extension offset word. */ |
6780 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
6781 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6782 | = (uint8_t *)phba->mbox_ext | |
6783 | - (uint8_t *)phba->mbox; | |
6784 | } | |
6785 | ||
6786 | /* Copy the mailbox extension data */ | |
6787 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6788 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
6789 | (uint8_t *)phba->mbox_ext, | |
6790 | pmbox->in_ext_byte_len); | |
6791 | } | |
6792 | /* Copy command data to host SLIM area */ | |
34b02dcd | 6793 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 6794 | } else { |
7a470277 JS |
6795 | /* Populate mbox extension offset word. */ |
6796 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
6797 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6798 | = MAILBOX_HBA_EXT_OFFSET; | |
6799 | ||
6800 | /* Copy the mailbox extension data */ | |
6801 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6802 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
6803 | MAILBOX_HBA_EXT_OFFSET, | |
6804 | pmbox->context2, pmbox->in_ext_byte_len); | |
6805 | ||
6806 | } | |
9290831f | 6807 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 6808 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 6809 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e JB |
6810 | } |
6811 | ||
6812 | /* First copy mbox command data to HBA SLIM, skip past first | |
6813 | word */ | |
6814 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
6815 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
6816 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
6817 | ||
6818 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 6819 | ldata = *((uint32_t *)mb); |
dea3101e JB |
6820 | to_slim = phba->MBslimaddr; |
6821 | writel(ldata, to_slim); | |
6822 | readl(to_slim); /* flush */ | |
6823 | ||
6824 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6825 | /* switch over to host mailbox */ | |
3772a991 | 6826 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
6827 | } |
6828 | } | |
6829 | ||
6830 | wmb(); | |
dea3101e JB |
6831 | |
6832 | switch (flag) { | |
6833 | case MBX_NOWAIT: | |
09372820 | 6834 | /* Set up reference to mailbox command */ |
dea3101e | 6835 | psli->mbox_active = pmbox; |
09372820 JS |
6836 | /* Interrupt board to do it */ |
6837 | writel(CA_MBATT, phba->CAregaddr); | |
6838 | readl(phba->CAregaddr); /* flush */ | |
6839 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
6840 | break; |
6841 | ||
6842 | case MBX_POLL: | |
09372820 | 6843 | /* Set up null reference to mailbox command */ |
dea3101e | 6844 | psli->mbox_active = NULL; |
09372820 JS |
6845 | /* Interrupt board to do it */ |
6846 | writel(CA_MBATT, phba->CAregaddr); | |
6847 | readl(phba->CAregaddr); /* flush */ | |
6848 | ||
3772a991 | 6849 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6850 | /* First read mbox status word */ |
34b02dcd | 6851 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
6852 | word0 = le32_to_cpu(word0); |
6853 | } else { | |
6854 | /* First read mbox status word */ | |
9940b97b JS |
6855 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
6856 | spin_unlock_irqrestore(&phba->hbalock, | |
6857 | drvr_flag); | |
6858 | goto out_not_finished; | |
6859 | } | |
dea3101e JB |
6860 | } |
6861 | ||
6862 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6863 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6864 | spin_unlock_irqrestore(&phba->hbalock, | |
6865 | drvr_flag); | |
6866 | goto out_not_finished; | |
6867 | } | |
a183a15f JS |
6868 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
6869 | 1000) + jiffies; | |
09372820 | 6870 | i = 0; |
dea3101e | 6871 | /* Wait for command to complete */ |
41415862 JW |
6872 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
6873 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 6874 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 6875 | if (time_after(jiffies, timeout)) { |
dea3101e | 6876 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6877 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 6878 | drvr_flag); |
58da1ffb | 6879 | goto out_not_finished; |
dea3101e JB |
6880 | } |
6881 | ||
6882 | /* Check if we took a mbox interrupt while we were | |
6883 | polling */ | |
6884 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
6885 | && (evtctr != psli->slistat.mbox_event)) | |
6886 | break; | |
6887 | ||
09372820 JS |
6888 | if (i++ > 10) { |
6889 | spin_unlock_irqrestore(&phba->hbalock, | |
6890 | drvr_flag); | |
6891 | msleep(1); | |
6892 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6893 | } | |
dea3101e | 6894 | |
3772a991 | 6895 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6896 | /* First copy command data */ |
34b02dcd | 6897 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
6898 | word0 = le32_to_cpu(word0); |
6899 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6900 | MAILBOX_t *slimmb; | |
34b02dcd | 6901 | uint32_t slimword0; |
dea3101e JB |
6902 | /* Check real SLIM for any errors */ |
6903 | slimword0 = readl(phba->MBslimaddr); | |
6904 | slimmb = (MAILBOX_t *) & slimword0; | |
6905 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
6906 | && slimmb->mbxStatus) { | |
6907 | psli->sli_flag &= | |
3772a991 | 6908 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
6909 | word0 = slimword0; |
6910 | } | |
6911 | } | |
6912 | } else { | |
6913 | /* First copy command data */ | |
6914 | word0 = readl(phba->MBslimaddr); | |
6915 | } | |
6916 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6917 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6918 | spin_unlock_irqrestore(&phba->hbalock, | |
6919 | drvr_flag); | |
6920 | goto out_not_finished; | |
6921 | } | |
dea3101e JB |
6922 | } |
6923 | ||
3772a991 | 6924 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6925 | /* copy results back to user */ |
34b02dcd | 6926 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
6927 | /* Copy the mailbox extension data */ |
6928 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6929 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
6930 | pmbox->context2, | |
6931 | pmbox->out_ext_byte_len); | |
6932 | } | |
dea3101e JB |
6933 | } else { |
6934 | /* First copy command data */ | |
6935 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
6936 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
6937 | /* Copy the mailbox extension data */ |
6938 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6939 | lpfc_memcpy_from_slim(pmbox->context2, | |
6940 | phba->MBslimaddr + | |
6941 | MAILBOX_HBA_EXT_OFFSET, | |
6942 | pmbox->out_ext_byte_len); | |
dea3101e JB |
6943 | } |
6944 | } | |
6945 | ||
6946 | writel(HA_MBATT, phba->HAregaddr); | |
6947 | readl(phba->HAregaddr); /* flush */ | |
6948 | ||
6949 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6950 | status = mb->mbxStatus; | |
6951 | } | |
6952 | ||
2e0fef85 JS |
6953 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
6954 | return status; | |
58da1ffb JS |
6955 | |
6956 | out_not_finished: | |
6957 | if (processing_queue) { | |
da0436e9 | 6958 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
6959 | lpfc_mbox_cmpl_put(phba, pmbox); |
6960 | } | |
6961 | return MBX_NOT_FINISHED; | |
dea3101e JB |
6962 | } |
6963 | ||
f1126688 JS |
6964 | /** |
6965 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
6966 | * @phba: Pointer to HBA context object. | |
6967 | * | |
6968 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
6969 | * the driver internal pending mailbox queue. It will then try to wait out the | |
6970 | * possible outstanding mailbox command before return. | |
6971 | * | |
6972 | * Returns: | |
6973 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
6974 | * the outstanding mailbox command timed out. | |
6975 | **/ | |
6976 | static int | |
6977 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
6978 | { | |
6979 | struct lpfc_sli *psli = &phba->sli; | |
f1126688 | 6980 | int rc = 0; |
a183a15f | 6981 | unsigned long timeout = 0; |
f1126688 JS |
6982 | |
6983 | /* Mark the asynchronous mailbox command posting as blocked */ | |
6984 | spin_lock_irq(&phba->hbalock); | |
6985 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
f1126688 JS |
6986 | /* Determine how long we might wait for the active mailbox |
6987 | * command to be gracefully completed by firmware. | |
6988 | */ | |
a183a15f JS |
6989 | if (phba->sli.mbox_active) |
6990 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
6991 | phba->sli.mbox_active) * | |
6992 | 1000) + jiffies; | |
6993 | spin_unlock_irq(&phba->hbalock); | |
6994 | ||
f1126688 JS |
6995 | /* Wait for the outstnading mailbox command to complete */ |
6996 | while (phba->sli.mbox_active) { | |
6997 | /* Check active mailbox complete status every 2ms */ | |
6998 | msleep(2); | |
6999 | if (time_after(jiffies, timeout)) { | |
7000 | /* Timeout, marked the outstanding cmd not complete */ | |
7001 | rc = 1; | |
7002 | break; | |
7003 | } | |
7004 | } | |
7005 | ||
7006 | /* Can not cleanly block async mailbox command, fails it */ | |
7007 | if (rc) { | |
7008 | spin_lock_irq(&phba->hbalock); | |
7009 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7010 | spin_unlock_irq(&phba->hbalock); | |
7011 | } | |
7012 | return rc; | |
7013 | } | |
7014 | ||
7015 | /** | |
7016 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
7017 | * @phba: Pointer to HBA context object. | |
7018 | * | |
7019 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
7020 | * commands from the driver internal pending mailbox queue. It makes sure | |
7021 | * that there is no outstanding mailbox command before resuming posting | |
7022 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
7023 | * mailbox command, it will try to wait it out before resuming asynchronous | |
7024 | * mailbox command posting. | |
7025 | **/ | |
7026 | static void | |
7027 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
7028 | { | |
7029 | struct lpfc_sli *psli = &phba->sli; | |
7030 | ||
7031 | spin_lock_irq(&phba->hbalock); | |
7032 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7033 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
7034 | spin_unlock_irq(&phba->hbalock); | |
7035 | return; | |
7036 | } | |
7037 | ||
7038 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
7039 | * successful or timeout, after timing-out the outstanding mailbox | |
7040 | * command shall always be removed, so just unblock posting async | |
7041 | * mailbox command and resume | |
7042 | */ | |
7043 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
7044 | spin_unlock_irq(&phba->hbalock); | |
7045 | ||
7046 | /* wake up worker thread to post asynchronlous mailbox command */ | |
7047 | lpfc_worker_wake_up(phba); | |
7048 | } | |
7049 | ||
da0436e9 JS |
7050 | /** |
7051 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
7052 | * @phba: Pointer to HBA context object. | |
7053 | * @mboxq: Pointer to mailbox object. | |
7054 | * | |
7055 | * The function posts a mailbox to the port. The mailbox is expected | |
7056 | * to be comletely filled in and ready for the port to operate on it. | |
7057 | * This routine executes a synchronous completion operation on the | |
7058 | * mailbox by polling for its completion. | |
7059 | * | |
7060 | * The caller must not be holding any locks when calling this routine. | |
7061 | * | |
7062 | * Returns: | |
7063 | * MBX_SUCCESS - mailbox posted successfully | |
7064 | * Any of the MBX error values. | |
7065 | **/ | |
7066 | static int | |
7067 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7068 | { | |
7069 | int rc = MBX_SUCCESS; | |
7070 | unsigned long iflag; | |
7071 | uint32_t db_ready; | |
7072 | uint32_t mcqe_status; | |
7073 | uint32_t mbx_cmnd; | |
7074 | unsigned long timeout; | |
7075 | struct lpfc_sli *psli = &phba->sli; | |
7076 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
7077 | struct lpfc_bmbx_create *mbox_rgn; | |
7078 | struct dma_address *dma_address; | |
7079 | struct lpfc_register bmbx_reg; | |
7080 | ||
7081 | /* | |
7082 | * Only one mailbox can be active to the bootstrap mailbox region | |
7083 | * at a time and there is no queueing provided. | |
7084 | */ | |
7085 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7086 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7087 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7088 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7089 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7090 | "cannot issue Data: x%x x%x\n", |
7091 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7092 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7093 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7094 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7095 | psli->sli_flag, MBX_POLL); |
7096 | return MBXERR_ERROR; | |
7097 | } | |
7098 | /* The server grabs the token and owns it until release */ | |
7099 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7100 | phba->sli.mbox_active = mboxq; | |
7101 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7102 | ||
7103 | /* | |
7104 | * Initialize the bootstrap memory region to avoid stale data areas | |
7105 | * in the mailbox post. Then copy the caller's mailbox contents to | |
7106 | * the bmbx mailbox region. | |
7107 | */ | |
7108 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
7109 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
7110 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
7111 | sizeof(struct lpfc_mqe)); | |
7112 | ||
7113 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
7114 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
7115 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
7116 | ||
a183a15f | 7117 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
da0436e9 JS |
7118 | * 1000) + jiffies; |
7119 | do { | |
7120 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
7121 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
7122 | if (!db_ready) | |
7123 | msleep(2); | |
7124 | ||
7125 | if (time_after(jiffies, timeout)) { | |
7126 | rc = MBXERR_ERROR; | |
7127 | goto exit; | |
7128 | } | |
7129 | } while (!db_ready); | |
7130 | ||
7131 | /* Post the low mailbox dma address to the port. */ | |
7132 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
a183a15f | 7133 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
da0436e9 JS |
7134 | * 1000) + jiffies; |
7135 | do { | |
7136 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
7137 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
7138 | if (!db_ready) | |
7139 | msleep(2); | |
7140 | ||
7141 | if (time_after(jiffies, timeout)) { | |
7142 | rc = MBXERR_ERROR; | |
7143 | goto exit; | |
7144 | } | |
7145 | } while (!db_ready); | |
7146 | ||
7147 | /* | |
7148 | * Read the CQ to ensure the mailbox has completed. | |
7149 | * If so, update the mailbox status so that the upper layers | |
7150 | * can complete the request normally. | |
7151 | */ | |
7152 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
7153 | sizeof(struct lpfc_mqe)); | |
7154 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
7155 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
7156 | sizeof(struct lpfc_mcqe)); | |
7157 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
0558056c JS |
7158 | /* |
7159 | * When the CQE status indicates a failure and the mailbox status | |
7160 | * indicates success then copy the CQE status into the mailbox status | |
7161 | * (and prefix it with x4000). | |
7162 | */ | |
da0436e9 | 7163 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
7164 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
7165 | bf_set(lpfc_mqe_status, mb, | |
7166 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 7167 | rc = MBXERR_ERROR; |
d7c47992 JS |
7168 | } else |
7169 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
7170 | |
7171 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7172 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
da0436e9 JS |
7173 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
7174 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
a183a15f JS |
7175 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
7176 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
7177 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7178 | bf_get(lpfc_mqe_status, mb), |
7179 | mb->un.mb_words[0], mb->un.mb_words[1], | |
7180 | mb->un.mb_words[2], mb->un.mb_words[3], | |
7181 | mb->un.mb_words[4], mb->un.mb_words[5], | |
7182 | mb->un.mb_words[6], mb->un.mb_words[7], | |
7183 | mb->un.mb_words[8], mb->un.mb_words[9], | |
7184 | mb->un.mb_words[10], mb->un.mb_words[11], | |
7185 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
7186 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
7187 | mboxq->mcqe.trailer); | |
7188 | exit: | |
7189 | /* We are holding the token, no needed for lock when release */ | |
7190 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7191 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7192 | phba->sli.mbox_active = NULL; | |
7193 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7194 | return rc; | |
7195 | } | |
7196 | ||
7197 | /** | |
7198 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
7199 | * @phba: Pointer to HBA context object. | |
7200 | * @pmbox: Pointer to mailbox object. | |
7201 | * @flag: Flag indicating how the mailbox need to be processed. | |
7202 | * | |
7203 | * This function is called by discovery code and HBA management code to submit | |
7204 | * a mailbox command to firmware with SLI-4 interface spec. | |
7205 | * | |
7206 | * Return codes the caller owns the mailbox command after the return of the | |
7207 | * function. | |
7208 | **/ | |
7209 | static int | |
7210 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
7211 | uint32_t flag) | |
7212 | { | |
7213 | struct lpfc_sli *psli = &phba->sli; | |
7214 | unsigned long iflags; | |
7215 | int rc; | |
7216 | ||
b76f2dc9 JS |
7217 | /* dump from issue mailbox command if setup */ |
7218 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); | |
7219 | ||
8fa38513 JS |
7220 | rc = lpfc_mbox_dev_check(phba); |
7221 | if (unlikely(rc)) { | |
7222 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7223 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
8fa38513 JS |
7224 | "cannot issue Data: x%x x%x\n", |
7225 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7226 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7227 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7228 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
8fa38513 JS |
7229 | psli->sli_flag, flag); |
7230 | goto out_not_finished; | |
7231 | } | |
7232 | ||
da0436e9 JS |
7233 | /* Detect polling mode and jump to a handler */ |
7234 | if (!phba->sli4_hba.intr_enable) { | |
7235 | if (flag == MBX_POLL) | |
7236 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7237 | else | |
7238 | rc = -EIO; | |
7239 | if (rc != MBX_SUCCESS) | |
0558056c | 7240 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 | 7241 | "(%d):2541 Mailbox command x%x " |
cc459f19 JS |
7242 | "(x%x/x%x) failure: " |
7243 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7244 | "Data: x%x x%x\n,", | |
da0436e9 JS |
7245 | mboxq->vport ? mboxq->vport->vpi : 0, |
7246 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7247 | lpfc_sli_config_mbox_subsys_get(phba, |
7248 | mboxq), | |
7249 | lpfc_sli_config_mbox_opcode_get(phba, | |
7250 | mboxq), | |
cc459f19 JS |
7251 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7252 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7253 | bf_get(lpfc_mcqe_ext_status, | |
7254 | &mboxq->mcqe), | |
da0436e9 JS |
7255 | psli->sli_flag, flag); |
7256 | return rc; | |
7257 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
7258 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
7259 | "(%d):2542 Try to issue mailbox command " | |
a183a15f | 7260 | "x%x (x%x/x%x) synchronously ahead of async" |
f1126688 | 7261 | "mailbox command queue: x%x x%x\n", |
da0436e9 JS |
7262 | mboxq->vport ? mboxq->vport->vpi : 0, |
7263 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7264 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7265 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 | 7266 | psli->sli_flag, flag); |
f1126688 JS |
7267 | /* Try to block the asynchronous mailbox posting */ |
7268 | rc = lpfc_sli4_async_mbox_block(phba); | |
7269 | if (!rc) { | |
7270 | /* Successfully blocked, now issue sync mbox cmd */ | |
7271 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7272 | if (rc != MBX_SUCCESS) | |
cc459f19 | 7273 | lpfc_printf_log(phba, KERN_WARNING, |
a183a15f | 7274 | LOG_MBOX | LOG_SLI, |
cc459f19 JS |
7275 | "(%d):2597 Sync Mailbox command " |
7276 | "x%x (x%x/x%x) failure: " | |
7277 | "mqe_sta: x%x mcqe_sta: x%x/x%x " | |
7278 | "Data: x%x x%x\n,", | |
7279 | mboxq->vport ? mboxq->vport->vpi : 0, | |
a183a15f JS |
7280 | mboxq->u.mb.mbxCommand, |
7281 | lpfc_sli_config_mbox_subsys_get(phba, | |
7282 | mboxq), | |
7283 | lpfc_sli_config_mbox_opcode_get(phba, | |
7284 | mboxq), | |
cc459f19 JS |
7285 | bf_get(lpfc_mqe_status, &mboxq->u.mqe), |
7286 | bf_get(lpfc_mcqe_status, &mboxq->mcqe), | |
7287 | bf_get(lpfc_mcqe_ext_status, | |
7288 | &mboxq->mcqe), | |
a183a15f | 7289 | psli->sli_flag, flag); |
f1126688 JS |
7290 | /* Unblock the async mailbox posting afterward */ |
7291 | lpfc_sli4_async_mbox_unblock(phba); | |
7292 | } | |
7293 | return rc; | |
da0436e9 JS |
7294 | } |
7295 | ||
7296 | /* Now, interrupt mode asynchrous mailbox command */ | |
7297 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
7298 | if (rc) { | |
7299 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7300 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7301 | "cannot issue Data: x%x x%x\n", |
7302 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7303 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7304 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7305 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7306 | psli->sli_flag, flag); |
7307 | goto out_not_finished; | |
7308 | } | |
da0436e9 JS |
7309 | |
7310 | /* Put the mailbox command to the driver internal FIFO */ | |
7311 | psli->slistat.mbox_busy++; | |
7312 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7313 | lpfc_mbox_put(phba, mboxq); | |
7314 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7315 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7316 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
a183a15f | 7317 | "x%x (x%x/x%x) x%x x%x x%x\n", |
da0436e9 JS |
7318 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
7319 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
a183a15f JS |
7320 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7321 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7322 | phba->pport->port_state, |
7323 | psli->sli_flag, MBX_NOWAIT); | |
7324 | /* Wake up worker thread to transport mailbox command from head */ | |
7325 | lpfc_worker_wake_up(phba); | |
7326 | ||
7327 | return MBX_BUSY; | |
7328 | ||
7329 | out_not_finished: | |
7330 | return MBX_NOT_FINISHED; | |
7331 | } | |
7332 | ||
7333 | /** | |
7334 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
7335 | * @phba: Pointer to HBA context object. | |
7336 | * | |
7337 | * This function is called by worker thread to send a mailbox command to | |
7338 | * SLI4 HBA firmware. | |
7339 | * | |
7340 | **/ | |
7341 | int | |
7342 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
7343 | { | |
7344 | struct lpfc_sli *psli = &phba->sli; | |
7345 | LPFC_MBOXQ_t *mboxq; | |
7346 | int rc = MBX_SUCCESS; | |
7347 | unsigned long iflags; | |
7348 | struct lpfc_mqe *mqe; | |
7349 | uint32_t mbx_cmnd; | |
7350 | ||
7351 | /* Check interrupt mode before post async mailbox command */ | |
7352 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
7353 | return MBX_NOT_FINISHED; | |
7354 | ||
7355 | /* Check for mailbox command service token */ | |
7356 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7357 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7358 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7359 | return MBX_NOT_FINISHED; | |
7360 | } | |
7361 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7362 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7363 | return MBX_NOT_FINISHED; | |
7364 | } | |
7365 | if (unlikely(phba->sli.mbox_active)) { | |
7366 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7367 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7368 | "0384 There is pending active mailbox cmd\n"); | |
7369 | return MBX_NOT_FINISHED; | |
7370 | } | |
7371 | /* Take the mailbox command service token */ | |
7372 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7373 | ||
7374 | /* Get the next mailbox command from head of queue */ | |
7375 | mboxq = lpfc_mbox_get(phba); | |
7376 | ||
7377 | /* If no more mailbox command waiting for post, we're done */ | |
7378 | if (!mboxq) { | |
7379 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7380 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7381 | return MBX_SUCCESS; | |
7382 | } | |
7383 | phba->sli.mbox_active = mboxq; | |
7384 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7385 | ||
7386 | /* Check device readiness for posting mailbox command */ | |
7387 | rc = lpfc_mbox_dev_check(phba); | |
7388 | if (unlikely(rc)) | |
7389 | /* Driver clean routine will clean up pending mailbox */ | |
7390 | goto out_not_finished; | |
7391 | ||
7392 | /* Prepare the mbox command to be posted */ | |
7393 | mqe = &mboxq->u.mqe; | |
7394 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
7395 | ||
7396 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
7397 | mod_timer(&psli->mbox_tmo, (jiffies + | |
a183a15f | 7398 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
da0436e9 JS |
7399 | |
7400 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7401 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
da0436e9 JS |
7402 | "x%x x%x\n", |
7403 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
a183a15f JS |
7404 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7405 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7406 | phba->pport->port_state, psli->sli_flag); |
7407 | ||
7408 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
7409 | if (mboxq->vport) { | |
7410 | lpfc_debugfs_disc_trc(mboxq->vport, | |
7411 | LPFC_DISC_TRC_MBOX_VPORT, | |
7412 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
7413 | mbx_cmnd, mqe->un.mb_words[0], | |
7414 | mqe->un.mb_words[1]); | |
7415 | } else { | |
7416 | lpfc_debugfs_disc_trc(phba->pport, | |
7417 | LPFC_DISC_TRC_MBOX, | |
7418 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
7419 | mbx_cmnd, mqe->un.mb_words[0], | |
7420 | mqe->un.mb_words[1]); | |
7421 | } | |
7422 | } | |
7423 | psli->slistat.mbox_cmd++; | |
7424 | ||
7425 | /* Post the mailbox command to the port */ | |
7426 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
7427 | if (rc != MBX_SUCCESS) { | |
7428 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7429 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7430 | "cannot issue Data: x%x x%x\n", |
7431 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7432 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7433 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7434 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7435 | psli->sli_flag, MBX_NOWAIT); |
7436 | goto out_not_finished; | |
7437 | } | |
7438 | ||
7439 | return rc; | |
7440 | ||
7441 | out_not_finished: | |
7442 | spin_lock_irqsave(&phba->hbalock, iflags); | |
d7069f09 JS |
7443 | if (phba->sli.mbox_active) { |
7444 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7445 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7446 | /* Release the token */ | |
7447 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7448 | phba->sli.mbox_active = NULL; | |
7449 | } | |
da0436e9 JS |
7450 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
7451 | ||
7452 | return MBX_NOT_FINISHED; | |
7453 | } | |
7454 | ||
7455 | /** | |
7456 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
7457 | * @phba: Pointer to HBA context object. | |
7458 | * @pmbox: Pointer to mailbox object. | |
7459 | * @flag: Flag indicating how the mailbox need to be processed. | |
7460 | * | |
7461 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
7462 | * the API jump table function pointer from the lpfc_hba struct. | |
7463 | * | |
7464 | * Return codes the caller owns the mailbox command after the return of the | |
7465 | * function. | |
7466 | **/ | |
7467 | int | |
7468 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
7469 | { | |
7470 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
7471 | } | |
7472 | ||
7473 | /** | |
25985edc | 7474 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
7475 | * @phba: The hba struct for which this call is being executed. |
7476 | * @dev_grp: The HBA PCI-Device group number. | |
7477 | * | |
7478 | * This routine sets up the mbox interface API function jump table in @phba | |
7479 | * struct. | |
7480 | * Returns: 0 - success, -ENODEV - failure. | |
7481 | **/ | |
7482 | int | |
7483 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
7484 | { | |
7485 | ||
7486 | switch (dev_grp) { | |
7487 | case LPFC_PCI_DEV_LP: | |
7488 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
7489 | phba->lpfc_sli_handle_slow_ring_event = | |
7490 | lpfc_sli_handle_slow_ring_event_s3; | |
7491 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
7492 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
7493 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
7494 | break; | |
7495 | case LPFC_PCI_DEV_OC: | |
7496 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
7497 | phba->lpfc_sli_handle_slow_ring_event = | |
7498 | lpfc_sli_handle_slow_ring_event_s4; | |
7499 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
7500 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
7501 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
7502 | break; | |
7503 | default: | |
7504 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7505 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
7506 | dev_grp); | |
7507 | return -ENODEV; | |
7508 | break; | |
7509 | } | |
7510 | return 0; | |
7511 | } | |
7512 | ||
e59058c4 | 7513 | /** |
3621a710 | 7514 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
7515 | * @phba: Pointer to HBA context object. |
7516 | * @pring: Pointer to driver SLI ring object. | |
7517 | * @piocb: Pointer to address of newly added command iocb. | |
7518 | * | |
7519 | * This function is called with hbalock held to add a command | |
7520 | * iocb to the txq when SLI layer cannot submit the command iocb | |
7521 | * to the ring. | |
7522 | **/ | |
2a9bf3d0 | 7523 | void |
92d7f7b0 | 7524 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 7525 | struct lpfc_iocbq *piocb) |
dea3101e JB |
7526 | { |
7527 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
7528 | list_add_tail(&piocb->list, &pring->txq); | |
7529 | pring->txq_cnt++; | |
dea3101e JB |
7530 | } |
7531 | ||
e59058c4 | 7532 | /** |
3621a710 | 7533 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
7534 | * @phba: Pointer to HBA context object. |
7535 | * @pring: Pointer to driver SLI ring object. | |
7536 | * @piocb: Pointer to address of newly added command iocb. | |
7537 | * | |
7538 | * This function is called with hbalock held before a new | |
7539 | * iocb is submitted to the firmware. This function checks | |
7540 | * txq to flush the iocbs in txq to Firmware before | |
7541 | * submitting new iocbs to the Firmware. | |
7542 | * If there are iocbs in the txq which need to be submitted | |
7543 | * to firmware, lpfc_sli_next_iocb returns the first element | |
7544 | * of the txq after dequeuing it from txq. | |
7545 | * If there is no iocb in the txq then the function will return | |
7546 | * *piocb and *piocb is set to NULL. Caller needs to check | |
7547 | * *piocb to find if there are more commands in the txq. | |
7548 | **/ | |
dea3101e JB |
7549 | static struct lpfc_iocbq * |
7550 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7551 | struct lpfc_iocbq **piocb) |
dea3101e JB |
7552 | { |
7553 | struct lpfc_iocbq * nextiocb; | |
7554 | ||
7555 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
7556 | if (!nextiocb) { | |
7557 | nextiocb = *piocb; | |
7558 | *piocb = NULL; | |
7559 | } | |
7560 | ||
7561 | return nextiocb; | |
7562 | } | |
7563 | ||
e59058c4 | 7564 | /** |
3772a991 | 7565 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 7566 | * @phba: Pointer to HBA context object. |
3772a991 | 7567 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
7568 | * @piocb: Pointer to command iocb. |
7569 | * @flag: Flag indicating if this command can be put into txq. | |
7570 | * | |
3772a991 JS |
7571 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
7572 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
7573 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
7574 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
7575 | * this function allows only iocbs for posting buffers. This function finds | |
7576 | * next available slot in the command ring and posts the command to the | |
7577 | * available slot and writes the port attention register to request HBA start | |
7578 | * processing new iocb. If there is no slot available in the ring and | |
7579 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
7580 | * the function returns IOCB_BUSY. | |
e59058c4 | 7581 | * |
3772a991 JS |
7582 | * This function is called with hbalock held. The function will return success |
7583 | * after it successfully submit the iocb to firmware or after adding to the | |
7584 | * txq. | |
e59058c4 | 7585 | **/ |
98c9ea5c | 7586 | static int |
3772a991 | 7587 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
7588 | struct lpfc_iocbq *piocb, uint32_t flag) |
7589 | { | |
7590 | struct lpfc_iocbq *nextiocb; | |
7591 | IOCB_t *iocb; | |
3772a991 | 7592 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 7593 | |
92d7f7b0 JS |
7594 | if (piocb->iocb_cmpl && (!piocb->vport) && |
7595 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
7596 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
7597 | lpfc_printf_log(phba, KERN_ERR, | |
7598 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 7599 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
7600 | piocb->iocb.ulpCommand); |
7601 | dump_stack(); | |
7602 | return IOCB_ERROR; | |
7603 | } | |
7604 | ||
7605 | ||
8d63f375 LV |
7606 | /* If the PCI channel is in offline state, do not post iocbs. */ |
7607 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
7608 | return IOCB_ERROR; | |
7609 | ||
a257bf90 JS |
7610 | /* If HBA has a deferred error attention, fail the iocb. */ |
7611 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
7612 | return IOCB_ERROR; | |
7613 | ||
dea3101e JB |
7614 | /* |
7615 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
7616 | */ | |
2e0fef85 | 7617 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
7618 | return IOCB_ERROR; |
7619 | ||
7620 | /* | |
7621 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 7622 | * outstanding event. |
dea3101e | 7623 | */ |
0b727fea | 7624 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
7625 | goto iocb_busy; |
7626 | ||
2e0fef85 | 7627 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 7628 | /* |
2680eeaa | 7629 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
7630 | * can be issued if the link is not up. |
7631 | */ | |
7632 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
7633 | case CMD_GEN_REQUEST64_CR: |
7634 | case CMD_GEN_REQUEST64_CX: | |
7635 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
7636 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 7637 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
7638 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
7639 | MENLO_TRANSPORT_TYPE)) | |
7640 | ||
7641 | goto iocb_busy; | |
7642 | break; | |
dea3101e JB |
7643 | case CMD_QUE_RING_BUF_CN: |
7644 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
7645 | /* |
7646 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
7647 | * completion, iocb_cmpl MUST be 0. | |
7648 | */ | |
7649 | if (piocb->iocb_cmpl) | |
7650 | piocb->iocb_cmpl = NULL; | |
7651 | /*FALLTHROUGH*/ | |
7652 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
7653 | case CMD_CLOSE_XRI_CN: |
7654 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
7655 | break; |
7656 | default: | |
7657 | goto iocb_busy; | |
7658 | } | |
7659 | ||
7660 | /* | |
7661 | * For FCP commands, we must be in a state where we can process link | |
7662 | * attention events. | |
7663 | */ | |
7664 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 7665 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 7666 | goto iocb_busy; |
92d7f7b0 | 7667 | } |
dea3101e | 7668 | |
dea3101e JB |
7669 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
7670 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
7671 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
7672 | ||
7673 | if (iocb) | |
7674 | lpfc_sli_update_ring(phba, pring); | |
7675 | else | |
7676 | lpfc_sli_update_full_ring(phba, pring); | |
7677 | ||
7678 | if (!piocb) | |
7679 | return IOCB_SUCCESS; | |
7680 | ||
7681 | goto out_busy; | |
7682 | ||
7683 | iocb_busy: | |
7684 | pring->stats.iocb_cmd_delay++; | |
7685 | ||
7686 | out_busy: | |
7687 | ||
7688 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 7689 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
7690 | return IOCB_SUCCESS; |
7691 | } | |
7692 | ||
7693 | return IOCB_BUSY; | |
7694 | } | |
7695 | ||
3772a991 | 7696 | /** |
4f774513 JS |
7697 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
7698 | * @phba: Pointer to HBA context object. | |
7699 | * @piocb: Pointer to command iocb. | |
7700 | * @sglq: Pointer to the scatter gather queue object. | |
7701 | * | |
7702 | * This routine converts the bpl or bde that is in the IOCB | |
7703 | * to a sgl list for the sli4 hardware. The physical address | |
7704 | * of the bpl/bde is converted back to a virtual address. | |
7705 | * If the IOCB contains a BPL then the list of BDE's is | |
7706 | * converted to sli4_sge's. If the IOCB contains a single | |
7707 | * BDE then it is converted to a single sli_sge. | |
7708 | * The IOCB is still in cpu endianess so the contents of | |
7709 | * the bpl can be used without byte swapping. | |
7710 | * | |
7711 | * Returns valid XRI = Success, NO_XRI = Failure. | |
7712 | **/ | |
7713 | static uint16_t | |
7714 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
7715 | struct lpfc_sglq *sglq) | |
3772a991 | 7716 | { |
4f774513 JS |
7717 | uint16_t xritag = NO_XRI; |
7718 | struct ulp_bde64 *bpl = NULL; | |
7719 | struct ulp_bde64 bde; | |
7720 | struct sli4_sge *sgl = NULL; | |
1b51197d | 7721 | struct lpfc_dmabuf *dmabuf; |
4f774513 JS |
7722 | IOCB_t *icmd; |
7723 | int numBdes = 0; | |
7724 | int i = 0; | |
63e801ce JS |
7725 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
7726 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 7727 | |
4f774513 JS |
7728 | if (!piocbq || !sglq) |
7729 | return xritag; | |
7730 | ||
7731 | sgl = (struct sli4_sge *)sglq->sgl; | |
7732 | icmd = &piocbq->iocb; | |
6b5151fd JS |
7733 | if (icmd->ulpCommand == CMD_XMIT_BLS_RSP64_CX) |
7734 | return sglq->sli4_xritag; | |
4f774513 JS |
7735 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { |
7736 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
7737 | sizeof(struct ulp_bde64); | |
7738 | /* The addrHigh and addrLow fields within the IOCB | |
7739 | * have not been byteswapped yet so there is no | |
7740 | * need to swap them back. | |
7741 | */ | |
1b51197d JS |
7742 | if (piocbq->context3) |
7743 | dmabuf = (struct lpfc_dmabuf *)piocbq->context3; | |
7744 | else | |
7745 | return xritag; | |
4f774513 | 7746 | |
1b51197d | 7747 | bpl = (struct ulp_bde64 *)dmabuf->virt; |
4f774513 JS |
7748 | if (!bpl) |
7749 | return xritag; | |
7750 | ||
7751 | for (i = 0; i < numBdes; i++) { | |
7752 | /* Should already be byte swapped. */ | |
28baac74 JS |
7753 | sgl->addr_hi = bpl->addrHigh; |
7754 | sgl->addr_lo = bpl->addrLow; | |
7755 | ||
0558056c | 7756 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7757 | if ((i+1) == numBdes) |
7758 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
7759 | else | |
7760 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
7761 | /* swap the size field back to the cpu so we |
7762 | * can assign it to the sgl. | |
7763 | */ | |
7764 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
7765 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
7766 | /* The offsets in the sgl need to be accumulated |
7767 | * separately for the request and reply lists. | |
7768 | * The request is always first, the reply follows. | |
7769 | */ | |
7770 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
7771 | /* add up the reply sg entries */ | |
7772 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
7773 | inbound++; | |
7774 | /* first inbound? reset the offset */ | |
7775 | if (inbound == 1) | |
7776 | offset = 0; | |
7777 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
f9bb2da1 JS |
7778 | bf_set(lpfc_sli4_sge_type, sgl, |
7779 | LPFC_SGE_TYPE_DATA); | |
63e801ce JS |
7780 | offset += bde.tus.f.bdeSize; |
7781 | } | |
546fc854 | 7782 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
7783 | bpl++; |
7784 | sgl++; | |
7785 | } | |
7786 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
7787 | /* The addrHigh and addrLow fields of the BDE have not | |
7788 | * been byteswapped yet so they need to be swapped | |
7789 | * before putting them in the sgl. | |
7790 | */ | |
7791 | sgl->addr_hi = | |
7792 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
7793 | sgl->addr_lo = | |
7794 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 7795 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7796 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
7797 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
7798 | sgl->sge_len = |
7799 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
7800 | } |
7801 | return sglq->sli4_xritag; | |
3772a991 | 7802 | } |
92d7f7b0 | 7803 | |
e59058c4 | 7804 | /** |
4f774513 | 7805 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 7806 | * @phba: Pointer to HBA context object. |
e59058c4 | 7807 | * |
a93ff37a | 7808 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
7809 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
7810 | * held. | |
4f774513 JS |
7811 | * |
7812 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 7813 | **/ |
2a76a283 | 7814 | static inline uint32_t |
8fa38513 | 7815 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 7816 | { |
2a76a283 | 7817 | int i; |
92d7f7b0 | 7818 | |
49aa143d JS |
7819 | if (phba->cfg_fcp_io_sched == LPFC_FCP_SCHED_BY_CPU) |
7820 | i = smp_processor_id(); | |
7821 | else | |
7822 | i = atomic_add_return(1, &phba->fcp_qidx); | |
7823 | ||
67d12733 | 7824 | i = (i % phba->cfg_fcp_io_channel); |
2a76a283 | 7825 | return i; |
92d7f7b0 JS |
7826 | } |
7827 | ||
e59058c4 | 7828 | /** |
4f774513 | 7829 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 7830 | * @phba: Pointer to HBA context object. |
4f774513 JS |
7831 | * @piocb: Pointer to command iocb. |
7832 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 7833 | * |
4f774513 JS |
7834 | * This routine converts the iocb command to its Work Queue Entry |
7835 | * equivalent. The wqe pointer should not have any fields set when | |
7836 | * this routine is called because it will memcpy over them. | |
7837 | * This routine does not set the CQ_ID or the WQEC bits in the | |
7838 | * wqe. | |
e59058c4 | 7839 | * |
4f774513 | 7840 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 7841 | **/ |
cf5bf97e | 7842 | static int |
4f774513 JS |
7843 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
7844 | union lpfc_wqe *wqe) | |
cf5bf97e | 7845 | { |
5ffc266e | 7846 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
7847 | uint8_t ct = 0; |
7848 | uint32_t fip; | |
7849 | uint32_t abort_tag; | |
7850 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
7851 | uint8_t cmnd; | |
7852 | uint16_t xritag; | |
dcf2a4e0 JS |
7853 | uint16_t abrt_iotag; |
7854 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 7855 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 7856 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
7857 | int numBdes, i; |
7858 | struct ulp_bde64 bde; | |
c31098ce | 7859 | struct lpfc_nodelist *ndlp; |
ff78d8f9 | 7860 | uint32_t *pcmd; |
1b51197d | 7861 | uint32_t if_type; |
4f774513 | 7862 | |
45ed1190 | 7863 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 7864 | /* The fcp commands will set command type */ |
0c287589 | 7865 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 7866 | command_type = FCP_COMMAND; |
c868595d | 7867 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
7868 | command_type = ELS_COMMAND_FIP; |
7869 | else | |
7870 | command_type = ELS_COMMAND_NON_FIP; | |
7871 | ||
4f774513 JS |
7872 | /* Some of the fields are in the right position already */ |
7873 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
7874 | abort_tag = (uint32_t) iocbq->iotag; | |
7875 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 7876 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
7877 | /* words0-2 bpl convert bde */ |
7878 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
7879 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
7880 | sizeof(struct ulp_bde64); | |
4f774513 JS |
7881 | bpl = (struct ulp_bde64 *) |
7882 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
7883 | if (!bpl) | |
7884 | return IOCB_ERROR; | |
cf5bf97e | 7885 | |
4f774513 JS |
7886 | /* Should already be byte swapped. */ |
7887 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
7888 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
7889 | /* swap the size field back to the cpu so we | |
7890 | * can assign it to the sgl. | |
7891 | */ | |
7892 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
7893 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
7894 | total_len = 0; | |
7895 | for (i = 0; i < numBdes; i++) { | |
7896 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
7897 | total_len += bde.tus.f.bdeSize; | |
7898 | } | |
4f774513 | 7899 | } else |
5ffc266e | 7900 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 7901 | |
4f774513 JS |
7902 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
7903 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 7904 | |
4f774513 JS |
7905 | switch (iocbq->iocb.ulpCommand) { |
7906 | case CMD_ELS_REQUEST64_CR: | |
93d1379e JS |
7907 | if (iocbq->iocb_flag & LPFC_IO_LIBDFC) |
7908 | ndlp = iocbq->context_un.ndlp; | |
7909 | else | |
7910 | ndlp = (struct lpfc_nodelist *)iocbq->context1; | |
4f774513 JS |
7911 | if (!iocbq->iocb.ulpLe) { |
7912 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7913 | "2007 Only Limited Edition cmd Format" | |
7914 | " supported 0x%x\n", | |
7915 | iocbq->iocb.ulpCommand); | |
7916 | return IOCB_ERROR; | |
7917 | } | |
ff78d8f9 | 7918 | |
5ffc266e | 7919 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
7920 | /* Els_reguest64 has a TMO */ |
7921 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
7922 | iocbq->iocb.ulpTimeout); | |
7923 | /* Need a VF for word 4 set the vf bit*/ | |
7924 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
7925 | /* And a VFID for word 12 */ | |
7926 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 7927 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
7928 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
7929 | iocbq->iocb.ulpContext); | |
7930 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
7931 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 7932 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
ff78d8f9 | 7933 | if (command_type == ELS_COMMAND_FIP) |
c868595d JS |
7934 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
7935 | >> LPFC_FIP_ELS_ID_SHIFT); | |
ff78d8f9 JS |
7936 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
7937 | iocbq->context2)->virt); | |
1b51197d JS |
7938 | if_type = bf_get(lpfc_sli_intf_if_type, |
7939 | &phba->sli4_hba.sli_intf); | |
7940 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
ff78d8f9 | 7941 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || |
cb69f7de | 7942 | *pcmd == ELS_CMD_SCR || |
6b5151fd | 7943 | *pcmd == ELS_CMD_FDISC || |
bdcd2b92 | 7944 | *pcmd == ELS_CMD_LOGO || |
ff78d8f9 JS |
7945 | *pcmd == ELS_CMD_PLOGI)) { |
7946 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
7947 | bf_set(els_req64_sid, &wqe->els_req, | |
7948 | iocbq->vport->fc_myDID); | |
939723a4 JS |
7949 | if ((*pcmd == ELS_CMD_FLOGI) && |
7950 | !(phba->fc_topology == | |
7951 | LPFC_TOPOLOGY_LOOP)) | |
7952 | bf_set(els_req64_sid, &wqe->els_req, 0); | |
ff78d8f9 JS |
7953 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); |
7954 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
a7dd9c0f | 7955 | phba->vpi_ids[iocbq->vport->vpi]); |
3ef6d24c | 7956 | } else if (pcmd && iocbq->context1) { |
ff78d8f9 JS |
7957 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); |
7958 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
7959 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
7960 | } | |
c868595d | 7961 | } |
6d368e53 JS |
7962 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
7963 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
7964 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
7965 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
7966 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
7967 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
7968 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
7969 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
7851fe2c | 7970 | break; |
5ffc266e | 7971 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
7972 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
7973 | iocbq->iocb.un.ulpWord[3]); | |
7974 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7851fe2c | 7975 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
5ffc266e JS |
7976 | /* The entire sequence is transmitted for this IOCB */ |
7977 | xmit_len = total_len; | |
7978 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
1b51197d JS |
7979 | if (phba->link_flag & LS_LOOPBACK_MODE) |
7980 | bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1); | |
4f774513 | 7981 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
7982 | /* word3 iocb=io_tag32 wqe=reserved */ |
7983 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
7984 | /* word4 relative_offset memcpy */ |
7985 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
7986 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
7987 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
7988 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
7989 | LPFC_WQE_IOD_WRITE); | |
7990 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
7991 | LPFC_WQE_LENLOC_WORD12); | |
7992 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
7993 | wqe->xmit_sequence.xmit_len = xmit_len; |
7994 | command_type = OTHER_COMMAND; | |
7851fe2c | 7995 | break; |
4f774513 | 7996 | case CMD_XMIT_BCAST64_CN: |
f0d9bccc JS |
7997 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
7998 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
7999 | /* word4 iocb=rsvd wqe=rsvd */ |
8000 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
8001 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 8002 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 8003 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
8004 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
8005 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
8006 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
8007 | LPFC_WQE_LENLOC_WORD3); | |
8008 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
7851fe2c | 8009 | break; |
4f774513 JS |
8010 | case CMD_FCP_IWRITE64_CR: |
8011 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
8012 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8013 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
8014 | wqe->fcp_iwrite.payload_offset_len = | |
8015 | xmit_len + sizeof(struct fcp_rsp); | |
8016 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
8017 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8018 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
8019 | iocbq->iocb.ulpFCP2Rcvy); | |
8020 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
8021 | /* Always open the exchange */ | |
8022 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
f0d9bccc JS |
8023 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); |
8024 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
8025 | LPFC_WQE_LENLOC_WORD4); | |
8026 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
8027 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
acd6859b JS |
8028 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
8029 | iocbq->iocb_flag &= ~LPFC_IO_DIF; | |
8030 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); | |
8031 | } | |
8032 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
7851fe2c | 8033 | break; |
4f774513 | 8034 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
8035 | /* word3 iocb=iotag wqe=payload_offset_len */ |
8036 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
8037 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 8038 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
8039 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
8040 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
8041 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
8042 | iocbq->iocb.ulpFCP2Rcvy); | |
8043 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
8044 | /* Always open the exchange */ |
8045 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
8046 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); |
8047 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
8048 | LPFC_WQE_LENLOC_WORD4); | |
8049 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
8050 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
acd6859b JS |
8051 | if (iocbq->iocb_flag & LPFC_IO_DIF) { |
8052 | iocbq->iocb_flag &= ~LPFC_IO_DIF; | |
8053 | bf_set(wqe_dif, &wqe->generic.wqe_com, 1); | |
8054 | } | |
8055 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); | |
7851fe2c | 8056 | break; |
4f774513 | 8057 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
8058 | /* word3 iocb=IO_TAG wqe=reserved */ |
8059 | wqe->fcp_icmd.rsrvd3 = 0; | |
8060 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 8061 | /* Always open the exchange */ |
f0d9bccc JS |
8062 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
8063 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
8064 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
8065 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
8066 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
8067 | LPFC_WQE_LENLOC_NONE); | |
8068 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
7851fe2c | 8069 | break; |
4f774513 | 8070 | case CMD_GEN_REQUEST64_CR: |
63e801ce JS |
8071 | /* For this command calculate the xmit length of the |
8072 | * request bde. | |
8073 | */ | |
8074 | xmit_len = 0; | |
8075 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
8076 | sizeof(struct ulp_bde64); | |
8077 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 8078 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
8079 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
8080 | break; | |
63e801ce JS |
8081 | xmit_len += bde.tus.f.bdeSize; |
8082 | } | |
f0d9bccc JS |
8083 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
8084 | wqe->gen_req.request_payload_len = xmit_len; | |
8085 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
8086 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
8087 | /* word6 context tag copied in memcpy */ |
8088 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
8089 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
8090 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8091 | "2015 Invalid CT %x command 0x%x\n", | |
8092 | ct, iocbq->iocb.ulpCommand); | |
8093 | return IOCB_ERROR; | |
8094 | } | |
f0d9bccc JS |
8095 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
8096 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
8097 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
8098 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
8099 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
8100 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
8101 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
8102 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 | 8103 | command_type = OTHER_COMMAND; |
7851fe2c | 8104 | break; |
4f774513 | 8105 | case CMD_XMIT_ELS_RSP64_CX: |
c31098ce | 8106 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 8107 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
8108 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
8109 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
939723a4 JS |
8110 | /* word4 */ |
8111 | wqe->xmit_els_rsp.word4 = 0; | |
4f774513 JS |
8112 | /* word5 iocb=rsvd wge=did */ |
8113 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
939723a4 JS |
8114 | iocbq->iocb.un.xseq64.xmit_els_remoteID); |
8115 | ||
8116 | if_type = bf_get(lpfc_sli_intf_if_type, | |
8117 | &phba->sli4_hba.sli_intf); | |
8118 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
8119 | if (iocbq->vport->fc_flag & FC_PT2PT) { | |
8120 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); | |
8121 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
8122 | iocbq->vport->fc_myDID); | |
8123 | if (iocbq->vport->fc_myDID == Fabric_DID) { | |
8124 | bf_set(wqe_els_did, | |
8125 | &wqe->xmit_els_rsp.wqe_dest, 0); | |
8126 | } | |
8127 | } | |
8128 | } | |
f0d9bccc JS |
8129 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
8130 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
8131 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
8132 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7851fe2c | 8133 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
4f774513 | 8134 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 8135 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 8136 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
8137 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
8138 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
8139 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
8140 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
8141 | LPFC_WQE_LENLOC_WORD3); | |
8142 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
8143 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
8144 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
ff78d8f9 JS |
8145 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
8146 | iocbq->context2)->virt); | |
8147 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
939723a4 JS |
8148 | bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1); |
8149 | bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, | |
ff78d8f9 | 8150 | iocbq->vport->fc_myDID); |
939723a4 JS |
8151 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1); |
8152 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, | |
ff78d8f9 JS |
8153 | phba->vpi_ids[phba->pport->vpi]); |
8154 | } | |
4f774513 | 8155 | command_type = OTHER_COMMAND; |
7851fe2c | 8156 | break; |
4f774513 JS |
8157 | case CMD_CLOSE_XRI_CN: |
8158 | case CMD_ABORT_XRI_CN: | |
8159 | case CMD_ABORT_XRI_CX: | |
8160 | /* words 0-2 memcpy should be 0 rserved */ | |
8161 | /* port will send abts */ | |
dcf2a4e0 JS |
8162 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
8163 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
8164 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
8165 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
8166 | } else | |
8167 | fip = 0; | |
8168 | ||
8169 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 8170 | /* |
dcf2a4e0 JS |
8171 | * The link is down, or the command was ELS_FIP |
8172 | * so the fw does not need to send abts | |
4f774513 JS |
8173 | * on the wire. |
8174 | */ | |
8175 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
8176 | else | |
8177 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
8178 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
8179 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
8180 | wqe->abort_cmd.rsrvd5 = 0; | |
8181 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
8182 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
8183 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
8184 | /* |
8185 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
8186 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
8187 | */ | |
f0d9bccc JS |
8188 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
8189 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
8190 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
8191 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
8192 | cmnd = CMD_ABORT_XRI_CX; |
8193 | command_type = OTHER_COMMAND; | |
8194 | xritag = 0; | |
7851fe2c | 8195 | break; |
6669f9bb | 8196 | case CMD_XMIT_BLS_RSP64_CX: |
6b5151fd | 8197 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
546fc854 | 8198 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
8199 | * we re-construct this WQE here based on information in |
8200 | * iocbq from scratch. | |
8201 | */ | |
8202 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 8203 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 8204 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
8205 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
8206 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
8207 | LPFC_ABTS_UNSOL_INT) { |
8208 | /* ABTS sent by initiator to CT exchange, the | |
8209 | * RX_ID field will be filled with the newly | |
8210 | * allocated responder XRI. | |
8211 | */ | |
8212 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
8213 | iocbq->sli4_xritag); | |
8214 | } else { | |
8215 | /* ABTS sent by responder to CT exchange, the | |
8216 | * RX_ID field will be filled with the responder | |
8217 | * RX_ID from ABTS. | |
8218 | */ | |
8219 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 8220 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 8221 | } |
6669f9bb JS |
8222 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
8223 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6b5151fd JS |
8224 | |
8225 | /* Use CT=VPI */ | |
8226 | bf_set(wqe_els_did, &wqe->xmit_bls_rsp.wqe_dest, | |
8227 | ndlp->nlp_DID); | |
8228 | bf_set(xmit_bls_rsp64_temprpi, &wqe->xmit_bls_rsp, | |
8229 | iocbq->iocb.ulpContext); | |
8230 | bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1); | |
6669f9bb | 8231 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, |
6b5151fd | 8232 | phba->vpi_ids[phba->pport->vpi]); |
f0d9bccc JS |
8233 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
8234 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
8235 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
8236 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
8237 | command_type = OTHER_COMMAND; | |
546fc854 JS |
8238 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
8239 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
8240 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
8241 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
8242 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
8243 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
8244 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
8245 | } | |
8246 | ||
7851fe2c | 8247 | break; |
4f774513 JS |
8248 | case CMD_XRI_ABORTED_CX: |
8249 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
8250 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
8251 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
8252 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
8253 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
8254 | default: | |
8255 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8256 | "2014 Invalid command 0x%x\n", | |
8257 | iocbq->iocb.ulpCommand); | |
8258 | return IOCB_ERROR; | |
7851fe2c | 8259 | break; |
4f774513 | 8260 | } |
6d368e53 | 8261 | |
f0d9bccc JS |
8262 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
8263 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
8264 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
8265 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
8266 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
8267 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
8268 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
8269 | return 0; |
8270 | } | |
8271 | ||
8272 | /** | |
8273 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
8274 | * @phba: Pointer to HBA context object. | |
8275 | * @ring_number: SLI ring number to issue iocb on. | |
8276 | * @piocb: Pointer to command iocb. | |
8277 | * @flag: Flag indicating if this command can be put into txq. | |
8278 | * | |
8279 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
8280 | * an iocb command to an HBA with SLI-4 interface spec. | |
8281 | * | |
8282 | * This function is called with hbalock held. The function will return success | |
8283 | * after it successfully submit the iocb to firmware or after adding to the | |
8284 | * txq. | |
8285 | **/ | |
8286 | static int | |
8287 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
8288 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8289 | { | |
8290 | struct lpfc_sglq *sglq; | |
4f774513 JS |
8291 | union lpfc_wqe wqe; |
8292 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
8293 | |
8294 | if (piocb->sli4_xritag == NO_XRI) { | |
8295 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6b5151fd | 8296 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
8297 | sglq = NULL; |
8298 | else { | |
2a9bf3d0 JS |
8299 | if (pring->txq_cnt) { |
8300 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8301 | __lpfc_sli_ringtx_put(phba, | |
8302 | pring, piocb); | |
8303 | return IOCB_SUCCESS; | |
8304 | } else { | |
8305 | return IOCB_BUSY; | |
8306 | } | |
8307 | } else { | |
6d368e53 | 8308 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
8309 | if (!sglq) { |
8310 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8311 | __lpfc_sli_ringtx_put(phba, | |
8312 | pring, | |
8313 | piocb); | |
8314 | return IOCB_SUCCESS; | |
8315 | } else | |
8316 | return IOCB_BUSY; | |
8317 | } | |
8318 | } | |
4f774513 JS |
8319 | } |
8320 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6d368e53 JS |
8321 | /* These IO's already have an XRI and a mapped sgl. */ |
8322 | sglq = NULL; | |
4f774513 | 8323 | } else { |
6d368e53 JS |
8324 | /* |
8325 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
8326 | * sglq is on the active list |
8327 | */ | |
8328 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
8329 | if (!sglq) | |
8330 | return IOCB_ERROR; | |
8331 | } | |
8332 | ||
8333 | if (sglq) { | |
6d368e53 | 8334 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 8335 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 8336 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
8337 | return IOCB_ERROR; |
8338 | } | |
8339 | ||
8340 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
8341 | return IOCB_ERROR; | |
8342 | ||
341af102 JS |
8343 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
8344 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
8345 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], |
8346 | &wqe)) | |
4f774513 JS |
8347 | return IOCB_ERROR; |
8348 | } else { | |
8349 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
8350 | return IOCB_ERROR; | |
8351 | } | |
8352 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
8353 | ||
8354 | return 0; | |
8355 | } | |
8356 | ||
8357 | /** | |
8358 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
8359 | * | |
8360 | * This routine wraps the actual lockless version for issusing IOCB function | |
8361 | * pointer from the lpfc_hba struct. | |
8362 | * | |
8363 | * Return codes: | |
8364 | * IOCB_ERROR - Error | |
8365 | * IOCB_SUCCESS - Success | |
8366 | * IOCB_BUSY - Busy | |
8367 | **/ | |
2a9bf3d0 | 8368 | int |
4f774513 JS |
8369 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
8370 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8371 | { | |
8372 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8373 | } | |
8374 | ||
8375 | /** | |
25985edc | 8376 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
8377 | * @phba: The hba struct for which this call is being executed. |
8378 | * @dev_grp: The HBA PCI-Device group number. | |
8379 | * | |
8380 | * This routine sets up the SLI interface API function jump table in @phba | |
8381 | * struct. | |
8382 | * Returns: 0 - success, -ENODEV - failure. | |
8383 | **/ | |
8384 | int | |
8385 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
8386 | { | |
8387 | ||
8388 | switch (dev_grp) { | |
8389 | case LPFC_PCI_DEV_LP: | |
8390 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
8391 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
8392 | break; | |
8393 | case LPFC_PCI_DEV_OC: | |
8394 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
8395 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
8396 | break; | |
8397 | default: | |
8398 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8399 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
8400 | dev_grp); | |
8401 | return -ENODEV; | |
8402 | break; | |
8403 | } | |
8404 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
8405 | return 0; | |
8406 | } | |
8407 | ||
8408 | /** | |
8409 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
8410 | * @phba: Pointer to HBA context object. | |
8411 | * @pring: Pointer to driver SLI ring object. | |
8412 | * @piocb: Pointer to command iocb. | |
8413 | * @flag: Flag indicating if this command can be put into txq. | |
8414 | * | |
8415 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
8416 | * function. This function gets the hbalock and calls | |
8417 | * __lpfc_sli_issue_iocb function and will return the error returned | |
8418 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
8419 | * functions which do not hold hbalock. | |
8420 | **/ | |
8421 | int | |
8422 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
8423 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8424 | { | |
2a76a283 | 8425 | struct lpfc_sli_ring *pring; |
4f774513 | 8426 | unsigned long iflags; |
2a76a283 | 8427 | int rc, idx; |
4f774513 | 8428 | |
7e56aa25 | 8429 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2a76a283 JS |
8430 | if (piocb->iocb_flag & LPFC_IO_FCP) { |
8431 | if (unlikely(!phba->sli4_hba.fcp_wq)) | |
8432 | return IOCB_ERROR; | |
8433 | idx = lpfc_sli4_scmd_to_wqidx_distr(phba); | |
8434 | piocb->fcp_wqidx = idx; | |
8435 | ring_number = MAX_SLI3_CONFIGURED_RINGS + idx; | |
8436 | } | |
7e56aa25 JS |
8437 | pring = &phba->sli.ring[ring_number]; |
8438 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
8439 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8440 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
8441 | } else { | |
8442 | /* For now, SLI2/3 will still use hbalock */ | |
8443 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8444 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8445 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8446 | } | |
4f774513 JS |
8447 | return rc; |
8448 | } | |
8449 | ||
8450 | /** | |
8451 | * lpfc_extra_ring_setup - Extra ring setup function | |
8452 | * @phba: Pointer to HBA context object. | |
8453 | * | |
8454 | * This function is called while driver attaches with the | |
8455 | * HBA to setup the extra ring. The extra ring is used | |
8456 | * only when driver needs to support target mode functionality | |
8457 | * or IP over FC functionalities. | |
8458 | * | |
8459 | * This function is called with no lock held. | |
8460 | **/ | |
8461 | static int | |
8462 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
8463 | { | |
8464 | struct lpfc_sli *psli; | |
8465 | struct lpfc_sli_ring *pring; | |
8466 | ||
8467 | psli = &phba->sli; | |
8468 | ||
8469 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
8470 | ||
8471 | /* Take some away from the FCP ring */ | |
8472 | pring = &psli->ring[psli->fcp_ring]; | |
7e56aa25 JS |
8473 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8474 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8475 | pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8476 | pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e | 8477 | |
a4bc3379 JS |
8478 | /* and give them to the extra ring */ |
8479 | pring = &psli->ring[psli->extra_ring]; | |
8480 | ||
7e56aa25 JS |
8481 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8482 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8483 | pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8484 | pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
cf5bf97e JW |
8485 | |
8486 | /* Setup default profile for this ring */ | |
8487 | pring->iotag_max = 4096; | |
8488 | pring->num_mask = 1; | |
8489 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
8490 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
8491 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
8492 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
8493 | return 0; | |
8494 | } | |
8495 | ||
cb69f7de JS |
8496 | /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS. |
8497 | * @vport: pointer to virtual port object. | |
8498 | * @ndlp: nodelist pointer for the impacted rport. | |
8499 | * | |
8500 | * The driver calls this routine in response to a XRI ABORT CQE | |
8501 | * event from the port. In this event, the driver is required to | |
8502 | * recover its login to the rport even though its login may be valid | |
8503 | * from the driver's perspective. The failed ABTS notice from the | |
8504 | * port indicates the rport is not responding. | |
8505 | */ | |
8506 | static void | |
8507 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, | |
8508 | struct lpfc_nodelist *ndlp) | |
8509 | { | |
8510 | struct Scsi_Host *shost; | |
8511 | struct lpfc_hba *phba; | |
8512 | unsigned long flags = 0; | |
8513 | ||
8514 | shost = lpfc_shost_from_vport(vport); | |
8515 | phba = vport->phba; | |
8516 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { | |
8517 | lpfc_printf_log(phba, KERN_INFO, | |
8518 | LOG_SLI, "3093 No rport recovery needed. " | |
8519 | "rport in state 0x%x\n", | |
8520 | ndlp->nlp_state); | |
8521 | return; | |
8522 | } | |
8523 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8524 | "3094 Start rport recovery on shost id 0x%x " | |
8525 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " | |
8526 | "flags 0x%x\n", | |
8527 | shost->host_no, ndlp->nlp_DID, | |
8528 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, | |
8529 | ndlp->nlp_flag); | |
8530 | /* | |
8531 | * The rport is not responding. Don't attempt ADISC recovery. | |
8532 | * Remove the FCP-2 flag to force a PLOGI. | |
8533 | */ | |
8534 | spin_lock_irqsave(shost->host_lock, flags); | |
8535 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
8536 | spin_unlock_irqrestore(shost->host_lock, flags); | |
8537 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
8538 | NLP_EVT_DEVICE_RECOVERY); | |
8539 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
8540 | spin_lock_irqsave(shost->host_lock, flags); | |
8541 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
8542 | spin_unlock_irqrestore(shost->host_lock, flags); | |
8543 | lpfc_disc_start(vport); | |
8544 | } | |
8545 | ||
8546 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. | |
8547 | * @phba: Pointer to HBA context object. | |
8548 | * @iocbq: Pointer to iocb object. | |
8549 | * | |
8550 | * The async_event handler calls this routine when it receives | |
8551 | * an ASYNC_STATUS_CN event from the port. The port generates | |
8552 | * this event when an Abort Sequence request to an rport fails | |
8553 | * twice in succession. The abort could be originated by the | |
8554 | * driver or by the port. The ABTS could have been for an ELS | |
8555 | * or FCP IO. The port only generates this event when an ABTS | |
8556 | * fails to complete after one retry. | |
8557 | */ | |
8558 | static void | |
8559 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, | |
8560 | struct lpfc_iocbq *iocbq) | |
8561 | { | |
8562 | struct lpfc_nodelist *ndlp = NULL; | |
8563 | uint16_t rpi = 0, vpi = 0; | |
8564 | struct lpfc_vport *vport = NULL; | |
8565 | ||
8566 | /* The rpi in the ulpContext is vport-sensitive. */ | |
8567 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; | |
8568 | rpi = iocbq->iocb.ulpContext; | |
8569 | ||
8570 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8571 | "3092 Port generated ABTS async event " | |
8572 | "on vpi %d rpi %d status 0x%x\n", | |
8573 | vpi, rpi, iocbq->iocb.ulpStatus); | |
8574 | ||
8575 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
8576 | if (!vport) | |
8577 | goto err_exit; | |
8578 | ndlp = lpfc_findnode_rpi(vport, rpi); | |
8579 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
8580 | goto err_exit; | |
8581 | ||
8582 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | |
8583 | lpfc_sli_abts_recover_port(vport, ndlp); | |
8584 | return; | |
8585 | ||
8586 | err_exit: | |
8587 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8588 | "3095 Event Context not found, no " | |
8589 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", | |
8590 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, | |
8591 | vpi, rpi); | |
8592 | } | |
8593 | ||
8594 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. | |
8595 | * @phba: pointer to HBA context object. | |
8596 | * @ndlp: nodelist pointer for the impacted rport. | |
8597 | * @axri: pointer to the wcqe containing the failed exchange. | |
8598 | * | |
8599 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the | |
8600 | * port. The port generates this event when an abort exchange request to an | |
8601 | * rport fails twice in succession with no reply. The abort could be originated | |
8602 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. | |
8603 | */ | |
8604 | void | |
8605 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, | |
8606 | struct lpfc_nodelist *ndlp, | |
8607 | struct sli4_wcqe_xri_aborted *axri) | |
8608 | { | |
8609 | struct lpfc_vport *vport; | |
5c1db2ac | 8610 | uint32_t ext_status = 0; |
cb69f7de | 8611 | |
6b5151fd | 8612 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) { |
cb69f7de JS |
8613 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
8614 | "3115 Node Context not found, driver " | |
8615 | "ignoring abts err event\n"); | |
6b5151fd JS |
8616 | return; |
8617 | } | |
8618 | ||
cb69f7de JS |
8619 | vport = ndlp->vport; |
8620 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8621 | "3116 Port generated FCP XRI ABORT event on " | |
5c1db2ac | 8622 | "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n", |
cb69f7de JS |
8623 | ndlp->vport->vpi, ndlp->nlp_rpi, |
8624 | bf_get(lpfc_wcqe_xa_xri, axri), | |
5c1db2ac JS |
8625 | bf_get(lpfc_wcqe_xa_status, axri), |
8626 | axri->parameter); | |
cb69f7de | 8627 | |
5c1db2ac JS |
8628 | /* |
8629 | * Catch the ABTS protocol failure case. Older OCe FW releases returned | |
8630 | * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and | |
8631 | * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT. | |
8632 | */ | |
8633 | ext_status = axri->parameter & WCQE_PARAM_MASK; | |
8634 | if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) && | |
8635 | ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0))) | |
cb69f7de JS |
8636 | lpfc_sli_abts_recover_port(vport, ndlp); |
8637 | } | |
8638 | ||
e59058c4 | 8639 | /** |
3621a710 | 8640 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
8641 | * @phba: Pointer to HBA context object. |
8642 | * @pring: Pointer to driver SLI ring object. | |
8643 | * @iocbq: Pointer to iocb object. | |
8644 | * | |
8645 | * This function is called by the slow ring event handler | |
8646 | * function when there is an ASYNC event iocb in the ring. | |
8647 | * This function is called with no lock held. | |
8648 | * Currently this function handles only temperature related | |
8649 | * ASYNC events. The function decodes the temperature sensor | |
8650 | * event message and posts events for the management applications. | |
8651 | **/ | |
98c9ea5c | 8652 | static void |
57127f15 JS |
8653 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
8654 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
8655 | { | |
8656 | IOCB_t *icmd; | |
8657 | uint16_t evt_code; | |
57127f15 JS |
8658 | struct temp_event temp_event_data; |
8659 | struct Scsi_Host *shost; | |
a257bf90 | 8660 | uint32_t *iocb_w; |
57127f15 JS |
8661 | |
8662 | icmd = &iocbq->iocb; | |
8663 | evt_code = icmd->un.asyncstat.evt_code; | |
57127f15 | 8664 | |
cb69f7de JS |
8665 | switch (evt_code) { |
8666 | case ASYNC_TEMP_WARN: | |
8667 | case ASYNC_TEMP_SAFE: | |
8668 | temp_event_data.data = (uint32_t) icmd->ulpContext; | |
8669 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
8670 | if (evt_code == ASYNC_TEMP_WARN) { | |
8671 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
8672 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
8673 | "0347 Adapter is very hot, please take " | |
8674 | "corrective action. temperature : %d Celsius\n", | |
8675 | (uint32_t) icmd->ulpContext); | |
8676 | } else { | |
8677 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
8678 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
8679 | "0340 Adapter temperature is OK now. " | |
8680 | "temperature : %d Celsius\n", | |
8681 | (uint32_t) icmd->ulpContext); | |
8682 | } | |
8683 | ||
8684 | /* Send temperature change event to applications */ | |
8685 | shost = lpfc_shost_from_vport(phba->pport); | |
8686 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
8687 | sizeof(temp_event_data), (char *) &temp_event_data, | |
8688 | LPFC_NL_VENDOR_ID); | |
8689 | break; | |
8690 | case ASYNC_STATUS_CN: | |
8691 | lpfc_sli_abts_err_handler(phba, iocbq); | |
8692 | break; | |
8693 | default: | |
a257bf90 | 8694 | iocb_w = (uint32_t *) icmd; |
cb69f7de | 8695 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
76bb24ef | 8696 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 8697 | " evt_code 0x%x\n" |
a257bf90 JS |
8698 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
8699 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
8700 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
8701 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
cb69f7de | 8702 | pring->ringno, icmd->un.asyncstat.evt_code, |
a257bf90 JS |
8703 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
8704 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
8705 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
8706 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
8707 | ||
cb69f7de | 8708 | break; |
57127f15 | 8709 | } |
57127f15 JS |
8710 | } |
8711 | ||
8712 | ||
e59058c4 | 8713 | /** |
3621a710 | 8714 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
8715 | * @phba: Pointer to HBA context object. |
8716 | * | |
8717 | * lpfc_sli_setup sets up rings of the SLI interface with | |
8718 | * number of iocbs per ring and iotags. This function is | |
8719 | * called while driver attach to the HBA and before the | |
8720 | * interrupts are enabled. So there is no need for locking. | |
8721 | * | |
8722 | * This function always returns 0. | |
8723 | **/ | |
dea3101e JB |
8724 | int |
8725 | lpfc_sli_setup(struct lpfc_hba *phba) | |
8726 | { | |
ed957684 | 8727 | int i, totiocbsize = 0; |
dea3101e JB |
8728 | struct lpfc_sli *psli = &phba->sli; |
8729 | struct lpfc_sli_ring *pring; | |
8730 | ||
2a76a283 JS |
8731 | psli->num_rings = MAX_SLI3_CONFIGURED_RINGS; |
8732 | if (phba->sli_rev == LPFC_SLI_REV4) | |
67d12733 | 8733 | psli->num_rings += phba->cfg_fcp_io_channel; |
dea3101e JB |
8734 | psli->sli_flag = 0; |
8735 | psli->fcp_ring = LPFC_FCP_RING; | |
8736 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 8737 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 8738 | |
604a3e30 JB |
8739 | psli->iocbq_lookup = NULL; |
8740 | psli->iocbq_lookup_len = 0; | |
8741 | psli->last_iotag = 0; | |
8742 | ||
dea3101e JB |
8743 | for (i = 0; i < psli->num_rings; i++) { |
8744 | pring = &psli->ring[i]; | |
8745 | switch (i) { | |
8746 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
8747 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
8748 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; |
8749 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
8750 | pring->sli.sli3.numCiocb += | |
8751 | SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
8752 | pring->sli.sli3.numRiocb += | |
8753 | SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8754 | pring->sli.sli3.numCiocb += | |
8755 | SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8756 | pring->sli.sli3.numRiocb += | |
8757 | SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
8758 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
8759 | SLI3_IOCB_CMD_SIZE : |
8760 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 8761 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8762 | SLI3_IOCB_RSP_SIZE : |
8763 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
8764 | pring->iotag_ctr = 0; |
8765 | pring->iotag_max = | |
92d7f7b0 | 8766 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
8767 | pring->fast_iotag = pring->iotag_max; |
8768 | pring->num_mask = 0; | |
8769 | break; | |
a4bc3379 | 8770 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 8771 | /* numCiocb and numRiocb are used in config_port */ |
7e56aa25 JS |
8772 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; |
8773 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
8774 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
8775 | SLI3_IOCB_CMD_SIZE : |
8776 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 8777 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8778 | SLI3_IOCB_RSP_SIZE : |
8779 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 8780 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
8781 | pring->num_mask = 0; |
8782 | break; | |
8783 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
8784 | /* numCiocb and numRiocb are used in config_port */ | |
7e56aa25 JS |
8785 | pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; |
8786 | pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
8787 | pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ? | |
92d7f7b0 JS |
8788 | SLI3_IOCB_CMD_SIZE : |
8789 | SLI2_IOCB_CMD_SIZE; | |
7e56aa25 | 8790 | pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8791 | SLI3_IOCB_RSP_SIZE : |
8792 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
8793 | pring->fast_iotag = 0; |
8794 | pring->iotag_ctr = 0; | |
8795 | pring->iotag_max = 4096; | |
57127f15 JS |
8796 | pring->lpfc_sli_rcv_async_status = |
8797 | lpfc_sli_async_event_handler; | |
6669f9bb | 8798 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 8799 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
8800 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
8801 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 8802 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8803 | lpfc_els_unsol_event; |
dea3101e | 8804 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
8805 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
8806 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 8807 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8808 | lpfc_els_unsol_event; |
dea3101e JB |
8809 | pring->prt[2].profile = 0; /* Mask 2 */ |
8810 | /* NameServer Inquiry */ | |
6a9c52cf | 8811 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 8812 | /* NameServer */ |
6a9c52cf | 8813 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 8814 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8815 | lpfc_ct_unsol_event; |
dea3101e JB |
8816 | pring->prt[3].profile = 0; /* Mask 3 */ |
8817 | /* NameServer response */ | |
6a9c52cf | 8818 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 8819 | /* NameServer */ |
6a9c52cf | 8820 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 8821 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8822 | lpfc_ct_unsol_event; |
6669f9bb JS |
8823 | /* abort unsolicited sequence */ |
8824 | pring->prt[4].profile = 0; /* Mask 4 */ | |
8825 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
8826 | pring->prt[4].type = FC_TYPE_BLS; | |
8827 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
8828 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e JB |
8829 | break; |
8830 | } | |
7e56aa25 JS |
8831 | totiocbsize += (pring->sli.sli3.numCiocb * |
8832 | pring->sli.sli3.sizeCiocb) + | |
8833 | (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb); | |
dea3101e | 8834 | } |
ed957684 | 8835 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 8836 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
8837 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
8838 | "SLI2 SLIM Data: x%x x%lx\n", | |
8839 | phba->brd_no, totiocbsize, | |
8840 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 8841 | } |
cf5bf97e JW |
8842 | if (phba->cfg_multi_ring_support == 2) |
8843 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
8844 | |
8845 | return 0; | |
8846 | } | |
8847 | ||
e59058c4 | 8848 | /** |
3621a710 | 8849 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
8850 | * @phba: Pointer to HBA context object. |
8851 | * | |
8852 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
8853 | * ring. This function also initializes ring indices of each ring. | |
8854 | * This function is called during the initialization of the SLI | |
8855 | * interface of an HBA. | |
8856 | * This function is called with no lock held and always returns | |
8857 | * 1. | |
8858 | **/ | |
dea3101e | 8859 | int |
2e0fef85 | 8860 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
8861 | { |
8862 | struct lpfc_sli *psli; | |
8863 | struct lpfc_sli_ring *pring; | |
604a3e30 | 8864 | int i; |
dea3101e JB |
8865 | |
8866 | psli = &phba->sli; | |
2e0fef85 | 8867 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8868 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 8869 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
8870 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
8871 | for (i = 0; i < psli->num_rings; i++) { | |
8872 | pring = &psli->ring[i]; | |
8873 | pring->ringno = i; | |
7e56aa25 JS |
8874 | pring->sli.sli3.next_cmdidx = 0; |
8875 | pring->sli.sli3.local_getidx = 0; | |
8876 | pring->sli.sli3.cmdidx = 0; | |
dea3101e JB |
8877 | INIT_LIST_HEAD(&pring->txq); |
8878 | INIT_LIST_HEAD(&pring->txcmplq); | |
8879 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 8880 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 8881 | INIT_LIST_HEAD(&pring->postbufq); |
7e56aa25 | 8882 | spin_lock_init(&pring->ring_lock); |
dea3101e | 8883 | } |
2e0fef85 JS |
8884 | spin_unlock_irq(&phba->hbalock); |
8885 | return 1; | |
dea3101e JB |
8886 | } |
8887 | ||
04c68496 JS |
8888 | /** |
8889 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
8890 | * @phba: Pointer to HBA context object. | |
8891 | * | |
8892 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
8893 | * flush all the mailbox commands in the three possible stages in the mailbox | |
8894 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
8895 | * command; and completed mailbox command queue. It is caller's responsibility | |
8896 | * to make sure that the driver is in the proper state to flush the mailbox | |
8897 | * command sub-system. Namely, the posting of mailbox commands into the | |
8898 | * pending mailbox command queue from the various clients must be stopped; | |
8899 | * either the HBA is in a state that it will never works on the outstanding | |
8900 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
8901 | * mailbox command has been completed. | |
8902 | **/ | |
8903 | static void | |
8904 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
8905 | { | |
8906 | LIST_HEAD(completions); | |
8907 | struct lpfc_sli *psli = &phba->sli; | |
8908 | LPFC_MBOXQ_t *pmb; | |
8909 | unsigned long iflag; | |
8910 | ||
8911 | /* Flush all the mailbox commands in the mbox system */ | |
8912 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8913 | /* The pending mailbox command queue */ | |
8914 | list_splice_init(&phba->sli.mboxq, &completions); | |
8915 | /* The outstanding active mailbox command */ | |
8916 | if (psli->mbox_active) { | |
8917 | list_add_tail(&psli->mbox_active->list, &completions); | |
8918 | psli->mbox_active = NULL; | |
8919 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8920 | } | |
8921 | /* The completed mailbox command queue */ | |
8922 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
8923 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8924 | ||
8925 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
8926 | while (!list_empty(&completions)) { | |
8927 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
8928 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8929 | if (pmb->mbox_cmpl) | |
8930 | pmb->mbox_cmpl(phba, pmb); | |
8931 | } | |
8932 | } | |
8933 | ||
e59058c4 | 8934 | /** |
3621a710 | 8935 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
8936 | * @vport: Pointer to virtual port object. |
8937 | * | |
8938 | * lpfc_sli_host_down is called to clean up the resources | |
8939 | * associated with a vport before destroying virtual | |
8940 | * port data structures. | |
8941 | * This function does following operations: | |
8942 | * - Free discovery resources associated with this virtual | |
8943 | * port. | |
8944 | * - Free iocbs associated with this virtual port in | |
8945 | * the txq. | |
8946 | * - Send abort for all iocb commands associated with this | |
8947 | * vport in txcmplq. | |
8948 | * | |
8949 | * This function is called with no lock held and always returns 1. | |
8950 | **/ | |
92d7f7b0 JS |
8951 | int |
8952 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
8953 | { | |
858c9f6c | 8954 | LIST_HEAD(completions); |
92d7f7b0 JS |
8955 | struct lpfc_hba *phba = vport->phba; |
8956 | struct lpfc_sli *psli = &phba->sli; | |
8957 | struct lpfc_sli_ring *pring; | |
8958 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
8959 | int i; |
8960 | unsigned long flags = 0; | |
8961 | uint16_t prev_pring_flag; | |
8962 | ||
8963 | lpfc_cleanup_discovery_resources(vport); | |
8964 | ||
8965 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
8966 | for (i = 0; i < psli->num_rings; i++) { |
8967 | pring = &psli->ring[i]; | |
8968 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
8969 | /* Only slow rings */ |
8970 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 8971 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
8972 | /* Set the lpfc data pending flag */ |
8973 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
8974 | } | |
92d7f7b0 JS |
8975 | /* |
8976 | * Error everything on the txq since these iocbs have not been | |
8977 | * given to the FW yet. | |
8978 | */ | |
92d7f7b0 JS |
8979 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
8980 | if (iocb->vport != vport) | |
8981 | continue; | |
858c9f6c | 8982 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 8983 | pring->txq_cnt--; |
92d7f7b0 JS |
8984 | } |
8985 | ||
8986 | /* Next issue ABTS for everything on the txcmplq */ | |
8987 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
8988 | list) { | |
8989 | if (iocb->vport != vport) | |
8990 | continue; | |
8991 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
8992 | } | |
8993 | ||
8994 | pring->flag = prev_pring_flag; | |
8995 | } | |
8996 | ||
8997 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
8998 | ||
a257bf90 JS |
8999 | /* Cancel all the IOCBs from the completions list */ |
9000 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9001 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
9002 | return 1; |
9003 | } | |
9004 | ||
e59058c4 | 9005 | /** |
3621a710 | 9006 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
9007 | * @phba: Pointer to HBA context object. |
9008 | * | |
9009 | * This function cleans up all iocb, buffers, mailbox commands | |
9010 | * while shutting down the HBA. This function is called with no | |
9011 | * lock held and always returns 1. | |
9012 | * This function does the following to cleanup driver resources: | |
9013 | * - Free discovery resources for each virtual port | |
9014 | * - Cleanup any pending fabric iocbs | |
9015 | * - Iterate through the iocb txq and free each entry | |
9016 | * in the list. | |
9017 | * - Free up any buffer posted to the HBA | |
9018 | * - Free mailbox commands in the mailbox queue. | |
9019 | **/ | |
dea3101e | 9020 | int |
2e0fef85 | 9021 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 9022 | { |
2534ba75 | 9023 | LIST_HEAD(completions); |
2e0fef85 | 9024 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 9025 | struct lpfc_sli_ring *pring; |
0ff10d46 | 9026 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 9027 | unsigned long flags = 0; |
04c68496 JS |
9028 | int i; |
9029 | ||
9030 | /* Shutdown the mailbox command sub-system */ | |
618a5230 | 9031 | lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT); |
dea3101e | 9032 | |
dea3101e JB |
9033 | lpfc_hba_down_prep(phba); |
9034 | ||
92d7f7b0 JS |
9035 | lpfc_fabric_abort_hba(phba); |
9036 | ||
2e0fef85 | 9037 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
9038 | for (i = 0; i < psli->num_rings; i++) { |
9039 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
9040 | /* Only slow rings */ |
9041 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 9042 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
9043 | /* Set the lpfc data pending flag */ |
9044 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
9045 | } | |
dea3101e JB |
9046 | |
9047 | /* | |
9048 | * Error everything on the txq since these iocbs have not been | |
9049 | * given to the FW yet. | |
9050 | */ | |
2534ba75 | 9051 | list_splice_init(&pring->txq, &completions); |
dea3101e JB |
9052 | pring->txq_cnt = 0; |
9053 | ||
2534ba75 | 9054 | } |
2e0fef85 | 9055 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 9056 | |
a257bf90 JS |
9057 | /* Cancel all the IOCBs from the completions list */ |
9058 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9059 | IOERR_SLI_DOWN); | |
dea3101e | 9060 | |
0ff10d46 JS |
9061 | spin_lock_irqsave(&phba->hbalock, flags); |
9062 | list_splice_init(&phba->elsbuf, &completions); | |
9063 | phba->elsbuf_cnt = 0; | |
9064 | phba->elsbuf_prev_cnt = 0; | |
9065 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
9066 | ||
9067 | while (!list_empty(&completions)) { | |
9068 | list_remove_head(&completions, buf_ptr, | |
9069 | struct lpfc_dmabuf, list); | |
9070 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
9071 | kfree(buf_ptr); | |
9072 | } | |
9073 | ||
dea3101e JB |
9074 | /* Return any active mbox cmds */ |
9075 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 9076 | |
da0436e9 | 9077 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9078 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 9079 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 9080 | |
da0436e9 JS |
9081 | return 1; |
9082 | } | |
9083 | ||
e59058c4 | 9084 | /** |
3621a710 | 9085 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
9086 | * @srcp: Source memory pointer. |
9087 | * @destp: Destination memory pointer. | |
9088 | * @cnt: Number of words required to be copied. | |
9089 | * | |
9090 | * This function is used for copying data between driver memory | |
9091 | * and the SLI memory. This function also changes the endianness | |
9092 | * of each word if native endianness is different from SLI | |
9093 | * endianness. This function can be called with or without | |
9094 | * lock. | |
9095 | **/ | |
dea3101e JB |
9096 | void |
9097 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9098 | { | |
9099 | uint32_t *src = srcp; | |
9100 | uint32_t *dest = destp; | |
9101 | uint32_t ldata; | |
9102 | int i; | |
9103 | ||
9104 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
9105 | ldata = *src; | |
9106 | ldata = le32_to_cpu(ldata); | |
9107 | *dest = ldata; | |
9108 | src++; | |
9109 | dest++; | |
9110 | } | |
9111 | } | |
9112 | ||
e59058c4 | 9113 | |
a0c87cbd JS |
9114 | /** |
9115 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
9116 | * @srcp: Source memory pointer. | |
9117 | * @destp: Destination memory pointer. | |
9118 | * @cnt: Number of words required to be copied. | |
9119 | * | |
9120 | * This function is used for copying data between a data structure | |
9121 | * with big endian representation to local endianness. | |
9122 | * This function can be called with or without lock. | |
9123 | **/ | |
9124 | void | |
9125 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
9126 | { | |
9127 | uint32_t *src = srcp; | |
9128 | uint32_t *dest = destp; | |
9129 | uint32_t ldata; | |
9130 | int i; | |
9131 | ||
9132 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
9133 | ldata = *src; | |
9134 | ldata = be32_to_cpu(ldata); | |
9135 | *dest = ldata; | |
9136 | src++; | |
9137 | dest++; | |
9138 | } | |
9139 | } | |
9140 | ||
e59058c4 | 9141 | /** |
3621a710 | 9142 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
9143 | * @phba: Pointer to HBA context object. |
9144 | * @pring: Pointer to driver SLI ring object. | |
9145 | * @mp: Pointer to driver buffer object. | |
9146 | * | |
9147 | * This function is called with no lock held. | |
9148 | * It always return zero after adding the buffer to the postbufq | |
9149 | * buffer list. | |
9150 | **/ | |
dea3101e | 9151 | int |
2e0fef85 JS |
9152 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
9153 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
9154 | { |
9155 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
9156 | later */ | |
2e0fef85 | 9157 | spin_lock_irq(&phba->hbalock); |
dea3101e | 9158 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 9159 | pring->postbufq_cnt++; |
2e0fef85 | 9160 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
9161 | return 0; |
9162 | } | |
9163 | ||
e59058c4 | 9164 | /** |
3621a710 | 9165 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
9166 | * @phba: Pointer to HBA context object. |
9167 | * | |
9168 | * When HBQ is enabled, buffers are searched based on tags. This function | |
9169 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
9170 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
9171 | * does not conflict with tags of buffer posted for unsolicited events. | |
9172 | * The function returns the allocated tag. The function is called with | |
9173 | * no locks held. | |
9174 | **/ | |
76bb24ef JS |
9175 | uint32_t |
9176 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
9177 | { | |
9178 | spin_lock_irq(&phba->hbalock); | |
9179 | phba->buffer_tag_count++; | |
9180 | /* | |
9181 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
9182 | * a tag assigned by HBQ. | |
9183 | */ | |
9184 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
9185 | spin_unlock_irq(&phba->hbalock); | |
9186 | return phba->buffer_tag_count; | |
9187 | } | |
9188 | ||
e59058c4 | 9189 | /** |
3621a710 | 9190 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
9191 | * @phba: Pointer to HBA context object. |
9192 | * @pring: Pointer to driver SLI ring object. | |
9193 | * @tag: Buffer tag. | |
9194 | * | |
9195 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
9196 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
9197 | * iocb is posted to the response ring with the tag of the buffer. | |
9198 | * This function searches the pring->postbufq list using the tag | |
9199 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
9200 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
9201 | * buffer is returned to the caller else NULL is returned. | |
9202 | * This function is called with no lock held. | |
9203 | **/ | |
76bb24ef JS |
9204 | struct lpfc_dmabuf * |
9205 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9206 | uint32_t tag) | |
9207 | { | |
9208 | struct lpfc_dmabuf *mp, *next_mp; | |
9209 | struct list_head *slp = &pring->postbufq; | |
9210 | ||
25985edc | 9211 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
9212 | spin_lock_irq(&phba->hbalock); |
9213 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
9214 | if (mp->buffer_tag == tag) { | |
9215 | list_del_init(&mp->list); | |
9216 | pring->postbufq_cnt--; | |
9217 | spin_unlock_irq(&phba->hbalock); | |
9218 | return mp; | |
9219 | } | |
9220 | } | |
9221 | ||
9222 | spin_unlock_irq(&phba->hbalock); | |
9223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 9224 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
9225 | "ring %d Data x%lx x%p x%p x%x\n", |
9226 | pring->ringno, (unsigned long) tag, | |
9227 | slp->next, slp->prev, pring->postbufq_cnt); | |
9228 | ||
9229 | return NULL; | |
9230 | } | |
dea3101e | 9231 | |
e59058c4 | 9232 | /** |
3621a710 | 9233 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
9234 | * @phba: Pointer to HBA context object. |
9235 | * @pring: Pointer to driver SLI ring object. | |
9236 | * @phys: DMA address of the buffer. | |
9237 | * | |
9238 | * This function searches the buffer list using the dma_address | |
9239 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
9240 | * corresponding to the dma_address. The function returns the | |
9241 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
9242 | * This function is called by the ct and els unsolicited event | |
9243 | * handlers to get the buffer associated with the unsolicited | |
9244 | * event. | |
9245 | * | |
9246 | * This function is called with no lock held. | |
9247 | **/ | |
dea3101e JB |
9248 | struct lpfc_dmabuf * |
9249 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9250 | dma_addr_t phys) | |
9251 | { | |
9252 | struct lpfc_dmabuf *mp, *next_mp; | |
9253 | struct list_head *slp = &pring->postbufq; | |
9254 | ||
25985edc | 9255 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 9256 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
9257 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
9258 | if (mp->phys == phys) { | |
9259 | list_del_init(&mp->list); | |
9260 | pring->postbufq_cnt--; | |
2e0fef85 | 9261 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
9262 | return mp; |
9263 | } | |
9264 | } | |
9265 | ||
2e0fef85 | 9266 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 9267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 9268 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 9269 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 9270 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
9271 | slp->next, slp->prev, pring->postbufq_cnt); |
9272 | return NULL; | |
9273 | } | |
9274 | ||
e59058c4 | 9275 | /** |
3621a710 | 9276 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
9277 | * @phba: Pointer to HBA context object. |
9278 | * @cmdiocb: Pointer to driver command iocb object. | |
9279 | * @rspiocb: Pointer to driver response iocb object. | |
9280 | * | |
9281 | * This function is the completion handler for the abort iocbs for | |
9282 | * ELS commands. This function is called from the ELS ring event | |
9283 | * handler with no lock held. This function frees memory resources | |
9284 | * associated with the abort iocb. | |
9285 | **/ | |
dea3101e | 9286 | static void |
2e0fef85 JS |
9287 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9288 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 9289 | { |
2e0fef85 | 9290 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 9291 | uint16_t abort_iotag, abort_context; |
ff78d8f9 | 9292 | struct lpfc_iocbq *abort_iocb = NULL; |
2680eeaa JS |
9293 | |
9294 | if (irsp->ulpStatus) { | |
ff78d8f9 JS |
9295 | |
9296 | /* | |
9297 | * Assume that the port already completed and returned, or | |
9298 | * will return the iocb. Just Log the message. | |
9299 | */ | |
2680eeaa JS |
9300 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
9301 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
9302 | ||
2e0fef85 | 9303 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
9304 | if (phba->sli_rev < LPFC_SLI_REV4) { |
9305 | if (abort_iotag != 0 && | |
9306 | abort_iotag <= phba->sli.last_iotag) | |
9307 | abort_iocb = | |
9308 | phba->sli.iocbq_lookup[abort_iotag]; | |
9309 | } else | |
9310 | /* For sli4 the abort_tag is the XRI, | |
9311 | * so the abort routine puts the iotag of the iocb | |
9312 | * being aborted in the context field of the abort | |
9313 | * IOCB. | |
9314 | */ | |
9315 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 9316 | |
2a9bf3d0 JS |
9317 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
9318 | "0327 Cannot abort els iocb %p " | |
9319 | "with tag %x context %x, abort status %x, " | |
9320 | "abort code %x\n", | |
9321 | abort_iocb, abort_iotag, abort_context, | |
9322 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
341af102 | 9323 | |
ff78d8f9 | 9324 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 9325 | } |
604a3e30 | 9326 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
9327 | return; |
9328 | } | |
9329 | ||
e59058c4 | 9330 | /** |
3621a710 | 9331 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
9332 | * @phba: Pointer to HBA context object. |
9333 | * @cmdiocb: Pointer to driver command iocb object. | |
9334 | * @rspiocb: Pointer to driver response iocb object. | |
9335 | * | |
9336 | * The function is called from SLI ring event handler with no | |
9337 | * lock held. This function is the completion handler for ELS commands | |
9338 | * which are aborted. The function frees memory resources used for | |
9339 | * the aborted ELS commands. | |
9340 | **/ | |
92d7f7b0 JS |
9341 | static void |
9342 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
9343 | struct lpfc_iocbq *rspiocb) | |
9344 | { | |
9345 | IOCB_t *irsp = &rspiocb->iocb; | |
9346 | ||
9347 | /* ELS cmd tag <ulpIoTag> completes */ | |
9348 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 9349 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 9350 | "x%x x%x x%x\n", |
e8b62011 | 9351 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 9352 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
9353 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
9354 | lpfc_ct_free_iocb(phba, cmdiocb); | |
9355 | else | |
9356 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
9357 | return; |
9358 | } | |
9359 | ||
e59058c4 | 9360 | /** |
5af5eee7 | 9361 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
9362 | * @phba: Pointer to HBA context object. |
9363 | * @pring: Pointer to driver SLI ring object. | |
9364 | * @cmdiocb: Pointer to driver command iocb object. | |
9365 | * | |
5af5eee7 JS |
9366 | * This function issues an abort iocb for the provided command iocb down to |
9367 | * the port. Other than the case the outstanding command iocb is an abort | |
9368 | * request, this function issues abort out unconditionally. This function is | |
9369 | * called with hbalock held. The function returns 0 when it fails due to | |
9370 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 9371 | **/ |
5af5eee7 JS |
9372 | static int |
9373 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 9374 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 9375 | { |
2e0fef85 | 9376 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 9377 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
9378 | IOCB_t *icmd = NULL; |
9379 | IOCB_t *iabt = NULL; | |
5af5eee7 | 9380 | int retval; |
7e56aa25 | 9381 | unsigned long iflags; |
07951076 | 9382 | |
92d7f7b0 JS |
9383 | /* |
9384 | * There are certain command types we don't want to abort. And we | |
9385 | * don't want to abort commands that are already in the process of | |
9386 | * being aborted. | |
07951076 JS |
9387 | */ |
9388 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 9389 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
9390 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
9391 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
9392 | return 0; |
9393 | ||
dea3101e | 9394 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 9395 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
9396 | if (abtsiocbp == NULL) |
9397 | return 0; | |
dea3101e | 9398 | |
07951076 | 9399 | /* This signals the response to set the correct status |
341af102 | 9400 | * before calling the completion handler |
07951076 JS |
9401 | */ |
9402 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
9403 | ||
dea3101e | 9404 | iabt = &abtsiocbp->iocb; |
07951076 JS |
9405 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
9406 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 9407 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 9408 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
9409 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
9410 | } | |
da0436e9 JS |
9411 | else |
9412 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
9413 | iabt->ulpLe = 1; |
9414 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 9415 | |
5ffc266e JS |
9416 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9417 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
9418 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
9419 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9420 | |
2e0fef85 | 9421 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
9422 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
9423 | else | |
9424 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 9425 | |
07951076 | 9426 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 9427 | |
e8b62011 JS |
9428 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
9429 | "0339 Abort xri x%x, original iotag x%x, " | |
9430 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 9431 | iabt->un.acxri.abortIoTag, |
e8b62011 | 9432 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 9433 | abtsiocbp->iotag); |
7e56aa25 JS |
9434 | |
9435 | if (phba->sli_rev == LPFC_SLI_REV4) { | |
9436 | /* Note: both hbalock and ring_lock need to be set here */ | |
9437 | spin_lock_irqsave(&pring->ring_lock, iflags); | |
9438 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
9439 | abtsiocbp, 0); | |
9440 | spin_unlock_irqrestore(&pring->ring_lock, iflags); | |
9441 | } else { | |
9442 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, | |
9443 | abtsiocbp, 0); | |
9444 | } | |
dea3101e | 9445 | |
d7c255b2 JS |
9446 | if (retval) |
9447 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
9448 | |
9449 | /* | |
9450 | * Caller to this routine should check for IOCB_ERROR | |
9451 | * and handle it properly. This routine no longer removes | |
9452 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
9453 | */ | |
9454 | return retval; | |
9455 | } | |
9456 | ||
9457 | /** | |
9458 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
9459 | * @phba: Pointer to HBA context object. | |
9460 | * @pring: Pointer to driver SLI ring object. | |
9461 | * @cmdiocb: Pointer to driver command iocb object. | |
9462 | * | |
9463 | * This function issues an abort iocb for the provided command iocb. In case | |
9464 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
9465 | * ring. Instead, the callback function shall be changed to those commands | |
9466 | * so that nothing happens when them finishes. This function is called with | |
9467 | * hbalock held. The function returns 0 when the command iocb is an abort | |
9468 | * request. | |
9469 | **/ | |
9470 | int | |
9471 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9472 | struct lpfc_iocbq *cmdiocb) | |
9473 | { | |
9474 | struct lpfc_vport *vport = cmdiocb->vport; | |
9475 | int retval = IOCB_ERROR; | |
9476 | IOCB_t *icmd = NULL; | |
9477 | ||
9478 | /* | |
9479 | * There are certain command types we don't want to abort. And we | |
9480 | * don't want to abort commands that are already in the process of | |
9481 | * being aborted. | |
9482 | */ | |
9483 | icmd = &cmdiocb->iocb; | |
9484 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
9485 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
9486 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
9487 | return 0; | |
9488 | ||
9489 | /* | |
9490 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
9491 | * the callback so that nothing happens when it finishes. | |
9492 | */ | |
9493 | if ((vport->load_flag & FC_UNLOADING) && | |
9494 | (pring->ringno == LPFC_ELS_RING)) { | |
9495 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
9496 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
9497 | else | |
9498 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
9499 | goto abort_iotag_exit; | |
9500 | } | |
9501 | ||
9502 | /* Now, we try to issue the abort to the cmdiocb out */ | |
9503 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
9504 | ||
07951076 | 9505 | abort_iotag_exit: |
2e0fef85 JS |
9506 | /* |
9507 | * Caller to this routine should check for IOCB_ERROR | |
9508 | * and handle it properly. This routine no longer removes | |
9509 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 9510 | */ |
2e0fef85 | 9511 | return retval; |
dea3101e JB |
9512 | } |
9513 | ||
5af5eee7 JS |
9514 | /** |
9515 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
9516 | * @phba: Pointer to HBA context object. | |
9517 | * @pring: Pointer to driver SLI ring object. | |
9518 | * | |
9519 | * This function aborts all iocbs in the given ring and frees all the iocb | |
9520 | * objects in txq. This function issues abort iocbs unconditionally for all | |
9521 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
9522 | * to complete before the return of this function. The caller is not required | |
9523 | * to hold any locks. | |
9524 | **/ | |
9525 | static void | |
9526 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
9527 | { | |
9528 | LIST_HEAD(completions); | |
9529 | struct lpfc_iocbq *iocb, *next_iocb; | |
9530 | ||
9531 | if (pring->ringno == LPFC_ELS_RING) | |
9532 | lpfc_fabric_abort_hba(phba); | |
9533 | ||
9534 | spin_lock_irq(&phba->hbalock); | |
9535 | ||
9536 | /* Take off all the iocbs on txq for cancelling */ | |
9537 | list_splice_init(&pring->txq, &completions); | |
9538 | pring->txq_cnt = 0; | |
9539 | ||
9540 | /* Next issue ABTS for everything on the txcmplq */ | |
9541 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
9542 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
9543 | ||
9544 | spin_unlock_irq(&phba->hbalock); | |
9545 | ||
9546 | /* Cancel all the IOCBs from the completions list */ | |
9547 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9548 | IOERR_SLI_ABORTED); | |
9549 | } | |
9550 | ||
9551 | /** | |
9552 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
9553 | * @phba: pointer to lpfc HBA data structure. | |
9554 | * | |
9555 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
9556 | **/ | |
9557 | void | |
9558 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
9559 | { | |
9560 | struct lpfc_sli *psli = &phba->sli; | |
9561 | struct lpfc_sli_ring *pring; | |
9562 | int i; | |
9563 | ||
9564 | for (i = 0; i < psli->num_rings; i++) { | |
9565 | pring = &psli->ring[i]; | |
9566 | lpfc_sli_iocb_ring_abort(phba, pring); | |
9567 | } | |
9568 | } | |
9569 | ||
e59058c4 | 9570 | /** |
3621a710 | 9571 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
9572 | * @iocbq: Pointer to driver iocb object. |
9573 | * @vport: Pointer to driver virtual port object. | |
9574 | * @tgt_id: SCSI ID of the target. | |
9575 | * @lun_id: LUN ID of the scsi device. | |
9576 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
9577 | * | |
3621a710 | 9578 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
9579 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
9580 | * 0 if the filtering criteria is met for the given iocb and will return | |
9581 | * 1 if the filtering criteria is not met. | |
9582 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
9583 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
9584 | * lun_id parameter. | |
9585 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
9586 | * given iocb is for the SCSI target specified by vport and tgt_id | |
9587 | * parameters. | |
9588 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
9589 | * given iocb is for the SCSI host associated with the given vport. | |
9590 | * This function is called with no locks held. | |
9591 | **/ | |
dea3101e | 9592 | static int |
51ef4c26 JS |
9593 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
9594 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 9595 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 9596 | { |
0bd4ca25 | 9597 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
9598 | int rc = 1; |
9599 | ||
0bd4ca25 JSEC |
9600 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
9601 | return rc; | |
9602 | ||
51ef4c26 JS |
9603 | if (iocbq->vport != vport) |
9604 | return rc; | |
9605 | ||
0bd4ca25 | 9606 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 9607 | |
495a714c | 9608 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
9609 | return rc; |
9610 | ||
9611 | switch (ctx_cmd) { | |
9612 | case LPFC_CTX_LUN: | |
495a714c JS |
9613 | if ((lpfc_cmd->rdata->pnode) && |
9614 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
9615 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
9616 | rc = 0; |
9617 | break; | |
9618 | case LPFC_CTX_TGT: | |
495a714c JS |
9619 | if ((lpfc_cmd->rdata->pnode) && |
9620 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
9621 | rc = 0; |
9622 | break; | |
dea3101e JB |
9623 | case LPFC_CTX_HOST: |
9624 | rc = 0; | |
9625 | break; | |
9626 | default: | |
9627 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 9628 | __func__, ctx_cmd); |
dea3101e JB |
9629 | break; |
9630 | } | |
9631 | ||
9632 | return rc; | |
9633 | } | |
9634 | ||
e59058c4 | 9635 | /** |
3621a710 | 9636 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
9637 | * @vport: Pointer to virtual port. |
9638 | * @tgt_id: SCSI ID of the target. | |
9639 | * @lun_id: LUN ID of the scsi device. | |
9640 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9641 | * | |
9642 | * This function returns number of FCP commands pending for the vport. | |
9643 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
9644 | * commands pending on the vport associated with SCSI device specified | |
9645 | * by tgt_id and lun_id parameters. | |
9646 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
9647 | * commands pending on the vport associated with SCSI target specified | |
9648 | * by tgt_id parameter. | |
9649 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
9650 | * commands pending on the vport. | |
9651 | * This function returns the number of iocbs which satisfy the filter. | |
9652 | * This function is called without any lock held. | |
9653 | **/ | |
dea3101e | 9654 | int |
51ef4c26 JS |
9655 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
9656 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 9657 | { |
51ef4c26 | 9658 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9659 | struct lpfc_iocbq *iocbq; |
9660 | int sum, i; | |
dea3101e | 9661 | |
0bd4ca25 JSEC |
9662 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
9663 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9664 | |
51ef4c26 JS |
9665 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
9666 | ctx_cmd) == 0) | |
0bd4ca25 | 9667 | sum++; |
dea3101e | 9668 | } |
0bd4ca25 | 9669 | |
dea3101e JB |
9670 | return sum; |
9671 | } | |
9672 | ||
e59058c4 | 9673 | /** |
3621a710 | 9674 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
9675 | * @phba: Pointer to HBA context object |
9676 | * @cmdiocb: Pointer to command iocb object. | |
9677 | * @rspiocb: Pointer to response iocb object. | |
9678 | * | |
9679 | * This function is called when an aborted FCP iocb completes. This | |
9680 | * function is called by the ring event handler with no lock held. | |
9681 | * This function frees the iocb. | |
9682 | **/ | |
5eb95af0 | 9683 | void |
2e0fef85 JS |
9684 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9685 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 9686 | { |
cb69f7de JS |
9687 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
9688 | "3096 ABORT_XRI_CN completing on xri x%x " | |
9689 | "original iotag x%x, abort cmd iotag x%x " | |
9690 | "status 0x%x, reason 0x%x\n", | |
9691 | cmdiocb->iocb.un.acxri.abortContextTag, | |
9692 | cmdiocb->iocb.un.acxri.abortIoTag, | |
9693 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, | |
9694 | rspiocb->iocb.un.ulpWord[4]); | |
604a3e30 | 9695 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
9696 | return; |
9697 | } | |
9698 | ||
e59058c4 | 9699 | /** |
3621a710 | 9700 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
9701 | * @vport: Pointer to virtual port. |
9702 | * @pring: Pointer to driver SLI ring object. | |
9703 | * @tgt_id: SCSI ID of the target. | |
9704 | * @lun_id: LUN ID of the scsi device. | |
9705 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9706 | * | |
9707 | * This function sends an abort command for every SCSI command | |
9708 | * associated with the given virtual port pending on the ring | |
9709 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
9710 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
9711 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
9712 | * parameters | |
9713 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
9714 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
9715 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
9716 | * FCP iocbs associated with virtual port. | |
9717 | * This function returns number of iocbs it failed to abort. | |
9718 | * This function is called with no locks held. | |
9719 | **/ | |
dea3101e | 9720 | int |
51ef4c26 JS |
9721 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
9722 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 9723 | { |
51ef4c26 | 9724 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9725 | struct lpfc_iocbq *iocbq; |
9726 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 9727 | IOCB_t *cmd = NULL; |
dea3101e | 9728 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 9729 | int i; |
dea3101e | 9730 | |
0bd4ca25 JSEC |
9731 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
9732 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9733 | |
51ef4c26 | 9734 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 9735 | abort_cmd) != 0) |
dea3101e JB |
9736 | continue; |
9737 | ||
9738 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 9739 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
9740 | if (abtsiocb == NULL) { |
9741 | errcnt++; | |
9742 | continue; | |
9743 | } | |
dea3101e | 9744 | |
0bd4ca25 | 9745 | cmd = &iocbq->iocb; |
dea3101e JB |
9746 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
9747 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
9748 | if (phba->sli_rev == LPFC_SLI_REV4) |
9749 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
9750 | else | |
9751 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
9752 | abtsiocb->iocb.ulpLe = 1; |
9753 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 9754 | abtsiocb->vport = phba->pport; |
dea3101e | 9755 | |
5ffc266e JS |
9756 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9757 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
9758 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
9759 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9760 | |
2e0fef85 | 9761 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
9762 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
9763 | else | |
9764 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
9765 | ||
5eb95af0 JSEC |
9766 | /* Setup callback routine and issue the command. */ |
9767 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
9768 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
9769 | abtsiocb, 0); | |
dea3101e | 9770 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 9771 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
9772 | errcnt++; |
9773 | continue; | |
9774 | } | |
9775 | } | |
9776 | ||
9777 | return errcnt; | |
9778 | } | |
9779 | ||
e59058c4 | 9780 | /** |
3621a710 | 9781 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
9782 | * @phba: Pointer to HBA context object. |
9783 | * @cmdiocbq: Pointer to command iocb. | |
9784 | * @rspiocbq: Pointer to response iocb. | |
9785 | * | |
9786 | * This function is the completion handler for iocbs issued using | |
9787 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
9788 | * ring event handler function without any lock held. This function | |
9789 | * can be called from both worker thread context and interrupt | |
9790 | * context. This function also can be called from other thread which | |
9791 | * cleans up the SLI layer objects. | |
9792 | * This function copy the contents of the response iocb to the | |
9793 | * response iocb memory object provided by the caller of | |
9794 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
9795 | * sleeps for the iocb completion. | |
9796 | **/ | |
68876920 JSEC |
9797 | static void |
9798 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
9799 | struct lpfc_iocbq *cmdiocbq, | |
9800 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 9801 | { |
68876920 JSEC |
9802 | wait_queue_head_t *pdone_q; |
9803 | unsigned long iflags; | |
0f65ff68 | 9804 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 9805 | |
2e0fef85 | 9806 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
9807 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
9808 | if (cmdiocbq->context2 && rspiocbq) | |
9809 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
9810 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
9811 | ||
0f65ff68 JS |
9812 | /* Set the exchange busy flag for task management commands */ |
9813 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
9814 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
9815 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
9816 | cur_iocbq); | |
9817 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
9818 | } | |
9819 | ||
68876920 | 9820 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
9821 | if (pdone_q) |
9822 | wake_up(pdone_q); | |
858c9f6c | 9823 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
9824 | return; |
9825 | } | |
9826 | ||
d11e31dd JS |
9827 | /** |
9828 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
9829 | * @phba: Pointer to HBA context object.. | |
9830 | * @piocbq: Pointer to command iocb. | |
9831 | * @flag: Flag to test. | |
9832 | * | |
9833 | * This routine grabs the hbalock and then test the iocb_flag to | |
9834 | * see if the passed in flag is set. | |
9835 | * Returns: | |
9836 | * 1 if flag is set. | |
9837 | * 0 if flag is not set. | |
9838 | **/ | |
9839 | static int | |
9840 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
9841 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
9842 | { | |
9843 | unsigned long iflags; | |
9844 | int ret; | |
9845 | ||
9846 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9847 | ret = piocbq->iocb_flag & flag; | |
9848 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9849 | return ret; | |
9850 | ||
9851 | } | |
9852 | ||
e59058c4 | 9853 | /** |
3621a710 | 9854 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
9855 | * @phba: Pointer to HBA context object.. |
9856 | * @pring: Pointer to sli ring. | |
9857 | * @piocb: Pointer to command iocb. | |
9858 | * @prspiocbq: Pointer to response iocb. | |
9859 | * @timeout: Timeout in number of seconds. | |
9860 | * | |
9861 | * This function issues the iocb to firmware and waits for the | |
9862 | * iocb to complete. If the iocb command is not | |
9863 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
9864 | * Caller should not free the iocb resources if this function | |
9865 | * returns IOCB_TIMEDOUT. | |
9866 | * The function waits for the iocb completion using an | |
9867 | * non-interruptible wait. | |
9868 | * This function will sleep while waiting for iocb completion. | |
9869 | * So, this function should not be called from any context which | |
9870 | * does not allow sleeping. Due to the same reason, this function | |
9871 | * cannot be called with interrupt disabled. | |
9872 | * This function assumes that the iocb completions occur while | |
9873 | * this function sleep. So, this function cannot be called from | |
9874 | * the thread which process iocb completion for this ring. | |
9875 | * This function clears the iocb_flag of the iocb object before | |
9876 | * issuing the iocb and the iocb completion handler sets this | |
9877 | * flag and wakes this thread when the iocb completes. | |
9878 | * The contents of the response iocb will be copied to prspiocbq | |
9879 | * by the completion handler when the command completes. | |
9880 | * This function returns IOCB_SUCCESS when success. | |
9881 | * This function is called with no lock held. | |
9882 | **/ | |
dea3101e | 9883 | int |
2e0fef85 | 9884 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 9885 | uint32_t ring_number, |
2e0fef85 JS |
9886 | struct lpfc_iocbq *piocb, |
9887 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 9888 | uint32_t timeout) |
dea3101e | 9889 | { |
7259f0d0 | 9890 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
9891 | long timeleft, timeout_req = 0; |
9892 | int retval = IOCB_SUCCESS; | |
875fbdfe | 9893 | uint32_t creg_val; |
2a9bf3d0 | 9894 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 9895 | /* |
68876920 JSEC |
9896 | * If the caller has provided a response iocbq buffer, then context2 |
9897 | * is NULL or its an error. | |
dea3101e | 9898 | */ |
68876920 JSEC |
9899 | if (prspiocbq) { |
9900 | if (piocb->context2) | |
9901 | return IOCB_ERROR; | |
9902 | piocb->context2 = prspiocbq; | |
dea3101e JB |
9903 | } |
9904 | ||
68876920 JSEC |
9905 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
9906 | piocb->context_un.wait_queue = &done_q; | |
9907 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 9908 | |
875fbdfe | 9909 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9910 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9911 | return IOCB_ERROR; | |
875fbdfe JSEC |
9912 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
9913 | writel(creg_val, phba->HCregaddr); | |
9914 | readl(phba->HCregaddr); /* flush */ | |
9915 | } | |
9916 | ||
2a9bf3d0 JS |
9917 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
9918 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
9919 | if (retval == IOCB_SUCCESS) { |
9920 | timeout_req = timeout * HZ; | |
68876920 | 9921 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 9922 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 9923 | timeout_req); |
dea3101e | 9924 | |
7054a606 JS |
9925 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
9926 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 9927 | "0331 IOCB wake signaled\n"); |
7054a606 | 9928 | } else if (timeleft == 0) { |
68876920 | 9929 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9930 | "0338 IOCB wait timeout error - no " |
9931 | "wake response Data x%x\n", timeout); | |
68876920 | 9932 | retval = IOCB_TIMEDOUT; |
7054a606 | 9933 | } else { |
68876920 | 9934 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9935 | "0330 IOCB wake NOT set, " |
9936 | "Data x%x x%lx\n", | |
68876920 JSEC |
9937 | timeout, (timeleft / jiffies)); |
9938 | retval = IOCB_TIMEDOUT; | |
dea3101e | 9939 | } |
2a9bf3d0 JS |
9940 | } else if (retval == IOCB_BUSY) { |
9941 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9942 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
9943 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
9944 | return retval; | |
68876920 JSEC |
9945 | } else { |
9946 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 9947 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 9948 | retval); |
68876920 | 9949 | retval = IOCB_ERROR; |
dea3101e JB |
9950 | } |
9951 | ||
875fbdfe | 9952 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9953 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9954 | return IOCB_ERROR; | |
875fbdfe JSEC |
9955 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
9956 | writel(creg_val, phba->HCregaddr); | |
9957 | readl(phba->HCregaddr); /* flush */ | |
9958 | } | |
9959 | ||
68876920 JSEC |
9960 | if (prspiocbq) |
9961 | piocb->context2 = NULL; | |
9962 | ||
9963 | piocb->context_un.wait_queue = NULL; | |
9964 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
9965 | return retval; |
9966 | } | |
68876920 | 9967 | |
e59058c4 | 9968 | /** |
3621a710 | 9969 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
9970 | * @phba: Pointer to HBA context object. |
9971 | * @pmboxq: Pointer to driver mailbox object. | |
9972 | * @timeout: Timeout in number of seconds. | |
9973 | * | |
9974 | * This function issues the mailbox to firmware and waits for the | |
9975 | * mailbox command to complete. If the mailbox command is not | |
9976 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
9977 | * The function waits for the mailbox completion using an | |
9978 | * interruptible wait. If the thread is woken up due to a | |
9979 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
9980 | * should not free the mailbox resources, if this function returns | |
9981 | * MBX_TIMEOUT. | |
9982 | * This function will sleep while waiting for mailbox completion. | |
9983 | * So, this function should not be called from any context which | |
9984 | * does not allow sleeping. Due to the same reason, this function | |
9985 | * cannot be called with interrupt disabled. | |
9986 | * This function assumes that the mailbox completion occurs while | |
9987 | * this function sleep. So, this function cannot be called from | |
9988 | * the worker thread which processes mailbox completion. | |
9989 | * This function is called in the context of HBA management | |
9990 | * applications. | |
9991 | * This function returns MBX_SUCCESS when successful. | |
9992 | * This function is called with no lock held. | |
9993 | **/ | |
dea3101e | 9994 | int |
2e0fef85 | 9995 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
9996 | uint32_t timeout) |
9997 | { | |
7259f0d0 | 9998 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 9999 | int retval; |
858c9f6c | 10000 | unsigned long flag; |
dea3101e JB |
10001 | |
10002 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 10003 | if (pmboxq->context1) |
2e0fef85 | 10004 | return MBX_NOT_FINISHED; |
dea3101e | 10005 | |
495a714c | 10006 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
10007 | /* setup wake call as IOCB callback */ |
10008 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
10009 | /* setup context field to pass wait_queue pointer to wake function */ | |
10010 | pmboxq->context1 = &done_q; | |
10011 | ||
dea3101e JB |
10012 | /* now issue the command */ |
10013 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
dea3101e | 10014 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
7054a606 JS |
10015 | wait_event_interruptible_timeout(done_q, |
10016 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
10017 | timeout * HZ); | |
10018 | ||
858c9f6c | 10019 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 10020 | pmboxq->context1 = NULL; |
7054a606 JS |
10021 | /* |
10022 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
10023 | * else do not free the resources. | |
10024 | */ | |
d7c47992 | 10025 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 10026 | retval = MBX_SUCCESS; |
d7c47992 JS |
10027 | lpfc_sli4_swap_str(phba, pmboxq); |
10028 | } else { | |
7054a606 | 10029 | retval = MBX_TIMEOUT; |
858c9f6c JS |
10030 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
10031 | } | |
10032 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e JB |
10033 | } |
10034 | ||
dea3101e JB |
10035 | return retval; |
10036 | } | |
10037 | ||
e59058c4 | 10038 | /** |
3772a991 | 10039 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
10040 | * @phba: Pointer to HBA context. |
10041 | * | |
3772a991 JS |
10042 | * This function is called to shutdown the driver's mailbox sub-system. |
10043 | * It first marks the mailbox sub-system is in a block state to prevent | |
10044 | * the asynchronous mailbox command from issued off the pending mailbox | |
10045 | * command queue. If the mailbox command sub-system shutdown is due to | |
10046 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
10047 | * the mailbox sub-system flush routine to forcefully bring down the | |
10048 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
10049 | * as with offline or HBA function reset), this routine will wait for the | |
10050 | * outstanding mailbox command to complete before invoking the mailbox | |
10051 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 10052 | **/ |
3772a991 | 10053 | void |
618a5230 | 10054 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action) |
b4c02652 | 10055 | { |
3772a991 | 10056 | struct lpfc_sli *psli = &phba->sli; |
3772a991 | 10057 | unsigned long timeout; |
b4c02652 | 10058 | |
618a5230 JS |
10059 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
10060 | /* delay 100ms for port state */ | |
10061 | msleep(100); | |
10062 | lpfc_sli_mbox_sys_flush(phba); | |
10063 | return; | |
10064 | } | |
a183a15f | 10065 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
d7069f09 | 10066 | |
3772a991 JS |
10067 | spin_lock_irq(&phba->hbalock); |
10068 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
b4c02652 | 10069 | |
3772a991 | 10070 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3772a991 JS |
10071 | /* Determine how long we might wait for the active mailbox |
10072 | * command to be gracefully completed by firmware. | |
10073 | */ | |
a183a15f JS |
10074 | if (phba->sli.mbox_active) |
10075 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
10076 | phba->sli.mbox_active) * | |
10077 | 1000) + jiffies; | |
10078 | spin_unlock_irq(&phba->hbalock); | |
10079 | ||
3772a991 JS |
10080 | while (phba->sli.mbox_active) { |
10081 | /* Check active mailbox complete status every 2ms */ | |
10082 | msleep(2); | |
10083 | if (time_after(jiffies, timeout)) | |
10084 | /* Timeout, let the mailbox flush routine to | |
10085 | * forcefully release active mailbox command | |
10086 | */ | |
10087 | break; | |
10088 | } | |
d7069f09 JS |
10089 | } else |
10090 | spin_unlock_irq(&phba->hbalock); | |
10091 | ||
3772a991 JS |
10092 | lpfc_sli_mbox_sys_flush(phba); |
10093 | } | |
ed957684 | 10094 | |
3772a991 JS |
10095 | /** |
10096 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
10097 | * @phba: Pointer to HBA context. | |
10098 | * | |
10099 | * This function is called to read the SLI3 device error attention registers | |
10100 | * for possible error attention events. The caller must hold the hostlock | |
10101 | * with spin_lock_irq(). | |
10102 | * | |
25985edc | 10103 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
10104 | * Register and returns 0 otherwise. |
10105 | **/ | |
10106 | static int | |
10107 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
10108 | { | |
10109 | uint32_t ha_copy; | |
b4c02652 | 10110 | |
3772a991 | 10111 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
10112 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10113 | goto unplug_err; | |
10114 | ||
3772a991 JS |
10115 | if (ha_copy & HA_ERATT) { |
10116 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
10117 | if (lpfc_sli_read_hs(phba)) |
10118 | goto unplug_err; | |
b4c02652 | 10119 | |
3772a991 JS |
10120 | /* Check if there is a deferred error condition is active */ |
10121 | if ((HS_FFER1 & phba->work_hs) && | |
10122 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 10123 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 10124 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
10125 | /* Clear all interrupt enable conditions */ |
10126 | writel(0, phba->HCregaddr); | |
10127 | readl(phba->HCregaddr); | |
10128 | } | |
10129 | ||
10130 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
10131 | phba->work_ha |= HA_ERATT; |
10132 | /* Indicate polling handles this ERATT */ | |
10133 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
10134 | return 1; |
10135 | } | |
10136 | return 0; | |
9940b97b JS |
10137 | |
10138 | unplug_err: | |
10139 | /* Set the driver HS work bitmap */ | |
10140 | phba->work_hs |= UNPLUG_ERR; | |
10141 | /* Set the driver HA work bitmap */ | |
10142 | phba->work_ha |= HA_ERATT; | |
10143 | /* Indicate polling handles this ERATT */ | |
10144 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10145 | return 1; | |
b4c02652 JS |
10146 | } |
10147 | ||
da0436e9 JS |
10148 | /** |
10149 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
10150 | * @phba: Pointer to HBA context. | |
10151 | * | |
10152 | * This function is called to read the SLI4 device error attention registers | |
10153 | * for possible error attention events. The caller must hold the hostlock | |
10154 | * with spin_lock_irq(). | |
10155 | * | |
25985edc | 10156 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
10157 | * Register and returns 0 otherwise. |
10158 | **/ | |
10159 | static int | |
10160 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
10161 | { | |
10162 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
10163 | uint32_t if_type, portsmphr; |
10164 | struct lpfc_register portstat_reg; | |
da0436e9 | 10165 | |
2fcee4bf JS |
10166 | /* |
10167 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
10168 | * registers for error attention. This can be changed later. |
10169 | */ | |
2fcee4bf JS |
10170 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
10171 | switch (if_type) { | |
10172 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
10173 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
10174 | &uerr_sta_lo) || | |
10175 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
10176 | &uerr_sta_hi)) { | |
10177 | phba->work_hs |= UNPLUG_ERR; | |
10178 | phba->work_ha |= HA_ERATT; | |
10179 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10180 | return 1; | |
10181 | } | |
2fcee4bf JS |
10182 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
10183 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
10184 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10185 | "1423 HBA Unrecoverable error: " | |
10186 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
10187 | "ue_mask_lo_reg=0x%x, " | |
10188 | "ue_mask_hi_reg=0x%x\n", | |
10189 | uerr_sta_lo, uerr_sta_hi, | |
10190 | phba->sli4_hba.ue_mask_lo, | |
10191 | phba->sli4_hba.ue_mask_hi); | |
10192 | phba->work_status[0] = uerr_sta_lo; | |
10193 | phba->work_status[1] = uerr_sta_hi; | |
10194 | phba->work_ha |= HA_ERATT; | |
10195 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10196 | return 1; | |
10197 | } | |
10198 | break; | |
10199 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
10200 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
10201 | &portstat_reg.word0) || | |
10202 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
10203 | &portsmphr)){ | |
10204 | phba->work_hs |= UNPLUG_ERR; | |
10205 | phba->work_ha |= HA_ERATT; | |
10206 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10207 | return 1; | |
10208 | } | |
2fcee4bf JS |
10209 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
10210 | phba->work_status[0] = | |
10211 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
10212 | phba->work_status[1] = | |
10213 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
10214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2e90f4b5 | 10215 | "2885 Port Status Event: " |
2fcee4bf JS |
10216 | "port status reg 0x%x, " |
10217 | "port smphr reg 0x%x, " | |
10218 | "error 1=0x%x, error 2=0x%x\n", | |
10219 | portstat_reg.word0, | |
10220 | portsmphr, | |
10221 | phba->work_status[0], | |
10222 | phba->work_status[1]); | |
10223 | phba->work_ha |= HA_ERATT; | |
10224 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10225 | return 1; | |
10226 | } | |
10227 | break; | |
10228 | case LPFC_SLI_INTF_IF_TYPE_1: | |
10229 | default: | |
a747c9ce | 10230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
10231 | "2886 HBA Error Attention on unsupported " |
10232 | "if type %d.", if_type); | |
a747c9ce | 10233 | return 1; |
da0436e9 | 10234 | } |
2fcee4bf | 10235 | |
da0436e9 JS |
10236 | return 0; |
10237 | } | |
10238 | ||
e59058c4 | 10239 | /** |
3621a710 | 10240 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
10241 | * @phba: Pointer to HBA context. |
10242 | * | |
3772a991 | 10243 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
10244 | * error attention register bit for error attention events. |
10245 | * | |
25985edc | 10246 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
10247 | * Register and returns 0 otherwise. |
10248 | **/ | |
10249 | int | |
10250 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
10251 | { | |
10252 | uint32_t ha_copy; | |
10253 | ||
10254 | /* If somebody is waiting to handle an eratt, don't process it | |
10255 | * here. The brdkill function will do this. | |
10256 | */ | |
10257 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10258 | return 0; | |
10259 | ||
10260 | /* Check if interrupt handler handles this ERATT */ | |
10261 | spin_lock_irq(&phba->hbalock); | |
10262 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
10263 | /* Interrupt handler has handled ERATT */ | |
10264 | spin_unlock_irq(&phba->hbalock); | |
10265 | return 0; | |
10266 | } | |
10267 | ||
a257bf90 JS |
10268 | /* |
10269 | * If there is deferred error attention, do not check for error | |
10270 | * attention | |
10271 | */ | |
10272 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
10273 | spin_unlock_irq(&phba->hbalock); | |
10274 | return 0; | |
10275 | } | |
10276 | ||
3772a991 JS |
10277 | /* If PCI channel is offline, don't process it */ |
10278 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 10279 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
10280 | return 0; |
10281 | } | |
10282 | ||
10283 | switch (phba->sli_rev) { | |
10284 | case LPFC_SLI_REV2: | |
10285 | case LPFC_SLI_REV3: | |
10286 | /* Read chip Host Attention (HA) register */ | |
10287 | ha_copy = lpfc_sli_eratt_read(phba); | |
10288 | break; | |
da0436e9 | 10289 | case LPFC_SLI_REV4: |
2fcee4bf | 10290 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
10291 | ha_copy = lpfc_sli4_eratt_read(phba); |
10292 | break; | |
3772a991 JS |
10293 | default: |
10294 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10295 | "0299 Invalid SLI revision (%d)\n", | |
10296 | phba->sli_rev); | |
10297 | ha_copy = 0; | |
10298 | break; | |
9399627f JS |
10299 | } |
10300 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
10301 | |
10302 | return ha_copy; | |
10303 | } | |
10304 | ||
10305 | /** | |
10306 | * lpfc_intr_state_check - Check device state for interrupt handling | |
10307 | * @phba: Pointer to HBA context. | |
10308 | * | |
10309 | * This inline routine checks whether a device or its PCI slot is in a state | |
10310 | * that the interrupt should be handled. | |
10311 | * | |
10312 | * This function returns 0 if the device or the PCI slot is in a state that | |
10313 | * interrupt should be handled, otherwise -EIO. | |
10314 | */ | |
10315 | static inline int | |
10316 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
10317 | { | |
10318 | /* If the pci channel is offline, ignore all the interrupts */ | |
10319 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
10320 | return -EIO; | |
10321 | ||
10322 | /* Update device level interrupt statistics */ | |
10323 | phba->sli.slistat.sli_intr++; | |
10324 | ||
10325 | /* Ignore all interrupts during initialization. */ | |
10326 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
10327 | return -EIO; | |
10328 | ||
9399627f JS |
10329 | return 0; |
10330 | } | |
10331 | ||
10332 | /** | |
3772a991 | 10333 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
10334 | * @irq: Interrupt number. |
10335 | * @dev_id: The device context pointer. | |
10336 | * | |
9399627f | 10337 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
10338 | * service routine when device with SLI-3 interface spec is enabled with |
10339 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
10340 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
10341 | * interrupt mode, this function is called as part of the device-level | |
10342 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
10343 | * is undergoing initialization, the interrupt handler will not process | |
10344 | * the interrupt. The link attention and ELS ring attention events are | |
10345 | * handled by the worker thread. The interrupt handler signals the worker | |
10346 | * thread and returns for these events. This function is called without | |
10347 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
10348 | * structures. |
10349 | * | |
10350 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10351 | * returns IRQ_NONE. | |
e59058c4 | 10352 | **/ |
dea3101e | 10353 | irqreturn_t |
3772a991 | 10354 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 10355 | { |
2e0fef85 | 10356 | struct lpfc_hba *phba; |
a747c9ce | 10357 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
10358 | uint32_t work_ha_copy; |
10359 | unsigned long status; | |
5b75da2f | 10360 | unsigned long iflag; |
dea3101e JB |
10361 | uint32_t control; |
10362 | ||
92d7f7b0 | 10363 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
10364 | struct lpfc_vport *vport; |
10365 | struct lpfc_nodelist *ndlp; | |
10366 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
10367 | LPFC_MBOXQ_t *pmb; |
10368 | int rc; | |
10369 | ||
dea3101e JB |
10370 | /* |
10371 | * Get the driver's phba structure from the dev_id and | |
10372 | * assume the HBA is not interrupting. | |
10373 | */ | |
9399627f | 10374 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
10375 | |
10376 | if (unlikely(!phba)) | |
10377 | return IRQ_NONE; | |
10378 | ||
dea3101e | 10379 | /* |
9399627f JS |
10380 | * Stuff needs to be attented to when this function is invoked as an |
10381 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 10382 | */ |
9399627f | 10383 | if (phba->intr_type == MSIX) { |
3772a991 JS |
10384 | /* Check device state for handling interrupt */ |
10385 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10386 | return IRQ_NONE; |
10387 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 10388 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10389 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10390 | goto unplug_error; | |
9399627f JS |
10391 | /* If somebody is waiting to handle an eratt don't process it |
10392 | * here. The brdkill function will do this. | |
10393 | */ | |
10394 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10395 | ha_copy &= ~HA_ERATT; | |
10396 | /* Check the need for handling ERATT in interrupt handler */ | |
10397 | if (ha_copy & HA_ERATT) { | |
10398 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10399 | /* ERATT polling has handled ERATT */ | |
10400 | ha_copy &= ~HA_ERATT; | |
10401 | else | |
10402 | /* Indicate interrupt handler handles ERATT */ | |
10403 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10404 | } | |
a257bf90 JS |
10405 | |
10406 | /* | |
10407 | * If there is deferred error attention, do not check for any | |
10408 | * interrupt. | |
10409 | */ | |
10410 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10411 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10412 | return IRQ_NONE; |
10413 | } | |
10414 | ||
9399627f | 10415 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
10416 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
10417 | goto unplug_error; | |
10418 | ||
a747c9ce JS |
10419 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
10420 | HC_LAINT_ENA | HC_ERINT_ENA), | |
10421 | phba->HCregaddr); | |
9399627f JS |
10422 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
10423 | phba->HAregaddr); | |
a747c9ce | 10424 | writel(hc_copy, phba->HCregaddr); |
9399627f | 10425 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 10426 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10427 | } else |
10428 | ha_copy = phba->ha_copy; | |
dea3101e | 10429 | |
dea3101e JB |
10430 | work_ha_copy = ha_copy & phba->work_ha_mask; |
10431 | ||
9399627f | 10432 | if (work_ha_copy) { |
dea3101e JB |
10433 | if (work_ha_copy & HA_LATT) { |
10434 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
10435 | /* | |
10436 | * Turn off Link Attention interrupts | |
10437 | * until CLEAR_LA done | |
10438 | */ | |
5b75da2f | 10439 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10440 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
10441 | if (lpfc_readl(phba->HCregaddr, &control)) |
10442 | goto unplug_error; | |
dea3101e JB |
10443 | control &= ~HC_LAINT_ENA; |
10444 | writel(control, phba->HCregaddr); | |
10445 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 10446 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
10447 | } |
10448 | else | |
10449 | work_ha_copy &= ~HA_LATT; | |
10450 | } | |
10451 | ||
9399627f | 10452 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
10453 | /* |
10454 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
10455 | * the only slow ring. | |
10456 | */ | |
10457 | status = (work_ha_copy & | |
10458 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10459 | status >>= (4*LPFC_ELS_RING); | |
10460 | if (status & HA_RXMASK) { | |
5b75da2f | 10461 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10462 | if (lpfc_readl(phba->HCregaddr, &control)) |
10463 | goto unplug_error; | |
a58cbd52 JS |
10464 | |
10465 | lpfc_debugfs_slow_ring_trc(phba, | |
10466 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
10467 | control, status, | |
10468 | (uint32_t)phba->sli.slistat.sli_intr); | |
10469 | ||
858c9f6c | 10470 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
10471 | lpfc_debugfs_slow_ring_trc(phba, |
10472 | "ISR Disable ring:" | |
10473 | "pwork:x%x hawork:x%x wait:x%x", | |
10474 | phba->work_ha, work_ha_copy, | |
10475 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10476 | &phba->work_waitq)); |
a58cbd52 | 10477 | |
858c9f6c JS |
10478 | control &= |
10479 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
10480 | writel(control, phba->HCregaddr); |
10481 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 10482 | } |
a58cbd52 JS |
10483 | else { |
10484 | lpfc_debugfs_slow_ring_trc(phba, | |
10485 | "ISR slow ring: pwork:" | |
10486 | "x%x hawork:x%x wait:x%x", | |
10487 | phba->work_ha, work_ha_copy, | |
10488 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10489 | &phba->work_waitq)); |
a58cbd52 | 10490 | } |
5b75da2f | 10491 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
10492 | } |
10493 | } | |
5b75da2f | 10494 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 10495 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
10496 | if (lpfc_sli_read_hs(phba)) |
10497 | goto unplug_error; | |
a257bf90 JS |
10498 | /* |
10499 | * Check if there is a deferred error condition | |
10500 | * is active | |
10501 | */ | |
10502 | if ((HS_FFER1 & phba->work_hs) && | |
10503 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
10504 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
10505 | phba->work_hs)) { | |
a257bf90 JS |
10506 | phba->hba_flag |= DEFER_ERATT; |
10507 | /* Clear all interrupt enable conditions */ | |
10508 | writel(0, phba->HCregaddr); | |
10509 | readl(phba->HCregaddr); | |
10510 | } | |
10511 | } | |
10512 | ||
9399627f | 10513 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 10514 | pmb = phba->sli.mbox_active; |
04c68496 | 10515 | pmbox = &pmb->u.mb; |
34b02dcd | 10516 | mbox = phba->mbox; |
858c9f6c | 10517 | vport = pmb->vport; |
92d7f7b0 JS |
10518 | |
10519 | /* First check out the status word */ | |
10520 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
10521 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 10522 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
10523 | /* |
10524 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
10525 | * mbxStatus <status> | |
10526 | */ | |
09372820 | 10527 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 10528 | LOG_SLI, |
e8b62011 | 10529 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
10530 | "Interrupt mbxCommand x%x " |
10531 | "mbxStatus x%x\n", | |
e8b62011 | 10532 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
10533 | pmbox->mbxCommand, |
10534 | pmbox->mbxStatus); | |
09372820 JS |
10535 | /* clear mailbox attention bit */ |
10536 | work_ha_copy &= ~HA_MBATT; | |
10537 | } else { | |
97eab634 | 10538 | phba->sli.mbox_active = NULL; |
5b75da2f | 10539 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
10540 | phba->last_completion_time = jiffies; |
10541 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
10542 | if (pmb->mbox_cmpl) { |
10543 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
10544 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
10545 | if (pmb->out_ext_byte_len && |
10546 | pmb->context2) | |
10547 | lpfc_sli_pcimem_bcopy( | |
10548 | phba->mbox_ext, | |
10549 | pmb->context2, | |
10550 | pmb->out_ext_byte_len); | |
09372820 JS |
10551 | } |
10552 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
10553 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
10554 | ||
10555 | lpfc_debugfs_disc_trc(vport, | |
10556 | LPFC_DISC_TRC_MBOX_VPORT, | |
10557 | "MBOX dflt rpi: : " | |
10558 | "status:x%x rpi:x%x", | |
10559 | (uint32_t)pmbox->mbxStatus, | |
10560 | pmbox->un.varWords[0], 0); | |
10561 | ||
10562 | if (!pmbox->mbxStatus) { | |
10563 | mp = (struct lpfc_dmabuf *) | |
10564 | (pmb->context1); | |
10565 | ndlp = (struct lpfc_nodelist *) | |
10566 | pmb->context2; | |
10567 | ||
10568 | /* Reg_LOGIN of dflt RPI was | |
10569 | * successful. new lets get | |
10570 | * rid of the RPI using the | |
10571 | * same mbox buffer. | |
10572 | */ | |
10573 | lpfc_unreg_login(phba, | |
10574 | vport->vpi, | |
10575 | pmbox->un.varWords[0], | |
10576 | pmb); | |
10577 | pmb->mbox_cmpl = | |
10578 | lpfc_mbx_cmpl_dflt_rpi; | |
10579 | pmb->context1 = mp; | |
10580 | pmb->context2 = ndlp; | |
10581 | pmb->vport = vport; | |
58da1ffb JS |
10582 | rc = lpfc_sli_issue_mbox(phba, |
10583 | pmb, | |
10584 | MBX_NOWAIT); | |
10585 | if (rc != MBX_BUSY) | |
10586 | lpfc_printf_log(phba, | |
10587 | KERN_ERR, | |
10588 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 10589 | "0350 rc should have" |
6a9c52cf | 10590 | "been MBX_BUSY\n"); |
3772a991 JS |
10591 | if (rc != MBX_NOT_FINISHED) |
10592 | goto send_current_mbox; | |
09372820 | 10593 | } |
858c9f6c | 10594 | } |
5b75da2f JS |
10595 | spin_lock_irqsave( |
10596 | &phba->pport->work_port_lock, | |
10597 | iflag); | |
09372820 JS |
10598 | phba->pport->work_port_events &= |
10599 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
10600 | spin_unlock_irqrestore( |
10601 | &phba->pport->work_port_lock, | |
10602 | iflag); | |
09372820 | 10603 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 10604 | } |
97eab634 | 10605 | } else |
5b75da2f | 10606 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 10607 | |
92d7f7b0 JS |
10608 | if ((work_ha_copy & HA_MBATT) && |
10609 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 10610 | send_current_mbox: |
92d7f7b0 | 10611 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
10612 | do { |
10613 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
10614 | MBX_NOWAIT); | |
10615 | } while (rc == MBX_NOT_FINISHED); | |
10616 | if (rc != MBX_SUCCESS) | |
10617 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
10618 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 10619 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
10620 | } |
10621 | ||
5b75da2f | 10622 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10623 | phba->work_ha |= work_ha_copy; |
5b75da2f | 10624 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 10625 | lpfc_worker_wake_up(phba); |
dea3101e | 10626 | } |
9399627f | 10627 | return IRQ_HANDLED; |
9940b97b JS |
10628 | unplug_error: |
10629 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10630 | return IRQ_HANDLED; | |
dea3101e | 10631 | |
3772a991 | 10632 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
10633 | |
10634 | /** | |
3772a991 | 10635 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
10636 | * @irq: Interrupt number. |
10637 | * @dev_id: The device context pointer. | |
10638 | * | |
10639 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
10640 | * service routine when device with SLI-3 interface spec is enabled with |
10641 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10642 | * ring event in the HBA. However, when the device is enabled with either | |
10643 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10644 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10645 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10646 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
10647 | * the intrrupt context. This function is called without any lock held. | |
10648 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
10649 | * |
10650 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10651 | * returns IRQ_NONE. | |
10652 | **/ | |
10653 | irqreturn_t | |
3772a991 | 10654 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
10655 | { |
10656 | struct lpfc_hba *phba; | |
10657 | uint32_t ha_copy; | |
10658 | unsigned long status; | |
5b75da2f | 10659 | unsigned long iflag; |
9399627f JS |
10660 | |
10661 | /* Get the driver's phba structure from the dev_id and | |
10662 | * assume the HBA is not interrupting. | |
10663 | */ | |
10664 | phba = (struct lpfc_hba *) dev_id; | |
10665 | ||
10666 | if (unlikely(!phba)) | |
10667 | return IRQ_NONE; | |
10668 | ||
10669 | /* | |
10670 | * Stuff needs to be attented to when this function is invoked as an | |
10671 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
10672 | */ | |
10673 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
10674 | /* Check device state for handling interrupt */ |
10675 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10676 | return IRQ_NONE; |
10677 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
10678 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10679 | return IRQ_HANDLED; | |
9399627f | 10680 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 10681 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
10682 | /* |
10683 | * If there is deferred error attention, do not check for | |
10684 | * any interrupt. | |
10685 | */ | |
10686 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10687 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10688 | return IRQ_NONE; |
10689 | } | |
9399627f JS |
10690 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
10691 | phba->HAregaddr); | |
10692 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 10693 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10694 | } else |
10695 | ha_copy = phba->ha_copy; | |
dea3101e JB |
10696 | |
10697 | /* | |
9399627f | 10698 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 10699 | */ |
9399627f JS |
10700 | ha_copy &= ~(phba->work_ha_mask); |
10701 | ||
10702 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 10703 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 10704 | if (status & HA_RXMASK) |
dea3101e JB |
10705 | lpfc_sli_handle_fast_ring_event(phba, |
10706 | &phba->sli.ring[LPFC_FCP_RING], | |
10707 | status); | |
a4bc3379 JS |
10708 | |
10709 | if (phba->cfg_multi_ring_support == 2) { | |
10710 | /* | |
9399627f JS |
10711 | * Process all events on extra ring. Take the optimized path |
10712 | * for extra ring IO. | |
a4bc3379 | 10713 | */ |
9399627f | 10714 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 10715 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 10716 | if (status & HA_RXMASK) { |
a4bc3379 JS |
10717 | lpfc_sli_handle_fast_ring_event(phba, |
10718 | &phba->sli.ring[LPFC_EXTRA_RING], | |
10719 | status); | |
10720 | } | |
10721 | } | |
dea3101e | 10722 | return IRQ_HANDLED; |
3772a991 | 10723 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
10724 | |
10725 | /** | |
3772a991 | 10726 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
10727 | * @irq: Interrupt number. |
10728 | * @dev_id: The device context pointer. | |
10729 | * | |
3772a991 JS |
10730 | * This function is the HBA device-level interrupt handler to device with |
10731 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
10732 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
10733 | * requires driver attention. This function invokes the slow-path interrupt | |
10734 | * attention handling function and fast-path interrupt attention handling | |
10735 | * function in turn to process the relevant HBA attention events. This | |
10736 | * function is called without any lock held. It gets the hbalock to access | |
10737 | * and update SLI data structures. | |
9399627f JS |
10738 | * |
10739 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
10740 | * returns IRQ_NONE. | |
10741 | **/ | |
10742 | irqreturn_t | |
3772a991 | 10743 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
10744 | { |
10745 | struct lpfc_hba *phba; | |
10746 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
10747 | unsigned long status1, status2; | |
a747c9ce | 10748 | uint32_t hc_copy; |
9399627f JS |
10749 | |
10750 | /* | |
10751 | * Get the driver's phba structure from the dev_id and | |
10752 | * assume the HBA is not interrupting. | |
10753 | */ | |
10754 | phba = (struct lpfc_hba *) dev_id; | |
10755 | ||
10756 | if (unlikely(!phba)) | |
10757 | return IRQ_NONE; | |
10758 | ||
3772a991 JS |
10759 | /* Check device state for handling interrupt */ |
10760 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10761 | return IRQ_NONE; |
10762 | ||
10763 | spin_lock(&phba->hbalock); | |
9940b97b JS |
10764 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
10765 | spin_unlock(&phba->hbalock); | |
10766 | return IRQ_HANDLED; | |
10767 | } | |
10768 | ||
9399627f JS |
10769 | if (unlikely(!phba->ha_copy)) { |
10770 | spin_unlock(&phba->hbalock); | |
10771 | return IRQ_NONE; | |
10772 | } else if (phba->ha_copy & HA_ERATT) { | |
10773 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10774 | /* ERATT polling has handled ERATT */ | |
10775 | phba->ha_copy &= ~HA_ERATT; | |
10776 | else | |
10777 | /* Indicate interrupt handler handles ERATT */ | |
10778 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10779 | } | |
10780 | ||
a257bf90 JS |
10781 | /* |
10782 | * If there is deferred error attention, do not check for any interrupt. | |
10783 | */ | |
10784 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 10785 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
10786 | return IRQ_NONE; |
10787 | } | |
10788 | ||
9399627f | 10789 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
10790 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
10791 | spin_unlock(&phba->hbalock); | |
10792 | return IRQ_HANDLED; | |
10793 | } | |
a747c9ce JS |
10794 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
10795 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
10796 | phba->HCregaddr); | |
9399627f | 10797 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 10798 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
10799 | readl(phba->HAregaddr); /* flush */ |
10800 | spin_unlock(&phba->hbalock); | |
10801 | ||
10802 | /* | |
10803 | * Invokes slow-path host attention interrupt handling as appropriate. | |
10804 | */ | |
10805 | ||
10806 | /* status of events with mailbox and link attention */ | |
10807 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
10808 | ||
10809 | /* status of events with ELS ring */ | |
10810 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10811 | status2 >>= (4*LPFC_ELS_RING); | |
10812 | ||
10813 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 10814 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
10815 | else |
10816 | sp_irq_rc = IRQ_NONE; | |
10817 | ||
10818 | /* | |
10819 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10820 | */ | |
10821 | ||
10822 | /* status of events with FCP ring */ | |
10823 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
10824 | status1 >>= (4*LPFC_FCP_RING); | |
10825 | ||
10826 | /* status of events with extra ring */ | |
10827 | if (phba->cfg_multi_ring_support == 2) { | |
10828 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
10829 | status2 >>= (4*LPFC_EXTRA_RING); | |
10830 | } else | |
10831 | status2 = 0; | |
10832 | ||
10833 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 10834 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
10835 | else |
10836 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 10837 | |
9399627f JS |
10838 | /* Return device-level interrupt handling status */ |
10839 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 10840 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
10841 | |
10842 | /** | |
10843 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
10844 | * @phba: pointer to lpfc hba data structure. | |
10845 | * | |
10846 | * This routine is invoked by the worker thread to process all the pending | |
10847 | * SLI4 FCP abort XRI events. | |
10848 | **/ | |
10849 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
10850 | { | |
10851 | struct lpfc_cq_event *cq_event; | |
10852 | ||
10853 | /* First, declare the fcp xri abort event has been handled */ | |
10854 | spin_lock_irq(&phba->hbalock); | |
10855 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
10856 | spin_unlock_irq(&phba->hbalock); | |
10857 | /* Now, handle all the fcp xri abort events */ | |
10858 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
10859 | /* Get the first event from the head of the event queue */ | |
10860 | spin_lock_irq(&phba->hbalock); | |
10861 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
10862 | cq_event, struct lpfc_cq_event, list); | |
10863 | spin_unlock_irq(&phba->hbalock); | |
10864 | /* Notify aborted XRI for FCP work queue */ | |
10865 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10866 | /* Free the event processed back to the free pool */ | |
10867 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10868 | } | |
10869 | } | |
10870 | ||
10871 | /** | |
10872 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
10873 | * @phba: pointer to lpfc hba data structure. | |
10874 | * | |
10875 | * This routine is invoked by the worker thread to process all the pending | |
10876 | * SLI4 els abort xri events. | |
10877 | **/ | |
10878 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
10879 | { | |
10880 | struct lpfc_cq_event *cq_event; | |
10881 | ||
10882 | /* First, declare the els xri abort event has been handled */ | |
10883 | spin_lock_irq(&phba->hbalock); | |
10884 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
10885 | spin_unlock_irq(&phba->hbalock); | |
10886 | /* Now, handle all the els xri abort events */ | |
10887 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
10888 | /* Get the first event from the head of the event queue */ | |
10889 | spin_lock_irq(&phba->hbalock); | |
10890 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
10891 | cq_event, struct lpfc_cq_event, list); | |
10892 | spin_unlock_irq(&phba->hbalock); | |
10893 | /* Notify aborted XRI for ELS work queue */ | |
10894 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10895 | /* Free the event processed back to the free pool */ | |
10896 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10897 | } | |
10898 | } | |
10899 | ||
341af102 JS |
10900 | /** |
10901 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
10902 | * @phba: pointer to lpfc hba data structure | |
10903 | * @pIocbIn: pointer to the rspiocbq | |
10904 | * @pIocbOut: pointer to the cmdiocbq | |
10905 | * @wcqe: pointer to the complete wcqe | |
10906 | * | |
10907 | * This routine transfers the fields of a command iocbq to a response iocbq | |
10908 | * by copying all the IOCB fields from command iocbq and transferring the | |
10909 | * completion status information from the complete wcqe. | |
10910 | **/ | |
4f774513 | 10911 | static void |
341af102 JS |
10912 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
10913 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
10914 | struct lpfc_iocbq *pIocbOut, |
10915 | struct lpfc_wcqe_complete *wcqe) | |
10916 | { | |
341af102 | 10917 | unsigned long iflags; |
acd6859b | 10918 | uint32_t status; |
4f774513 JS |
10919 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
10920 | ||
10921 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
10922 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 | 10923 | /* Map WCQE parameters into irspiocb parameters */ |
acd6859b JS |
10924 | status = bf_get(lpfc_wcqe_c_status, wcqe); |
10925 | pIocbIn->iocb.ulpStatus = (status & LPFC_IOCB_STATUS_MASK); | |
4f774513 JS |
10926 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) |
10927 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
10928 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
10929 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
10930 | wcqe->total_data_placed; | |
10931 | else | |
10932 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 10933 | else { |
4f774513 | 10934 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
10935 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
10936 | } | |
341af102 | 10937 | |
acd6859b JS |
10938 | /* Convert BG errors for completion status */ |
10939 | if (status == CQE_STATUS_DI_ERROR) { | |
10940 | pIocbIn->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; | |
10941 | ||
10942 | if (bf_get(lpfc_wcqe_c_bg_edir, wcqe)) | |
10943 | pIocbIn->iocb.un.ulpWord[4] = IOERR_RX_DMA_FAILED; | |
10944 | else | |
10945 | pIocbIn->iocb.un.ulpWord[4] = IOERR_TX_DMA_FAILED; | |
10946 | ||
10947 | pIocbIn->iocb.unsli3.sli3_bg.bgstat = 0; | |
10948 | if (bf_get(lpfc_wcqe_c_bg_ge, wcqe)) /* Guard Check failed */ | |
10949 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10950 | BGS_GUARD_ERR_MASK; | |
10951 | if (bf_get(lpfc_wcqe_c_bg_ae, wcqe)) /* App Tag Check failed */ | |
10952 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10953 | BGS_APPTAG_ERR_MASK; | |
10954 | if (bf_get(lpfc_wcqe_c_bg_re, wcqe)) /* Ref Tag Check failed */ | |
10955 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10956 | BGS_REFTAG_ERR_MASK; | |
10957 | ||
10958 | /* Check to see if there was any good data before the error */ | |
10959 | if (bf_get(lpfc_wcqe_c_bg_tdpv, wcqe)) { | |
10960 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10961 | BGS_HI_WATER_MARK_PRESENT_MASK; | |
10962 | pIocbIn->iocb.unsli3.sli3_bg.bghm = | |
10963 | wcqe->total_data_placed; | |
10964 | } | |
10965 | ||
10966 | /* | |
10967 | * Set ALL the error bits to indicate we don't know what | |
10968 | * type of error it is. | |
10969 | */ | |
10970 | if (!pIocbIn->iocb.unsli3.sli3_bg.bgstat) | |
10971 | pIocbIn->iocb.unsli3.sli3_bg.bgstat |= | |
10972 | (BGS_REFTAG_ERR_MASK | BGS_APPTAG_ERR_MASK | | |
10973 | BGS_GUARD_ERR_MASK); | |
10974 | } | |
10975 | ||
341af102 JS |
10976 | /* Pick up HBA exchange busy condition */ |
10977 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
10978 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10979 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
10980 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10981 | } | |
4f774513 JS |
10982 | } |
10983 | ||
45ed1190 JS |
10984 | /** |
10985 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
10986 | * @phba: Pointer to HBA context object. | |
10987 | * @wcqe: Pointer to work-queue completion queue entry. | |
10988 | * | |
10989 | * This routine handles an ELS work-queue completion event and construct | |
10990 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
10991 | * discovery engine to handle. | |
10992 | * | |
10993 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
10994 | **/ | |
10995 | static struct lpfc_iocbq * | |
10996 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
10997 | struct lpfc_iocbq *irspiocbq) | |
10998 | { | |
10999 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
11000 | struct lpfc_iocbq *cmdiocbq; | |
11001 | struct lpfc_wcqe_complete *wcqe; | |
11002 | unsigned long iflags; | |
11003 | ||
11004 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
7e56aa25 | 11005 | spin_lock_irqsave(&pring->ring_lock, iflags); |
45ed1190 JS |
11006 | pring->stats.iocb_event++; |
11007 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
11008 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
11009 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 11010 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
45ed1190 JS |
11011 | |
11012 | if (unlikely(!cmdiocbq)) { | |
11013 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11014 | "0386 ELS complete with no corresponding " | |
11015 | "cmdiocb: iotag (%d)\n", | |
11016 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11017 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
11018 | return NULL; | |
11019 | } | |
11020 | ||
11021 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 11022 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
11023 | |
11024 | return irspiocbq; | |
11025 | } | |
11026 | ||
04c68496 JS |
11027 | /** |
11028 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
11029 | * @phba: Pointer to HBA context object. | |
11030 | * @cqe: Pointer to mailbox completion queue entry. | |
11031 | * | |
11032 | * This routine process a mailbox completion queue entry with asynchrous | |
11033 | * event. | |
11034 | * | |
11035 | * Return: true if work posted to worker thread, otherwise false. | |
11036 | **/ | |
11037 | static bool | |
11038 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11039 | { | |
11040 | struct lpfc_cq_event *cq_event; | |
11041 | unsigned long iflags; | |
11042 | ||
11043 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
11044 | "0392 Async Event: word0:x%x, word1:x%x, " | |
11045 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
11046 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
11047 | ||
11048 | /* Allocate a new internal CQ_EVENT entry */ | |
11049 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11050 | if (!cq_event) { | |
11051 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11052 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
11053 | return false; | |
11054 | } | |
11055 | ||
11056 | /* Move the CQE into an asynchronous event entry */ | |
11057 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
11058 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11059 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
11060 | /* Set the async event flag */ | |
11061 | phba->hba_flag |= ASYNC_EVENT; | |
11062 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11063 | ||
11064 | return true; | |
11065 | } | |
11066 | ||
11067 | /** | |
11068 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
11069 | * @phba: Pointer to HBA context object. | |
11070 | * @cqe: Pointer to mailbox completion queue entry. | |
11071 | * | |
11072 | * This routine process a mailbox completion queue entry with mailbox | |
11073 | * completion event. | |
11074 | * | |
11075 | * Return: true if work posted to worker thread, otherwise false. | |
11076 | **/ | |
11077 | static bool | |
11078 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
11079 | { | |
11080 | uint32_t mcqe_status; | |
11081 | MAILBOX_t *mbox, *pmbox; | |
11082 | struct lpfc_mqe *mqe; | |
11083 | struct lpfc_vport *vport; | |
11084 | struct lpfc_nodelist *ndlp; | |
11085 | struct lpfc_dmabuf *mp; | |
11086 | unsigned long iflags; | |
11087 | LPFC_MBOXQ_t *pmb; | |
11088 | bool workposted = false; | |
11089 | int rc; | |
11090 | ||
11091 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
11092 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
11093 | goto out_no_mqe_complete; | |
11094 | ||
11095 | /* Get the reference to the active mbox command */ | |
11096 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11097 | pmb = phba->sli.mbox_active; | |
11098 | if (unlikely(!pmb)) { | |
11099 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
11100 | "1832 No pending MBOX command to handle\n"); | |
11101 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11102 | goto out_no_mqe_complete; | |
11103 | } | |
11104 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11105 | mqe = &pmb->u.mqe; | |
11106 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
11107 | mbox = phba->mbox; | |
11108 | vport = pmb->vport; | |
11109 | ||
11110 | /* Reset heartbeat timer */ | |
11111 | phba->last_completion_time = jiffies; | |
11112 | del_timer(&phba->sli.mbox_tmo); | |
11113 | ||
11114 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
11115 | if (pmb->mbox_cmpl && mbox) | |
11116 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
04c68496 | 11117 | |
73d91e50 JS |
11118 | /* |
11119 | * For mcqe errors, conditionally move a modified error code to | |
11120 | * the mbox so that the error will not be missed. | |
11121 | */ | |
11122 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
11123 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
11124 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) | |
11125 | bf_set(lpfc_mqe_status, mqe, | |
11126 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
11127 | } | |
04c68496 JS |
11128 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
11129 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
11130 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
11131 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
11132 | mcqe_status, | |
11133 | pmbox->un.varWords[0], 0); | |
11134 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
11135 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
11136 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
11137 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
11138 | * RID of the PPI using the same mbox buffer. | |
11139 | */ | |
11140 | lpfc_unreg_login(phba, vport->vpi, | |
11141 | pmbox->un.varWords[0], pmb); | |
11142 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
11143 | pmb->context1 = mp; | |
11144 | pmb->context2 = ndlp; | |
11145 | pmb->vport = vport; | |
11146 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
11147 | if (rc != MBX_BUSY) | |
11148 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
11149 | LOG_SLI, "0385 rc should " | |
11150 | "have been MBX_BUSY\n"); | |
11151 | if (rc != MBX_NOT_FINISHED) | |
11152 | goto send_current_mbox; | |
11153 | } | |
11154 | } | |
11155 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
11156 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
11157 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
11158 | ||
11159 | /* There is mailbox completion work to do */ | |
11160 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11161 | __lpfc_mbox_cmpl_put(phba, pmb); | |
11162 | phba->work_ha |= HA_MBATT; | |
11163 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11164 | workposted = true; | |
11165 | ||
11166 | send_current_mbox: | |
11167 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11168 | /* Release the mailbox command posting token */ | |
11169 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
11170 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
11171 | phba->sli.mbox_active = NULL; | |
11172 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11173 | /* Wake up worker thread to post the next pending mailbox command */ | |
11174 | lpfc_worker_wake_up(phba); | |
11175 | out_no_mqe_complete: | |
11176 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
11177 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
11178 | return workposted; | |
11179 | } | |
11180 | ||
11181 | /** | |
11182 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
11183 | * @phba: Pointer to HBA context object. | |
11184 | * @cqe: Pointer to mailbox completion queue entry. | |
11185 | * | |
11186 | * This routine process a mailbox completion queue entry, it invokes the | |
11187 | * proper mailbox complete handling or asynchrous event handling routine | |
11188 | * according to the MCQE's async bit. | |
11189 | * | |
11190 | * Return: true if work posted to worker thread, otherwise false. | |
11191 | **/ | |
11192 | static bool | |
11193 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
11194 | { | |
11195 | struct lpfc_mcqe mcqe; | |
11196 | bool workposted; | |
11197 | ||
11198 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
11199 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
11200 | ||
11201 | /* Invoke the proper event handling routine */ | |
11202 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
11203 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
11204 | else | |
11205 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
11206 | return workposted; | |
11207 | } | |
11208 | ||
4f774513 JS |
11209 | /** |
11210 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
11211 | * @phba: Pointer to HBA context object. | |
2a76a283 | 11212 | * @cq: Pointer to associated CQ |
4f774513 JS |
11213 | * @wcqe: Pointer to work-queue completion queue entry. |
11214 | * | |
11215 | * This routine handles an ELS work-queue completion event. | |
11216 | * | |
11217 | * Return: true if work posted to worker thread, otherwise false. | |
11218 | **/ | |
11219 | static bool | |
2a76a283 | 11220 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
11221 | struct lpfc_wcqe_complete *wcqe) |
11222 | { | |
4f774513 JS |
11223 | struct lpfc_iocbq *irspiocbq; |
11224 | unsigned long iflags; | |
2a76a283 | 11225 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 | 11226 | |
45ed1190 | 11227 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
11228 | irspiocbq = lpfc_sli_get_iocbq(phba); |
11229 | if (!irspiocbq) { | |
11230 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
11231 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
11232 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
11233 | pring->txq_cnt, phba->iocb_cnt, | |
11234 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
11235 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 11236 | return false; |
4f774513 | 11237 | } |
4f774513 | 11238 | |
45ed1190 JS |
11239 | /* Save off the slow-path queue event for work thread to process */ |
11240 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 11241 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 11242 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
11243 | &phba->sli4_hba.sp_queue_event); |
11244 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 11245 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 11246 | |
45ed1190 | 11247 | return true; |
4f774513 JS |
11248 | } |
11249 | ||
11250 | /** | |
11251 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
11252 | * @phba: Pointer to HBA context object. | |
11253 | * @wcqe: Pointer to work-queue completion queue entry. | |
11254 | * | |
11255 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
11256 | * proper WQ release routine to the slow-path WQ. | |
11257 | **/ | |
11258 | static void | |
11259 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
11260 | struct lpfc_wcqe_release *wcqe) | |
11261 | { | |
2e90f4b5 JS |
11262 | /* sanity check on queue memory */ |
11263 | if (unlikely(!phba->sli4_hba.els_wq)) | |
11264 | return; | |
4f774513 JS |
11265 | /* Check for the slow-path ELS work queue */ |
11266 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
11267 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
11268 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
11269 | else | |
11270 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11271 | "2579 Slow-path wqe consume event carries " | |
11272 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
11273 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
11274 | phba->sli4_hba.els_wq->queue_id); | |
11275 | } | |
11276 | ||
11277 | /** | |
11278 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
11279 | * @phba: Pointer to HBA context object. | |
11280 | * @cq: Pointer to a WQ completion queue. | |
11281 | * @wcqe: Pointer to work-queue completion queue entry. | |
11282 | * | |
11283 | * This routine handles an XRI abort event. | |
11284 | * | |
11285 | * Return: true if work posted to worker thread, otherwise false. | |
11286 | **/ | |
11287 | static bool | |
11288 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
11289 | struct lpfc_queue *cq, | |
11290 | struct sli4_wcqe_xri_aborted *wcqe) | |
11291 | { | |
11292 | bool workposted = false; | |
11293 | struct lpfc_cq_event *cq_event; | |
11294 | unsigned long iflags; | |
11295 | ||
11296 | /* Allocate a new internal CQ_EVENT entry */ | |
11297 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
11298 | if (!cq_event) { | |
11299 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11300 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
11301 | return false; | |
11302 | } | |
11303 | ||
11304 | /* Move the CQE into the proper xri abort event list */ | |
11305 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
11306 | switch (cq->subtype) { | |
11307 | case LPFC_FCP: | |
11308 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11309 | list_add_tail(&cq_event->list, | |
11310 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
11311 | /* Set the fcp xri abort event flag */ | |
11312 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
11313 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11314 | workposted = true; | |
11315 | break; | |
11316 | case LPFC_ELS: | |
11317 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11318 | list_add_tail(&cq_event->list, | |
11319 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
11320 | /* Set the els xri abort event flag */ | |
11321 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
11322 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11323 | workposted = true; | |
11324 | break; | |
11325 | default: | |
11326 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11327 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
11328 | cq->subtype); | |
11329 | workposted = false; | |
11330 | break; | |
11331 | } | |
11332 | return workposted; | |
11333 | } | |
11334 | ||
4f774513 JS |
11335 | /** |
11336 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
11337 | * @phba: Pointer to HBA context object. | |
11338 | * @rcqe: Pointer to receive-queue completion queue entry. | |
11339 | * | |
11340 | * This routine process a receive-queue completion queue entry. | |
11341 | * | |
11342 | * Return: true if work posted to worker thread, otherwise false. | |
11343 | **/ | |
11344 | static bool | |
4d9ab994 | 11345 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 11346 | { |
4f774513 JS |
11347 | bool workposted = false; |
11348 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
11349 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
11350 | struct hbq_dmabuf *dma_buf; | |
7851fe2c | 11351 | uint32_t status, rq_id; |
4f774513 JS |
11352 | unsigned long iflags; |
11353 | ||
2e90f4b5 JS |
11354 | /* sanity check on queue memory */ |
11355 | if (unlikely(!hrq) || unlikely(!drq)) | |
11356 | return workposted; | |
11357 | ||
7851fe2c JS |
11358 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
11359 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
11360 | else | |
11361 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
11362 | if (rq_id != hrq->queue_id) | |
4f774513 JS |
11363 | goto out; |
11364 | ||
4d9ab994 | 11365 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
11366 | switch (status) { |
11367 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
11368 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11369 | "2537 Receive Frame Truncated!!\n"); | |
b84daac9 | 11370 | hrq->RQ_buf_trunc++; |
4f774513 | 11371 | case FC_STATUS_RQ_SUCCESS: |
5ffc266e | 11372 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
11373 | spin_lock_irqsave(&phba->hbalock, iflags); |
11374 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
11375 | if (!dma_buf) { | |
b84daac9 | 11376 | hrq->RQ_no_buf_found++; |
4f774513 JS |
11377 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11378 | goto out; | |
11379 | } | |
b84daac9 | 11380 | hrq->RQ_rcv_buf++; |
4d9ab994 | 11381 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 11382 | /* save off the frame for the word thread to process */ |
4d9ab994 | 11383 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 11384 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 11385 | /* Frame received */ |
45ed1190 | 11386 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
11387 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11388 | workposted = true; | |
11389 | break; | |
11390 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
11391 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
b84daac9 | 11392 | hrq->RQ_no_posted_buf++; |
4f774513 JS |
11393 | /* Post more buffers if possible */ |
11394 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11395 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
11396 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11397 | workposted = true; | |
11398 | break; | |
11399 | } | |
11400 | out: | |
11401 | return workposted; | |
4f774513 JS |
11402 | } |
11403 | ||
4d9ab994 JS |
11404 | /** |
11405 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
11406 | * @phba: Pointer to HBA context object. | |
11407 | * @cq: Pointer to the completion queue. | |
11408 | * @wcqe: Pointer to a completion queue entry. | |
11409 | * | |
25985edc | 11410 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
11411 | * entry. |
11412 | * | |
11413 | * Return: true if work posted to worker thread, otherwise false. | |
11414 | **/ | |
11415 | static bool | |
11416 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11417 | struct lpfc_cqe *cqe) | |
11418 | { | |
45ed1190 | 11419 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
11420 | bool workposted = false; |
11421 | ||
11422 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 11423 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
11424 | |
11425 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 11426 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 11427 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 11428 | /* Process the WQ/RQ complete event */ |
bc73905a | 11429 | phba->last_completion_time = jiffies; |
2a76a283 | 11430 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq, |
45ed1190 | 11431 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
11432 | break; |
11433 | case CQE_CODE_RELEASE_WQE: | |
11434 | /* Process the WQ release event */ | |
11435 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 11436 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
11437 | break; |
11438 | case CQE_CODE_XRI_ABORTED: | |
11439 | /* Process the WQ XRI abort event */ | |
bc73905a | 11440 | phba->last_completion_time = jiffies; |
4d9ab994 | 11441 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 11442 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
11443 | break; |
11444 | case CQE_CODE_RECEIVE: | |
7851fe2c | 11445 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 | 11446 | /* Process the RQ event */ |
bc73905a | 11447 | phba->last_completion_time = jiffies; |
4d9ab994 | 11448 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 11449 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
11450 | break; |
11451 | default: | |
11452 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11453 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 11454 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
11455 | break; |
11456 | } | |
11457 | return workposted; | |
11458 | } | |
11459 | ||
4f774513 JS |
11460 | /** |
11461 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
11462 | * @phba: Pointer to HBA context object. | |
11463 | * @eqe: Pointer to fast-path event queue entry. | |
11464 | * | |
11465 | * This routine process a event queue entry from the slow-path event queue. | |
11466 | * It will check the MajorCode and MinorCode to determine this is for a | |
11467 | * completion event on a completion queue, if not, an error shall be logged | |
11468 | * and just return. Otherwise, it will get to the corresponding completion | |
11469 | * queue and process all the entries on that completion queue, rearm the | |
11470 | * completion queue, and then return. | |
11471 | * | |
11472 | **/ | |
11473 | static void | |
67d12733 JS |
11474 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
11475 | struct lpfc_queue *speq) | |
4f774513 | 11476 | { |
67d12733 | 11477 | struct lpfc_queue *cq = NULL, *childq; |
4f774513 JS |
11478 | struct lpfc_cqe *cqe; |
11479 | bool workposted = false; | |
11480 | int ecount = 0; | |
11481 | uint16_t cqid; | |
11482 | ||
4f774513 | 11483 | /* Get the reference to the corresponding CQ */ |
cb5172ea | 11484 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 | 11485 | |
4f774513 JS |
11486 | list_for_each_entry(childq, &speq->child_list, list) { |
11487 | if (childq->queue_id == cqid) { | |
11488 | cq = childq; | |
11489 | break; | |
11490 | } | |
11491 | } | |
11492 | if (unlikely(!cq)) { | |
75baf696 JS |
11493 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
11494 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11495 | "0365 Slow-path CQ identifier " | |
11496 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
11497 | return; |
11498 | } | |
11499 | ||
11500 | /* Process all the entries to the CQ */ | |
11501 | switch (cq->type) { | |
11502 | case LPFC_MCQ: | |
11503 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
11504 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
73d91e50 | 11505 | if (!(++ecount % cq->entry_repost)) |
4f774513 | 11506 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
b84daac9 | 11507 | cq->CQ_mbox++; |
4f774513 JS |
11508 | } |
11509 | break; | |
11510 | case LPFC_WCQ: | |
11511 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
0558056c JS |
11512 | if (cq->subtype == LPFC_FCP) |
11513 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, | |
11514 | cqe); | |
11515 | else | |
11516 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, | |
11517 | cqe); | |
73d91e50 | 11518 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11519 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11520 | } | |
b84daac9 JS |
11521 | |
11522 | /* Track the max number of CQEs processed in 1 EQ */ | |
11523 | if (ecount > cq->CQ_max_cqe) | |
11524 | cq->CQ_max_cqe = ecount; | |
4f774513 JS |
11525 | break; |
11526 | default: | |
11527 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11528 | "0370 Invalid completion queue type (%d)\n", | |
11529 | cq->type); | |
11530 | return; | |
11531 | } | |
11532 | ||
11533 | /* Catch the no cq entry condition, log an error */ | |
11534 | if (unlikely(ecount == 0)) | |
11535 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11536 | "0371 No entry from the CQ: identifier " | |
11537 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
11538 | ||
11539 | /* In any case, flash and re-arm the RCQ */ | |
11540 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
11541 | ||
11542 | /* wake up worker thread if there are works to be done */ | |
11543 | if (workposted) | |
11544 | lpfc_worker_wake_up(phba); | |
11545 | } | |
11546 | ||
11547 | /** | |
11548 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
2a76a283 JS |
11549 | * @phba: Pointer to HBA context object. |
11550 | * @cq: Pointer to associated CQ | |
11551 | * @wcqe: Pointer to work-queue completion queue entry. | |
4f774513 JS |
11552 | * |
11553 | * This routine process a fast-path work queue completion entry from fast-path | |
11554 | * event queue for FCP command response completion. | |
11555 | **/ | |
11556 | static void | |
2a76a283 | 11557 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, |
4f774513 JS |
11558 | struct lpfc_wcqe_complete *wcqe) |
11559 | { | |
2a76a283 | 11560 | struct lpfc_sli_ring *pring = cq->pring; |
4f774513 JS |
11561 | struct lpfc_iocbq *cmdiocbq; |
11562 | struct lpfc_iocbq irspiocbq; | |
11563 | unsigned long iflags; | |
11564 | ||
4f774513 JS |
11565 | /* Check for response status */ |
11566 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
11567 | /* If resource errors reported from HBA, reduce queue | |
11568 | * depth of the SCSI device. | |
11569 | */ | |
11570 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
11571 | IOSTAT_LOCAL_REJECT) && | |
11572 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
11573 | phba->lpfc_rampdown_queue_depth(phba); | |
11574 | } | |
11575 | /* Log the error status */ | |
11576 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11577 | "0373 FCP complete error: status=x%x, " | |
11578 | "hw_status=x%x, total_data_specified=%d, " | |
11579 | "parameter=x%x, word3=x%x\n", | |
11580 | bf_get(lpfc_wcqe_c_status, wcqe), | |
11581 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
11582 | wcqe->total_data_placed, wcqe->parameter, | |
11583 | wcqe->word3); | |
11584 | } | |
11585 | ||
11586 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
7e56aa25 JS |
11587 | spin_lock_irqsave(&pring->ring_lock, iflags); |
11588 | pring->stats.iocb_event++; | |
4f774513 JS |
11589 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, |
11590 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
7e56aa25 | 11591 | spin_unlock_irqrestore(&pring->ring_lock, iflags); |
4f774513 JS |
11592 | if (unlikely(!cmdiocbq)) { |
11593 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11594 | "0374 FCP complete with no corresponding " | |
11595 | "cmdiocb: iotag (%d)\n", | |
11596 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11597 | return; | |
11598 | } | |
11599 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
11600 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11601 | "0375 FCP cmdiocb not callback function " | |
11602 | "iotag: (%d)\n", | |
11603 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11604 | return; | |
11605 | } | |
11606 | ||
11607 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 11608 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 11609 | |
0f65ff68 JS |
11610 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
11611 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11612 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
11613 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11614 | } | |
11615 | ||
4f774513 JS |
11616 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
11617 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
11618 | } | |
11619 | ||
11620 | /** | |
11621 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
11622 | * @phba: Pointer to HBA context object. | |
11623 | * @cq: Pointer to completion queue. | |
11624 | * @wcqe: Pointer to work-queue completion queue entry. | |
11625 | * | |
11626 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
11627 | * proper WQ release routine to the slow-path WQ. | |
11628 | **/ | |
11629 | static void | |
11630 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11631 | struct lpfc_wcqe_release *wcqe) | |
11632 | { | |
11633 | struct lpfc_queue *childwq; | |
11634 | bool wqid_matched = false; | |
11635 | uint16_t fcp_wqid; | |
11636 | ||
11637 | /* Check for fast-path FCP work queue release */ | |
11638 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
11639 | list_for_each_entry(childwq, &cq->child_list, list) { | |
11640 | if (childwq->queue_id == fcp_wqid) { | |
11641 | lpfc_sli4_wq_release(childwq, | |
11642 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
11643 | wqid_matched = true; | |
11644 | break; | |
11645 | } | |
11646 | } | |
11647 | /* Report warning log message if no match found */ | |
11648 | if (wqid_matched != true) | |
11649 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11650 | "2580 Fast-path wqe consume event carries " | |
11651 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
11652 | } | |
11653 | ||
11654 | /** | |
11655 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
11656 | * @cq: Pointer to the completion queue. | |
11657 | * @eqe: Pointer to fast-path completion queue entry. | |
11658 | * | |
11659 | * This routine process a fast-path work queue completion entry from fast-path | |
11660 | * event queue for FCP command response completion. | |
11661 | **/ | |
11662 | static int | |
11663 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11664 | struct lpfc_cqe *cqe) | |
11665 | { | |
11666 | struct lpfc_wcqe_release wcqe; | |
11667 | bool workposted = false; | |
11668 | ||
11669 | /* Copy the work queue CQE and convert endian order if needed */ | |
11670 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
11671 | ||
11672 | /* Check and process for different type of WCQE and dispatch */ | |
11673 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
11674 | case CQE_CODE_COMPL_WQE: | |
b84daac9 | 11675 | cq->CQ_wq++; |
4f774513 | 11676 | /* Process the WQ complete event */ |
98fc5dd9 | 11677 | phba->last_completion_time = jiffies; |
2a76a283 | 11678 | lpfc_sli4_fp_handle_fcp_wcqe(phba, cq, |
4f774513 JS |
11679 | (struct lpfc_wcqe_complete *)&wcqe); |
11680 | break; | |
11681 | case CQE_CODE_RELEASE_WQE: | |
b84daac9 | 11682 | cq->CQ_release_wqe++; |
4f774513 JS |
11683 | /* Process the WQ release event */ |
11684 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
11685 | (struct lpfc_wcqe_release *)&wcqe); | |
11686 | break; | |
11687 | case CQE_CODE_XRI_ABORTED: | |
b84daac9 | 11688 | cq->CQ_xri_aborted++; |
4f774513 | 11689 | /* Process the WQ XRI abort event */ |
bc73905a | 11690 | phba->last_completion_time = jiffies; |
4f774513 JS |
11691 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
11692 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
11693 | break; | |
11694 | default: | |
11695 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11696 | "0144 Not a valid WCQE code: x%x\n", | |
11697 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
11698 | break; | |
11699 | } | |
11700 | return workposted; | |
11701 | } | |
11702 | ||
11703 | /** | |
67d12733 | 11704 | * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry |
4f774513 JS |
11705 | * @phba: Pointer to HBA context object. |
11706 | * @eqe: Pointer to fast-path event queue entry. | |
11707 | * | |
11708 | * This routine process a event queue entry from the fast-path event queue. | |
11709 | * It will check the MajorCode and MinorCode to determine this is for a | |
11710 | * completion event on a completion queue, if not, an error shall be logged | |
11711 | * and just return. Otherwise, it will get to the corresponding completion | |
11712 | * queue and process all the entries on the completion queue, rearm the | |
11713 | * completion queue, and then return. | |
11714 | **/ | |
11715 | static void | |
67d12733 JS |
11716 | lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, |
11717 | uint32_t qidx) | |
4f774513 JS |
11718 | { |
11719 | struct lpfc_queue *cq; | |
11720 | struct lpfc_cqe *cqe; | |
11721 | bool workposted = false; | |
11722 | uint16_t cqid; | |
11723 | int ecount = 0; | |
11724 | ||
cb5172ea | 11725 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 | 11726 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
67d12733 | 11727 | "0366 Not a valid completion " |
4f774513 | 11728 | "event: majorcode=x%x, minorcode=x%x\n", |
cb5172ea JS |
11729 | bf_get_le32(lpfc_eqe_major_code, eqe), |
11730 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
11731 | return; |
11732 | } | |
11733 | ||
67d12733 JS |
11734 | /* Get the reference to the corresponding CQ */ |
11735 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); | |
11736 | ||
11737 | /* Check if this is a Slow path event */ | |
11738 | if (unlikely(cqid != phba->sli4_hba.fcp_cq_map[qidx])) { | |
11739 | lpfc_sli4_sp_handle_eqe(phba, eqe, | |
11740 | phba->sli4_hba.hba_eq[qidx]); | |
11741 | return; | |
11742 | } | |
11743 | ||
2e90f4b5 JS |
11744 | if (unlikely(!phba->sli4_hba.fcp_cq)) { |
11745 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11746 | "3146 Fast-path completion queues " | |
11747 | "does not exist\n"); | |
11748 | return; | |
11749 | } | |
67d12733 | 11750 | cq = phba->sli4_hba.fcp_cq[qidx]; |
4f774513 | 11751 | if (unlikely(!cq)) { |
75baf696 JS |
11752 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
11753 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11754 | "0367 Fast-path completion queue " | |
67d12733 | 11755 | "(%d) does not exist\n", qidx); |
4f774513 JS |
11756 | return; |
11757 | } | |
11758 | ||
4f774513 JS |
11759 | if (unlikely(cqid != cq->queue_id)) { |
11760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11761 | "0368 Miss-matched fast-path completion " | |
11762 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
11763 | cqid, cq->queue_id); | |
11764 | return; | |
11765 | } | |
11766 | ||
11767 | /* Process all the entries to the CQ */ | |
11768 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
11769 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
73d91e50 | 11770 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11771 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11772 | } | |
11773 | ||
b84daac9 JS |
11774 | /* Track the max number of CQEs processed in 1 EQ */ |
11775 | if (ecount > cq->CQ_max_cqe) | |
11776 | cq->CQ_max_cqe = ecount; | |
11777 | ||
4f774513 JS |
11778 | /* Catch the no cq entry condition */ |
11779 | if (unlikely(ecount == 0)) | |
11780 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11781 | "0369 No entry from fast-path completion " | |
11782 | "queue fcpcqid=%d\n", cq->queue_id); | |
11783 | ||
11784 | /* In any case, flash and re-arm the CQ */ | |
11785 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
11786 | ||
11787 | /* wake up worker thread if there are works to be done */ | |
11788 | if (workposted) | |
11789 | lpfc_worker_wake_up(phba); | |
11790 | } | |
11791 | ||
11792 | static void | |
11793 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
11794 | { | |
11795 | struct lpfc_eqe *eqe; | |
11796 | ||
11797 | /* walk all the EQ entries and drop on the floor */ | |
11798 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
11799 | ; | |
11800 | ||
11801 | /* Clear and re-arm the EQ */ | |
11802 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
11803 | } | |
11804 | ||
11805 | /** | |
67d12733 | 11806 | * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device |
4f774513 JS |
11807 | * @irq: Interrupt number. |
11808 | * @dev_id: The device context pointer. | |
11809 | * | |
11810 | * This function is directly called from the PCI layer as an interrupt | |
11811 | * service routine when device with SLI-4 interface spec is enabled with | |
11812 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
11813 | * ring event in the HBA. However, when the device is enabled with either | |
11814 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
11815 | * device-level interrupt handler. When the PCI slot is in error recovery | |
11816 | * or the HBA is undergoing initialization, the interrupt handler will not | |
11817 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
11818 | * the intrrupt context. This function is called without any lock held. | |
11819 | * It gets the hbalock to access and update SLI data structures. Note that, | |
11820 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
11821 | * equal to that of FCP CQ index. | |
11822 | * | |
67d12733 JS |
11823 | * The link attention and ELS ring attention events are handled |
11824 | * by the worker thread. The interrupt handler signals the worker thread | |
11825 | * and returns for these events. This function is called without any lock | |
11826 | * held. It gets the hbalock to access and update SLI data structures. | |
11827 | * | |
4f774513 JS |
11828 | * This function returns IRQ_HANDLED when interrupt is handled else it |
11829 | * returns IRQ_NONE. | |
11830 | **/ | |
11831 | irqreturn_t | |
67d12733 | 11832 | lpfc_sli4_hba_intr_handler(int irq, void *dev_id) |
4f774513 JS |
11833 | { |
11834 | struct lpfc_hba *phba; | |
11835 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
11836 | struct lpfc_queue *fpeq; | |
11837 | struct lpfc_eqe *eqe; | |
11838 | unsigned long iflag; | |
11839 | int ecount = 0; | |
11840 | uint32_t fcp_eqidx; | |
11841 | ||
11842 | /* Get the driver's phba structure from the dev_id */ | |
11843 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
11844 | phba = fcp_eq_hdl->phba; | |
11845 | fcp_eqidx = fcp_eq_hdl->idx; | |
11846 | ||
11847 | if (unlikely(!phba)) | |
11848 | return IRQ_NONE; | |
67d12733 | 11849 | if (unlikely(!phba->sli4_hba.hba_eq)) |
5350d872 | 11850 | return IRQ_NONE; |
4f774513 JS |
11851 | |
11852 | /* Get to the EQ struct associated with this vector */ | |
67d12733 | 11853 | fpeq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
2e90f4b5 JS |
11854 | if (unlikely(!fpeq)) |
11855 | return IRQ_NONE; | |
4f774513 JS |
11856 | |
11857 | /* Check device state for handling interrupt */ | |
11858 | if (unlikely(lpfc_intr_state_check(phba))) { | |
b84daac9 | 11859 | fpeq->EQ_badstate++; |
4f774513 JS |
11860 | /* Check again for link_state with lock held */ |
11861 | spin_lock_irqsave(&phba->hbalock, iflag); | |
11862 | if (phba->link_state < LPFC_LINK_DOWN) | |
11863 | /* Flush, clear interrupt, and rearm the EQ */ | |
11864 | lpfc_sli4_eq_flush(phba, fpeq); | |
11865 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
11866 | return IRQ_NONE; | |
11867 | } | |
11868 | ||
11869 | /* | |
11870 | * Process all the event on FCP fast-path EQ | |
11871 | */ | |
11872 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
67d12733 | 11873 | lpfc_sli4_hba_handle_eqe(phba, eqe, fcp_eqidx); |
73d91e50 | 11874 | if (!(++ecount % fpeq->entry_repost)) |
4f774513 | 11875 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
b84daac9 | 11876 | fpeq->EQ_processed++; |
4f774513 JS |
11877 | } |
11878 | ||
b84daac9 JS |
11879 | /* Track the max number of EQEs processed in 1 intr */ |
11880 | if (ecount > fpeq->EQ_max_eqe) | |
11881 | fpeq->EQ_max_eqe = ecount; | |
11882 | ||
4f774513 JS |
11883 | /* Always clear and re-arm the fast-path EQ */ |
11884 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
11885 | ||
11886 | if (unlikely(ecount == 0)) { | |
b84daac9 | 11887 | fpeq->EQ_no_entry++; |
4f774513 JS |
11888 | if (phba->intr_type == MSIX) |
11889 | /* MSI-X treated interrupt served as no EQ share INT */ | |
11890 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11891 | "0358 MSI-X interrupt with no EQE\n"); | |
11892 | else | |
11893 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
11894 | return IRQ_NONE; | |
11895 | } | |
11896 | ||
11897 | return IRQ_HANDLED; | |
11898 | } /* lpfc_sli4_fp_intr_handler */ | |
11899 | ||
11900 | /** | |
11901 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
11902 | * @irq: Interrupt number. | |
11903 | * @dev_id: The device context pointer. | |
11904 | * | |
11905 | * This function is the device-level interrupt handler to device with SLI-4 | |
11906 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
11907 | * interrupt mode is enabled and there is an event in the HBA which requires | |
11908 | * driver attention. This function invokes the slow-path interrupt attention | |
11909 | * handling function and fast-path interrupt attention handling function in | |
11910 | * turn to process the relevant HBA attention events. This function is called | |
11911 | * without any lock held. It gets the hbalock to access and update SLI data | |
11912 | * structures. | |
11913 | * | |
11914 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
11915 | * returns IRQ_NONE. | |
11916 | **/ | |
11917 | irqreturn_t | |
11918 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
11919 | { | |
11920 | struct lpfc_hba *phba; | |
67d12733 JS |
11921 | irqreturn_t hba_irq_rc; |
11922 | bool hba_handled = false; | |
4f774513 JS |
11923 | uint32_t fcp_eqidx; |
11924 | ||
11925 | /* Get the driver's phba structure from the dev_id */ | |
11926 | phba = (struct lpfc_hba *)dev_id; | |
11927 | ||
11928 | if (unlikely(!phba)) | |
11929 | return IRQ_NONE; | |
11930 | ||
4f774513 JS |
11931 | /* |
11932 | * Invoke fast-path host attention interrupt handling as appropriate. | |
11933 | */ | |
67d12733 JS |
11934 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
11935 | hba_irq_rc = lpfc_sli4_hba_intr_handler(irq, | |
4f774513 | 11936 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); |
67d12733 JS |
11937 | if (hba_irq_rc == IRQ_HANDLED) |
11938 | hba_handled |= true; | |
4f774513 JS |
11939 | } |
11940 | ||
67d12733 | 11941 | return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE; |
4f774513 JS |
11942 | } /* lpfc_sli4_intr_handler */ |
11943 | ||
11944 | /** | |
11945 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
11946 | * @queue: The queue structure to free. | |
11947 | * | |
b595076a | 11948 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
11949 | * the host resident queue. This function must be called after destroying the |
11950 | * queue on the HBA. | |
11951 | **/ | |
11952 | void | |
11953 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
11954 | { | |
11955 | struct lpfc_dmabuf *dmabuf; | |
11956 | ||
11957 | if (!queue) | |
11958 | return; | |
11959 | ||
11960 | while (!list_empty(&queue->page_list)) { | |
11961 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
11962 | list); | |
49198b37 | 11963 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
11964 | dmabuf->virt, dmabuf->phys); |
11965 | kfree(dmabuf); | |
11966 | } | |
11967 | kfree(queue); | |
11968 | return; | |
11969 | } | |
11970 | ||
11971 | /** | |
11972 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
11973 | * @phba: The HBA that this queue is being created on. | |
11974 | * @entry_size: The size of each queue entry for this queue. | |
11975 | * @entry count: The number of entries that this queue will handle. | |
11976 | * | |
11977 | * This function allocates a queue structure and the DMAable memory used for | |
11978 | * the host resident queue. This function must be called before creating the | |
11979 | * queue on the HBA. | |
11980 | **/ | |
11981 | struct lpfc_queue * | |
11982 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
11983 | uint32_t entry_count) | |
11984 | { | |
11985 | struct lpfc_queue *queue; | |
11986 | struct lpfc_dmabuf *dmabuf; | |
11987 | int x, total_qe_count; | |
11988 | void *dma_pointer; | |
cb5172ea | 11989 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 11990 | |
cb5172ea JS |
11991 | if (!phba->sli4_hba.pc_sli4_params.supported) |
11992 | hw_page_size = SLI4_PAGE_SIZE; | |
11993 | ||
4f774513 JS |
11994 | queue = kzalloc(sizeof(struct lpfc_queue) + |
11995 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
11996 | if (!queue) | |
11997 | return NULL; | |
cb5172ea JS |
11998 | queue->page_count = (ALIGN(entry_size * entry_count, |
11999 | hw_page_size))/hw_page_size; | |
4f774513 JS |
12000 | INIT_LIST_HEAD(&queue->list); |
12001 | INIT_LIST_HEAD(&queue->page_list); | |
12002 | INIT_LIST_HEAD(&queue->child_list); | |
12003 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
12004 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
12005 | if (!dmabuf) | |
12006 | goto out_fail; | |
12007 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 12008 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
12009 | GFP_KERNEL); |
12010 | if (!dmabuf->virt) { | |
12011 | kfree(dmabuf); | |
12012 | goto out_fail; | |
12013 | } | |
cb5172ea | 12014 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12015 | dmabuf->buffer_tag = x; |
12016 | list_add_tail(&dmabuf->list, &queue->page_list); | |
12017 | /* initialize queue's entry array */ | |
12018 | dma_pointer = dmabuf->virt; | |
12019 | for (; total_qe_count < entry_count && | |
cb5172ea | 12020 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
12021 | total_qe_count++, dma_pointer += entry_size) { |
12022 | queue->qe[total_qe_count].address = dma_pointer; | |
12023 | } | |
12024 | } | |
12025 | queue->entry_size = entry_size; | |
12026 | queue->entry_count = entry_count; | |
73d91e50 JS |
12027 | |
12028 | /* | |
12029 | * entry_repost is calculated based on the number of entries in the | |
12030 | * queue. This works out except for RQs. If buffers are NOT initially | |
12031 | * posted for every RQE, entry_repost should be adjusted accordingly. | |
12032 | */ | |
12033 | queue->entry_repost = (entry_count >> 3); | |
12034 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) | |
12035 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; | |
4f774513 JS |
12036 | queue->phba = phba; |
12037 | ||
12038 | return queue; | |
12039 | out_fail: | |
12040 | lpfc_sli4_queue_free(queue); | |
12041 | return NULL; | |
12042 | } | |
12043 | ||
173edbb2 JS |
12044 | /** |
12045 | * lpfc_modify_fcp_eq_delay - Modify Delay Multiplier on FCP EQs | |
12046 | * @phba: HBA structure that indicates port to create a queue on. | |
12047 | * @startq: The starting FCP EQ to modify | |
12048 | * | |
12049 | * This function sends an MODIFY_EQ_DELAY mailbox command to the HBA. | |
12050 | * | |
12051 | * The @phba struct is used to send mailbox command to HBA. The @startq | |
12052 | * is used to get the starting FCP EQ to change. | |
12053 | * This function is asynchronous and will wait for the mailbox | |
12054 | * command to finish before continuing. | |
12055 | * | |
12056 | * On success this function will return a zero. If unable to allocate enough | |
12057 | * memory this function will return -ENOMEM. If the queue create mailbox command | |
12058 | * fails this function will return -ENXIO. | |
12059 | **/ | |
12060 | uint32_t | |
12061 | lpfc_modify_fcp_eq_delay(struct lpfc_hba *phba, uint16_t startq) | |
12062 | { | |
12063 | struct lpfc_mbx_modify_eq_delay *eq_delay; | |
12064 | LPFC_MBOXQ_t *mbox; | |
12065 | struct lpfc_queue *eq; | |
12066 | int cnt, rc, length, status = 0; | |
12067 | uint32_t shdr_status, shdr_add_status; | |
12068 | int fcp_eqidx; | |
12069 | union lpfc_sli4_cfg_shdr *shdr; | |
12070 | uint16_t dmult; | |
12071 | ||
67d12733 | 12072 | if (startq >= phba->cfg_fcp_io_channel) |
173edbb2 JS |
12073 | return 0; |
12074 | ||
12075 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12076 | if (!mbox) | |
12077 | return -ENOMEM; | |
12078 | length = (sizeof(struct lpfc_mbx_modify_eq_delay) - | |
12079 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12080 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12081 | LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY, | |
12082 | length, LPFC_SLI4_MBX_EMBED); | |
12083 | eq_delay = &mbox->u.mqe.un.eq_delay; | |
12084 | ||
12085 | /* Calculate delay multiper from maximum interrupt per second */ | |
bf8dae83 JS |
12086 | dmult = phba->cfg_fcp_imax / phba->cfg_fcp_io_channel; |
12087 | dmult = LPFC_DMULT_CONST/dmult - 1; | |
173edbb2 JS |
12088 | |
12089 | cnt = 0; | |
67d12733 | 12090 | for (fcp_eqidx = startq; fcp_eqidx < phba->cfg_fcp_io_channel; |
173edbb2 | 12091 | fcp_eqidx++) { |
67d12733 | 12092 | eq = phba->sli4_hba.hba_eq[fcp_eqidx]; |
173edbb2 JS |
12093 | if (!eq) |
12094 | continue; | |
12095 | eq_delay->u.request.eq[cnt].eq_id = eq->queue_id; | |
12096 | eq_delay->u.request.eq[cnt].phase = 0; | |
12097 | eq_delay->u.request.eq[cnt].delay_multi = dmult; | |
12098 | cnt++; | |
12099 | if (cnt >= LPFC_MAX_EQ_DELAY) | |
12100 | break; | |
12101 | } | |
12102 | eq_delay->u.request.num_eq = cnt; | |
12103 | ||
12104 | mbox->vport = phba->pport; | |
12105 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12106 | mbox->context1 = NULL; | |
12107 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12108 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr; | |
12109 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12110 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12111 | if (shdr_status || shdr_add_status || rc) { | |
12112 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12113 | "2512 MODIFY_EQ_DELAY mailbox failed with " | |
12114 | "status x%x add_status x%x, mbx status x%x\n", | |
12115 | shdr_status, shdr_add_status, rc); | |
12116 | status = -ENXIO; | |
12117 | } | |
12118 | mempool_free(mbox, phba->mbox_mem_pool); | |
12119 | return status; | |
12120 | } | |
12121 | ||
4f774513 JS |
12122 | /** |
12123 | * lpfc_eq_create - Create an Event Queue on the HBA | |
12124 | * @phba: HBA structure that indicates port to create a queue on. | |
12125 | * @eq: The queue structure to use to create the event queue. | |
12126 | * @imax: The maximum interrupt per second limit. | |
12127 | * | |
12128 | * This function creates an event queue, as detailed in @eq, on a port, | |
12129 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
12130 | * | |
12131 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
12132 | * is used to get the entry count and entry size that are necessary to | |
12133 | * determine the number of pages to allocate and use for this queue. This | |
12134 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
12135 | * event queue. This function is asynchronous and will wait for the mailbox | |
12136 | * command to finish before continuing. | |
12137 | * | |
12138 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12139 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12140 | * fails this function will return -ENXIO. | |
4f774513 JS |
12141 | **/ |
12142 | uint32_t | |
12143 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
12144 | { | |
12145 | struct lpfc_mbx_eq_create *eq_create; | |
12146 | LPFC_MBOXQ_t *mbox; | |
12147 | int rc, length, status = 0; | |
12148 | struct lpfc_dmabuf *dmabuf; | |
12149 | uint32_t shdr_status, shdr_add_status; | |
12150 | union lpfc_sli4_cfg_shdr *shdr; | |
12151 | uint16_t dmult; | |
49198b37 JS |
12152 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12153 | ||
2e90f4b5 JS |
12154 | /* sanity check on queue memory */ |
12155 | if (!eq) | |
12156 | return -ENODEV; | |
49198b37 JS |
12157 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12158 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12159 | |
12160 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12161 | if (!mbox) | |
12162 | return -ENOMEM; | |
12163 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
12164 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12165 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12166 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
12167 | length, LPFC_SLI4_MBX_EMBED); | |
12168 | eq_create = &mbox->u.mqe.un.eq_create; | |
12169 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
12170 | eq->page_count); | |
12171 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
12172 | LPFC_EQE_SIZE); | |
12173 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
12174 | /* Calculate delay multiper from maximum interrupt per second */ | |
12175 | dmult = LPFC_DMULT_CONST/imax - 1; | |
12176 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
12177 | dmult); | |
12178 | switch (eq->entry_count) { | |
12179 | default: | |
12180 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12181 | "0360 Unsupported EQ count. (%d)\n", | |
12182 | eq->entry_count); | |
12183 | if (eq->entry_count < 256) | |
12184 | return -EINVAL; | |
12185 | /* otherwise default to smallest count (drop through) */ | |
12186 | case 256: | |
12187 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12188 | LPFC_EQ_CNT_256); | |
12189 | break; | |
12190 | case 512: | |
12191 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12192 | LPFC_EQ_CNT_512); | |
12193 | break; | |
12194 | case 1024: | |
12195 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12196 | LPFC_EQ_CNT_1024); | |
12197 | break; | |
12198 | case 2048: | |
12199 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12200 | LPFC_EQ_CNT_2048); | |
12201 | break; | |
12202 | case 4096: | |
12203 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
12204 | LPFC_EQ_CNT_4096); | |
12205 | break; | |
12206 | } | |
12207 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 12208 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12209 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12210 | putPaddrLow(dmabuf->phys); | |
12211 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12212 | putPaddrHigh(dmabuf->phys); | |
12213 | } | |
12214 | mbox->vport = phba->pport; | |
12215 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12216 | mbox->context1 = NULL; | |
12217 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12218 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
12219 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12220 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12221 | if (shdr_status || shdr_add_status || rc) { | |
12222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12223 | "2500 EQ_CREATE mailbox failed with " | |
12224 | "status x%x add_status x%x, mbx status x%x\n", | |
12225 | shdr_status, shdr_add_status, rc); | |
12226 | status = -ENXIO; | |
12227 | } | |
12228 | eq->type = LPFC_EQ; | |
12229 | eq->subtype = LPFC_NONE; | |
12230 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
12231 | if (eq->queue_id == 0xFFFF) | |
12232 | status = -ENXIO; | |
12233 | eq->host_index = 0; | |
12234 | eq->hba_index = 0; | |
12235 | ||
8fa38513 | 12236 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12237 | return status; |
12238 | } | |
12239 | ||
12240 | /** | |
12241 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
12242 | * @phba: HBA structure that indicates port to create a queue on. | |
12243 | * @cq: The queue structure to use to create the completion queue. | |
12244 | * @eq: The event queue to bind this completion queue to. | |
12245 | * | |
12246 | * This function creates a completion queue, as detailed in @wq, on a port, | |
12247 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
12248 | * | |
12249 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
12250 | * is used to get the entry count and entry size that are necessary to | |
12251 | * determine the number of pages to allocate and use for this queue. The @eq | |
12252 | * is used to indicate which event queue to bind this completion queue to. This | |
12253 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
12254 | * completion queue. This function is asynchronous and will wait for the mailbox | |
12255 | * command to finish before continuing. | |
12256 | * | |
12257 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12258 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12259 | * fails this function will return -ENXIO. | |
4f774513 JS |
12260 | **/ |
12261 | uint32_t | |
12262 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
12263 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
12264 | { | |
12265 | struct lpfc_mbx_cq_create *cq_create; | |
12266 | struct lpfc_dmabuf *dmabuf; | |
12267 | LPFC_MBOXQ_t *mbox; | |
12268 | int rc, length, status = 0; | |
12269 | uint32_t shdr_status, shdr_add_status; | |
12270 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
12271 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12272 | ||
2e90f4b5 JS |
12273 | /* sanity check on queue memory */ |
12274 | if (!cq || !eq) | |
12275 | return -ENODEV; | |
49198b37 JS |
12276 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12277 | hw_page_size = SLI4_PAGE_SIZE; | |
12278 | ||
4f774513 JS |
12279 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12280 | if (!mbox) | |
12281 | return -ENOMEM; | |
12282 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
12283 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12284 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12285 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
12286 | length, LPFC_SLI4_MBX_EMBED); | |
12287 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 12288 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
12289 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
12290 | cq->page_count); | |
12291 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
12292 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
12293 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12294 | phba->sli4_hba.pc_sli4_params.cqv); | |
12295 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
12296 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
12297 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
12298 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
12299 | eq->queue_id); | |
12300 | } else { | |
12301 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
12302 | eq->queue_id); | |
12303 | } | |
4f774513 JS |
12304 | switch (cq->entry_count) { |
12305 | default: | |
12306 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12307 | "0361 Unsupported CQ count. (%d)\n", | |
12308 | cq->entry_count); | |
4f4c1863 JS |
12309 | if (cq->entry_count < 256) { |
12310 | status = -EINVAL; | |
12311 | goto out; | |
12312 | } | |
4f774513 JS |
12313 | /* otherwise default to smallest count (drop through) */ |
12314 | case 256: | |
12315 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
12316 | LPFC_CQ_CNT_256); | |
12317 | break; | |
12318 | case 512: | |
12319 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
12320 | LPFC_CQ_CNT_512); | |
12321 | break; | |
12322 | case 1024: | |
12323 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
12324 | LPFC_CQ_CNT_1024); | |
12325 | break; | |
12326 | } | |
12327 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 12328 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12329 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12330 | putPaddrLow(dmabuf->phys); | |
12331 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12332 | putPaddrHigh(dmabuf->phys); | |
12333 | } | |
12334 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12335 | ||
12336 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12337 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12338 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12339 | if (shdr_status || shdr_add_status || rc) { | |
12340 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12341 | "2501 CQ_CREATE mailbox failed with " | |
12342 | "status x%x add_status x%x, mbx status x%x\n", | |
12343 | shdr_status, shdr_add_status, rc); | |
12344 | status = -ENXIO; | |
12345 | goto out; | |
12346 | } | |
12347 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
12348 | if (cq->queue_id == 0xFFFF) { | |
12349 | status = -ENXIO; | |
12350 | goto out; | |
12351 | } | |
12352 | /* link the cq onto the parent eq child list */ | |
12353 | list_add_tail(&cq->list, &eq->child_list); | |
12354 | /* Set up completion queue's type and subtype */ | |
12355 | cq->type = type; | |
12356 | cq->subtype = subtype; | |
12357 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 12358 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
12359 | cq->host_index = 0; |
12360 | cq->hba_index = 0; | |
4f774513 | 12361 | |
8fa38513 JS |
12362 | out: |
12363 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
12364 | return status; |
12365 | } | |
12366 | ||
b19a061a JS |
12367 | /** |
12368 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
12369 | * @phba: HBA structure that indicates port to create a queue on. | |
12370 | * @mq: The queue structure to use to create the mailbox queue. | |
12371 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
12372 | * @cq: The completion queue to associate with this cq. | |
12373 | * | |
12374 | * This function provides failback (fb) functionality when the | |
12375 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
12376 | * to mq_create_ext otherwise. | |
12377 | * | |
12378 | * This routine cannot fail as all attributes were previously accessed and | |
12379 | * initialized in mq_create_ext. | |
12380 | **/ | |
12381 | static void | |
12382 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
12383 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
12384 | { | |
12385 | struct lpfc_mbx_mq_create *mq_create; | |
12386 | struct lpfc_dmabuf *dmabuf; | |
12387 | int length; | |
12388 | ||
12389 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
12390 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12391 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12392 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
12393 | length, LPFC_SLI4_MBX_EMBED); | |
12394 | mq_create = &mbox->u.mqe.un.mq_create; | |
12395 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
12396 | mq->page_count); | |
12397 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
12398 | cq->queue_id); | |
12399 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
12400 | switch (mq->entry_count) { | |
12401 | case 16: | |
5a6f133e JS |
12402 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12403 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
12404 | break; |
12405 | case 32: | |
5a6f133e JS |
12406 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12407 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
12408 | break; |
12409 | case 64: | |
5a6f133e JS |
12410 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12411 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
12412 | break; |
12413 | case 128: | |
5a6f133e JS |
12414 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12415 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
12416 | break; |
12417 | } | |
12418 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
12419 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
12420 | putPaddrLow(dmabuf->phys); | |
12421 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12422 | putPaddrHigh(dmabuf->phys); | |
12423 | } | |
12424 | } | |
12425 | ||
04c68496 JS |
12426 | /** |
12427 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
12428 | * @phba: HBA structure that indicates port to create a queue on. | |
12429 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
12430 | * @cq: The completion queue to associate with this cq. |
12431 | * @subtype: The queue's subtype. | |
04c68496 JS |
12432 | * |
12433 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
12434 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
12435 | * | |
12436 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
12437 | * is used to get the entry count and entry size that are necessary to | |
12438 | * determine the number of pages to allocate and use for this queue. This | |
12439 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
12440 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
12441 | * command to finish before continuing. | |
12442 | * | |
12443 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12444 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12445 | * fails this function will return -ENXIO. | |
04c68496 | 12446 | **/ |
b19a061a | 12447 | int32_t |
04c68496 JS |
12448 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
12449 | struct lpfc_queue *cq, uint32_t subtype) | |
12450 | { | |
12451 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 12452 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
12453 | struct lpfc_dmabuf *dmabuf; |
12454 | LPFC_MBOXQ_t *mbox; | |
12455 | int rc, length, status = 0; | |
12456 | uint32_t shdr_status, shdr_add_status; | |
12457 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 12458 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 12459 | |
2e90f4b5 JS |
12460 | /* sanity check on queue memory */ |
12461 | if (!mq || !cq) | |
12462 | return -ENODEV; | |
49198b37 JS |
12463 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12464 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 12465 | |
04c68496 JS |
12466 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12467 | if (!mbox) | |
12468 | return -ENOMEM; | |
b19a061a | 12469 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
12470 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
12471 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 12472 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 12473 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
12474 | |
12475 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 12476 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
12477 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
12478 | &mq_create_ext->u.request, mq->page_count); | |
12479 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
12480 | &mq_create_ext->u.request, 1); | |
12481 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
12482 | &mq_create_ext->u.request, 1); |
12483 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
12484 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
12485 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
12486 | &mq_create_ext->u.request, 1); | |
12487 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
12488 | &mq_create_ext->u.request, 1); | |
b19a061a | 12489 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
12490 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12491 | phba->sli4_hba.pc_sli4_params.mqv); | |
12492 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
12493 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
12494 | cq->queue_id); | |
12495 | else | |
12496 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
12497 | cq->queue_id); | |
04c68496 JS |
12498 | switch (mq->entry_count) { |
12499 | default: | |
12500 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12501 | "0362 Unsupported MQ count. (%d)\n", | |
12502 | mq->entry_count); | |
4f4c1863 JS |
12503 | if (mq->entry_count < 16) { |
12504 | status = -EINVAL; | |
12505 | goto out; | |
12506 | } | |
04c68496 JS |
12507 | /* otherwise default to smallest count (drop through) */ |
12508 | case 16: | |
5a6f133e JS |
12509 | bf_set(lpfc_mq_context_ring_size, |
12510 | &mq_create_ext->u.request.context, | |
12511 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
12512 | break; |
12513 | case 32: | |
5a6f133e JS |
12514 | bf_set(lpfc_mq_context_ring_size, |
12515 | &mq_create_ext->u.request.context, | |
12516 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
12517 | break; |
12518 | case 64: | |
5a6f133e JS |
12519 | bf_set(lpfc_mq_context_ring_size, |
12520 | &mq_create_ext->u.request.context, | |
12521 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
12522 | break; |
12523 | case 128: | |
5a6f133e JS |
12524 | bf_set(lpfc_mq_context_ring_size, |
12525 | &mq_create_ext->u.request.context, | |
12526 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
12527 | break; |
12528 | } | |
12529 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 12530 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 12531 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 12532 | putPaddrLow(dmabuf->phys); |
b19a061a | 12533 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
12534 | putPaddrHigh(dmabuf->phys); |
12535 | } | |
12536 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
12537 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
12538 | &mq_create_ext->u.response); | |
12539 | if (rc != MBX_SUCCESS) { | |
12540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12541 | "2795 MQ_CREATE_EXT failed with " | |
12542 | "status x%x. Failback to MQ_CREATE.\n", | |
12543 | rc); | |
12544 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
12545 | mq_create = &mbox->u.mqe.un.mq_create; | |
12546 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12547 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
12548 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
12549 | &mq_create->u.response); | |
12550 | } | |
12551 | ||
04c68496 | 12552 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
12553 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12554 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12555 | if (shdr_status || shdr_add_status || rc) { | |
12556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12557 | "2502 MQ_CREATE mailbox failed with " | |
12558 | "status x%x add_status x%x, mbx status x%x\n", | |
12559 | shdr_status, shdr_add_status, rc); | |
12560 | status = -ENXIO; | |
12561 | goto out; | |
12562 | } | |
04c68496 JS |
12563 | if (mq->queue_id == 0xFFFF) { |
12564 | status = -ENXIO; | |
12565 | goto out; | |
12566 | } | |
12567 | mq->type = LPFC_MQ; | |
2a622bfb | 12568 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
12569 | mq->subtype = subtype; |
12570 | mq->host_index = 0; | |
12571 | mq->hba_index = 0; | |
12572 | ||
12573 | /* link the mq onto the parent cq child list */ | |
12574 | list_add_tail(&mq->list, &cq->child_list); | |
12575 | out: | |
8fa38513 | 12576 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
12577 | return status; |
12578 | } | |
12579 | ||
4f774513 JS |
12580 | /** |
12581 | * lpfc_wq_create - Create a Work Queue on the HBA | |
12582 | * @phba: HBA structure that indicates port to create a queue on. | |
12583 | * @wq: The queue structure to use to create the work queue. | |
12584 | * @cq: The completion queue to bind this work queue to. | |
12585 | * @subtype: The subtype of the work queue indicating its functionality. | |
12586 | * | |
12587 | * This function creates a work queue, as detailed in @wq, on a port, described | |
12588 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
12589 | * | |
12590 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
12591 | * is used to get the entry count and entry size that are necessary to | |
12592 | * determine the number of pages to allocate and use for this queue. The @cq | |
12593 | * is used to indicate which completion queue to bind this work queue to. This | |
12594 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
12595 | * work queue. This function is asynchronous and will wait for the mailbox | |
12596 | * command to finish before continuing. | |
12597 | * | |
12598 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12599 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12600 | * fails this function will return -ENXIO. | |
4f774513 JS |
12601 | **/ |
12602 | uint32_t | |
12603 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
12604 | struct lpfc_queue *cq, uint32_t subtype) | |
12605 | { | |
12606 | struct lpfc_mbx_wq_create *wq_create; | |
12607 | struct lpfc_dmabuf *dmabuf; | |
12608 | LPFC_MBOXQ_t *mbox; | |
12609 | int rc, length, status = 0; | |
12610 | uint32_t shdr_status, shdr_add_status; | |
12611 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 12612 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 12613 | struct dma_address *page; |
49198b37 | 12614 | |
2e90f4b5 JS |
12615 | /* sanity check on queue memory */ |
12616 | if (!wq || !cq) | |
12617 | return -ENODEV; | |
49198b37 JS |
12618 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12619 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12620 | |
12621 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12622 | if (!mbox) | |
12623 | return -ENOMEM; | |
12624 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
12625 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12626 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12627 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
12628 | length, LPFC_SLI4_MBX_EMBED); | |
12629 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 12630 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
12631 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
12632 | wq->page_count); | |
12633 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
12634 | cq->queue_id); | |
5a6f133e JS |
12635 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12636 | phba->sli4_hba.pc_sli4_params.wqv); | |
12637 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { | |
12638 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, | |
12639 | wq->entry_count); | |
12640 | switch (wq->entry_size) { | |
12641 | default: | |
12642 | case 64: | |
12643 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
12644 | &wq_create->u.request_1, | |
12645 | LPFC_WQ_WQE_SIZE_64); | |
12646 | break; | |
12647 | case 128: | |
12648 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
12649 | &wq_create->u.request_1, | |
12650 | LPFC_WQ_WQE_SIZE_128); | |
12651 | break; | |
12652 | } | |
12653 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
12654 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
12655 | page = wq_create->u.request_1.page; | |
12656 | } else { | |
12657 | page = wq_create->u.request.page; | |
12658 | } | |
4f774513 | 12659 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 12660 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
12661 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
12662 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 JS |
12663 | } |
12664 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12665 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12666 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12667 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12668 | if (shdr_status || shdr_add_status || rc) { | |
12669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12670 | "2503 WQ_CREATE mailbox failed with " | |
12671 | "status x%x add_status x%x, mbx status x%x\n", | |
12672 | shdr_status, shdr_add_status, rc); | |
12673 | status = -ENXIO; | |
12674 | goto out; | |
12675 | } | |
12676 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
12677 | if (wq->queue_id == 0xFFFF) { | |
12678 | status = -ENXIO; | |
12679 | goto out; | |
12680 | } | |
12681 | wq->type = LPFC_WQ; | |
2a622bfb | 12682 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
12683 | wq->subtype = subtype; |
12684 | wq->host_index = 0; | |
12685 | wq->hba_index = 0; | |
ff78d8f9 | 12686 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
4f774513 JS |
12687 | |
12688 | /* link the wq onto the parent cq child list */ | |
12689 | list_add_tail(&wq->list, &cq->child_list); | |
12690 | out: | |
8fa38513 | 12691 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12692 | return status; |
12693 | } | |
12694 | ||
73d91e50 JS |
12695 | /** |
12696 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ | |
12697 | * @phba: HBA structure that indicates port to create a queue on. | |
12698 | * @rq: The queue structure to use for the receive queue. | |
12699 | * @qno: The associated HBQ number | |
12700 | * | |
12701 | * | |
12702 | * For SLI4 we need to adjust the RQ repost value based on | |
12703 | * the number of buffers that are initially posted to the RQ. | |
12704 | */ | |
12705 | void | |
12706 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) | |
12707 | { | |
12708 | uint32_t cnt; | |
12709 | ||
2e90f4b5 JS |
12710 | /* sanity check on queue memory */ |
12711 | if (!rq) | |
12712 | return; | |
73d91e50 JS |
12713 | cnt = lpfc_hbq_defs[qno]->entry_count; |
12714 | ||
12715 | /* Recalc repost for RQs based on buffers initially posted */ | |
12716 | cnt = (cnt >> 3); | |
12717 | if (cnt < LPFC_QUEUE_MIN_REPOST) | |
12718 | cnt = LPFC_QUEUE_MIN_REPOST; | |
12719 | ||
12720 | rq->entry_repost = cnt; | |
12721 | } | |
12722 | ||
4f774513 JS |
12723 | /** |
12724 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
12725 | * @phba: HBA structure that indicates port to create a queue on. | |
12726 | * @hrq: The queue structure to use to create the header receive queue. | |
12727 | * @drq: The queue structure to use to create the data receive queue. | |
12728 | * @cq: The completion queue to bind this work queue to. | |
12729 | * | |
12730 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
12731 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
12732 | * to the HBA. | |
12733 | * | |
12734 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
12735 | * struct is used to get the entry count that is necessary to determine the | |
12736 | * number of pages to use for this queue. The @cq is used to indicate which | |
12737 | * completion queue to bind received buffers that are posted to these queues to. | |
12738 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
12739 | * receive queue pair. This function is asynchronous and will wait for the | |
12740 | * mailbox command to finish before continuing. | |
12741 | * | |
12742 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12743 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12744 | * fails this function will return -ENXIO. | |
4f774513 JS |
12745 | **/ |
12746 | uint32_t | |
12747 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
12748 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
12749 | { | |
12750 | struct lpfc_mbx_rq_create *rq_create; | |
12751 | struct lpfc_dmabuf *dmabuf; | |
12752 | LPFC_MBOXQ_t *mbox; | |
12753 | int rc, length, status = 0; | |
12754 | uint32_t shdr_status, shdr_add_status; | |
12755 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
12756 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12757 | ||
2e90f4b5 JS |
12758 | /* sanity check on queue memory */ |
12759 | if (!hrq || !drq || !cq) | |
12760 | return -ENODEV; | |
49198b37 JS |
12761 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12762 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12763 | |
12764 | if (hrq->entry_count != drq->entry_count) | |
12765 | return -EINVAL; | |
12766 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12767 | if (!mbox) | |
12768 | return -ENOMEM; | |
12769 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
12770 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12771 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12772 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
12773 | length, LPFC_SLI4_MBX_EMBED); | |
12774 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
12775 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
12776 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
12777 | phba->sli4_hba.pc_sli4_params.rqv); | |
12778 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
12779 | bf_set(lpfc_rq_context_rqe_count_1, | |
12780 | &rq_create->u.request.context, | |
12781 | hrq->entry_count); | |
12782 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
12783 | bf_set(lpfc_rq_context_rqe_size, |
12784 | &rq_create->u.request.context, | |
12785 | LPFC_RQE_SIZE_8); | |
12786 | bf_set(lpfc_rq_context_page_size, | |
12787 | &rq_create->u.request.context, | |
12788 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
12789 | } else { |
12790 | switch (hrq->entry_count) { | |
12791 | default: | |
12792 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12793 | "2535 Unsupported RQ count. (%d)\n", | |
12794 | hrq->entry_count); | |
4f4c1863 JS |
12795 | if (hrq->entry_count < 512) { |
12796 | status = -EINVAL; | |
12797 | goto out; | |
12798 | } | |
5a6f133e JS |
12799 | /* otherwise default to smallest count (drop through) */ |
12800 | case 512: | |
12801 | bf_set(lpfc_rq_context_rqe_count, | |
12802 | &rq_create->u.request.context, | |
12803 | LPFC_RQ_RING_SIZE_512); | |
12804 | break; | |
12805 | case 1024: | |
12806 | bf_set(lpfc_rq_context_rqe_count, | |
12807 | &rq_create->u.request.context, | |
12808 | LPFC_RQ_RING_SIZE_1024); | |
12809 | break; | |
12810 | case 2048: | |
12811 | bf_set(lpfc_rq_context_rqe_count, | |
12812 | &rq_create->u.request.context, | |
12813 | LPFC_RQ_RING_SIZE_2048); | |
12814 | break; | |
12815 | case 4096: | |
12816 | bf_set(lpfc_rq_context_rqe_count, | |
12817 | &rq_create->u.request.context, | |
12818 | LPFC_RQ_RING_SIZE_4096); | |
12819 | break; | |
12820 | } | |
12821 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
12822 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
12823 | } |
12824 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
12825 | cq->queue_id); | |
12826 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
12827 | hrq->page_count); | |
4f774513 | 12828 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 12829 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12830 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12831 | putPaddrLow(dmabuf->phys); | |
12832 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12833 | putPaddrHigh(dmabuf->phys); | |
12834 | } | |
12835 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12836 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12837 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12838 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12839 | if (shdr_status || shdr_add_status || rc) { | |
12840 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12841 | "2504 RQ_CREATE mailbox failed with " | |
12842 | "status x%x add_status x%x, mbx status x%x\n", | |
12843 | shdr_status, shdr_add_status, rc); | |
12844 | status = -ENXIO; | |
12845 | goto out; | |
12846 | } | |
12847 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
12848 | if (hrq->queue_id == 0xFFFF) { | |
12849 | status = -ENXIO; | |
12850 | goto out; | |
12851 | } | |
12852 | hrq->type = LPFC_HRQ; | |
2a622bfb | 12853 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
12854 | hrq->subtype = subtype; |
12855 | hrq->host_index = 0; | |
12856 | hrq->hba_index = 0; | |
12857 | ||
12858 | /* now create the data queue */ | |
12859 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12860 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
12861 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
12862 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12863 | phba->sli4_hba.pc_sli4_params.rqv); | |
12864 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
12865 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 12866 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 12867 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
12868 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
12869 | LPFC_RQE_SIZE_8); | |
12870 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
12871 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
12872 | } else { |
12873 | switch (drq->entry_count) { | |
12874 | default: | |
12875 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12876 | "2536 Unsupported RQ count. (%d)\n", | |
12877 | drq->entry_count); | |
4f4c1863 JS |
12878 | if (drq->entry_count < 512) { |
12879 | status = -EINVAL; | |
12880 | goto out; | |
12881 | } | |
5a6f133e JS |
12882 | /* otherwise default to smallest count (drop through) */ |
12883 | case 512: | |
12884 | bf_set(lpfc_rq_context_rqe_count, | |
12885 | &rq_create->u.request.context, | |
12886 | LPFC_RQ_RING_SIZE_512); | |
12887 | break; | |
12888 | case 1024: | |
12889 | bf_set(lpfc_rq_context_rqe_count, | |
12890 | &rq_create->u.request.context, | |
12891 | LPFC_RQ_RING_SIZE_1024); | |
12892 | break; | |
12893 | case 2048: | |
12894 | bf_set(lpfc_rq_context_rqe_count, | |
12895 | &rq_create->u.request.context, | |
12896 | LPFC_RQ_RING_SIZE_2048); | |
12897 | break; | |
12898 | case 4096: | |
12899 | bf_set(lpfc_rq_context_rqe_count, | |
12900 | &rq_create->u.request.context, | |
12901 | LPFC_RQ_RING_SIZE_4096); | |
12902 | break; | |
12903 | } | |
12904 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
12905 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
12906 | } |
12907 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
12908 | cq->queue_id); | |
12909 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
12910 | drq->page_count); | |
4f774513 JS |
12911 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
12912 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
12913 | putPaddrLow(dmabuf->phys); | |
12914 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12915 | putPaddrHigh(dmabuf->phys); | |
12916 | } | |
12917 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12918 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12919 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
12920 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12921 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12922 | if (shdr_status || shdr_add_status || rc) { | |
12923 | status = -ENXIO; | |
12924 | goto out; | |
12925 | } | |
12926 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
12927 | if (drq->queue_id == 0xFFFF) { | |
12928 | status = -ENXIO; | |
12929 | goto out; | |
12930 | } | |
12931 | drq->type = LPFC_DRQ; | |
2a622bfb | 12932 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
12933 | drq->subtype = subtype; |
12934 | drq->host_index = 0; | |
12935 | drq->hba_index = 0; | |
12936 | ||
12937 | /* link the header and data RQs onto the parent cq child list */ | |
12938 | list_add_tail(&hrq->list, &cq->child_list); | |
12939 | list_add_tail(&drq->list, &cq->child_list); | |
12940 | ||
12941 | out: | |
8fa38513 | 12942 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12943 | return status; |
12944 | } | |
12945 | ||
12946 | /** | |
12947 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
12948 | * @eq: The queue structure associated with the queue to destroy. | |
12949 | * | |
12950 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
12951 | * command, specific to the type of queue, to the HBA. | |
12952 | * | |
12953 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
12954 | * | |
12955 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12956 | * command fails this function will return -ENXIO. |
4f774513 JS |
12957 | **/ |
12958 | uint32_t | |
12959 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
12960 | { | |
12961 | LPFC_MBOXQ_t *mbox; | |
12962 | int rc, length, status = 0; | |
12963 | uint32_t shdr_status, shdr_add_status; | |
12964 | union lpfc_sli4_cfg_shdr *shdr; | |
12965 | ||
2e90f4b5 | 12966 | /* sanity check on queue memory */ |
4f774513 JS |
12967 | if (!eq) |
12968 | return -ENODEV; | |
12969 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
12970 | if (!mbox) | |
12971 | return -ENOMEM; | |
12972 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
12973 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12974 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12975 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
12976 | length, LPFC_SLI4_MBX_EMBED); | |
12977 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
12978 | eq->queue_id); | |
12979 | mbox->vport = eq->phba->pport; | |
12980 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12981 | ||
12982 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
12983 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12984 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12985 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
12986 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12987 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12988 | if (shdr_status || shdr_add_status || rc) { | |
12989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12990 | "2505 EQ_DESTROY mailbox failed with " | |
12991 | "status x%x add_status x%x, mbx status x%x\n", | |
12992 | shdr_status, shdr_add_status, rc); | |
12993 | status = -ENXIO; | |
12994 | } | |
12995 | ||
12996 | /* Remove eq from any list */ | |
12997 | list_del_init(&eq->list); | |
8fa38513 | 12998 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
12999 | return status; |
13000 | } | |
13001 | ||
13002 | /** | |
13003 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
13004 | * @cq: The queue structure associated with the queue to destroy. | |
13005 | * | |
13006 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
13007 | * command, specific to the type of queue, to the HBA. | |
13008 | * | |
13009 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
13010 | * | |
13011 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13012 | * command fails this function will return -ENXIO. |
4f774513 JS |
13013 | **/ |
13014 | uint32_t | |
13015 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
13016 | { | |
13017 | LPFC_MBOXQ_t *mbox; | |
13018 | int rc, length, status = 0; | |
13019 | uint32_t shdr_status, shdr_add_status; | |
13020 | union lpfc_sli4_cfg_shdr *shdr; | |
13021 | ||
2e90f4b5 | 13022 | /* sanity check on queue memory */ |
4f774513 JS |
13023 | if (!cq) |
13024 | return -ENODEV; | |
13025 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
13026 | if (!mbox) | |
13027 | return -ENOMEM; | |
13028 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
13029 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13030 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13031 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
13032 | length, LPFC_SLI4_MBX_EMBED); | |
13033 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
13034 | cq->queue_id); | |
13035 | mbox->vport = cq->phba->pport; | |
13036 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13037 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
13038 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13039 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13040 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
13041 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13042 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13043 | if (shdr_status || shdr_add_status || rc) { | |
13044 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13045 | "2506 CQ_DESTROY mailbox failed with " | |
13046 | "status x%x add_status x%x, mbx status x%x\n", | |
13047 | shdr_status, shdr_add_status, rc); | |
13048 | status = -ENXIO; | |
13049 | } | |
13050 | /* Remove cq from any list */ | |
13051 | list_del_init(&cq->list); | |
8fa38513 | 13052 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
13053 | return status; |
13054 | } | |
13055 | ||
04c68496 JS |
13056 | /** |
13057 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
13058 | * @qm: The queue structure associated with the queue to destroy. | |
13059 | * | |
13060 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
13061 | * command, specific to the type of queue, to the HBA. | |
13062 | * | |
13063 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
13064 | * | |
13065 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13066 | * command fails this function will return -ENXIO. |
04c68496 JS |
13067 | **/ |
13068 | uint32_t | |
13069 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
13070 | { | |
13071 | LPFC_MBOXQ_t *mbox; | |
13072 | int rc, length, status = 0; | |
13073 | uint32_t shdr_status, shdr_add_status; | |
13074 | union lpfc_sli4_cfg_shdr *shdr; | |
13075 | ||
2e90f4b5 | 13076 | /* sanity check on queue memory */ |
04c68496 JS |
13077 | if (!mq) |
13078 | return -ENODEV; | |
13079 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
13080 | if (!mbox) | |
13081 | return -ENOMEM; | |
13082 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
13083 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13084 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
13085 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
13086 | length, LPFC_SLI4_MBX_EMBED); | |
13087 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
13088 | mq->queue_id); | |
13089 | mbox->vport = mq->phba->pport; | |
13090 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13091 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
13092 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13093 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13094 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
13095 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13096 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13097 | if (shdr_status || shdr_add_status || rc) { | |
13098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13099 | "2507 MQ_DESTROY mailbox failed with " | |
13100 | "status x%x add_status x%x, mbx status x%x\n", | |
13101 | shdr_status, shdr_add_status, rc); | |
13102 | status = -ENXIO; | |
13103 | } | |
13104 | /* Remove mq from any list */ | |
13105 | list_del_init(&mq->list); | |
8fa38513 | 13106 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
13107 | return status; |
13108 | } | |
13109 | ||
4f774513 JS |
13110 | /** |
13111 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
13112 | * @wq: The queue structure associated with the queue to destroy. | |
13113 | * | |
13114 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
13115 | * command, specific to the type of queue, to the HBA. | |
13116 | * | |
13117 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
13118 | * | |
13119 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13120 | * command fails this function will return -ENXIO. |
4f774513 JS |
13121 | **/ |
13122 | uint32_t | |
13123 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
13124 | { | |
13125 | LPFC_MBOXQ_t *mbox; | |
13126 | int rc, length, status = 0; | |
13127 | uint32_t shdr_status, shdr_add_status; | |
13128 | union lpfc_sli4_cfg_shdr *shdr; | |
13129 | ||
2e90f4b5 | 13130 | /* sanity check on queue memory */ |
4f774513 JS |
13131 | if (!wq) |
13132 | return -ENODEV; | |
13133 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
13134 | if (!mbox) | |
13135 | return -ENOMEM; | |
13136 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
13137 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13138 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13139 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
13140 | length, LPFC_SLI4_MBX_EMBED); | |
13141 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
13142 | wq->queue_id); | |
13143 | mbox->vport = wq->phba->pport; | |
13144 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13145 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
13146 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13147 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
13148 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13149 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13150 | if (shdr_status || shdr_add_status || rc) { | |
13151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13152 | "2508 WQ_DESTROY mailbox failed with " | |
13153 | "status x%x add_status x%x, mbx status x%x\n", | |
13154 | shdr_status, shdr_add_status, rc); | |
13155 | status = -ENXIO; | |
13156 | } | |
13157 | /* Remove wq from any list */ | |
13158 | list_del_init(&wq->list); | |
8fa38513 | 13159 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
13160 | return status; |
13161 | } | |
13162 | ||
13163 | /** | |
13164 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
13165 | * @rq: The queue structure associated with the queue to destroy. | |
13166 | * | |
13167 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
13168 | * command, specific to the type of queue, to the HBA. | |
13169 | * | |
13170 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
13171 | * | |
13172 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 13173 | * command fails this function will return -ENXIO. |
4f774513 JS |
13174 | **/ |
13175 | uint32_t | |
13176 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
13177 | struct lpfc_queue *drq) | |
13178 | { | |
13179 | LPFC_MBOXQ_t *mbox; | |
13180 | int rc, length, status = 0; | |
13181 | uint32_t shdr_status, shdr_add_status; | |
13182 | union lpfc_sli4_cfg_shdr *shdr; | |
13183 | ||
2e90f4b5 | 13184 | /* sanity check on queue memory */ |
4f774513 JS |
13185 | if (!hrq || !drq) |
13186 | return -ENODEV; | |
13187 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
13188 | if (!mbox) | |
13189 | return -ENOMEM; | |
13190 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 13191 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
13192 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
13193 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
13194 | length, LPFC_SLI4_MBX_EMBED); | |
13195 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
13196 | hrq->queue_id); | |
13197 | mbox->vport = hrq->phba->pport; | |
13198 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13199 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
13200 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
13201 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13202 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
13203 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13204 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13205 | if (shdr_status || shdr_add_status || rc) { | |
13206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13207 | "2509 RQ_DESTROY mailbox failed with " | |
13208 | "status x%x add_status x%x, mbx status x%x\n", | |
13209 | shdr_status, shdr_add_status, rc); | |
13210 | if (rc != MBX_TIMEOUT) | |
13211 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
13212 | return -ENXIO; | |
13213 | } | |
13214 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
13215 | drq->queue_id); | |
13216 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
13217 | shdr = (union lpfc_sli4_cfg_shdr *) | |
13218 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
13219 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13220 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13221 | if (shdr_status || shdr_add_status || rc) { | |
13222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13223 | "2510 RQ_DESTROY mailbox failed with " | |
13224 | "status x%x add_status x%x, mbx status x%x\n", | |
13225 | shdr_status, shdr_add_status, rc); | |
13226 | status = -ENXIO; | |
13227 | } | |
13228 | list_del_init(&hrq->list); | |
13229 | list_del_init(&drq->list); | |
8fa38513 | 13230 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
13231 | return status; |
13232 | } | |
13233 | ||
13234 | /** | |
13235 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
13236 | * @phba: The virtual port for which this call being executed. | |
13237 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
13238 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
13239 | * @xritag: the xritag that ties this io to the SGL pages. | |
13240 | * | |
13241 | * This routine will post the sgl pages for the IO that has the xritag | |
13242 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
13243 | * creation and persists for as long as the driver is loaded. | |
13244 | * if the caller has fewer than 256 scatter gather segments to map then | |
13245 | * pdma_phys_addr1 should be 0. | |
13246 | * If the caller needs to map more than 256 scatter gather segment then | |
13247 | * pdma_phys_addr1 should be a valid physical address. | |
13248 | * physical address for SGLs must be 64 byte aligned. | |
13249 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
13250 | * the second sgl can have between 1 and 256 entries. | |
13251 | * | |
13252 | * Return codes: | |
13253 | * 0 - Success | |
13254 | * -ENXIO, -ENOMEM - Failure | |
13255 | **/ | |
13256 | int | |
13257 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
13258 | dma_addr_t pdma_phys_addr0, | |
13259 | dma_addr_t pdma_phys_addr1, | |
13260 | uint16_t xritag) | |
13261 | { | |
13262 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
13263 | LPFC_MBOXQ_t *mbox; | |
13264 | int rc; | |
13265 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 13266 | uint32_t mbox_tmo; |
4f774513 JS |
13267 | union lpfc_sli4_cfg_shdr *shdr; |
13268 | ||
13269 | if (xritag == NO_XRI) { | |
13270 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13271 | "0364 Invalid param:\n"); | |
13272 | return -EINVAL; | |
13273 | } | |
13274 | ||
13275 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13276 | if (!mbox) | |
13277 | return -ENOMEM; | |
13278 | ||
13279 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13280 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
13281 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 13282 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
13283 | |
13284 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
13285 | &mbox->u.mqe.un.post_sgl_pages; | |
13286 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
13287 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
13288 | ||
13289 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
13290 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
13291 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
13292 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
13293 | ||
13294 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
13295 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
13296 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
13297 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
13298 | if (!phba->sli4_hba.intr_enable) | |
13299 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 | 13300 | else { |
a183a15f | 13301 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
13302 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13303 | } | |
4f774513 JS |
13304 | /* The IOCTL status is embedded in the mailbox subheader. */ |
13305 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
13306 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13307 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13308 | if (rc != MBX_TIMEOUT) | |
13309 | mempool_free(mbox, phba->mbox_mem_pool); | |
13310 | if (shdr_status || shdr_add_status || rc) { | |
13311 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13312 | "2511 POST_SGL mailbox failed with " | |
13313 | "status x%x add_status x%x, mbx status x%x\n", | |
13314 | shdr_status, shdr_add_status, rc); | |
13315 | rc = -ENXIO; | |
13316 | } | |
13317 | return 0; | |
13318 | } | |
4f774513 | 13319 | |
6d368e53 | 13320 | /** |
88a2cfbb | 13321 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
13322 | * @phba: pointer to lpfc hba data structure. |
13323 | * | |
13324 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
13325 | * HBA consistent with the SLI-4 interface spec. This routine |
13326 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
13327 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 13328 | * |
88a2cfbb JS |
13329 | * Returns |
13330 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
13331 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
13332 | **/ | |
6d368e53 JS |
13333 | uint16_t |
13334 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) | |
13335 | { | |
13336 | unsigned long xri; | |
13337 | ||
13338 | /* | |
13339 | * Fetch the next logical xri. Because this index is logical, | |
13340 | * the driver starts at 0 each time. | |
13341 | */ | |
13342 | spin_lock_irq(&phba->hbalock); | |
13343 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
13344 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
13345 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
13346 | spin_unlock_irq(&phba->hbalock); | |
13347 | return NO_XRI; | |
13348 | } else { | |
13349 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
13350 | phba->sli4_hba.max_cfg_param.xri_used++; | |
6d368e53 | 13351 | } |
6d368e53 JS |
13352 | spin_unlock_irq(&phba->hbalock); |
13353 | return xri; | |
13354 | } | |
13355 | ||
13356 | /** | |
13357 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
13358 | * @phba: pointer to lpfc hba data structure. | |
13359 | * | |
13360 | * This routine is invoked to release an xri to the pool of | |
13361 | * available rpis maintained by the driver. | |
13362 | **/ | |
13363 | void | |
13364 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
13365 | { | |
13366 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
6d368e53 JS |
13367 | phba->sli4_hba.max_cfg_param.xri_used--; |
13368 | } | |
13369 | } | |
13370 | ||
13371 | /** | |
13372 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
13373 | * @phba: pointer to lpfc hba data structure. | |
13374 | * | |
13375 | * This routine is invoked to release an xri to the pool of | |
13376 | * available rpis maintained by the driver. | |
13377 | **/ | |
13378 | void | |
13379 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
13380 | { | |
13381 | spin_lock_irq(&phba->hbalock); | |
13382 | __lpfc_sli4_free_xri(phba, xri); | |
13383 | spin_unlock_irq(&phba->hbalock); | |
13384 | } | |
13385 | ||
4f774513 JS |
13386 | /** |
13387 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
13388 | * @phba: Pointer to HBA context object. | |
13389 | * | |
13390 | * This function gets an xritag for the iocb. If there is no unused xritag | |
13391 | * it will return 0xffff. | |
13392 | * The function returns the allocated xritag if successful, else returns zero. | |
13393 | * Zero is not a valid xritag. | |
13394 | * The caller is not required to hold any lock. | |
13395 | **/ | |
13396 | uint16_t | |
13397 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
13398 | { | |
6d368e53 | 13399 | uint16_t xri_index; |
4f774513 | 13400 | |
6d368e53 | 13401 | xri_index = lpfc_sli4_alloc_xri(phba); |
81378052 JS |
13402 | if (xri_index == NO_XRI) |
13403 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
13404 | "2004 Failed to allocate XRI.last XRITAG is %d" | |
13405 | " Max XRI is %d, Used XRI is %d\n", | |
13406 | xri_index, | |
13407 | phba->sli4_hba.max_cfg_param.max_xri, | |
13408 | phba->sli4_hba.max_cfg_param.xri_used); | |
13409 | return xri_index; | |
4f774513 JS |
13410 | } |
13411 | ||
13412 | /** | |
6d368e53 | 13413 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
4f774513 | 13414 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 JS |
13415 | * @post_sgl_list: pointer to els sgl entry list. |
13416 | * @count: number of els sgl entries on the list. | |
4f774513 JS |
13417 | * |
13418 | * This routine is invoked to post a block of driver's sgl pages to the | |
13419 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
13420 | * is only called when the driver is loading and after all IO has been | |
13421 | * stopped. | |
13422 | **/ | |
8a9d2e80 JS |
13423 | static int |
13424 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba, | |
13425 | struct list_head *post_sgl_list, | |
13426 | int post_cnt) | |
4f774513 | 13427 | { |
8a9d2e80 | 13428 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4f774513 JS |
13429 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; |
13430 | struct sgl_page_pairs *sgl_pg_pairs; | |
13431 | void *viraddr; | |
13432 | LPFC_MBOXQ_t *mbox; | |
13433 | uint32_t reqlen, alloclen, pg_pairs; | |
13434 | uint32_t mbox_tmo; | |
8a9d2e80 JS |
13435 | uint16_t xritag_start = 0; |
13436 | int rc = 0; | |
4f774513 JS |
13437 | uint32_t shdr_status, shdr_add_status; |
13438 | union lpfc_sli4_cfg_shdr *shdr; | |
13439 | ||
8a9d2e80 | 13440 | reqlen = phba->sli4_hba.els_xri_cnt * sizeof(struct sgl_page_pairs) + |
4f774513 | 13441 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 13442 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
13443 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
13444 | "2559 Block sgl registration required DMA " | |
13445 | "size (%d) great than a page\n", reqlen); | |
13446 | return -ENOMEM; | |
13447 | } | |
13448 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6d368e53 | 13449 | if (!mbox) |
4f774513 | 13450 | return -ENOMEM; |
4f774513 JS |
13451 | |
13452 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
13453 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13454 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
13455 | LPFC_SLI4_MBX_NEMBED); | |
13456 | ||
13457 | if (alloclen < reqlen) { | |
13458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13459 | "0285 Allocated DMA memory size (%d) is " | |
13460 | "less than the requested DMA memory " | |
13461 | "size (%d)\n", alloclen, reqlen); | |
13462 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13463 | return -ENOMEM; | |
13464 | } | |
4f774513 | 13465 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 13466 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
13467 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
13468 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13469 | ||
8a9d2e80 JS |
13470 | pg_pairs = 0; |
13471 | list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) { | |
4f774513 JS |
13472 | /* Set up the sge entry */ |
13473 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13474 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
13475 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13476 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
13477 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13478 | cpu_to_le32(putPaddrLow(0)); | |
13479 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13480 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 13481 | |
4f774513 JS |
13482 | /* Keep the first xritag on the list */ |
13483 | if (pg_pairs == 0) | |
13484 | xritag_start = sglq_entry->sli4_xritag; | |
13485 | sgl_pg_pairs++; | |
8a9d2e80 | 13486 | pg_pairs++; |
4f774513 | 13487 | } |
6d368e53 JS |
13488 | |
13489 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 13490 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
8a9d2e80 | 13491 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, phba->sli4_hba.els_xri_cnt); |
4f774513 | 13492 | sgl->word0 = cpu_to_le32(sgl->word0); |
4f774513 JS |
13493 | if (!phba->sli4_hba.intr_enable) |
13494 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13495 | else { | |
a183a15f | 13496 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
13497 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13498 | } | |
13499 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13500 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13501 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13502 | if (rc != MBX_TIMEOUT) | |
13503 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13504 | if (shdr_status || shdr_add_status || rc) { | |
13505 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13506 | "2513 POST_SGL_BLOCK mailbox command failed " | |
13507 | "status x%x add_status x%x mbx status x%x\n", | |
13508 | shdr_status, shdr_add_status, rc); | |
13509 | rc = -ENXIO; | |
13510 | } | |
13511 | return rc; | |
13512 | } | |
13513 | ||
13514 | /** | |
13515 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
13516 | * @phba: pointer to lpfc hba data structure. | |
13517 | * @sblist: pointer to scsi buffer list. | |
13518 | * @count: number of scsi buffers on the list. | |
13519 | * | |
13520 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
13521 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
13522 | * No Lock is held. | |
13523 | * | |
13524 | **/ | |
13525 | int | |
8a9d2e80 JS |
13526 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, |
13527 | struct list_head *sblist, | |
13528 | int count) | |
4f774513 JS |
13529 | { |
13530 | struct lpfc_scsi_buf *psb; | |
13531 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
13532 | struct sgl_page_pairs *sgl_pg_pairs; | |
13533 | void *viraddr; | |
13534 | LPFC_MBOXQ_t *mbox; | |
13535 | uint32_t reqlen, alloclen, pg_pairs; | |
13536 | uint32_t mbox_tmo; | |
13537 | uint16_t xritag_start = 0; | |
13538 | int rc = 0; | |
13539 | uint32_t shdr_status, shdr_add_status; | |
13540 | dma_addr_t pdma_phys_bpl1; | |
13541 | union lpfc_sli4_cfg_shdr *shdr; | |
13542 | ||
13543 | /* Calculate the requested length of the dma memory */ | |
8a9d2e80 | 13544 | reqlen = count * sizeof(struct sgl_page_pairs) + |
4f774513 | 13545 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); |
49198b37 | 13546 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
13547 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
13548 | "0217 Block sgl registration required DMA " | |
13549 | "size (%d) great than a page\n", reqlen); | |
13550 | return -ENOMEM; | |
13551 | } | |
13552 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13553 | if (!mbox) { | |
13554 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13555 | "0283 Failed to allocate mbox cmd memory\n"); | |
13556 | return -ENOMEM; | |
13557 | } | |
13558 | ||
13559 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
13560 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13561 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
13562 | LPFC_SLI4_MBX_NEMBED); | |
13563 | ||
13564 | if (alloclen < reqlen) { | |
13565 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13566 | "2561 Allocated DMA memory size (%d) is " | |
13567 | "less than the requested DMA memory " | |
13568 | "size (%d)\n", alloclen, reqlen); | |
13569 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13570 | return -ENOMEM; | |
13571 | } | |
6d368e53 | 13572 | |
4f774513 | 13573 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
13574 | viraddr = mbox->sge_array->addr[0]; |
13575 | ||
13576 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
13577 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
13578 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13579 | ||
13580 | pg_pairs = 0; | |
13581 | list_for_each_entry(psb, sblist, list) { | |
13582 | /* Set up the sge entry */ | |
13583 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13584 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
13585 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13586 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
13587 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
13588 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
13589 | else | |
13590 | pdma_phys_bpl1 = 0; | |
13591 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13592 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
13593 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13594 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
13595 | /* Keep the first xritag on the list */ | |
13596 | if (pg_pairs == 0) | |
13597 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
13598 | sgl_pg_pairs++; | |
13599 | pg_pairs++; | |
13600 | } | |
13601 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
13602 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
13603 | /* Perform endian conversion if necessary */ | |
13604 | sgl->word0 = cpu_to_le32(sgl->word0); | |
13605 | ||
13606 | if (!phba->sli4_hba.intr_enable) | |
13607 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13608 | else { | |
a183a15f | 13609 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
13610 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13611 | } | |
13612 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13613 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13614 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13615 | if (rc != MBX_TIMEOUT) | |
13616 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13617 | if (shdr_status || shdr_add_status || rc) { | |
13618 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13619 | "2564 POST_SGL_BLOCK mailbox command failed " | |
13620 | "status x%x add_status x%x mbx status x%x\n", | |
13621 | shdr_status, shdr_add_status, rc); | |
13622 | rc = -ENXIO; | |
13623 | } | |
13624 | return rc; | |
13625 | } | |
13626 | ||
13627 | /** | |
13628 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
13629 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
13630 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13631 | * | |
13632 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
13633 | * valid type of frame that the LPFC driver will handle. This function will | |
13634 | * return a zero if the frame is a valid frame or a non zero value when the | |
13635 | * frame does not pass the check. | |
13636 | **/ | |
13637 | static int | |
13638 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
13639 | { | |
474ffb74 TH |
13640 | /* make rctl_names static to save stack space */ |
13641 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
13642 | char *type_names[] = FC_TYPE_NAMES_INIT; |
13643 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 13644 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
13645 | |
13646 | switch (fc_hdr->fh_r_ctl) { | |
13647 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
13648 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
13649 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
13650 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
13651 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
13652 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
13653 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
13654 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
13655 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
13656 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
13657 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
13658 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
13659 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
13660 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
13661 | case FC_RCTL_BA_RMC: /* remove connection */ | |
13662 | case FC_RCTL_BA_ACC: /* basic accept */ | |
13663 | case FC_RCTL_BA_RJT: /* basic reject */ | |
13664 | case FC_RCTL_BA_PRMT: | |
13665 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
13666 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
13667 | case FC_RCTL_P_RJT: /* port reject */ | |
13668 | case FC_RCTL_F_RJT: /* fabric reject */ | |
13669 | case FC_RCTL_P_BSY: /* port busy */ | |
13670 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
13671 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
13672 | case FC_RCTL_LCR: /* link credit reset */ | |
13673 | case FC_RCTL_END: /* end */ | |
13674 | break; | |
13675 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
13676 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13677 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
13678 | return lpfc_fc_frame_check(phba, fc_hdr); | |
13679 | default: | |
13680 | goto drop; | |
13681 | } | |
13682 | switch (fc_hdr->fh_type) { | |
13683 | case FC_TYPE_BLS: | |
13684 | case FC_TYPE_ELS: | |
13685 | case FC_TYPE_FCP: | |
13686 | case FC_TYPE_CT: | |
13687 | break; | |
13688 | case FC_TYPE_IP: | |
13689 | case FC_TYPE_ILS: | |
13690 | default: | |
13691 | goto drop; | |
13692 | } | |
546fc854 | 13693 | |
4f774513 | 13694 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
13695 | "2538 Received frame rctl:%s type:%s " |
13696 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", | |
4f774513 | 13697 | rctl_names[fc_hdr->fh_r_ctl], |
546fc854 JS |
13698 | type_names[fc_hdr->fh_type], |
13699 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), | |
13700 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
13701 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); | |
4f774513 JS |
13702 | return 0; |
13703 | drop: | |
13704 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
13705 | "2539 Dropped frame rctl:%s type:%s\n", | |
13706 | rctl_names[fc_hdr->fh_r_ctl], | |
13707 | type_names[fc_hdr->fh_type]); | |
13708 | return 1; | |
13709 | } | |
13710 | ||
13711 | /** | |
13712 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
13713 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13714 | * | |
13715 | * This function processes the FC header to retrieve the VFI from the VF | |
13716 | * header, if one exists. This function will return the VFI if one exists | |
13717 | * or 0 if no VSAN Header exists. | |
13718 | **/ | |
13719 | static uint32_t | |
13720 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
13721 | { | |
13722 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13723 | ||
13724 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
13725 | return 0; | |
13726 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
13727 | } | |
13728 | ||
13729 | /** | |
13730 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
13731 | * @phba: Pointer to the HBA structure to search for the vport on | |
13732 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13733 | * @fcfi: The FC Fabric ID that the frame came from | |
13734 | * | |
13735 | * This function searches the @phba for a vport that matches the content of the | |
13736 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
13737 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
13738 | * returns the matching vport pointer or NULL if unable to match frame to a | |
13739 | * vport. | |
13740 | **/ | |
13741 | static struct lpfc_vport * | |
13742 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
13743 | uint16_t fcfi) | |
13744 | { | |
13745 | struct lpfc_vport **vports; | |
13746 | struct lpfc_vport *vport = NULL; | |
13747 | int i; | |
13748 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
13749 | fc_hdr->fh_d_id[1] << 8 | | |
13750 | fc_hdr->fh_d_id[2]); | |
939723a4 | 13751 | |
bf08611b JS |
13752 | if (did == Fabric_DID) |
13753 | return phba->pport; | |
939723a4 JS |
13754 | if ((phba->pport->fc_flag & FC_PT2PT) && |
13755 | !(phba->link_state == LPFC_HBA_READY)) | |
13756 | return phba->pport; | |
13757 | ||
4f774513 JS |
13758 | vports = lpfc_create_vport_work_array(phba); |
13759 | if (vports != NULL) | |
13760 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
13761 | if (phba->fcf.fcfi == fcfi && | |
13762 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
13763 | vports[i]->fc_myDID == did) { | |
13764 | vport = vports[i]; | |
13765 | break; | |
13766 | } | |
13767 | } | |
13768 | lpfc_destroy_vport_work_array(phba, vports); | |
13769 | return vport; | |
13770 | } | |
13771 | ||
45ed1190 JS |
13772 | /** |
13773 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
13774 | * @vport: The vport to work on. | |
13775 | * | |
13776 | * This function updates the receive sequence time stamp for this vport. The | |
13777 | * receive sequence time stamp indicates the time that the last frame of the | |
13778 | * the sequence that has been idle for the longest amount of time was received. | |
13779 | * the driver uses this time stamp to indicate if any received sequences have | |
13780 | * timed out. | |
13781 | **/ | |
13782 | void | |
13783 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
13784 | { | |
13785 | struct lpfc_dmabuf *h_buf; | |
13786 | struct hbq_dmabuf *dmabuf = NULL; | |
13787 | ||
13788 | /* get the oldest sequence on the rcv list */ | |
13789 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
13790 | struct lpfc_dmabuf, list); | |
13791 | if (!h_buf) | |
13792 | return; | |
13793 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13794 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
13795 | } | |
13796 | ||
13797 | /** | |
13798 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
13799 | * @vport: The vport that the received sequences were sent to. | |
13800 | * | |
13801 | * This function cleans up all outstanding received sequences. This is called | |
13802 | * by the driver when a link event or user action invalidates all the received | |
13803 | * sequences. | |
13804 | **/ | |
13805 | void | |
13806 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
13807 | { | |
13808 | struct lpfc_dmabuf *h_buf, *hnext; | |
13809 | struct lpfc_dmabuf *d_buf, *dnext; | |
13810 | struct hbq_dmabuf *dmabuf = NULL; | |
13811 | ||
13812 | /* start with the oldest sequence on the rcv list */ | |
13813 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13814 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13815 | list_del_init(&dmabuf->hbuf.list); | |
13816 | list_for_each_entry_safe(d_buf, dnext, | |
13817 | &dmabuf->dbuf.list, list) { | |
13818 | list_del_init(&d_buf->list); | |
13819 | lpfc_in_buf_free(vport->phba, d_buf); | |
13820 | } | |
13821 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13822 | } | |
13823 | } | |
13824 | ||
13825 | /** | |
13826 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
13827 | * @vport: The vport that the received sequences were sent to. | |
13828 | * | |
13829 | * This function determines whether any received sequences have timed out by | |
13830 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
13831 | * indicates that there is at least one timed out sequence this routine will | |
13832 | * go through the received sequences one at a time from most inactive to most | |
13833 | * active to determine which ones need to be cleaned up. Once it has determined | |
13834 | * that a sequence needs to be cleaned up it will simply free up the resources | |
13835 | * without sending an abort. | |
13836 | **/ | |
13837 | void | |
13838 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
13839 | { | |
13840 | struct lpfc_dmabuf *h_buf, *hnext; | |
13841 | struct lpfc_dmabuf *d_buf, *dnext; | |
13842 | struct hbq_dmabuf *dmabuf = NULL; | |
13843 | unsigned long timeout; | |
13844 | int abort_count = 0; | |
13845 | ||
13846 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13847 | vport->rcv_buffer_time_stamp); | |
13848 | if (list_empty(&vport->rcv_buffer_list) || | |
13849 | time_before(jiffies, timeout)) | |
13850 | return; | |
13851 | /* start with the oldest sequence on the rcv list */ | |
13852 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13853 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13854 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13855 | dmabuf->time_stamp); | |
13856 | if (time_before(jiffies, timeout)) | |
13857 | break; | |
13858 | abort_count++; | |
13859 | list_del_init(&dmabuf->hbuf.list); | |
13860 | list_for_each_entry_safe(d_buf, dnext, | |
13861 | &dmabuf->dbuf.list, list) { | |
13862 | list_del_init(&d_buf->list); | |
13863 | lpfc_in_buf_free(vport->phba, d_buf); | |
13864 | } | |
13865 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13866 | } | |
13867 | if (abort_count) | |
13868 | lpfc_update_rcv_time_stamp(vport); | |
13869 | } | |
13870 | ||
4f774513 JS |
13871 | /** |
13872 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
13873 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
13874 | * | |
13875 | * This function searches through the existing incomplete sequences that have | |
13876 | * been sent to this @vport. If the frame matches one of the incomplete | |
13877 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
13878 | * make up that sequence. If no sequence is found that matches this frame then | |
13879 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
13880 | * This function returns a pointer to the first dmabuf in the sequence list that | |
13881 | * the frame was linked to. | |
13882 | **/ | |
13883 | static struct hbq_dmabuf * | |
13884 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
13885 | { | |
13886 | struct fc_frame_header *new_hdr; | |
13887 | struct fc_frame_header *temp_hdr; | |
13888 | struct lpfc_dmabuf *d_buf; | |
13889 | struct lpfc_dmabuf *h_buf; | |
13890 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13891 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
13892 | ||
4d9ab994 | 13893 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 13894 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
13895 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
13896 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
13897 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13898 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13899 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13900 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13901 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13902 | continue; | |
13903 | /* found a pending sequence that matches this frame */ | |
13904 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13905 | break; | |
13906 | } | |
13907 | if (!seq_dmabuf) { | |
13908 | /* | |
13909 | * This indicates first frame received for this sequence. | |
13910 | * Queue the buffer on the vport's rcv_buffer_list. | |
13911 | */ | |
13912 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 13913 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13914 | return dmabuf; |
13915 | } | |
13916 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
13917 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
13918 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
13919 | list_del_init(&seq_dmabuf->hbuf.list); |
13920 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13921 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 13922 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13923 | return dmabuf; |
13924 | } | |
45ed1190 JS |
13925 | /* move this sequence to the tail to indicate a young sequence */ |
13926 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13927 | seq_dmabuf->time_stamp = jiffies; | |
13928 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
13929 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
13930 | temp_hdr = dmabuf->hbuf.virt; | |
13931 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
13932 | return seq_dmabuf; | |
13933 | } | |
4f774513 JS |
13934 | /* find the correct place in the sequence to insert this frame */ |
13935 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
13936 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
13937 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
13938 | /* | |
13939 | * If the frame's sequence count is greater than the frame on | |
13940 | * the list then insert the frame right after this frame | |
13941 | */ | |
eeead811 JS |
13942 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
13943 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
13944 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
13945 | return seq_dmabuf; | |
13946 | } | |
13947 | } | |
13948 | return NULL; | |
13949 | } | |
13950 | ||
6669f9bb JS |
13951 | /** |
13952 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
13953 | * @vport: pointer to a vitural port | |
13954 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13955 | * | |
13956 | * This function tries to abort from the partially assembed sequence, described | |
13957 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
13958 | * partially assembled sequence held by the driver. If so, it shall free up all | |
13959 | * the frames from the partially assembled sequence. | |
13960 | * | |
13961 | * Return | |
13962 | * true -- if there is matching partially assembled sequence present and all | |
13963 | * the frames freed with the sequence; | |
13964 | * false -- if there is no matching partially assembled sequence present so | |
13965 | * nothing got aborted in the lower layer driver | |
13966 | **/ | |
13967 | static bool | |
13968 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
13969 | struct hbq_dmabuf *dmabuf) | |
13970 | { | |
13971 | struct fc_frame_header *new_hdr; | |
13972 | struct fc_frame_header *temp_hdr; | |
13973 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
13974 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13975 | ||
13976 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
13977 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
13978 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
13979 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
13980 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13981 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13982 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13983 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13984 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13985 | continue; | |
13986 | /* found a pending sequence that matches this frame */ | |
13987 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13988 | break; | |
13989 | } | |
13990 | ||
13991 | /* Free up all the frames from the partially assembled sequence */ | |
13992 | if (seq_dmabuf) { | |
13993 | list_for_each_entry_safe(d_buf, n_buf, | |
13994 | &seq_dmabuf->dbuf.list, list) { | |
13995 | list_del_init(&d_buf->list); | |
13996 | lpfc_in_buf_free(vport->phba, d_buf); | |
13997 | } | |
13998 | return true; | |
13999 | } | |
14000 | return false; | |
14001 | } | |
14002 | ||
14003 | /** | |
546fc854 | 14004 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
14005 | * @phba: Pointer to HBA context object. |
14006 | * @cmd_iocbq: pointer to the command iocbq structure. | |
14007 | * @rsp_iocbq: pointer to the response iocbq structure. | |
14008 | * | |
546fc854 | 14009 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
14010 | * event. It properly releases the memory allocated to the sequence abort |
14011 | * accept iocb. | |
14012 | **/ | |
14013 | static void | |
546fc854 | 14014 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
14015 | struct lpfc_iocbq *cmd_iocbq, |
14016 | struct lpfc_iocbq *rsp_iocbq) | |
14017 | { | |
14018 | if (cmd_iocbq) | |
14019 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
6b5151fd JS |
14020 | |
14021 | /* Failure means BLS ABORT RSP did not get delivered to remote node*/ | |
14022 | if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus) | |
14023 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14024 | "3154 BLS ABORT RSP failed, data: x%x/x%x\n", | |
14025 | rsp_iocbq->iocb.ulpStatus, | |
14026 | rsp_iocbq->iocb.un.ulpWord[4]); | |
6669f9bb JS |
14027 | } |
14028 | ||
6d368e53 JS |
14029 | /** |
14030 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
14031 | * @phba: Pointer to HBA context object. | |
14032 | * @xri: xri id in transaction. | |
14033 | * | |
14034 | * This function validates the xri maps to the known range of XRIs allocated an | |
14035 | * used by the driver. | |
14036 | **/ | |
7851fe2c | 14037 | uint16_t |
6d368e53 JS |
14038 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
14039 | uint16_t xri) | |
14040 | { | |
14041 | int i; | |
14042 | ||
14043 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
14044 | if (xri == phba->sli4_hba.xri_ids[i]) | |
14045 | return i; | |
14046 | } | |
14047 | return NO_XRI; | |
14048 | } | |
14049 | ||
6669f9bb | 14050 | /** |
546fc854 | 14051 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
14052 | * @phba: Pointer to HBA context object. |
14053 | * @fc_hdr: pointer to a FC frame header. | |
14054 | * | |
546fc854 | 14055 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
14056 | * event after aborting the sequence handling. |
14057 | **/ | |
14058 | static void | |
546fc854 | 14059 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
6669f9bb JS |
14060 | struct fc_frame_header *fc_hdr) |
14061 | { | |
14062 | struct lpfc_iocbq *ctiocb = NULL; | |
14063 | struct lpfc_nodelist *ndlp; | |
ee0f4fe1 | 14064 | uint16_t oxid, rxid, xri, lxri; |
5ffc266e | 14065 | uint32_t sid, fctl; |
6669f9bb | 14066 | IOCB_t *icmd; |
546fc854 | 14067 | int rc; |
6669f9bb JS |
14068 | |
14069 | if (!lpfc_is_link_up(phba)) | |
14070 | return; | |
14071 | ||
14072 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
14073 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 14074 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
14075 | |
14076 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
14077 | if (!ndlp) { | |
14078 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
14079 | "1268 Find ndlp returned NULL for oxid:x%x " | |
14080 | "SID:x%x\n", oxid, sid); | |
14081 | return; | |
14082 | } | |
14083 | ||
546fc854 | 14084 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
14085 | ctiocb = lpfc_sli_get_iocbq(phba); |
14086 | if (!ctiocb) | |
14087 | return; | |
14088 | ||
5ffc266e JS |
14089 | /* Extract the F_CTL field from FC_HDR */ |
14090 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
14091 | ||
6669f9bb | 14092 | icmd = &ctiocb->iocb; |
6669f9bb | 14093 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 14094 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
14095 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
14096 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
14097 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
14098 | ||
14099 | /* Fill in the rest of iocb fields */ | |
14100 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
14101 | icmd->ulpBdeCount = 0; | |
14102 | icmd->ulpLe = 1; | |
14103 | icmd->ulpClass = CLASS3; | |
6d368e53 | 14104 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
be858b65 | 14105 | ctiocb->context1 = ndlp; |
6669f9bb | 14106 | |
6669f9bb JS |
14107 | ctiocb->iocb_cmpl = NULL; |
14108 | ctiocb->vport = phba->pport; | |
546fc854 | 14109 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 14110 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
14111 | ctiocb->sli4_xritag = NO_XRI; |
14112 | ||
ee0f4fe1 JS |
14113 | if (fctl & FC_FC_EX_CTX) |
14114 | /* Exchange responder sent the abort so we | |
14115 | * own the oxid. | |
14116 | */ | |
14117 | xri = oxid; | |
14118 | else | |
14119 | xri = rxid; | |
14120 | lxri = lpfc_sli4_xri_inrange(phba, xri); | |
14121 | if (lxri != NO_XRI) | |
14122 | lpfc_set_rrq_active(phba, ndlp, lxri, | |
14123 | (xri == oxid) ? rxid : oxid, 0); | |
546fc854 JS |
14124 | /* If the oxid maps to the FCP XRI range or if it is out of range, |
14125 | * send a BLS_RJT. The driver no longer has that exchange. | |
14126 | * Override the IOCB for a BA_RJT. | |
14127 | */ | |
ee0f4fe1 | 14128 | if (xri > (phba->sli4_hba.max_cfg_param.max_xri + |
546fc854 | 14129 | phba->sli4_hba.max_cfg_param.xri_base) || |
ee0f4fe1 | 14130 | xri > (lpfc_sli4_get_els_iocb_cnt(phba) + |
546fc854 JS |
14131 | phba->sli4_hba.max_cfg_param.xri_base)) { |
14132 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
14133 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
14134 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
14135 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
14136 | } | |
6669f9bb | 14137 | |
5ffc266e JS |
14138 | if (fctl & FC_FC_EX_CTX) { |
14139 | /* ABTS sent by responder to CT exchange, construction | |
14140 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
14141 | * field and RX_ID from ABTS for RX_ID field. | |
14142 | */ | |
546fc854 | 14143 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
5ffc266e JS |
14144 | } else { |
14145 | /* ABTS sent by initiator to CT exchange, construction | |
14146 | * of BA_ACC will need to allocate a new XRI as for the | |
f09c3acc | 14147 | * XRI_TAG field. |
5ffc266e | 14148 | */ |
546fc854 | 14149 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
5ffc266e | 14150 | } |
f09c3acc | 14151 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); |
546fc854 | 14152 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 14153 | |
546fc854 | 14154 | /* Xmit CT abts response on exchange <xid> */ |
6669f9bb | 14155 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
14156 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
14157 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
14158 | ||
14159 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
14160 | if (rc == IOCB_ERROR) { | |
14161 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
14162 | "2925 Failed to issue CT ABTS RSP x%x on " | |
14163 | "xri x%x, Data x%x\n", | |
14164 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
14165 | phba->link_state); | |
14166 | lpfc_sli_release_iocbq(phba, ctiocb); | |
14167 | } | |
6669f9bb JS |
14168 | } |
14169 | ||
14170 | /** | |
14171 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
14172 | * @vport: Pointer to the vport on which this sequence was received | |
14173 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14174 | * | |
14175 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
14176 | * receive sequence is only partially assembed by the driver, it shall abort | |
14177 | * the partially assembled frames for the sequence. Otherwise, if the | |
14178 | * unsolicited receive sequence has been completely assembled and passed to | |
14179 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
14180 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
14181 | * accept to accept the abort. | |
14182 | **/ | |
14183 | void | |
14184 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
14185 | struct hbq_dmabuf *dmabuf) | |
14186 | { | |
14187 | struct lpfc_hba *phba = vport->phba; | |
14188 | struct fc_frame_header fc_hdr; | |
5ffc266e | 14189 | uint32_t fctl; |
6669f9bb JS |
14190 | bool abts_par; |
14191 | ||
6669f9bb JS |
14192 | /* Make a copy of fc_hdr before the dmabuf being released */ |
14193 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 14194 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 14195 | |
5ffc266e JS |
14196 | if (fctl & FC_FC_EX_CTX) { |
14197 | /* | |
14198 | * ABTS sent by responder to exchange, just free the buffer | |
14199 | */ | |
6669f9bb | 14200 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
14201 | } else { |
14202 | /* | |
14203 | * ABTS sent by initiator to exchange, need to do cleanup | |
14204 | */ | |
14205 | /* Try to abort partially assembled seq */ | |
14206 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
14207 | ||
14208 | /* Send abort to ULP if partially seq abort failed */ | |
14209 | if (abts_par == false) | |
14210 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
14211 | else | |
14212 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14213 | } | |
6669f9bb | 14214 | /* Send basic accept (BA_ACC) to the abort requester */ |
546fc854 | 14215 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
6669f9bb JS |
14216 | } |
14217 | ||
4f774513 JS |
14218 | /** |
14219 | * lpfc_seq_complete - Indicates if a sequence is complete | |
14220 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14221 | * | |
14222 | * This function checks the sequence, starting with the frame described by | |
14223 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
14224 | * the frames associated with this sequence are linked to the @dmabuf using the | |
14225 | * dbuf list. This function looks for two major things. 1) That the first frame | |
14226 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
14227 | * set. 3) That there are no holes in the sequence count. The function will | |
14228 | * return 1 when the sequence is complete, otherwise it will return 0. | |
14229 | **/ | |
14230 | static int | |
14231 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
14232 | { | |
14233 | struct fc_frame_header *hdr; | |
14234 | struct lpfc_dmabuf *d_buf; | |
14235 | struct hbq_dmabuf *seq_dmabuf; | |
14236 | uint32_t fctl; | |
14237 | int seq_count = 0; | |
14238 | ||
14239 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
14240 | /* make sure first fame of sequence has a sequence count of zero */ | |
14241 | if (hdr->fh_seq_cnt != seq_count) | |
14242 | return 0; | |
14243 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
14244 | hdr->fh_f_ctl[1] << 8 | | |
14245 | hdr->fh_f_ctl[2]); | |
14246 | /* If last frame of sequence we can return success. */ | |
14247 | if (fctl & FC_FC_END_SEQ) | |
14248 | return 1; | |
14249 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
14250 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14251 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14252 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 14253 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
14254 | return 0; |
14255 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
14256 | hdr->fh_f_ctl[1] << 8 | | |
14257 | hdr->fh_f_ctl[2]); | |
14258 | /* If last frame of sequence we can return success. */ | |
14259 | if (fctl & FC_FC_END_SEQ) | |
14260 | return 1; | |
14261 | } | |
14262 | return 0; | |
14263 | } | |
14264 | ||
14265 | /** | |
14266 | * lpfc_prep_seq - Prep sequence for ULP processing | |
14267 | * @vport: Pointer to the vport on which this sequence was received | |
14268 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14269 | * | |
14270 | * This function takes a sequence, described by a list of frames, and creates | |
14271 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
14272 | * used to issue to the generic unsolicited sequence handler. This routine | |
14273 | * returns a pointer to the first iocbq in the list. If the function is unable | |
14274 | * to allocate an iocbq then it throw out the received frames that were not | |
14275 | * able to be described and return a pointer to the first iocbq. If unable to | |
14276 | * allocate any iocbqs (including the first) this function will return NULL. | |
14277 | **/ | |
14278 | static struct lpfc_iocbq * | |
14279 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
14280 | { | |
7851fe2c | 14281 | struct hbq_dmabuf *hbq_buf; |
4f774513 JS |
14282 | struct lpfc_dmabuf *d_buf, *n_buf; |
14283 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
14284 | struct fc_frame_header *fc_hdr; | |
14285 | uint32_t sid; | |
7851fe2c | 14286 | uint32_t len, tot_len; |
eeead811 | 14287 | struct ulp_bde64 *pbde; |
4f774513 JS |
14288 | |
14289 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14290 | /* remove from receive buffer list */ | |
14291 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 14292 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 14293 | /* get the Remote Port's SID */ |
6669f9bb | 14294 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
7851fe2c | 14295 | tot_len = 0; |
4f774513 JS |
14296 | /* Get an iocbq struct to fill in. */ |
14297 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
14298 | if (first_iocbq) { | |
14299 | /* Initialize the first IOCB. */ | |
8fa38513 | 14300 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 | 14301 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
939723a4 JS |
14302 | |
14303 | /* Check FC Header to see what TYPE of frame we are rcv'ing */ | |
14304 | if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) { | |
14305 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_ELS64_CX; | |
14306 | first_iocbq->iocb.un.rcvels.parmRo = | |
14307 | sli4_did_from_fc_hdr(fc_hdr); | |
14308 | first_iocbq->iocb.ulpPU = PARM_NPIV_DID; | |
14309 | } else | |
14310 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
7851fe2c JS |
14311 | first_iocbq->iocb.ulpContext = NO_XRI; |
14312 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = | |
14313 | be16_to_cpu(fc_hdr->fh_ox_id); | |
14314 | /* iocbq is prepped for internal consumption. Physical vpi. */ | |
14315 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
14316 | vport->phba->vpi_ids[vport->vpi]; | |
4f774513 JS |
14317 | /* put the first buffer into the first IOCBq */ |
14318 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
14319 | first_iocbq->context3 = NULL; | |
14320 | first_iocbq->iocb.ulpBdeCount = 1; | |
14321 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
14322 | LPFC_DATA_BUF_SIZE; | |
14323 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
7851fe2c | 14324 | tot_len = bf_get(lpfc_rcqe_length, |
4d9ab994 | 14325 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
7851fe2c | 14326 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
4f774513 JS |
14327 | } |
14328 | iocbq = first_iocbq; | |
14329 | /* | |
14330 | * Each IOCBq can have two Buffers assigned, so go through the list | |
14331 | * of buffers for this sequence and save two buffers in each IOCBq | |
14332 | */ | |
14333 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
14334 | if (!iocbq) { | |
14335 | lpfc_in_buf_free(vport->phba, d_buf); | |
14336 | continue; | |
14337 | } | |
14338 | if (!iocbq->context3) { | |
14339 | iocbq->context3 = d_buf; | |
14340 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
14341 | pbde = (struct ulp_bde64 *) |
14342 | &iocbq->iocb.unsli3.sli3Words[4]; | |
14343 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
7851fe2c JS |
14344 | |
14345 | /* We need to get the size out of the right CQE */ | |
14346 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14347 | len = bf_get(lpfc_rcqe_length, | |
14348 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
14349 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; | |
14350 | tot_len += len; | |
4f774513 JS |
14351 | } else { |
14352 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
14353 | if (!iocbq) { | |
14354 | if (first_iocbq) { | |
14355 | first_iocbq->iocb.ulpStatus = | |
14356 | IOSTAT_FCP_RSP_ERROR; | |
14357 | first_iocbq->iocb.un.ulpWord[4] = | |
14358 | IOERR_NO_RESOURCES; | |
14359 | } | |
14360 | lpfc_in_buf_free(vport->phba, d_buf); | |
14361 | continue; | |
14362 | } | |
14363 | iocbq->context2 = d_buf; | |
14364 | iocbq->context3 = NULL; | |
14365 | iocbq->iocb.ulpBdeCount = 1; | |
14366 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
14367 | LPFC_DATA_BUF_SIZE; | |
7851fe2c JS |
14368 | |
14369 | /* We need to get the size out of the right CQE */ | |
14370 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14371 | len = bf_get(lpfc_rcqe_length, | |
14372 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
14373 | tot_len += len; | |
14374 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; | |
14375 | ||
4f774513 JS |
14376 | iocbq->iocb.un.rcvels.remoteID = sid; |
14377 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
14378 | } | |
14379 | } | |
14380 | return first_iocbq; | |
14381 | } | |
14382 | ||
6669f9bb JS |
14383 | static void |
14384 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
14385 | struct hbq_dmabuf *seq_dmabuf) | |
14386 | { | |
14387 | struct fc_frame_header *fc_hdr; | |
14388 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
14389 | struct lpfc_hba *phba = vport->phba; | |
14390 | ||
14391 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14392 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
14393 | if (!iocbq) { | |
14394 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14395 | "2707 Ring %d handler: Failed to allocate " | |
14396 | "iocb Rctl x%x Type x%x received\n", | |
14397 | LPFC_ELS_RING, | |
14398 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
14399 | return; | |
14400 | } | |
14401 | if (!lpfc_complete_unsol_iocb(phba, | |
14402 | &phba->sli.ring[LPFC_ELS_RING], | |
14403 | iocbq, fc_hdr->fh_r_ctl, | |
14404 | fc_hdr->fh_type)) | |
6d368e53 | 14405 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
14406 | "2540 Ring %d handler: unexpected Rctl " |
14407 | "x%x Type x%x received\n", | |
14408 | LPFC_ELS_RING, | |
14409 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
14410 | ||
14411 | /* Free iocb created in lpfc_prep_seq */ | |
14412 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
14413 | &iocbq->list, list) { | |
14414 | list_del_init(&curr_iocb->list); | |
14415 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
14416 | } | |
14417 | lpfc_sli_release_iocbq(phba, iocbq); | |
14418 | } | |
14419 | ||
4f774513 JS |
14420 | /** |
14421 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
14422 | * @phba: Pointer to HBA context object. | |
14423 | * | |
14424 | * This function is called with no lock held. This function processes all | |
14425 | * the received buffers and gives it to upper layers when a received buffer | |
14426 | * indicates that it is the final frame in the sequence. The interrupt | |
14427 | * service routine processes received buffers at interrupt contexts and adds | |
14428 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
14429 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
14430 | * appropriate receive function when the final frame in a sequence is received. | |
14431 | **/ | |
4d9ab994 JS |
14432 | void |
14433 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
14434 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 14435 | { |
4d9ab994 | 14436 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
14437 | struct fc_frame_header *fc_hdr; |
14438 | struct lpfc_vport *vport; | |
14439 | uint32_t fcfi; | |
939723a4 | 14440 | uint32_t did; |
4f774513 | 14441 | |
4f774513 | 14442 | /* Process each received buffer */ |
4d9ab994 JS |
14443 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
14444 | /* check to see if this a valid type of frame */ | |
14445 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
14446 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14447 | return; | |
14448 | } | |
7851fe2c JS |
14449 | if ((bf_get(lpfc_cqe_code, |
14450 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) | |
14451 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, | |
14452 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
14453 | else | |
14454 | fcfi = bf_get(lpfc_rcqe_fcf_id, | |
14455 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
939723a4 | 14456 | |
4d9ab994 | 14457 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
939723a4 | 14458 | if (!vport) { |
4d9ab994 JS |
14459 | /* throw out the frame */ |
14460 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14461 | return; | |
14462 | } | |
939723a4 JS |
14463 | |
14464 | /* d_id this frame is directed to */ | |
14465 | did = sli4_did_from_fc_hdr(fc_hdr); | |
14466 | ||
14467 | /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */ | |
14468 | if (!(vport->vpi_state & LPFC_VPI_REGISTERED) && | |
14469 | (did != Fabric_DID)) { | |
14470 | /* | |
14471 | * Throw out the frame if we are not pt2pt. | |
14472 | * The pt2pt protocol allows for discovery frames | |
14473 | * to be received without a registered VPI. | |
14474 | */ | |
14475 | if (!(vport->fc_flag & FC_PT2PT) || | |
14476 | (phba->link_state == LPFC_HBA_READY)) { | |
14477 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14478 | return; | |
14479 | } | |
14480 | } | |
14481 | ||
6669f9bb JS |
14482 | /* Handle the basic abort sequence (BA_ABTS) event */ |
14483 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
14484 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
14485 | return; | |
14486 | } | |
14487 | ||
4d9ab994 JS |
14488 | /* Link this frame */ |
14489 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
14490 | if (!seq_dmabuf) { | |
14491 | /* unable to add frame to vport - throw it out */ | |
14492 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14493 | return; | |
14494 | } | |
14495 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 14496 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 14497 | return; |
def9c7a9 | 14498 | |
6669f9bb JS |
14499 | /* Send the complete sequence to the upper layer protocol */ |
14500 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 14501 | } |
6fb120a7 JS |
14502 | |
14503 | /** | |
14504 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
14505 | * @phba: pointer to lpfc hba data structure. | |
14506 | * | |
14507 | * This routine is invoked to post rpi header templates to the | |
14508 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
14509 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
14510 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
14511 | * |
14512 | * This routine does not require any locks. It's usage is expected | |
14513 | * to be driver load or reset recovery when the driver is | |
14514 | * sequential. | |
14515 | * | |
14516 | * Return codes | |
af901ca1 | 14517 | * 0 - successful |
d439d286 | 14518 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
14519 | * When this error occurs, the driver is not guaranteed |
14520 | * to have any rpi regions posted to the device and | |
14521 | * must either attempt to repost the regions or take a | |
14522 | * fatal error. | |
14523 | **/ | |
14524 | int | |
14525 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
14526 | { | |
14527 | struct lpfc_rpi_hdr *rpi_page; | |
14528 | uint32_t rc = 0; | |
6d368e53 JS |
14529 | uint16_t lrpi = 0; |
14530 | ||
14531 | /* SLI4 ports that support extents do not require RPI headers. */ | |
14532 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
14533 | goto exit; | |
14534 | if (phba->sli4_hba.extents_in_use) | |
14535 | return -EIO; | |
6fb120a7 | 14536 | |
6fb120a7 | 14537 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
14538 | /* |
14539 | * Assign the rpi headers a physical rpi only if the driver | |
14540 | * has not initialized those resources. A port reset only | |
14541 | * needs the headers posted. | |
14542 | */ | |
14543 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
14544 | LPFC_RPI_RSRC_RDY) | |
14545 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
14546 | ||
6fb120a7 JS |
14547 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
14548 | if (rc != MBX_SUCCESS) { | |
14549 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14550 | "2008 Error %d posting all rpi " | |
14551 | "headers\n", rc); | |
14552 | rc = -EIO; | |
14553 | break; | |
14554 | } | |
14555 | } | |
14556 | ||
6d368e53 JS |
14557 | exit: |
14558 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
14559 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
14560 | return rc; |
14561 | } | |
14562 | ||
14563 | /** | |
14564 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
14565 | * @phba: pointer to lpfc hba data structure. | |
14566 | * @rpi_page: pointer to the rpi memory region. | |
14567 | * | |
14568 | * This routine is invoked to post a single rpi header to the | |
14569 | * HBA consistent with the SLI-4 interface spec. This memory region | |
14570 | * maps up to 64 rpi context regions. | |
14571 | * | |
14572 | * Return codes | |
af901ca1 | 14573 | * 0 - successful |
d439d286 JS |
14574 | * -ENOMEM - No available memory |
14575 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
14576 | **/ |
14577 | int | |
14578 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
14579 | { | |
14580 | LPFC_MBOXQ_t *mboxq; | |
14581 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
14582 | uint32_t rc = 0; | |
6fb120a7 JS |
14583 | uint32_t shdr_status, shdr_add_status; |
14584 | union lpfc_sli4_cfg_shdr *shdr; | |
14585 | ||
6d368e53 JS |
14586 | /* SLI4 ports that support extents do not require RPI headers. */ |
14587 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
14588 | return rc; | |
14589 | if (phba->sli4_hba.extents_in_use) | |
14590 | return -EIO; | |
14591 | ||
6fb120a7 JS |
14592 | /* The port is notified of the header region via a mailbox command. */ |
14593 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14594 | if (!mboxq) { | |
14595 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14596 | "2001 Unable to allocate memory for issuing " | |
14597 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
14598 | return -ENOMEM; | |
14599 | } | |
14600 | ||
14601 | /* Post all rpi memory regions to the port. */ | |
14602 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
14603 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
14604 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
14605 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
14606 | sizeof(struct lpfc_sli4_cfg_mhdr), |
14607 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
14608 | |
14609 | ||
14610 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
14611 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
14612 | rpi_page->start_rpi); | |
6d368e53 JS |
14613 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
14614 | hdr_tmpl, rpi_page->page_count); | |
14615 | ||
6fb120a7 JS |
14616 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
14617 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 14618 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
14619 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
14620 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14621 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14622 | if (rc != MBX_TIMEOUT) | |
14623 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14624 | if (shdr_status || shdr_add_status || rc) { | |
14625 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14626 | "2514 POST_RPI_HDR mailbox failed with " | |
14627 | "status x%x add_status x%x, mbx status x%x\n", | |
14628 | shdr_status, shdr_add_status, rc); | |
14629 | rc = -ENXIO; | |
14630 | } | |
14631 | return rc; | |
14632 | } | |
14633 | ||
14634 | /** | |
14635 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
14636 | * @phba: pointer to lpfc hba data structure. | |
14637 | * | |
14638 | * This routine is invoked to post rpi header templates to the | |
14639 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
14640 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
14641 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
14642 | * |
14643 | * Returns | |
af901ca1 | 14644 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
14645 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
14646 | **/ | |
14647 | int | |
14648 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
14649 | { | |
6d368e53 JS |
14650 | unsigned long rpi; |
14651 | uint16_t max_rpi, rpi_limit; | |
14652 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 JS |
14653 | struct lpfc_rpi_hdr *rpi_hdr; |
14654 | ||
14655 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6fb120a7 JS |
14656 | rpi_limit = phba->sli4_hba.next_rpi; |
14657 | ||
14658 | /* | |
6d368e53 JS |
14659 | * Fetch the next logical rpi. Because this index is logical, |
14660 | * the driver starts at 0 each time. | |
6fb120a7 JS |
14661 | */ |
14662 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
14663 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
14664 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
14665 | rpi = LPFC_RPI_ALLOC_ERROR; |
14666 | else { | |
14667 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
14668 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
14669 | phba->sli4_hba.rpi_count++; | |
14670 | } | |
14671 | ||
14672 | /* | |
14673 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 14674 | * has been exhausted. |
6fb120a7 JS |
14675 | */ |
14676 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
14677 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
14678 | spin_unlock_irq(&phba->hbalock); | |
14679 | return rpi; | |
14680 | } | |
14681 | ||
6d368e53 JS |
14682 | /* |
14683 | * RPI header postings are not required for SLI4 ports capable of | |
14684 | * extents. | |
14685 | */ | |
14686 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
14687 | spin_unlock_irq(&phba->hbalock); | |
14688 | return rpi; | |
14689 | } | |
14690 | ||
6fb120a7 JS |
14691 | /* |
14692 | * If the driver is running low on rpi resources, allocate another | |
14693 | * page now. Note that the next_rpi value is used because | |
14694 | * it represents how many are actually in use whereas max_rpi notes | |
14695 | * how many are supported max by the device. | |
14696 | */ | |
6d368e53 | 14697 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
6fb120a7 JS |
14698 | spin_unlock_irq(&phba->hbalock); |
14699 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
14700 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
14701 | if (!rpi_hdr) { | |
14702 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14703 | "2002 Error Could not grow rpi " | |
14704 | "count\n"); | |
14705 | } else { | |
6d368e53 JS |
14706 | lrpi = rpi_hdr->start_rpi; |
14707 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
14708 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
14709 | } | |
14710 | } | |
14711 | ||
14712 | return rpi; | |
14713 | } | |
14714 | ||
d7c47992 JS |
14715 | /** |
14716 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14717 | * @phba: pointer to lpfc hba data structure. | |
14718 | * | |
14719 | * This routine is invoked to release an rpi to the pool of | |
14720 | * available rpis maintained by the driver. | |
14721 | **/ | |
14722 | void | |
14723 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14724 | { | |
14725 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
14726 | phba->sli4_hba.rpi_count--; | |
14727 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
14728 | } | |
14729 | } | |
14730 | ||
6fb120a7 JS |
14731 | /** |
14732 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14733 | * @phba: pointer to lpfc hba data structure. | |
14734 | * | |
14735 | * This routine is invoked to release an rpi to the pool of | |
14736 | * available rpis maintained by the driver. | |
14737 | **/ | |
14738 | void | |
14739 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14740 | { | |
14741 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 14742 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
14743 | spin_unlock_irq(&phba->hbalock); |
14744 | } | |
14745 | ||
14746 | /** | |
14747 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
14748 | * @phba: pointer to lpfc hba data structure. | |
14749 | * | |
14750 | * This routine is invoked to remove the memory region that | |
14751 | * provided rpi via a bitmask. | |
14752 | **/ | |
14753 | void | |
14754 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
14755 | { | |
14756 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
14757 | kfree(phba->sli4_hba.rpi_ids); |
14758 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
14759 | } |
14760 | ||
14761 | /** | |
14762 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
14763 | * @phba: pointer to lpfc hba data structure. | |
14764 | * | |
14765 | * This routine is invoked to remove the memory region that | |
14766 | * provided rpi via a bitmask. | |
14767 | **/ | |
14768 | int | |
6b5151fd JS |
14769 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp, |
14770 | void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg) | |
6fb120a7 JS |
14771 | { |
14772 | LPFC_MBOXQ_t *mboxq; | |
14773 | struct lpfc_hba *phba = ndlp->phba; | |
14774 | int rc; | |
14775 | ||
14776 | /* The port is notified of the header region via a mailbox command. */ | |
14777 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14778 | if (!mboxq) | |
14779 | return -ENOMEM; | |
14780 | ||
14781 | /* Post all rpi memory regions to the port. */ | |
14782 | lpfc_resume_rpi(mboxq, ndlp); | |
6b5151fd JS |
14783 | if (cmpl) { |
14784 | mboxq->mbox_cmpl = cmpl; | |
14785 | mboxq->context1 = arg; | |
14786 | mboxq->context2 = ndlp; | |
72859909 JS |
14787 | } else |
14788 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6b5151fd | 14789 | mboxq->vport = ndlp->vport; |
6fb120a7 JS |
14790 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
14791 | if (rc == MBX_NOT_FINISHED) { | |
14792 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14793 | "2010 Resume RPI Mailbox failed " | |
14794 | "status %d, mbxStatus x%x\n", rc, | |
14795 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
14796 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14797 | return -EIO; | |
14798 | } | |
14799 | return 0; | |
14800 | } | |
14801 | ||
14802 | /** | |
14803 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 14804 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 14805 | * |
76a95d75 | 14806 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
14807 | * |
14808 | * Returns: | |
14809 | * 0 success | |
14810 | * -Evalue otherwise | |
14811 | **/ | |
14812 | int | |
76a95d75 | 14813 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
14814 | { |
14815 | LPFC_MBOXQ_t *mboxq; | |
14816 | int rc = 0; | |
6a9c52cf | 14817 | int retval = MBX_SUCCESS; |
6fb120a7 | 14818 | uint32_t mbox_tmo; |
76a95d75 | 14819 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
14820 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14821 | if (!mboxq) | |
14822 | return -ENOMEM; | |
76a95d75 | 14823 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
a183a15f | 14824 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
6fb120a7 | 14825 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
6fb120a7 | 14826 | if (rc != MBX_SUCCESS) { |
76a95d75 | 14827 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
14828 | "2022 INIT VPI Mailbox failed " |
14829 | "status %d, mbxStatus x%x\n", rc, | |
14830 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 14831 | retval = -EIO; |
6fb120a7 | 14832 | } |
6a9c52cf | 14833 | if (rc != MBX_TIMEOUT) |
76a95d75 | 14834 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
14835 | |
14836 | return retval; | |
6fb120a7 JS |
14837 | } |
14838 | ||
14839 | /** | |
14840 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
14841 | * @phba: pointer to lpfc hba data structure. | |
14842 | * @mboxq: Pointer to mailbox object. | |
14843 | * | |
14844 | * This routine is invoked to manually add a single FCF record. The caller | |
14845 | * must pass a completely initialized FCF_Record. This routine takes | |
14846 | * care of the nonembedded mailbox operations. | |
14847 | **/ | |
14848 | static void | |
14849 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
14850 | { | |
14851 | void *virt_addr; | |
14852 | union lpfc_sli4_cfg_shdr *shdr; | |
14853 | uint32_t shdr_status, shdr_add_status; | |
14854 | ||
14855 | virt_addr = mboxq->sge_array->addr[0]; | |
14856 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14857 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
14858 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14859 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14860 | ||
14861 | if ((shdr_status || shdr_add_status) && | |
14862 | (shdr_status != STATUS_FCF_IN_USE)) | |
14863 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14864 | "2558 ADD_FCF_RECORD mailbox failed with " | |
14865 | "status x%x add_status x%x\n", | |
14866 | shdr_status, shdr_add_status); | |
14867 | ||
14868 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14869 | } | |
14870 | ||
14871 | /** | |
14872 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
14873 | * @phba: pointer to lpfc hba data structure. | |
14874 | * @fcf_record: pointer to the initialized fcf record to add. | |
14875 | * | |
14876 | * This routine is invoked to manually add a single FCF record. The caller | |
14877 | * must pass a completely initialized FCF_Record. This routine takes | |
14878 | * care of the nonembedded mailbox operations. | |
14879 | **/ | |
14880 | int | |
14881 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
14882 | { | |
14883 | int rc = 0; | |
14884 | LPFC_MBOXQ_t *mboxq; | |
14885 | uint8_t *bytep; | |
14886 | void *virt_addr; | |
14887 | dma_addr_t phys_addr; | |
14888 | struct lpfc_mbx_sge sge; | |
14889 | uint32_t alloc_len, req_len; | |
14890 | uint32_t fcfindex; | |
14891 | ||
14892 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14893 | if (!mboxq) { | |
14894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14895 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
14896 | return -ENOMEM; | |
14897 | } | |
14898 | ||
14899 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
14900 | sizeof(uint32_t); | |
14901 | ||
14902 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14903 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14904 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
14905 | req_len, LPFC_SLI4_MBX_NEMBED); | |
14906 | if (alloc_len < req_len) { | |
14907 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14908 | "2523 Allocated DMA memory size (x%x) is " | |
14909 | "less than the requested DMA memory " | |
14910 | "size (x%x)\n", alloc_len, req_len); | |
14911 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14912 | return -ENOMEM; | |
14913 | } | |
14914 | ||
14915 | /* | |
14916 | * Get the first SGE entry from the non-embedded DMA memory. This | |
14917 | * routine only uses a single SGE. | |
14918 | */ | |
14919 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
14920 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
14921 | virt_addr = mboxq->sge_array->addr[0]; |
14922 | /* | |
14923 | * Configure the FCF record for FCFI 0. This is the driver's | |
14924 | * hardcoded default and gets used in nonFIP mode. | |
14925 | */ | |
14926 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
14927 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
14928 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
14929 | ||
14930 | /* | |
14931 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
14932 | * the FCoE header plus word10. The data copy needs to be endian | |
14933 | * correct. | |
14934 | */ | |
14935 | bytep += sizeof(uint32_t); | |
14936 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
14937 | mboxq->vport = phba->pport; | |
14938 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
14939 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14940 | if (rc == MBX_NOT_FINISHED) { | |
14941 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14942 | "2515 ADD_FCF_RECORD mailbox failed with " | |
14943 | "status 0x%x\n", rc); | |
14944 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14945 | rc = -EIO; | |
14946 | } else | |
14947 | rc = 0; | |
14948 | ||
14949 | return rc; | |
14950 | } | |
14951 | ||
14952 | /** | |
14953 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
14954 | * @phba: pointer to lpfc hba data structure. | |
14955 | * @fcf_record: pointer to the fcf record to write the default data. | |
14956 | * @fcf_index: FCF table entry index. | |
14957 | * | |
14958 | * This routine is invoked to build the driver's default FCF record. The | |
14959 | * values used are hardcoded. This routine handles memory initialization. | |
14960 | * | |
14961 | **/ | |
14962 | void | |
14963 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
14964 | struct fcf_record *fcf_record, | |
14965 | uint16_t fcf_index) | |
14966 | { | |
14967 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
14968 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
14969 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
14970 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
14971 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
14972 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
14973 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
14974 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
14975 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
14976 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
14977 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
14978 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
14979 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
14980 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 14981 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
14982 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
14983 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
14984 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
14985 | /* Set the VLAN bit map */ | |
14986 | if (phba->valid_vlan) { | |
14987 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
14988 | = 1 << (phba->vlan_id % 8); | |
14989 | } | |
14990 | } | |
14991 | ||
14992 | /** | |
0c9ab6f5 | 14993 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
14994 | * @phba: pointer to lpfc hba data structure. |
14995 | * @fcf_index: FCF table entry offset. | |
14996 | * | |
0c9ab6f5 JS |
14997 | * This routine is invoked to scan the entire FCF table by reading FCF |
14998 | * record and processing it one at a time starting from the @fcf_index | |
14999 | * for initial FCF discovery or fast FCF failover rediscovery. | |
15000 | * | |
25985edc | 15001 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 15002 | * otherwise. |
6fb120a7 JS |
15003 | **/ |
15004 | int | |
0c9ab6f5 | 15005 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
15006 | { |
15007 | int rc = 0, error; | |
15008 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 15009 | |
32b9793f | 15010 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
80c17849 | 15011 | phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag; |
6fb120a7 JS |
15012 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15013 | if (!mboxq) { | |
15014 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15015 | "2000 Failed to allocate mbox for " | |
15016 | "READ_FCF cmd\n"); | |
4d9ab994 | 15017 | error = -ENOMEM; |
0c9ab6f5 | 15018 | goto fail_fcf_scan; |
6fb120a7 | 15019 | } |
ecfd03c6 | 15020 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 15021 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
15022 | if (rc) { |
15023 | error = -EINVAL; | |
0c9ab6f5 | 15024 | goto fail_fcf_scan; |
6fb120a7 | 15025 | } |
ecfd03c6 | 15026 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 15027 | mboxq->vport = phba->pport; |
0c9ab6f5 | 15028 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
15029 | |
15030 | spin_lock_irq(&phba->hbalock); | |
15031 | phba->hba_flag |= FCF_TS_INPROG; | |
15032 | spin_unlock_irq(&phba->hbalock); | |
15033 | ||
6fb120a7 | 15034 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 15035 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 15036 | error = -EIO; |
ecfd03c6 | 15037 | else { |
38b92ef8 JS |
15038 | /* Reset eligible FCF count for new scan */ |
15039 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 15040 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 15041 | error = 0; |
32b9793f | 15042 | } |
0c9ab6f5 | 15043 | fail_fcf_scan: |
4d9ab994 JS |
15044 | if (error) { |
15045 | if (mboxq) | |
15046 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 15047 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 15048 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 15049 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
15050 | spin_unlock_irq(&phba->hbalock); |
15051 | } | |
6fb120a7 JS |
15052 | return error; |
15053 | } | |
a0c87cbd | 15054 | |
0c9ab6f5 | 15055 | /** |
a93ff37a | 15056 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
15057 | * @phba: pointer to lpfc hba data structure. |
15058 | * @fcf_index: FCF table entry offset. | |
15059 | * | |
15060 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 15061 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 15062 | * |
25985edc | 15063 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
15064 | * otherwise. |
15065 | **/ | |
15066 | int | |
15067 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
15068 | { | |
15069 | int rc = 0, error; | |
15070 | LPFC_MBOXQ_t *mboxq; | |
15071 | ||
15072 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15073 | if (!mboxq) { | |
15074 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
15075 | "2763 Failed to allocate mbox for " | |
15076 | "READ_FCF cmd\n"); | |
15077 | error = -ENOMEM; | |
15078 | goto fail_fcf_read; | |
15079 | } | |
15080 | /* Construct the read FCF record mailbox command */ | |
15081 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
15082 | if (rc) { | |
15083 | error = -EINVAL; | |
15084 | goto fail_fcf_read; | |
15085 | } | |
15086 | /* Issue the mailbox command asynchronously */ | |
15087 | mboxq->vport = phba->pport; | |
15088 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
15089 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
15090 | if (rc == MBX_NOT_FINISHED) | |
15091 | error = -EIO; | |
15092 | else | |
15093 | error = 0; | |
15094 | ||
15095 | fail_fcf_read: | |
15096 | if (error && mboxq) | |
15097 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15098 | return error; | |
15099 | } | |
15100 | ||
15101 | /** | |
15102 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
15103 | * @phba: pointer to lpfc hba data structure. | |
15104 | * @fcf_index: FCF table entry offset. | |
15105 | * | |
15106 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 15107 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 15108 | * |
25985edc | 15109 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
15110 | * otherwise. |
15111 | **/ | |
15112 | int | |
15113 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
15114 | { | |
15115 | int rc = 0, error; | |
15116 | LPFC_MBOXQ_t *mboxq; | |
15117 | ||
15118 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15119 | if (!mboxq) { | |
15120 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
15121 | "2758 Failed to allocate mbox for " | |
15122 | "READ_FCF cmd\n"); | |
15123 | error = -ENOMEM; | |
15124 | goto fail_fcf_read; | |
15125 | } | |
15126 | /* Construct the read FCF record mailbox command */ | |
15127 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
15128 | if (rc) { | |
15129 | error = -EINVAL; | |
15130 | goto fail_fcf_read; | |
15131 | } | |
15132 | /* Issue the mailbox command asynchronously */ | |
15133 | mboxq->vport = phba->pport; | |
15134 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
15135 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
15136 | if (rc == MBX_NOT_FINISHED) | |
15137 | error = -EIO; | |
15138 | else | |
15139 | error = 0; | |
15140 | ||
15141 | fail_fcf_read: | |
15142 | if (error && mboxq) | |
15143 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15144 | return error; | |
15145 | } | |
15146 | ||
7d791df7 JS |
15147 | /** |
15148 | * lpfc_check_next_fcf_pri | |
15149 | * phba pointer to the lpfc_hba struct for this port. | |
15150 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get | |
15151 | * routine when the rr_bmask is empty. The FCF indecies are put into the | |
15152 | * rr_bmask based on their priority level. Starting from the highest priority | |
15153 | * to the lowest. The most likely FCF candidate will be in the highest | |
15154 | * priority group. When this routine is called it searches the fcf_pri list for | |
15155 | * next lowest priority group and repopulates the rr_bmask with only those | |
15156 | * fcf_indexes. | |
15157 | * returns: | |
15158 | * 1=success 0=failure | |
15159 | **/ | |
15160 | int | |
15161 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) | |
15162 | { | |
15163 | uint16_t next_fcf_pri; | |
15164 | uint16_t last_index; | |
15165 | struct lpfc_fcf_pri *fcf_pri; | |
15166 | int rc; | |
15167 | int ret = 0; | |
15168 | ||
15169 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
15170 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
15171 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
15172 | "3060 Last IDX %d\n", last_index); | |
15173 | if (list_empty(&phba->fcf.fcf_pri_list)) { | |
15174 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
15175 | "3061 Last IDX %d\n", last_index); | |
15176 | return 0; /* Empty rr list */ | |
15177 | } | |
15178 | next_fcf_pri = 0; | |
15179 | /* | |
15180 | * Clear the rr_bmask and set all of the bits that are at this | |
15181 | * priority. | |
15182 | */ | |
15183 | memset(phba->fcf.fcf_rr_bmask, 0, | |
15184 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
15185 | spin_lock_irq(&phba->hbalock); | |
15186 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15187 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) | |
15188 | continue; | |
15189 | /* | |
15190 | * the 1st priority that has not FLOGI failed | |
15191 | * will be the highest. | |
15192 | */ | |
15193 | if (!next_fcf_pri) | |
15194 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
15195 | spin_unlock_irq(&phba->hbalock); | |
15196 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
15197 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
15198 | fcf_pri->fcf_rec.fcf_index); | |
15199 | if (rc) | |
15200 | return 0; | |
15201 | } | |
15202 | spin_lock_irq(&phba->hbalock); | |
15203 | } | |
15204 | /* | |
15205 | * if next_fcf_pri was not set above and the list is not empty then | |
15206 | * we have failed flogis on all of them. So reset flogi failed | |
15207 | * and start at the begining. | |
15208 | */ | |
15209 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { | |
15210 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15211 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; | |
15212 | /* | |
15213 | * the 1st priority that has not FLOGI failed | |
15214 | * will be the highest. | |
15215 | */ | |
15216 | if (!next_fcf_pri) | |
15217 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
15218 | spin_unlock_irq(&phba->hbalock); | |
15219 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
15220 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
15221 | fcf_pri->fcf_rec.fcf_index); | |
15222 | if (rc) | |
15223 | return 0; | |
15224 | } | |
15225 | spin_lock_irq(&phba->hbalock); | |
15226 | } | |
15227 | } else | |
15228 | ret = 1; | |
15229 | spin_unlock_irq(&phba->hbalock); | |
15230 | ||
15231 | return ret; | |
15232 | } | |
0c9ab6f5 JS |
15233 | /** |
15234 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
15235 | * @phba: pointer to lpfc hba data structure. | |
15236 | * | |
15237 | * This routine is to get the next eligible FCF record index in a round | |
15238 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 15239 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
15240 | * shall be returned, otherwise, the next eligible FCF record's index |
15241 | * shall be returned. | |
15242 | **/ | |
15243 | uint16_t | |
15244 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
15245 | { | |
15246 | uint16_t next_fcf_index; | |
15247 | ||
3804dc84 | 15248 | /* Search start from next bit of currently registered FCF index */ |
7d791df7 | 15249 | next_priority: |
3804dc84 JS |
15250 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
15251 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
15252 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
15253 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
15254 | next_fcf_index); |
15255 | ||
0c9ab6f5 | 15256 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
7d791df7 JS |
15257 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
15258 | /* | |
15259 | * If we have wrapped then we need to clear the bits that | |
15260 | * have been tested so that we can detect when we should | |
15261 | * change the priority level. | |
15262 | */ | |
0c9ab6f5 JS |
15263 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
15264 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
7d791df7 JS |
15265 | } |
15266 | ||
3804dc84 JS |
15267 | |
15268 | /* Check roundrobin failover list empty condition */ | |
7d791df7 JS |
15269 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
15270 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { | |
15271 | /* | |
15272 | * If next fcf index is not found check if there are lower | |
15273 | * Priority level fcf's in the fcf_priority list. | |
15274 | * Set up the rr_bmask with all of the avaiable fcf bits | |
15275 | * at that level and continue the selection process. | |
15276 | */ | |
15277 | if (lpfc_check_next_fcf_pri_level(phba)) | |
15278 | goto next_priority; | |
3804dc84 JS |
15279 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
15280 | "2844 No roundrobin failover FCF available\n"); | |
7d791df7 JS |
15281 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
15282 | return LPFC_FCOE_FCF_NEXT_NONE; | |
15283 | else { | |
15284 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
15285 | "3063 Only FCF available idx %d, flag %x\n", | |
15286 | next_fcf_index, | |
15287 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); | |
15288 | return next_fcf_index; | |
15289 | } | |
3804dc84 JS |
15290 | } |
15291 | ||
7d791df7 JS |
15292 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
15293 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & | |
15294 | LPFC_FCF_FLOGI_FAILED) | |
15295 | goto next_priority; | |
15296 | ||
3804dc84 | 15297 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
15298 | "2845 Get next roundrobin failover FCF (x%x)\n", |
15299 | next_fcf_index); | |
15300 | ||
0c9ab6f5 JS |
15301 | return next_fcf_index; |
15302 | } | |
15303 | ||
15304 | /** | |
15305 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
15306 | * @phba: pointer to lpfc hba data structure. | |
15307 | * | |
15308 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 15309 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
15310 | * does not go beyond the range of the driver allocated bmask dimension |
15311 | * before setting the bit. | |
15312 | * | |
15313 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
15314 | * -EINVAL. | |
15315 | **/ | |
15316 | int | |
15317 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
15318 | { | |
15319 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
15320 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
15321 | "2610 FCF (x%x) reached driver's book " |
15322 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
15323 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
15324 | return -EINVAL; | |
15325 | } | |
15326 | /* Set the eligible FCF record index bmask */ | |
15327 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
15328 | ||
3804dc84 | 15329 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 15330 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
15331 | "bmask\n", fcf_index); |
15332 | ||
0c9ab6f5 JS |
15333 | return 0; |
15334 | } | |
15335 | ||
15336 | /** | |
3804dc84 | 15337 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
15338 | * @phba: pointer to lpfc hba data structure. |
15339 | * | |
15340 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 15341 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
15342 | * does not go beyond the range of the driver allocated bmask dimension |
15343 | * before clearing the bit. | |
15344 | **/ | |
15345 | void | |
15346 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
15347 | { | |
7d791df7 | 15348 | struct lpfc_fcf_pri *fcf_pri; |
0c9ab6f5 JS |
15349 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
15350 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
15351 | "2762 FCF (x%x) reached driver's book " |
15352 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
15353 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
15354 | return; | |
15355 | } | |
15356 | /* Clear the eligible FCF record index bmask */ | |
7d791df7 JS |
15357 | spin_lock_irq(&phba->hbalock); |
15358 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15359 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { | |
15360 | list_del_init(&fcf_pri->list); | |
15361 | break; | |
15362 | } | |
15363 | } | |
15364 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 15365 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
3804dc84 JS |
15366 | |
15367 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 15368 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 15369 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
15370 | } |
15371 | ||
ecfd03c6 JS |
15372 | /** |
15373 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
15374 | * @phba: pointer to lpfc hba data structure. | |
15375 | * | |
15376 | * This routine is the completion routine for the rediscover FCF table mailbox | |
15377 | * command. If the mailbox command returned failure, it will try to stop the | |
15378 | * FCF rediscover wait timer. | |
15379 | **/ | |
15380 | void | |
15381 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
15382 | { | |
15383 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
15384 | uint32_t shdr_status, shdr_add_status; | |
15385 | ||
15386 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
15387 | ||
15388 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
15389 | &redisc_fcf->header.cfg_shdr.response); | |
15390 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
15391 | &redisc_fcf->header.cfg_shdr.response); | |
15392 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 15393 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
15394 | "2746 Requesting for FCF rediscovery failed " |
15395 | "status x%x add_status x%x\n", | |
15396 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 15397 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 15398 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 15399 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
15400 | spin_unlock_irq(&phba->hbalock); |
15401 | /* | |
15402 | * CVL event triggered FCF rediscover request failed, | |
15403 | * last resort to re-try current registered FCF entry. | |
15404 | */ | |
15405 | lpfc_retry_pport_discovery(phba); | |
15406 | } else { | |
15407 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 15408 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
15409 | spin_unlock_irq(&phba->hbalock); |
15410 | /* | |
15411 | * DEAD FCF event triggered FCF rediscover request | |
15412 | * failed, last resort to fail over as a link down | |
15413 | * to FCF registration. | |
15414 | */ | |
15415 | lpfc_sli4_fcf_dead_failthrough(phba); | |
15416 | } | |
0c9ab6f5 JS |
15417 | } else { |
15418 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 15419 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
15420 | /* |
15421 | * Start FCF rediscovery wait timer for pending FCF | |
15422 | * before rescan FCF record table. | |
15423 | */ | |
15424 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 15425 | } |
ecfd03c6 JS |
15426 | |
15427 | mempool_free(mbox, phba->mbox_mem_pool); | |
15428 | } | |
15429 | ||
15430 | /** | |
3804dc84 | 15431 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
15432 | * @phba: pointer to lpfc hba data structure. |
15433 | * | |
15434 | * This routine is invoked to request for rediscovery of the entire FCF table | |
15435 | * by the port. | |
15436 | **/ | |
15437 | int | |
15438 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
15439 | { | |
15440 | LPFC_MBOXQ_t *mbox; | |
15441 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
15442 | int rc, length; | |
15443 | ||
0c9ab6f5 JS |
15444 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
15445 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
15446 | ||
ecfd03c6 JS |
15447 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15448 | if (!mbox) { | |
15449 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15450 | "2745 Failed to allocate mbox for " | |
15451 | "requesting FCF rediscover.\n"); | |
15452 | return -ENOMEM; | |
15453 | } | |
15454 | ||
15455 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
15456 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
15457 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15458 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
15459 | length, LPFC_SLI4_MBX_EMBED); | |
15460 | ||
15461 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
15462 | /* Set count to 0 for invalidating the entire FCF database */ | |
15463 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
15464 | ||
15465 | /* Issue the mailbox command asynchronously */ | |
15466 | mbox->vport = phba->pport; | |
15467 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
15468 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
15469 | ||
15470 | if (rc == MBX_NOT_FINISHED) { | |
15471 | mempool_free(mbox, phba->mbox_mem_pool); | |
15472 | return -EIO; | |
15473 | } | |
15474 | return 0; | |
15475 | } | |
15476 | ||
fc2b989b JS |
15477 | /** |
15478 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
15479 | * @phba: pointer to lpfc hba data structure. | |
15480 | * | |
15481 | * This function is the failover routine as a last resort to the FCF DEAD | |
15482 | * event when driver failed to perform fast FCF failover. | |
15483 | **/ | |
15484 | void | |
15485 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
15486 | { | |
15487 | uint32_t link_state; | |
15488 | ||
15489 | /* | |
15490 | * Last resort as FCF DEAD event failover will treat this as | |
15491 | * a link down, but save the link state because we don't want | |
15492 | * it to be changed to Link Down unless it is already down. | |
15493 | */ | |
15494 | link_state = phba->link_state; | |
15495 | lpfc_linkdown(phba); | |
15496 | phba->link_state = link_state; | |
15497 | ||
15498 | /* Unregister FCF if no devices connected to it */ | |
15499 | lpfc_unregister_unused_fcf(phba); | |
15500 | } | |
15501 | ||
a0c87cbd | 15502 | /** |
026abb87 | 15503 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
a0c87cbd | 15504 | * @phba: pointer to lpfc hba data structure. |
026abb87 | 15505 | * @rgn23_data: pointer to configure region 23 data. |
a0c87cbd | 15506 | * |
026abb87 JS |
15507 | * This function gets SLI3 port configure region 23 data through memory dump |
15508 | * mailbox command. When it successfully retrieves data, the size of the data | |
15509 | * will be returned, otherwise, 0 will be returned. | |
a0c87cbd | 15510 | **/ |
026abb87 JS |
15511 | static uint32_t |
15512 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
a0c87cbd JS |
15513 | { |
15514 | LPFC_MBOXQ_t *pmb = NULL; | |
15515 | MAILBOX_t *mb; | |
026abb87 | 15516 | uint32_t offset = 0; |
a0c87cbd JS |
15517 | int rc; |
15518 | ||
026abb87 JS |
15519 | if (!rgn23_data) |
15520 | return 0; | |
15521 | ||
a0c87cbd JS |
15522 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15523 | if (!pmb) { | |
15524 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
026abb87 JS |
15525 | "2600 failed to allocate mailbox memory\n"); |
15526 | return 0; | |
a0c87cbd JS |
15527 | } |
15528 | mb = &pmb->u.mb; | |
15529 | ||
a0c87cbd JS |
15530 | do { |
15531 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
15532 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
15533 | ||
15534 | if (rc != MBX_SUCCESS) { | |
15535 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
026abb87 JS |
15536 | "2601 failed to read config " |
15537 | "region 23, rc 0x%x Status 0x%x\n", | |
15538 | rc, mb->mbxStatus); | |
a0c87cbd JS |
15539 | mb->un.varDmp.word_cnt = 0; |
15540 | } | |
15541 | /* | |
15542 | * dump mem may return a zero when finished or we got a | |
15543 | * mailbox error, either way we are done. | |
15544 | */ | |
15545 | if (mb->un.varDmp.word_cnt == 0) | |
15546 | break; | |
15547 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
15548 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
15549 | ||
15550 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
026abb87 JS |
15551 | rgn23_data + offset, |
15552 | mb->un.varDmp.word_cnt); | |
a0c87cbd JS |
15553 | offset += mb->un.varDmp.word_cnt; |
15554 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
15555 | ||
026abb87 JS |
15556 | mempool_free(pmb, phba->mbox_mem_pool); |
15557 | return offset; | |
15558 | } | |
15559 | ||
15560 | /** | |
15561 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. | |
15562 | * @phba: pointer to lpfc hba data structure. | |
15563 | * @rgn23_data: pointer to configure region 23 data. | |
15564 | * | |
15565 | * This function gets SLI4 port configure region 23 data through memory dump | |
15566 | * mailbox command. When it successfully retrieves data, the size of the data | |
15567 | * will be returned, otherwise, 0 will be returned. | |
15568 | **/ | |
15569 | static uint32_t | |
15570 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
15571 | { | |
15572 | LPFC_MBOXQ_t *mboxq = NULL; | |
15573 | struct lpfc_dmabuf *mp = NULL; | |
15574 | struct lpfc_mqe *mqe; | |
15575 | uint32_t data_length = 0; | |
15576 | int rc; | |
15577 | ||
15578 | if (!rgn23_data) | |
15579 | return 0; | |
15580 | ||
15581 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15582 | if (!mboxq) { | |
15583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15584 | "3105 failed to allocate mailbox memory\n"); | |
15585 | return 0; | |
15586 | } | |
15587 | ||
15588 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) | |
15589 | goto out; | |
15590 | mqe = &mboxq->u.mqe; | |
15591 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
15592 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
15593 | if (rc) | |
15594 | goto out; | |
15595 | data_length = mqe->un.mb_words[5]; | |
15596 | if (data_length == 0) | |
15597 | goto out; | |
15598 | if (data_length > DMP_RGN23_SIZE) { | |
15599 | data_length = 0; | |
15600 | goto out; | |
15601 | } | |
15602 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); | |
15603 | out: | |
15604 | mempool_free(mboxq, phba->mbox_mem_pool); | |
15605 | if (mp) { | |
15606 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
15607 | kfree(mp); | |
15608 | } | |
15609 | return data_length; | |
15610 | } | |
15611 | ||
15612 | /** | |
15613 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
15614 | * @phba: pointer to lpfc hba data structure. | |
15615 | * | |
15616 | * This function read region 23 and parse TLV for port status to | |
15617 | * decide if the user disaled the port. If the TLV indicates the | |
15618 | * port is disabled, the hba_flag is set accordingly. | |
15619 | **/ | |
15620 | void | |
15621 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
15622 | { | |
15623 | uint8_t *rgn23_data = NULL; | |
15624 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; | |
15625 | uint32_t offset = 0; | |
15626 | ||
15627 | /* Get adapter Region 23 data */ | |
15628 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
15629 | if (!rgn23_data) | |
15630 | goto out; | |
15631 | ||
15632 | if (phba->sli_rev < LPFC_SLI_REV4) | |
15633 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); | |
15634 | else { | |
15635 | if_type = bf_get(lpfc_sli_intf_if_type, | |
15636 | &phba->sli4_hba.sli_intf); | |
15637 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) | |
15638 | goto out; | |
15639 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); | |
15640 | } | |
a0c87cbd JS |
15641 | |
15642 | if (!data_size) | |
15643 | goto out; | |
15644 | ||
15645 | /* Check the region signature first */ | |
15646 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
15647 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15648 | "2619 Config region 23 has bad signature\n"); | |
15649 | goto out; | |
15650 | } | |
15651 | offset += 4; | |
15652 | ||
15653 | /* Check the data structure version */ | |
15654 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
15655 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15656 | "2620 Config region 23 has bad version\n"); | |
15657 | goto out; | |
15658 | } | |
15659 | offset += 4; | |
15660 | ||
15661 | /* Parse TLV entries in the region */ | |
15662 | while (offset < data_size) { | |
15663 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
15664 | break; | |
15665 | /* | |
15666 | * If the TLV is not driver specific TLV or driver id is | |
15667 | * not linux driver id, skip the record. | |
15668 | */ | |
15669 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
15670 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
15671 | (rgn23_data[offset + 3] != 0)) { | |
15672 | offset += rgn23_data[offset + 1] * 4 + 4; | |
15673 | continue; | |
15674 | } | |
15675 | ||
15676 | /* Driver found a driver specific TLV in the config region */ | |
15677 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
15678 | offset += 4; | |
15679 | tlv_offset = 0; | |
15680 | ||
15681 | /* | |
15682 | * Search for configured port state sub-TLV. | |
15683 | */ | |
15684 | while ((offset < data_size) && | |
15685 | (tlv_offset < sub_tlv_len)) { | |
15686 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
15687 | offset += 4; | |
15688 | tlv_offset += 4; | |
15689 | break; | |
15690 | } | |
15691 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
15692 | offset += rgn23_data[offset + 1] * 4 + 4; | |
15693 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
15694 | continue; | |
15695 | } | |
15696 | ||
15697 | /* This HBA contains PORT_STE configured */ | |
15698 | if (!rgn23_data[offset + 2]) | |
15699 | phba->hba_flag |= LINK_DISABLED; | |
15700 | ||
15701 | goto out; | |
15702 | } | |
15703 | } | |
026abb87 | 15704 | |
a0c87cbd | 15705 | out: |
a0c87cbd JS |
15706 | kfree(rgn23_data); |
15707 | return; | |
15708 | } | |
695a814e | 15709 | |
52d52440 JS |
15710 | /** |
15711 | * lpfc_wr_object - write an object to the firmware | |
15712 | * @phba: HBA structure that indicates port to create a queue on. | |
15713 | * @dmabuf_list: list of dmabufs to write to the port. | |
15714 | * @size: the total byte value of the objects to write to the port. | |
15715 | * @offset: the current offset to be used to start the transfer. | |
15716 | * | |
15717 | * This routine will create a wr_object mailbox command to send to the port. | |
15718 | * the mailbox command will be constructed using the dma buffers described in | |
15719 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
15720 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
15721 | * used to indicate the starting offset of the transfer and will also return | |
15722 | * the offset after the write object mailbox has completed. @size is used to | |
15723 | * determine the end of the object and whether the eof bit should be set. | |
15724 | * | |
15725 | * Return 0 is successful and offset will contain the the new offset to use | |
15726 | * for the next write. | |
15727 | * Return negative value for error cases. | |
15728 | **/ | |
15729 | int | |
15730 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
15731 | uint32_t size, uint32_t *offset) | |
15732 | { | |
15733 | struct lpfc_mbx_wr_object *wr_object; | |
15734 | LPFC_MBOXQ_t *mbox; | |
15735 | int rc = 0, i = 0; | |
15736 | uint32_t shdr_status, shdr_add_status; | |
15737 | uint32_t mbox_tmo; | |
15738 | union lpfc_sli4_cfg_shdr *shdr; | |
15739 | struct lpfc_dmabuf *dmabuf; | |
15740 | uint32_t written = 0; | |
15741 | ||
15742 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15743 | if (!mbox) | |
15744 | return -ENOMEM; | |
15745 | ||
15746 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
15747 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
15748 | sizeof(struct lpfc_mbx_wr_object) - | |
15749 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
15750 | ||
15751 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
15752 | wr_object->u.request.write_offset = *offset; | |
15753 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
15754 | wr_object->u.request.object_name[0] = | |
15755 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
15756 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
15757 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
15758 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
15759 | break; | |
15760 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
15761 | wr_object->u.request.bde[i].addrHigh = | |
15762 | putPaddrHigh(dmabuf->phys); | |
15763 | if (written + SLI4_PAGE_SIZE >= size) { | |
15764 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
15765 | (size - written); | |
15766 | written += (size - written); | |
15767 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
15768 | } else { | |
15769 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
15770 | SLI4_PAGE_SIZE; | |
15771 | written += SLI4_PAGE_SIZE; | |
15772 | } | |
15773 | i++; | |
15774 | } | |
15775 | wr_object->u.request.bde_count = i; | |
15776 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
15777 | if (!phba->sli4_hba.intr_enable) | |
15778 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
15779 | else { | |
a183a15f | 15780 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
52d52440 JS |
15781 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
15782 | } | |
15783 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
15784 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
15785 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15786 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15787 | if (rc != MBX_TIMEOUT) | |
15788 | mempool_free(mbox, phba->mbox_mem_pool); | |
15789 | if (shdr_status || shdr_add_status || rc) { | |
15790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15791 | "3025 Write Object mailbox failed with " | |
15792 | "status x%x add_status x%x, mbx status x%x\n", | |
15793 | shdr_status, shdr_add_status, rc); | |
15794 | rc = -ENXIO; | |
15795 | } else | |
15796 | *offset += wr_object->u.response.actual_write_length; | |
15797 | return rc; | |
15798 | } | |
15799 | ||
695a814e JS |
15800 | /** |
15801 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
15802 | * @vport: pointer to vport data structure. | |
15803 | * | |
15804 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
15805 | * and REG_VPI mailbox commands associated with the vport. This function | |
15806 | * is called when driver want to restart discovery of the vport due to | |
15807 | * a Clear Virtual Link event. | |
15808 | **/ | |
15809 | void | |
15810 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
15811 | { | |
15812 | struct lpfc_hba *phba = vport->phba; | |
15813 | LPFC_MBOXQ_t *mb, *nextmb; | |
15814 | struct lpfc_dmabuf *mp; | |
78730cfe | 15815 | struct lpfc_nodelist *ndlp; |
d439d286 | 15816 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 15817 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 15818 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 15819 | uint8_t restart_loop; |
695a814e | 15820 | |
d439d286 | 15821 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
15822 | spin_lock_irq(&phba->hbalock); |
15823 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
15824 | if (mb->vport != vport) | |
15825 | continue; | |
15826 | ||
15827 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
15828 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
15829 | continue; | |
15830 | ||
d439d286 JS |
15831 | list_del(&mb->list); |
15832 | list_add_tail(&mb->list, &mbox_cmd_list); | |
15833 | } | |
15834 | /* Clean up active mailbox command with the vport */ | |
15835 | mb = phba->sli.mbox_active; | |
15836 | if (mb && (mb->vport == vport)) { | |
15837 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
15838 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
15839 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
15840 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
15841 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
15842 | /* Put reference count for delayed processing */ | |
15843 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
15844 | /* Unregister the RPI when mailbox complete */ | |
15845 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
15846 | } | |
15847 | } | |
63e801ce JS |
15848 | /* Cleanup any mailbox completions which are not yet processed */ |
15849 | do { | |
15850 | restart_loop = 0; | |
15851 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
15852 | /* | |
15853 | * If this mailox is already processed or it is | |
15854 | * for another vport ignore it. | |
15855 | */ | |
15856 | if ((mb->vport != vport) || | |
15857 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
15858 | continue; | |
15859 | ||
15860 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
15861 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
15862 | continue; | |
15863 | ||
15864 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
15865 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
15866 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
15867 | /* Unregister the RPI when mailbox complete */ | |
15868 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
15869 | restart_loop = 1; | |
15870 | spin_unlock_irq(&phba->hbalock); | |
15871 | spin_lock(shost->host_lock); | |
15872 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15873 | spin_unlock(shost->host_lock); | |
15874 | spin_lock_irq(&phba->hbalock); | |
15875 | break; | |
15876 | } | |
15877 | } | |
15878 | } while (restart_loop); | |
15879 | ||
d439d286 JS |
15880 | spin_unlock_irq(&phba->hbalock); |
15881 | ||
15882 | /* Release the cleaned-up mailbox commands */ | |
15883 | while (!list_empty(&mbox_cmd_list)) { | |
15884 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
15885 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
15886 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
15887 | if (mp) { | |
15888 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
15889 | kfree(mp); | |
15890 | } | |
78730cfe | 15891 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 15892 | mb->context2 = NULL; |
78730cfe | 15893 | if (ndlp) { |
ec21b3b0 | 15894 | spin_lock(shost->host_lock); |
589a52d6 | 15895 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 15896 | spin_unlock(shost->host_lock); |
78730cfe | 15897 | lpfc_nlp_put(ndlp); |
78730cfe | 15898 | } |
695a814e | 15899 | } |
695a814e JS |
15900 | mempool_free(mb, phba->mbox_mem_pool); |
15901 | } | |
d439d286 JS |
15902 | |
15903 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
15904 | if (act_mbx_ndlp) { | |
15905 | spin_lock(shost->host_lock); | |
15906 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15907 | spin_unlock(shost->host_lock); | |
15908 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 15909 | } |
695a814e JS |
15910 | } |
15911 | ||
2a9bf3d0 JS |
15912 | /** |
15913 | * lpfc_drain_txq - Drain the txq | |
15914 | * @phba: Pointer to HBA context object. | |
15915 | * | |
15916 | * This function attempt to submit IOCBs on the txq | |
15917 | * to the adapter. For SLI4 adapters, the txq contains | |
15918 | * ELS IOCBs that have been deferred because the there | |
15919 | * are no SGLs. This congestion can occur with large | |
15920 | * vport counts during node discovery. | |
15921 | **/ | |
15922 | ||
15923 | uint32_t | |
15924 | lpfc_drain_txq(struct lpfc_hba *phba) | |
15925 | { | |
15926 | LIST_HEAD(completions); | |
15927 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
15928 | struct lpfc_iocbq *piocbq = 0; | |
15929 | unsigned long iflags = 0; | |
15930 | char *fail_msg = NULL; | |
15931 | struct lpfc_sglq *sglq; | |
15932 | union lpfc_wqe wqe; | |
15933 | ||
15934 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15935 | if (pring->txq_cnt > pring->txq_max) | |
15936 | pring->txq_max = pring->txq_cnt; | |
15937 | ||
15938 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15939 | ||
15940 | while (pring->txq_cnt) { | |
15941 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15942 | ||
19ca7609 | 15943 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
a629852a JS |
15944 | if (!piocbq) { |
15945 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15946 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15947 | "2823 txq empty and txq_cnt is %d\n ", | |
15948 | pring->txq_cnt); | |
15949 | break; | |
15950 | } | |
19ca7609 | 15951 | sglq = __lpfc_sli_get_sglq(phba, piocbq); |
2a9bf3d0 | 15952 | if (!sglq) { |
19ca7609 | 15953 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
15954 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
15955 | break; | |
2a9bf3d0 JS |
15956 | } |
15957 | ||
15958 | /* The xri and iocb resources secured, | |
15959 | * attempt to issue request | |
15960 | */ | |
6d368e53 | 15961 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
15962 | piocbq->sli4_xritag = sglq->sli4_xritag; |
15963 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
15964 | fail_msg = "to convert bpl to sgl"; | |
15965 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
15966 | fail_msg = "to convert iocb to wqe"; | |
15967 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
15968 | fail_msg = " - Wq is full"; | |
15969 | else | |
15970 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
15971 | ||
15972 | if (fail_msg) { | |
15973 | /* Failed means we can't issue and need to cancel */ | |
15974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15975 | "2822 IOCB failed %s iotag 0x%x " | |
15976 | "xri 0x%x\n", | |
15977 | fail_msg, | |
15978 | piocbq->iotag, piocbq->sli4_xritag); | |
15979 | list_add_tail(&piocbq->list, &completions); | |
15980 | } | |
15981 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15982 | } | |
15983 | ||
2a9bf3d0 JS |
15984 | /* Cancel all the IOCBs that cannot be issued */ |
15985 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
15986 | IOERR_SLI_ABORTED); | |
15987 | ||
15988 | return pring->txq_cnt; | |
15989 | } |