]>
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. * |
792581de | 4 | * Copyright (C) 2004-2011 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 *); | |
70 | ||
4f774513 JS |
71 | static IOCB_t * |
72 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
73 | { | |
74 | return &iocbq->iocb; | |
75 | } | |
76 | ||
77 | /** | |
78 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
79 | * @q: The Work Queue to operate on. | |
80 | * @wqe: The work Queue Entry to put on the Work queue. | |
81 | * | |
82 | * This routine will copy the contents of @wqe to the next available entry on | |
83 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
84 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
85 | * successful. If no entries are available on @q then this function will return | |
86 | * -ENOMEM. | |
87 | * The caller is expected to hold the hbalock when calling this routine. | |
88 | **/ | |
89 | static uint32_t | |
90 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
91 | { | |
92 | union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe; | |
93 | struct lpfc_register doorbell; | |
94 | uint32_t host_index; | |
95 | ||
96 | /* If the host has not yet processed the next entry then we are done */ | |
97 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
98 | return -ENOMEM; | |
99 | /* set consumption flag every once in a while */ | |
100 | if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL)) | |
f0d9bccc | 101 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
fedd3b7b JS |
102 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
103 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
4f774513 JS |
104 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
105 | ||
106 | /* Update the host index before invoking device */ | |
107 | host_index = q->host_index; | |
108 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
109 | ||
110 | /* Ring Doorbell */ | |
111 | doorbell.word0 = 0; | |
112 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); | |
113 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); | |
114 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); | |
115 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); | |
116 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ | |
117 | ||
118 | return 0; | |
119 | } | |
120 | ||
121 | /** | |
122 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
123 | * @q: The Work Queue to operate on. | |
124 | * @index: The index to advance the hba index to. | |
125 | * | |
126 | * This routine will update the HBA index of a queue to reflect consumption of | |
127 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
128 | * an entry the host calls this function to update the queue's internal | |
129 | * pointers. This routine returns the number of entries that were consumed by | |
130 | * the HBA. | |
131 | **/ | |
132 | static uint32_t | |
133 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
134 | { | |
135 | uint32_t released = 0; | |
136 | ||
137 | if (q->hba_index == index) | |
138 | return 0; | |
139 | do { | |
140 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
141 | released++; | |
142 | } while (q->hba_index != index); | |
143 | return released; | |
144 | } | |
145 | ||
146 | /** | |
147 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
148 | * @q: The Mailbox Queue to operate on. | |
149 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
150 | * | |
151 | * This routine will copy the contents of @mqe to the next available entry on | |
152 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
153 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
154 | * successful. If no entries are available on @q then this function will return | |
155 | * -ENOMEM. | |
156 | * The caller is expected to hold the hbalock when calling this routine. | |
157 | **/ | |
158 | static uint32_t | |
159 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
160 | { | |
161 | struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe; | |
162 | struct lpfc_register doorbell; | |
163 | uint32_t host_index; | |
164 | ||
165 | /* If the host has not yet processed the next entry then we are done */ | |
166 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
167 | return -ENOMEM; | |
168 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | |
169 | /* Save off the mailbox pointer for completion */ | |
170 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
171 | ||
172 | /* Update the host index before invoking device */ | |
173 | host_index = q->host_index; | |
174 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
175 | ||
176 | /* Ring Doorbell */ | |
177 | doorbell.word0 = 0; | |
178 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
179 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
180 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
181 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ | |
182 | return 0; | |
183 | } | |
184 | ||
185 | /** | |
186 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
187 | * @q: The Mailbox Queue to operate on. | |
188 | * | |
189 | * This routine will update the HBA index of a queue to reflect consumption of | |
190 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
191 | * an entry the host calls this function to update the queue's internal | |
192 | * pointers. This routine returns the number of entries that were consumed by | |
193 | * the HBA. | |
194 | **/ | |
195 | static uint32_t | |
196 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
197 | { | |
198 | /* Clear the mailbox pointer for completion */ | |
199 | q->phba->mbox = NULL; | |
200 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
201 | return 1; | |
202 | } | |
203 | ||
204 | /** | |
205 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
206 | * @q: The Event Queue to get the first valid EQE from | |
207 | * | |
208 | * This routine will get the first valid Event Queue Entry from @q, update | |
209 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
210 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
211 | * processed, but not popped back to the HBA then this routine will return NULL. | |
212 | **/ | |
213 | static struct lpfc_eqe * | |
214 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
215 | { | |
216 | struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe; | |
217 | ||
218 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 219 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
220 | return NULL; |
221 | /* If the host has not yet processed the next entry then we are done */ | |
222 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | |
223 | return NULL; | |
224 | ||
225 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
226 | return eqe; | |
227 | } | |
228 | ||
229 | /** | |
230 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
231 | * @q: The Event Queue that the host has completed processing for. | |
232 | * @arm: Indicates whether the host wants to arms this CQ. | |
233 | * | |
234 | * This routine will mark all Event Queue Entries on @q, from the last | |
235 | * known completed entry to the last entry that was processed, as completed | |
236 | * by clearing the valid bit for each completion queue entry. Then it will | |
237 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
238 | * The internal host index in the @q will be updated by this routine to indicate | |
239 | * that the host has finished processing the entries. The @arm parameter | |
240 | * indicates that the queue should be rearmed when ringing the doorbell. | |
241 | * | |
242 | * This function will return the number of EQEs that were popped. | |
243 | **/ | |
244 | uint32_t | |
245 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
246 | { | |
247 | uint32_t released = 0; | |
248 | struct lpfc_eqe *temp_eqe; | |
249 | struct lpfc_register doorbell; | |
250 | ||
251 | /* while there are valid entries */ | |
252 | while (q->hba_index != q->host_index) { | |
253 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 254 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
255 | released++; |
256 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
257 | } | |
258 | if (unlikely(released == 0 && !arm)) | |
259 | return 0; | |
260 | ||
261 | /* ring doorbell for number popped */ | |
262 | doorbell.word0 = 0; | |
263 | if (arm) { | |
264 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
265 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
266 | } | |
267 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
268 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
269 | bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id); | |
270 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
a747c9ce JS |
271 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
272 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
273 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
274 | return released; |
275 | } | |
276 | ||
277 | /** | |
278 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
279 | * @q: The Completion Queue to get the first valid CQE from | |
280 | * | |
281 | * This routine will get the first valid Completion Queue Entry from @q, update | |
282 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
283 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
284 | * processed, but not popped back to the HBA then this routine will return NULL. | |
285 | **/ | |
286 | static struct lpfc_cqe * | |
287 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
288 | { | |
289 | struct lpfc_cqe *cqe; | |
290 | ||
291 | /* If the next CQE is not valid then we are done */ | |
cb5172ea | 292 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
293 | return NULL; |
294 | /* If the host has not yet processed the next entry then we are done */ | |
295 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | |
296 | return NULL; | |
297 | ||
298 | cqe = q->qe[q->hba_index].cqe; | |
299 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
300 | return cqe; | |
301 | } | |
302 | ||
303 | /** | |
304 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
305 | * @q: The Completion Queue that the host has completed processing for. | |
306 | * @arm: Indicates whether the host wants to arms this CQ. | |
307 | * | |
308 | * This routine will mark all Completion queue entries on @q, from the last | |
309 | * known completed entry to the last entry that was processed, as completed | |
310 | * by clearing the valid bit for each completion queue entry. Then it will | |
311 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
312 | * The internal host index in the @q will be updated by this routine to indicate | |
313 | * that the host has finished processing the entries. The @arm parameter | |
314 | * indicates that the queue should be rearmed when ringing the doorbell. | |
315 | * | |
316 | * This function will return the number of CQEs that were released. | |
317 | **/ | |
318 | uint32_t | |
319 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
320 | { | |
321 | uint32_t released = 0; | |
322 | struct lpfc_cqe *temp_qe; | |
323 | struct lpfc_register doorbell; | |
324 | ||
325 | /* while there are valid entries */ | |
326 | while (q->hba_index != q->host_index) { | |
327 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 328 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
329 | released++; |
330 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
331 | } | |
332 | if (unlikely(released == 0 && !arm)) | |
333 | return 0; | |
334 | ||
335 | /* ring doorbell for number popped */ | |
336 | doorbell.word0 = 0; | |
337 | if (arm) | |
338 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
339 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
340 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
341 | bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id); | |
342 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
343 | return released; | |
344 | } | |
345 | ||
346 | /** | |
347 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
348 | * @q: The Header Receive Queue to operate on. | |
349 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
350 | * | |
351 | * This routine will copy the contents of @wqe to the next available entry on | |
352 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
353 | * HBA to start processing the Receive Queue Entry. This function returns the | |
354 | * index that the rqe was copied to if successful. If no entries are available | |
355 | * on @q then this function will return -ENOMEM. | |
356 | * The caller is expected to hold the hbalock when calling this routine. | |
357 | **/ | |
358 | static int | |
359 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
360 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
361 | { | |
362 | struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe; | |
363 | struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe; | |
364 | struct lpfc_register doorbell; | |
365 | int put_index = hq->host_index; | |
366 | ||
367 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) | |
368 | return -EINVAL; | |
369 | if (hq->host_index != dq->host_index) | |
370 | return -EINVAL; | |
371 | /* If the host has not yet processed the next entry then we are done */ | |
372 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
373 | return -EBUSY; | |
374 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
375 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
376 | ||
377 | /* Update the host index to point to the next slot */ | |
378 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
379 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
380 | ||
381 | /* Ring The Header Receive Queue Doorbell */ | |
382 | if (!(hq->host_index % LPFC_RQ_POST_BATCH)) { | |
383 | doorbell.word0 = 0; | |
384 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | |
385 | LPFC_RQ_POST_BATCH); | |
386 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); | |
387 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); | |
388 | } | |
389 | return put_index; | |
390 | } | |
391 | ||
392 | /** | |
393 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
394 | * @q: The Header Receive Queue to operate on. | |
395 | * | |
396 | * This routine will update the HBA index of a queue to reflect consumption of | |
397 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
398 | * consumed an entry the host calls this function to update the queue's | |
399 | * internal pointers. This routine returns the number of entries that were | |
400 | * consumed by the HBA. | |
401 | **/ | |
402 | static uint32_t | |
403 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
404 | { | |
405 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) | |
406 | return 0; | |
407 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
408 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
409 | return 1; | |
410 | } | |
411 | ||
e59058c4 | 412 | /** |
3621a710 | 413 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
414 | * @phba: Pointer to HBA context object. |
415 | * @pring: Pointer to driver SLI ring object. | |
416 | * | |
417 | * This function returns pointer to next command iocb entry | |
418 | * in the command ring. The caller must hold hbalock to prevent | |
419 | * other threads consume the next command iocb. | |
420 | * SLI-2/SLI-3 provide different sized iocbs. | |
421 | **/ | |
ed957684 JS |
422 | static inline IOCB_t * |
423 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
424 | { | |
425 | return (IOCB_t *) (((char *) pring->cmdringaddr) + | |
426 | pring->cmdidx * phba->iocb_cmd_size); | |
427 | } | |
428 | ||
e59058c4 | 429 | /** |
3621a710 | 430 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
431 | * @phba: Pointer to HBA context object. |
432 | * @pring: Pointer to driver SLI ring object. | |
433 | * | |
434 | * This function returns pointer to next response iocb entry | |
435 | * in the response ring. The caller must hold hbalock to make sure | |
436 | * that no other thread consume the next response iocb. | |
437 | * SLI-2/SLI-3 provide different sized iocbs. | |
438 | **/ | |
ed957684 JS |
439 | static inline IOCB_t * |
440 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
441 | { | |
442 | return (IOCB_t *) (((char *) pring->rspringaddr) + | |
443 | pring->rspidx * phba->iocb_rsp_size); | |
444 | } | |
445 | ||
e59058c4 | 446 | /** |
3621a710 | 447 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
448 | * @phba: Pointer to HBA context object. |
449 | * | |
450 | * This function is called with hbalock held. This function | |
451 | * allocates a new driver iocb object from the iocb pool. If the | |
452 | * allocation is successful, it returns pointer to the newly | |
453 | * allocated iocb object else it returns NULL. | |
454 | **/ | |
2e0fef85 JS |
455 | static struct lpfc_iocbq * |
456 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
0bd4ca25 JSEC |
457 | { |
458 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
459 | struct lpfc_iocbq * iocbq = NULL; | |
460 | ||
461 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
2a9bf3d0 JS |
462 | if (iocbq) |
463 | phba->iocb_cnt++; | |
464 | if (phba->iocb_cnt > phba->iocb_max) | |
465 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
466 | return iocbq; |
467 | } | |
468 | ||
da0436e9 JS |
469 | /** |
470 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
471 | * @phba: Pointer to HBA context object. | |
472 | * @xritag: XRI value. | |
473 | * | |
474 | * This function clears the sglq pointer from the array of acive | |
475 | * sglq's. The xritag that is passed in is used to index into the | |
476 | * array. Before the xritag can be used it needs to be adjusted | |
477 | * by subtracting the xribase. | |
478 | * | |
479 | * Returns sglq ponter = success, NULL = Failure. | |
480 | **/ | |
481 | static struct lpfc_sglq * | |
482 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
483 | { | |
da0436e9 | 484 | struct lpfc_sglq *sglq; |
6d368e53 JS |
485 | |
486 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
487 | phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL; | |
da0436e9 JS |
488 | return sglq; |
489 | } | |
490 | ||
491 | /** | |
492 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
493 | * @phba: Pointer to HBA context object. | |
494 | * @xritag: XRI value. | |
495 | * | |
496 | * This function returns the sglq pointer from the array of acive | |
497 | * sglq's. The xritag that is passed in is used to index into the | |
498 | * array. Before the xritag can be used it needs to be adjusted | |
499 | * by subtracting the xribase. | |
500 | * | |
501 | * Returns sglq ponter = success, NULL = Failure. | |
502 | **/ | |
0f65ff68 | 503 | struct lpfc_sglq * |
da0436e9 JS |
504 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
505 | { | |
da0436e9 | 506 | struct lpfc_sglq *sglq; |
6d368e53 JS |
507 | |
508 | sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag]; | |
da0436e9 JS |
509 | return sglq; |
510 | } | |
511 | ||
19ca7609 JS |
512 | /** |
513 | * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap. | |
514 | * @phba: Pointer to HBA context object. | |
515 | * @ndlp: nodelist pointer for this target. | |
516 | * @xritag: xri used in this exchange. | |
517 | * @rxid: Remote Exchange ID. | |
518 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
519 | * | |
520 | * This function is called with hbalock held. | |
521 | * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an | |
522 | * rrq struct and adds it to the active_rrq_list. | |
523 | * | |
524 | * returns 0 for rrq slot for this xri | |
525 | * < 0 Were not able to get rrq mem or invalid parameter. | |
526 | **/ | |
527 | static int | |
528 | __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
529 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) | |
530 | { | |
19ca7609 JS |
531 | struct lpfc_node_rrq *rrq; |
532 | int empty; | |
1151e3ec JS |
533 | uint32_t did = 0; |
534 | ||
535 | ||
536 | if (!ndlp) | |
537 | return -EINVAL; | |
538 | ||
539 | if (!phba->cfg_enable_rrq) | |
540 | return -EINVAL; | |
541 | ||
542 | if (phba->pport->load_flag & FC_UNLOADING) { | |
543 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
544 | goto out; | |
545 | } | |
546 | did = ndlp->nlp_DID; | |
19ca7609 JS |
547 | |
548 | /* | |
549 | * set the active bit even if there is no mem available. | |
550 | */ | |
1151e3ec JS |
551 | if (NLP_CHK_FREE_REQ(ndlp)) |
552 | goto out; | |
553 | ||
554 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
555 | goto out; | |
556 | ||
6d368e53 | 557 | if (test_and_set_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
1151e3ec JS |
558 | goto out; |
559 | ||
19ca7609 JS |
560 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
561 | if (rrq) { | |
562 | rrq->send_rrq = send_rrq; | |
6d368e53 | 563 | rrq->xritag = phba->sli4_hba.xri_ids[xritag]; |
19ca7609 JS |
564 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); |
565 | rrq->ndlp = ndlp; | |
566 | rrq->nlp_DID = ndlp->nlp_DID; | |
567 | rrq->vport = ndlp->vport; | |
568 | rrq->rxid = rxid; | |
569 | empty = list_empty(&phba->active_rrq_list); | |
1151e3ec | 570 | rrq->send_rrq = send_rrq; |
19ca7609 JS |
571 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
572 | if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) { | |
573 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
574 | if (empty) | |
575 | lpfc_worker_wake_up(phba); | |
576 | } | |
577 | return 0; | |
578 | } | |
1151e3ec JS |
579 | out: |
580 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
581 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
582 | " DID:0x%x Send:%d\n", | |
583 | xritag, rxid, did, send_rrq); | |
584 | return -EINVAL; | |
19ca7609 JS |
585 | } |
586 | ||
587 | /** | |
1151e3ec | 588 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
589 | * @phba: Pointer to HBA context object. |
590 | * @xritag: xri used in this exchange. | |
591 | * @rrq: The RRQ to be cleared. | |
592 | * | |
19ca7609 | 593 | **/ |
1151e3ec JS |
594 | void |
595 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
596 | uint16_t xritag, | |
597 | struct lpfc_node_rrq *rrq) | |
19ca7609 | 598 | { |
1151e3ec | 599 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 600 | |
1151e3ec JS |
601 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
602 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
603 | |
604 | /* The target DID could have been swapped (cable swap) | |
605 | * we should use the ndlp from the findnode if it is | |
606 | * available. | |
607 | */ | |
1151e3ec | 608 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
609 | ndlp = rrq->ndlp; |
610 | ||
1151e3ec JS |
611 | if (!ndlp) |
612 | goto out; | |
613 | ||
6d368e53 | 614 | if (test_and_clear_bit(xritag, ndlp->active_rrqs.xri_bitmap)) { |
19ca7609 JS |
615 | rrq->send_rrq = 0; |
616 | rrq->xritag = 0; | |
617 | rrq->rrq_stop_time = 0; | |
618 | } | |
1151e3ec | 619 | out: |
19ca7609 JS |
620 | mempool_free(rrq, phba->rrq_pool); |
621 | } | |
622 | ||
623 | /** | |
624 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
625 | * @phba: Pointer to HBA context object. | |
626 | * | |
627 | * This function is called with hbalock held. This function | |
628 | * Checks if stop_time (ratov from setting rrq active) has | |
629 | * been reached, if it has and the send_rrq flag is set then | |
630 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
631 | * then it will just call the routine to clear the rrq and | |
632 | * free the rrq resource. | |
633 | * The timer is set to the next rrq that is going to expire before | |
634 | * leaving the routine. | |
635 | * | |
636 | **/ | |
637 | void | |
638 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
639 | { | |
640 | struct lpfc_node_rrq *rrq; | |
641 | struct lpfc_node_rrq *nextrrq; | |
642 | unsigned long next_time; | |
643 | unsigned long iflags; | |
1151e3ec | 644 | LIST_HEAD(send_rrq); |
19ca7609 JS |
645 | |
646 | spin_lock_irqsave(&phba->hbalock, iflags); | |
647 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
648 | next_time = jiffies + HZ * (phba->fc_ratov + 1); | |
649 | list_for_each_entry_safe(rrq, nextrrq, | |
1151e3ec JS |
650 | &phba->active_rrq_list, list) { |
651 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
652 | list_move(&rrq->list, &send_rrq); | |
653 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
654 | next_time = rrq->rrq_stop_time; |
655 | } | |
656 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
657 | if (!list_empty(&phba->active_rrq_list)) | |
658 | mod_timer(&phba->rrq_tmr, next_time); | |
1151e3ec JS |
659 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
660 | list_del(&rrq->list); | |
661 | if (!rrq->send_rrq) | |
662 | /* this call will free the rrq */ | |
663 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
664 | else if (lpfc_send_rrq(phba, rrq)) { | |
665 | /* if we send the rrq then the completion handler | |
666 | * will clear the bit in the xribitmap. | |
667 | */ | |
668 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
669 | rrq); | |
670 | } | |
671 | } | |
19ca7609 JS |
672 | } |
673 | ||
674 | /** | |
675 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
676 | * @vport: Pointer to vport context object. | |
677 | * @xri: The xri used in the exchange. | |
678 | * @did: The targets DID for this exchange. | |
679 | * | |
680 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
681 | * rrq = rrq for this xri and target. | |
682 | **/ | |
683 | struct lpfc_node_rrq * | |
684 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
685 | { | |
686 | struct lpfc_hba *phba = vport->phba; | |
687 | struct lpfc_node_rrq *rrq; | |
688 | struct lpfc_node_rrq *nextrrq; | |
689 | unsigned long iflags; | |
690 | ||
691 | if (phba->sli_rev != LPFC_SLI_REV4) | |
692 | return NULL; | |
693 | spin_lock_irqsave(&phba->hbalock, iflags); | |
694 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
695 | if (rrq->vport == vport && rrq->xritag == xri && | |
696 | rrq->nlp_DID == did){ | |
697 | list_del(&rrq->list); | |
698 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
699 | return rrq; | |
700 | } | |
701 | } | |
702 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
703 | return NULL; | |
704 | } | |
705 | ||
706 | /** | |
707 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
708 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
709 | * @ndlp: Pointer to the lpfc_node_list structure. |
710 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
711 | * phba->active_rrq_list and clear the rrq. | |
712 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
713 | **/ |
714 | void | |
1151e3ec | 715 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
716 | |
717 | { | |
718 | struct lpfc_hba *phba = vport->phba; | |
719 | struct lpfc_node_rrq *rrq; | |
720 | struct lpfc_node_rrq *nextrrq; | |
721 | unsigned long iflags; | |
1151e3ec | 722 | LIST_HEAD(rrq_list); |
19ca7609 JS |
723 | |
724 | if (phba->sli_rev != LPFC_SLI_REV4) | |
725 | return; | |
1151e3ec JS |
726 | if (!ndlp) { |
727 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
728 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 729 | } |
1151e3ec JS |
730 | spin_lock_irqsave(&phba->hbalock, iflags); |
731 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
732 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
733 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 734 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
735 | |
736 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
737 | list_del(&rrq->list); | |
738 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
739 | } | |
19ca7609 JS |
740 | } |
741 | ||
742 | /** | |
743 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. | |
744 | * @phba: Pointer to HBA context object. | |
745 | * | |
746 | * Remove all rrqs from the phba->active_rrq_list and free them by | |
747 | * calling __lpfc_clr_active_rrq | |
748 | * | |
749 | **/ | |
750 | void | |
751 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) | |
752 | { | |
753 | struct lpfc_node_rrq *rrq; | |
754 | struct lpfc_node_rrq *nextrrq; | |
755 | unsigned long next_time; | |
756 | unsigned long iflags; | |
1151e3ec | 757 | LIST_HEAD(rrq_list); |
19ca7609 JS |
758 | |
759 | if (phba->sli_rev != LPFC_SLI_REV4) | |
760 | return; | |
761 | spin_lock_irqsave(&phba->hbalock, iflags); | |
762 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
763 | next_time = jiffies + HZ * (phba->fc_ratov * 2); | |
1151e3ec JS |
764 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
765 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
766 | ||
767 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
19ca7609 | 768 | list_del(&rrq->list); |
1151e3ec | 769 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
19ca7609 | 770 | } |
19ca7609 JS |
771 | if (!list_empty(&phba->active_rrq_list)) |
772 | mod_timer(&phba->rrq_tmr, next_time); | |
773 | } | |
774 | ||
775 | ||
776 | /** | |
1151e3ec | 777 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
778 | * @phba: Pointer to HBA context object. |
779 | * @ndlp: Targets nodelist pointer for this exchange. | |
780 | * @xritag the xri in the bitmap to test. | |
781 | * | |
782 | * This function is called with hbalock held. This function | |
783 | * returns 0 = rrq not active for this xri | |
784 | * 1 = rrq is valid for this xri. | |
785 | **/ | |
1151e3ec JS |
786 | int |
787 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
788 | uint16_t xritag) |
789 | { | |
19ca7609 JS |
790 | if (!ndlp) |
791 | return 0; | |
6d368e53 | 792 | if (test_bit(xritag, ndlp->active_rrqs.xri_bitmap)) |
19ca7609 JS |
793 | return 1; |
794 | else | |
795 | return 0; | |
796 | } | |
797 | ||
798 | /** | |
799 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
800 | * @phba: Pointer to HBA context object. | |
801 | * @ndlp: nodelist pointer for this target. | |
802 | * @xritag: xri used in this exchange. | |
803 | * @rxid: Remote Exchange ID. | |
804 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
805 | * | |
806 | * This function takes the hbalock. | |
807 | * The active bit is always set in the active rrq xri_bitmap even | |
808 | * if there is no slot avaiable for the other rrq information. | |
809 | * | |
810 | * returns 0 rrq actived for this xri | |
811 | * < 0 No memory or invalid ndlp. | |
812 | **/ | |
813 | int | |
814 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
815 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) | |
816 | { | |
817 | int ret; | |
818 | unsigned long iflags; | |
819 | ||
820 | spin_lock_irqsave(&phba->hbalock, iflags); | |
821 | ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq); | |
822 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
823 | return ret; | |
824 | } | |
825 | ||
da0436e9 JS |
826 | /** |
827 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
828 | * @phba: Pointer to HBA context object. | |
19ca7609 | 829 | * @piocb: Pointer to the iocbq. |
da0436e9 JS |
830 | * |
831 | * This function is called with hbalock held. This function | |
6d368e53 | 832 | * gets a new driver sglq object from the sglq list. If the |
da0436e9 JS |
833 | * list is not empty then it is successful, it returns pointer to the newly |
834 | * allocated sglq object else it returns NULL. | |
835 | **/ | |
836 | static struct lpfc_sglq * | |
19ca7609 | 837 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
838 | { |
839 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
840 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 841 | struct lpfc_sglq *start_sglq = NULL; |
19ca7609 JS |
842 | struct lpfc_scsi_buf *lpfc_cmd; |
843 | struct lpfc_nodelist *ndlp; | |
844 | int found = 0; | |
845 | ||
846 | if (piocbq->iocb_flag & LPFC_IO_FCP) { | |
847 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
848 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 JS |
849 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
850 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
19ca7609 | 851 | ndlp = piocbq->context_un.ndlp; |
19ca7609 JS |
852 | else |
853 | ndlp = piocbq->context1; | |
854 | ||
da0436e9 | 855 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
856 | start_sglq = sglq; |
857 | while (!found) { | |
858 | if (!sglq) | |
859 | return NULL; | |
1151e3ec | 860 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { |
19ca7609 JS |
861 | /* This xri has an rrq outstanding for this DID. |
862 | * put it back in the list and get another xri. | |
863 | */ | |
864 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
865 | sglq = NULL; | |
866 | list_remove_head(lpfc_sgl_list, sglq, | |
867 | struct lpfc_sglq, list); | |
868 | if (sglq == start_sglq) { | |
869 | sglq = NULL; | |
870 | break; | |
871 | } else | |
872 | continue; | |
873 | } | |
874 | sglq->ndlp = ndlp; | |
875 | found = 1; | |
6d368e53 | 876 | phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq; |
19ca7609 JS |
877 | sglq->state = SGL_ALLOCATED; |
878 | } | |
da0436e9 JS |
879 | return sglq; |
880 | } | |
881 | ||
e59058c4 | 882 | /** |
3621a710 | 883 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
884 | * @phba: Pointer to HBA context object. |
885 | * | |
886 | * This function is called with no lock held. This function | |
887 | * allocates a new driver iocb object from the iocb pool. If the | |
888 | * allocation is successful, it returns pointer to the newly | |
889 | * allocated iocb object else it returns NULL. | |
890 | **/ | |
2e0fef85 JS |
891 | struct lpfc_iocbq * |
892 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
893 | { | |
894 | struct lpfc_iocbq * iocbq = NULL; | |
895 | unsigned long iflags; | |
896 | ||
897 | spin_lock_irqsave(&phba->hbalock, iflags); | |
898 | iocbq = __lpfc_sli_get_iocbq(phba); | |
899 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
900 | return iocbq; | |
901 | } | |
902 | ||
4f774513 JS |
903 | /** |
904 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
905 | * @phba: Pointer to HBA context object. | |
906 | * @iocbq: Pointer to driver iocb object. | |
907 | * | |
908 | * This function is called with hbalock held to release driver | |
909 | * iocb object to the iocb pool. The iotag in the iocb object | |
910 | * does not change for each use of the iocb object. This function | |
911 | * clears all other fields of the iocb object when it is freed. | |
912 | * The sqlq structure that holds the xritag and phys and virtual | |
913 | * mappings for the scatter gather list is retrieved from the | |
914 | * active array of sglq. The get of the sglq pointer also clears | |
915 | * the entry in the array. If the status of the IO indiactes that | |
916 | * this IO was aborted then the sglq entry it put on the | |
917 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
918 | * IO has good status or fails for any other reason then the sglq | |
919 | * entry is added to the free list (lpfc_sgl_list). | |
920 | **/ | |
921 | static void | |
922 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
923 | { | |
924 | struct lpfc_sglq *sglq; | |
925 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
926 | unsigned long iflag = 0; |
927 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
928 | |
929 | if (iocbq->sli4_xritag == NO_XRI) | |
930 | sglq = NULL; | |
931 | else | |
6d368e53 JS |
932 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag); |
933 | ||
4f774513 | 934 | if (sglq) { |
0f65ff68 JS |
935 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
936 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
937 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
938 | iflag); | |
939 | list_add(&sglq->list, | |
940 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
941 | spin_unlock_irqrestore( | |
942 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
943 | } else { |
944 | sglq->state = SGL_FREED; | |
19ca7609 | 945 | sglq->ndlp = NULL; |
fedd3b7b JS |
946 | list_add_tail(&sglq->list, |
947 | &phba->sli4_hba.lpfc_sgl_list); | |
2a9bf3d0 JS |
948 | |
949 | /* Check if TXQ queue needs to be serviced */ | |
589a52d6 | 950 | if (pring->txq_cnt) |
2a9bf3d0 | 951 | lpfc_worker_wake_up(phba); |
0f65ff68 | 952 | } |
4f774513 JS |
953 | } |
954 | ||
955 | ||
956 | /* | |
957 | * Clean all volatile data fields, preserve iotag and node struct. | |
958 | */ | |
959 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
6d368e53 | 960 | iocbq->sli4_lxritag = NO_XRI; |
4f774513 JS |
961 | iocbq->sli4_xritag = NO_XRI; |
962 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
963 | } | |
964 | ||
2a9bf3d0 | 965 | |
e59058c4 | 966 | /** |
3772a991 | 967 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
968 | * @phba: Pointer to HBA context object. |
969 | * @iocbq: Pointer to driver iocb object. | |
970 | * | |
971 | * This function is called with hbalock held to release driver | |
972 | * iocb object to the iocb pool. The iotag in the iocb object | |
973 | * does not change for each use of the iocb object. This function | |
974 | * clears all other fields of the iocb object when it is freed. | |
975 | **/ | |
a6ababd2 | 976 | static void |
3772a991 | 977 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 978 | { |
2e0fef85 | 979 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
980 | |
981 | /* | |
982 | * Clean all volatile data fields, preserve iotag and node struct. | |
983 | */ | |
984 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 985 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
986 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
987 | } | |
988 | ||
3772a991 JS |
989 | /** |
990 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
991 | * @phba: Pointer to HBA context object. | |
992 | * @iocbq: Pointer to driver iocb object. | |
993 | * | |
994 | * This function is called with hbalock held to release driver | |
995 | * iocb object to the iocb pool. The iotag in the iocb object | |
996 | * does not change for each use of the iocb object. This function | |
997 | * clears all other fields of the iocb object when it is freed. | |
998 | **/ | |
999 | static void | |
1000 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1001 | { | |
1002 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1003 | phba->iocb_cnt--; |
3772a991 JS |
1004 | } |
1005 | ||
e59058c4 | 1006 | /** |
3621a710 | 1007 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1008 | * @phba: Pointer to HBA context object. |
1009 | * @iocbq: Pointer to driver iocb object. | |
1010 | * | |
1011 | * This function is called with no lock held to release the iocb to | |
1012 | * iocb pool. | |
1013 | **/ | |
2e0fef85 JS |
1014 | void |
1015 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1016 | { | |
1017 | unsigned long iflags; | |
1018 | ||
1019 | /* | |
1020 | * Clean all volatile data fields, preserve iotag and node struct. | |
1021 | */ | |
1022 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1023 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1024 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1025 | } | |
1026 | ||
a257bf90 JS |
1027 | /** |
1028 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1029 | * @phba: Pointer to HBA context object. | |
1030 | * @iocblist: List of IOCBs. | |
1031 | * @ulpstatus: ULP status in IOCB command field. | |
1032 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1033 | * | |
1034 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1035 | * on the list by invoking the complete callback function associated with the | |
1036 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1037 | * fields. | |
1038 | **/ | |
1039 | void | |
1040 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1041 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1042 | { | |
1043 | struct lpfc_iocbq *piocb; | |
1044 | ||
1045 | while (!list_empty(iocblist)) { | |
1046 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
1047 | ||
1048 | if (!piocb->iocb_cmpl) | |
1049 | lpfc_sli_release_iocbq(phba, piocb); | |
1050 | else { | |
1051 | piocb->iocb.ulpStatus = ulpstatus; | |
1052 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1053 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1054 | } | |
1055 | } | |
1056 | return; | |
1057 | } | |
1058 | ||
e59058c4 | 1059 | /** |
3621a710 JS |
1060 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1061 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1062 | * |
1063 | * This function is called by ring event handler function to get the iocb type. | |
1064 | * This function translates the iocb command to an iocb command type used to | |
1065 | * decide the final disposition of each completed IOCB. | |
1066 | * The function returns | |
1067 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1068 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1069 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1070 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1071 | * | |
1072 | * The caller is not required to hold any lock. | |
1073 | **/ | |
dea3101e JB |
1074 | static lpfc_iocb_type |
1075 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1076 | { | |
1077 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1078 | ||
1079 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1080 | return 0; | |
1081 | ||
1082 | switch (iocb_cmnd) { | |
1083 | case CMD_XMIT_SEQUENCE_CR: | |
1084 | case CMD_XMIT_SEQUENCE_CX: | |
1085 | case CMD_XMIT_BCAST_CN: | |
1086 | case CMD_XMIT_BCAST_CX: | |
1087 | case CMD_ELS_REQUEST_CR: | |
1088 | case CMD_ELS_REQUEST_CX: | |
1089 | case CMD_CREATE_XRI_CR: | |
1090 | case CMD_CREATE_XRI_CX: | |
1091 | case CMD_GET_RPI_CN: | |
1092 | case CMD_XMIT_ELS_RSP_CX: | |
1093 | case CMD_GET_RPI_CR: | |
1094 | case CMD_FCP_IWRITE_CR: | |
1095 | case CMD_FCP_IWRITE_CX: | |
1096 | case CMD_FCP_IREAD_CR: | |
1097 | case CMD_FCP_IREAD_CX: | |
1098 | case CMD_FCP_ICMND_CR: | |
1099 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1100 | case CMD_FCP_TSEND_CX: |
1101 | case CMD_FCP_TRSP_CX: | |
1102 | case CMD_FCP_TRECEIVE_CX: | |
1103 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
1104 | case CMD_ADAPTER_MSG: |
1105 | case CMD_ADAPTER_DUMP: | |
1106 | case CMD_XMIT_SEQUENCE64_CR: | |
1107 | case CMD_XMIT_SEQUENCE64_CX: | |
1108 | case CMD_XMIT_BCAST64_CN: | |
1109 | case CMD_XMIT_BCAST64_CX: | |
1110 | case CMD_ELS_REQUEST64_CR: | |
1111 | case CMD_ELS_REQUEST64_CX: | |
1112 | case CMD_FCP_IWRITE64_CR: | |
1113 | case CMD_FCP_IWRITE64_CX: | |
1114 | case CMD_FCP_IREAD64_CR: | |
1115 | case CMD_FCP_IREAD64_CX: | |
1116 | case CMD_FCP_ICMND64_CR: | |
1117 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1118 | case CMD_FCP_TSEND64_CX: |
1119 | case CMD_FCP_TRSP64_CX: | |
1120 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
1121 | case CMD_GEN_REQUEST64_CR: |
1122 | case CMD_GEN_REQUEST64_CX: | |
1123 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1124 | case DSSCMD_IWRITE64_CR: |
1125 | case DSSCMD_IWRITE64_CX: | |
1126 | case DSSCMD_IREAD64_CR: | |
1127 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
1128 | type = LPFC_SOL_IOCB; |
1129 | break; | |
1130 | case CMD_ABORT_XRI_CN: | |
1131 | case CMD_ABORT_XRI_CX: | |
1132 | case CMD_CLOSE_XRI_CN: | |
1133 | case CMD_CLOSE_XRI_CX: | |
1134 | case CMD_XRI_ABORTED_CX: | |
1135 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1136 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
1137 | type = LPFC_ABORT_IOCB; |
1138 | break; | |
1139 | case CMD_RCV_SEQUENCE_CX: | |
1140 | case CMD_RCV_ELS_REQ_CX: | |
1141 | case CMD_RCV_SEQUENCE64_CX: | |
1142 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1143 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1144 | case CMD_IOCB_RCV_SEQ64_CX: |
1145 | case CMD_IOCB_RCV_ELS64_CX: | |
1146 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1147 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
1148 | type = LPFC_UNSOL_IOCB; |
1149 | break; | |
3163f725 JS |
1150 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1151 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1152 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1153 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1154 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1155 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1156 | case CMD_IOCB_RET_HBQE64_CN: | |
1157 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1158 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1159 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1160 | case CMD_IOCB_LOGENTRY_CN: | |
1161 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1162 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1163 | __func__, iocb_cmnd); |
3163f725 JS |
1164 | type = LPFC_UNKNOWN_IOCB; |
1165 | break; | |
dea3101e JB |
1166 | default: |
1167 | type = LPFC_UNKNOWN_IOCB; | |
1168 | break; | |
1169 | } | |
1170 | ||
1171 | return type; | |
1172 | } | |
1173 | ||
e59058c4 | 1174 | /** |
3621a710 | 1175 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1176 | * @phba: Pointer to HBA context object. |
1177 | * | |
1178 | * This function is called from SLI initialization code | |
1179 | * to configure every ring of the HBA's SLI interface. The | |
1180 | * caller is not required to hold any lock. This function issues | |
1181 | * a config_ring mailbox command for each ring. | |
1182 | * This function returns zero if successful else returns a negative | |
1183 | * error code. | |
1184 | **/ | |
dea3101e | 1185 | static int |
ed957684 | 1186 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
1187 | { |
1188 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1189 | LPFC_MBOXQ_t *pmb; |
1190 | MAILBOX_t *pmbox; | |
1191 | int i, rc, ret = 0; | |
dea3101e | 1192 | |
ed957684 JS |
1193 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1194 | if (!pmb) | |
1195 | return -ENOMEM; | |
04c68496 | 1196 | pmbox = &pmb->u.mb; |
ed957684 | 1197 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1198 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
1199 | lpfc_config_ring(phba, i, pmb); |
1200 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1201 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1202 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1203 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
1204 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1205 | "ring %d\n", | |
e8b62011 JS |
1206 | rc, pmbox->mbxCommand, |
1207 | pmbox->mbxStatus, i); | |
2e0fef85 | 1208 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1209 | ret = -ENXIO; |
1210 | break; | |
dea3101e JB |
1211 | } |
1212 | } | |
ed957684 JS |
1213 | mempool_free(pmb, phba->mbox_mem_pool); |
1214 | return ret; | |
dea3101e JB |
1215 | } |
1216 | ||
e59058c4 | 1217 | /** |
3621a710 | 1218 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1219 | * @phba: Pointer to HBA context object. |
1220 | * @pring: Pointer to driver SLI ring object. | |
1221 | * @piocb: Pointer to the driver iocb object. | |
1222 | * | |
1223 | * This function is called with hbalock held. The function adds the | |
1224 | * new iocb to txcmplq of the given ring. This function always returns | |
1225 | * 0. If this function is called for ELS ring, this function checks if | |
1226 | * there is a vport associated with the ELS command. This function also | |
1227 | * starts els_tmofunc timer if this is an ELS command. | |
1228 | **/ | |
dea3101e | 1229 | static int |
2e0fef85 JS |
1230 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1231 | struct lpfc_iocbq *piocb) | |
dea3101e | 1232 | { |
dea3101e | 1233 | list_add_tail(&piocb->list, &pring->txcmplq); |
2a9bf3d0 | 1234 | piocb->iocb_flag |= LPFC_IO_ON_Q; |
dea3101e | 1235 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
1236 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
1237 | pring->txcmplq_max = pring->txcmplq_cnt; | |
1238 | ||
92d7f7b0 JS |
1239 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1240 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
1241 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
1242 | if (!piocb->vport) | |
1243 | BUG(); | |
1244 | else | |
1245 | mod_timer(&piocb->vport->els_tmofunc, | |
1246 | jiffies + HZ * (phba->fc_ratov << 1)); | |
1247 | } | |
1248 | ||
dea3101e | 1249 | |
2e0fef85 | 1250 | return 0; |
dea3101e JB |
1251 | } |
1252 | ||
e59058c4 | 1253 | /** |
3621a710 | 1254 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1255 | * @phba: Pointer to HBA context object. |
1256 | * @pring: Pointer to driver SLI ring object. | |
1257 | * | |
1258 | * This function is called with hbalock held to get next | |
1259 | * iocb in txq of the given ring. If there is any iocb in | |
1260 | * the txq, the function returns first iocb in the list after | |
1261 | * removing the iocb from the list, else it returns NULL. | |
1262 | **/ | |
2a9bf3d0 | 1263 | struct lpfc_iocbq * |
2e0fef85 | 1264 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1265 | { |
dea3101e JB |
1266 | struct lpfc_iocbq *cmd_iocb; |
1267 | ||
858c9f6c JS |
1268 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
1269 | if (cmd_iocb != NULL) | |
dea3101e | 1270 | pring->txq_cnt--; |
2e0fef85 | 1271 | return cmd_iocb; |
dea3101e JB |
1272 | } |
1273 | ||
e59058c4 | 1274 | /** |
3621a710 | 1275 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1276 | * @phba: Pointer to HBA context object. |
1277 | * @pring: Pointer to driver SLI ring object. | |
1278 | * | |
1279 | * This function is called with hbalock held and the caller must post the | |
1280 | * iocb without releasing the lock. If the caller releases the lock, | |
1281 | * iocb slot returned by the function is not guaranteed to be available. | |
1282 | * The function returns pointer to the next available iocb slot if there | |
1283 | * is available slot in the ring, else it returns NULL. | |
1284 | * If the get index of the ring is ahead of the put index, the function | |
1285 | * will post an error attention event to the worker thread to take the | |
1286 | * HBA to offline state. | |
1287 | **/ | |
dea3101e JB |
1288 | static IOCB_t * |
1289 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1290 | { | |
34b02dcd | 1291 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 1292 | uint32_t max_cmd_idx = pring->numCiocb; |
dea3101e JB |
1293 | if ((pring->next_cmdidx == pring->cmdidx) && |
1294 | (++pring->next_cmdidx >= max_cmd_idx)) | |
1295 | pring->next_cmdidx = 0; | |
1296 | ||
1297 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { | |
1298 | ||
1299 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
1300 | ||
1301 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { | |
1302 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 1303 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1304 | "is bigger than cmd ring %d\n", |
e8b62011 | 1305 | pring->ringno, |
dea3101e JB |
1306 | pring->local_getidx, max_cmd_idx); |
1307 | ||
2e0fef85 | 1308 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1309 | /* |
1310 | * All error attention handlers are posted to | |
1311 | * worker thread | |
1312 | */ | |
1313 | phba->work_ha |= HA_ERATT; | |
1314 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1315 | |
5e9d9b82 | 1316 | lpfc_worker_wake_up(phba); |
dea3101e JB |
1317 | |
1318 | return NULL; | |
1319 | } | |
1320 | ||
1321 | if (pring->local_getidx == pring->next_cmdidx) | |
1322 | return NULL; | |
1323 | } | |
1324 | ||
ed957684 | 1325 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
1326 | } |
1327 | ||
e59058c4 | 1328 | /** |
3621a710 | 1329 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1330 | * @phba: Pointer to HBA context object. |
1331 | * @iocbq: Pointer to driver iocb object. | |
1332 | * | |
1333 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1334 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1335 | * array and assigns a new iotag. | |
1336 | * The function returns the allocated iotag if successful, else returns zero. | |
1337 | * Zero is not a valid iotag. | |
1338 | * The caller is not required to hold any lock. | |
1339 | **/ | |
604a3e30 | 1340 | uint16_t |
2e0fef85 | 1341 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1342 | { |
2e0fef85 JS |
1343 | struct lpfc_iocbq **new_arr; |
1344 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1345 | size_t new_len; |
1346 | struct lpfc_sli *psli = &phba->sli; | |
1347 | uint16_t iotag; | |
dea3101e | 1348 | |
2e0fef85 | 1349 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1350 | iotag = psli->last_iotag; |
1351 | if(++iotag < psli->iocbq_lookup_len) { | |
1352 | psli->last_iotag = iotag; | |
1353 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1354 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1355 | iocbq->iotag = iotag; |
1356 | return iotag; | |
2e0fef85 | 1357 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1358 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1359 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1360 | spin_unlock_irq(&phba->hbalock); |
1361 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1362 | GFP_KERNEL); |
1363 | if (new_arr) { | |
2e0fef85 | 1364 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1365 | old_arr = psli->iocbq_lookup; |
1366 | if (new_len <= psli->iocbq_lookup_len) { | |
1367 | /* highly unprobable case */ | |
1368 | kfree(new_arr); | |
1369 | iotag = psli->last_iotag; | |
1370 | if(++iotag < psli->iocbq_lookup_len) { | |
1371 | psli->last_iotag = iotag; | |
1372 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1373 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1374 | iocbq->iotag = iotag; |
1375 | return iotag; | |
1376 | } | |
2e0fef85 | 1377 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1378 | return 0; |
1379 | } | |
1380 | if (psli->iocbq_lookup) | |
1381 | memcpy(new_arr, old_arr, | |
1382 | ((psli->last_iotag + 1) * | |
311464ec | 1383 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1384 | psli->iocbq_lookup = new_arr; |
1385 | psli->iocbq_lookup_len = new_len; | |
1386 | psli->last_iotag = iotag; | |
1387 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1388 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1389 | iocbq->iotag = iotag; |
1390 | kfree(old_arr); | |
1391 | return iotag; | |
1392 | } | |
8f6d98d2 | 1393 | } else |
2e0fef85 | 1394 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1395 | |
bc73905a | 1396 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1397 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1398 | psli->last_iotag); | |
dea3101e | 1399 | |
604a3e30 | 1400 | return 0; |
dea3101e JB |
1401 | } |
1402 | ||
e59058c4 | 1403 | /** |
3621a710 | 1404 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1405 | * @phba: Pointer to HBA context object. |
1406 | * @pring: Pointer to driver SLI ring object. | |
1407 | * @iocb: Pointer to iocb slot in the ring. | |
1408 | * @nextiocb: Pointer to driver iocb object which need to be | |
1409 | * posted to firmware. | |
1410 | * | |
1411 | * This function is called with hbalock held to post a new iocb to | |
1412 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1413 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1414 | * a completion call back for this iocb else the function will free the | |
1415 | * iocb object. | |
1416 | **/ | |
dea3101e JB |
1417 | static void |
1418 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1419 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1420 | { | |
1421 | /* | |
604a3e30 | 1422 | * Set up an iotag |
dea3101e | 1423 | */ |
604a3e30 | 1424 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1425 | |
e2a0a9d6 | 1426 | |
a58cbd52 JS |
1427 | if (pring->ringno == LPFC_ELS_RING) { |
1428 | lpfc_debugfs_slow_ring_trc(phba, | |
1429 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1430 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1431 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1432 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1433 | } | |
1434 | ||
dea3101e JB |
1435 | /* |
1436 | * Issue iocb command to adapter | |
1437 | */ | |
92d7f7b0 | 1438 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1439 | wmb(); |
1440 | pring->stats.iocb_cmd++; | |
1441 | ||
1442 | /* | |
1443 | * If there is no completion routine to call, we can release the | |
1444 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1445 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1446 | */ | |
1447 | if (nextiocb->iocb_cmpl) | |
1448 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1449 | else |
2e0fef85 | 1450 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1451 | |
1452 | /* | |
1453 | * Let the HBA know what IOCB slot will be the next one the | |
1454 | * driver will put a command into. | |
1455 | */ | |
1456 | pring->cmdidx = pring->next_cmdidx; | |
ed957684 | 1457 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
dea3101e JB |
1458 | } |
1459 | ||
e59058c4 | 1460 | /** |
3621a710 | 1461 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1462 | * @phba: Pointer to HBA context object. |
1463 | * @pring: Pointer to driver SLI ring object. | |
1464 | * | |
1465 | * The caller is not required to hold any lock for calling this function. | |
1466 | * This function updates the chip attention bits for the ring to inform firmware | |
1467 | * that there are pending work to be done for this ring and requests an | |
1468 | * interrupt when there is space available in the ring. This function is | |
1469 | * called when the driver is unable to post more iocbs to the ring due | |
1470 | * to unavailability of space in the ring. | |
1471 | **/ | |
dea3101e | 1472 | static void |
2e0fef85 | 1473 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1474 | { |
1475 | int ringno = pring->ringno; | |
1476 | ||
1477 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1478 | ||
1479 | wmb(); | |
1480 | ||
1481 | /* | |
1482 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1483 | * The HBA will tell us when an IOCB entry is available. | |
1484 | */ | |
1485 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1486 | readl(phba->CAregaddr); /* flush */ | |
1487 | ||
1488 | pring->stats.iocb_cmd_full++; | |
1489 | } | |
1490 | ||
e59058c4 | 1491 | /** |
3621a710 | 1492 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1493 | * @phba: Pointer to HBA context object. |
1494 | * @pring: Pointer to driver SLI ring object. | |
1495 | * | |
1496 | * This function updates the chip attention register bit for the | |
1497 | * given ring to inform HBA that there is more work to be done | |
1498 | * in this ring. The caller is not required to hold any lock. | |
1499 | **/ | |
dea3101e | 1500 | static void |
2e0fef85 | 1501 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1502 | { |
1503 | int ringno = pring->ringno; | |
1504 | ||
1505 | /* | |
1506 | * Tell the HBA that there is work to do in this ring. | |
1507 | */ | |
34b02dcd JS |
1508 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1509 | wmb(); | |
1510 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1511 | readl(phba->CAregaddr); /* flush */ | |
1512 | } | |
dea3101e JB |
1513 | } |
1514 | ||
e59058c4 | 1515 | /** |
3621a710 | 1516 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1517 | * @phba: Pointer to HBA context object. |
1518 | * @pring: Pointer to driver SLI ring object. | |
1519 | * | |
1520 | * This function is called with hbalock held to post pending iocbs | |
1521 | * in the txq to the firmware. This function is called when driver | |
1522 | * detects space available in the ring. | |
1523 | **/ | |
dea3101e | 1524 | static void |
2e0fef85 | 1525 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1526 | { |
1527 | IOCB_t *iocb; | |
1528 | struct lpfc_iocbq *nextiocb; | |
1529 | ||
1530 | /* | |
1531 | * Check to see if: | |
1532 | * (a) there is anything on the txq to send | |
1533 | * (b) link is up | |
1534 | * (c) link attention events can be processed (fcp ring only) | |
1535 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1536 | */ | |
1537 | if (pring->txq_cnt && | |
2e0fef85 | 1538 | lpfc_is_link_up(phba) && |
dea3101e | 1539 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1540 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1541 | |
1542 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1543 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1544 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1545 | ||
1546 | if (iocb) | |
1547 | lpfc_sli_update_ring(phba, pring); | |
1548 | else | |
1549 | lpfc_sli_update_full_ring(phba, pring); | |
1550 | } | |
1551 | ||
1552 | return; | |
1553 | } | |
1554 | ||
e59058c4 | 1555 | /** |
3621a710 | 1556 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1557 | * @phba: Pointer to HBA context object. |
1558 | * @hbqno: HBQ number. | |
1559 | * | |
1560 | * This function is called with hbalock held to get the next | |
1561 | * available slot for the given HBQ. If there is free slot | |
1562 | * available for the HBQ it will return pointer to the next available | |
1563 | * HBQ entry else it will return NULL. | |
1564 | **/ | |
a6ababd2 | 1565 | static struct lpfc_hbq_entry * |
ed957684 JS |
1566 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1567 | { | |
1568 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1569 | ||
1570 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1571 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1572 | hbqp->next_hbqPutIdx = 0; | |
1573 | ||
1574 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1575 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1576 | uint32_t getidx = le32_to_cpu(raw_index); |
1577 | ||
1578 | hbqp->local_hbqGetIdx = getidx; | |
1579 | ||
1580 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1581 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1582 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1583 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1584 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1585 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1586 | hbqp->entry_count); |
1587 | ||
1588 | phba->link_state = LPFC_HBA_ERROR; | |
1589 | return NULL; | |
1590 | } | |
1591 | ||
1592 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1593 | return NULL; | |
1594 | } | |
1595 | ||
51ef4c26 JS |
1596 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1597 | hbqp->hbqPutIdx; | |
ed957684 JS |
1598 | } |
1599 | ||
e59058c4 | 1600 | /** |
3621a710 | 1601 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1602 | * @phba: Pointer to HBA context object. |
1603 | * | |
1604 | * This function is called with no lock held to free all the | |
1605 | * hbq buffers while uninitializing the SLI interface. It also | |
1606 | * frees the HBQ buffers returned by the firmware but not yet | |
1607 | * processed by the upper layers. | |
1608 | **/ | |
ed957684 JS |
1609 | void |
1610 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1611 | { | |
92d7f7b0 JS |
1612 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1613 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1614 | unsigned long flags; |
51ef4c26 | 1615 | int i, hbq_count; |
3163f725 | 1616 | uint32_t hbqno; |
ed957684 | 1617 | |
51ef4c26 | 1618 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1619 | /* Return all memory used by all HBQs */ |
3163f725 | 1620 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1621 | for (i = 0; i < hbq_count; ++i) { |
1622 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1623 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1624 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1625 | list_del(&hbq_buf->dbuf.list); | |
1626 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1627 | } | |
a8adb832 | 1628 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1629 | } |
3163f725 | 1630 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1631 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1632 | list) { | |
3163f725 JS |
1633 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1634 | list_del(&hbq_buf->dbuf.list); | |
1635 | if (hbq_buf->tag == -1) { | |
1636 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1637 | (phba, hbq_buf); | |
1638 | } else { | |
1639 | hbqno = hbq_buf->tag >> 16; | |
1640 | if (hbqno >= LPFC_MAX_HBQS) | |
1641 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1642 | (phba, hbq_buf); | |
1643 | else | |
1644 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1645 | hbq_buf); | |
1646 | } | |
1647 | } | |
1648 | ||
1649 | /* Mark the HBQs not in use */ | |
1650 | phba->hbq_in_use = 0; | |
1651 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1652 | } |
1653 | ||
e59058c4 | 1654 | /** |
3621a710 | 1655 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1656 | * @phba: Pointer to HBA context object. |
1657 | * @hbqno: HBQ number. | |
1658 | * @hbq_buf: Pointer to HBQ buffer. | |
1659 | * | |
1660 | * This function is called with the hbalock held to post a | |
1661 | * hbq buffer to the firmware. If the function finds an empty | |
1662 | * slot in the HBQ, it will post the buffer. The function will return | |
1663 | * pointer to the hbq entry if it successfully post the buffer | |
1664 | * else it will return NULL. | |
1665 | **/ | |
3772a991 | 1666 | static int |
ed957684 | 1667 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1668 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1669 | { |
1670 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1671 | } | |
1672 | ||
1673 | /** | |
1674 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1675 | * @phba: Pointer to HBA context object. | |
1676 | * @hbqno: HBQ number. | |
1677 | * @hbq_buf: Pointer to HBQ buffer. | |
1678 | * | |
1679 | * This function is called with the hbalock held to post a hbq buffer to the | |
1680 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1681 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1682 | * it successfully post the buffer else it will return an error. | |
1683 | **/ | |
1684 | static int | |
1685 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1686 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1687 | { |
1688 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1689 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1690 | |
1691 | /* Get next HBQ entry slot to use */ | |
1692 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1693 | if (hbqe) { | |
1694 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1695 | ||
92d7f7b0 JS |
1696 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1697 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1698 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1699 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1700 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1701 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1702 | /* Sync SLIM */ | |
ed957684 JS |
1703 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1704 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1705 | /* flush */ |
ed957684 | 1706 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1707 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1708 | return 0; |
1709 | } else | |
1710 | return -ENOMEM; | |
ed957684 JS |
1711 | } |
1712 | ||
4f774513 JS |
1713 | /** |
1714 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1715 | * @phba: Pointer to HBA context object. | |
1716 | * @hbqno: HBQ number. | |
1717 | * @hbq_buf: Pointer to HBQ buffer. | |
1718 | * | |
1719 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1720 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1721 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1722 | **/ | |
1723 | static int | |
1724 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1725 | struct hbq_dmabuf *hbq_buf) | |
1726 | { | |
1727 | int rc; | |
1728 | struct lpfc_rqe hrqe; | |
1729 | struct lpfc_rqe drqe; | |
1730 | ||
1731 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1732 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1733 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1734 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1735 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1736 | &hrqe, &drqe); | |
1737 | if (rc < 0) | |
1738 | return rc; | |
1739 | hbq_buf->tag = rc; | |
1740 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1741 | return 0; | |
1742 | } | |
1743 | ||
e59058c4 | 1744 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1745 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1746 | .rn = 1, | |
def9c7a9 | 1747 | .entry_count = 256, |
92d7f7b0 JS |
1748 | .mask_count = 0, |
1749 | .profile = 0, | |
51ef4c26 | 1750 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1751 | .buffer_count = 0, |
a257bf90 JS |
1752 | .init_count = 40, |
1753 | .add_count = 40, | |
92d7f7b0 | 1754 | }; |
ed957684 | 1755 | |
e59058c4 | 1756 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1757 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1758 | .rn = 1, | |
1759 | .entry_count = 200, | |
1760 | .mask_count = 0, | |
1761 | .profile = 0, | |
1762 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1763 | .buffer_count = 0, | |
1764 | .init_count = 0, | |
1765 | .add_count = 5, | |
1766 | }; | |
1767 | ||
e59058c4 | 1768 | /* Array of HBQs */ |
78b2d852 | 1769 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1770 | &lpfc_els_hbq, |
51ef4c26 | 1771 | &lpfc_extra_hbq, |
92d7f7b0 | 1772 | }; |
ed957684 | 1773 | |
e59058c4 | 1774 | /** |
3621a710 | 1775 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1776 | * @phba: Pointer to HBA context object. |
1777 | * @hbqno: HBQ number. | |
1778 | * @count: Number of HBQ buffers to be posted. | |
1779 | * | |
d7c255b2 JS |
1780 | * This function is called with no lock held to post more hbq buffers to the |
1781 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1782 | * posted. | |
e59058c4 | 1783 | **/ |
311464ec | 1784 | static int |
92d7f7b0 | 1785 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1786 | { |
d7c255b2 | 1787 | uint32_t i, posted = 0; |
3163f725 | 1788 | unsigned long flags; |
92d7f7b0 | 1789 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1790 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1791 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1792 | return 0; |
51ef4c26 | 1793 | |
d7c255b2 JS |
1794 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1795 | lpfc_hbq_defs[hbqno]->entry_count) | |
1796 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1797 | phba->hbqs[hbqno].buffer_count; | |
1798 | if (!count) | |
1799 | return 0; | |
1800 | /* Allocate HBQ entries */ | |
1801 | for (i = 0; i < count; i++) { | |
1802 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1803 | if (!hbq_buffer) | |
1804 | break; | |
1805 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1806 | } | |
3163f725 JS |
1807 | /* Check whether HBQ is still in use */ |
1808 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1809 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1810 | goto err; |
1811 | while (!list_empty(&hbq_buf_list)) { | |
1812 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1813 | dbuf.list); | |
1814 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1815 | (hbqno << 16)); | |
3772a991 | 1816 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1817 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1818 | posted++; |
1819 | } else | |
51ef4c26 | 1820 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1821 | } |
3163f725 | 1822 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1823 | return posted; |
1824 | err: | |
eafe1df9 | 1825 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1826 | while (!list_empty(&hbq_buf_list)) { |
1827 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1828 | dbuf.list); | |
1829 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1830 | } | |
1831 | return 0; | |
ed957684 JS |
1832 | } |
1833 | ||
e59058c4 | 1834 | /** |
3621a710 | 1835 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1836 | * @phba: Pointer to HBA context object. |
1837 | * @qno: HBQ number. | |
1838 | * | |
1839 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1840 | * is called with no lock held. The function returns the number of HBQ entries |
1841 | * successfully allocated. | |
e59058c4 | 1842 | **/ |
92d7f7b0 JS |
1843 | int |
1844 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1845 | { |
def9c7a9 JS |
1846 | if (phba->sli_rev == LPFC_SLI_REV4) |
1847 | return 0; | |
1848 | else | |
1849 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1850 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1851 | } |
ed957684 | 1852 | |
e59058c4 | 1853 | /** |
3621a710 | 1854 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1855 | * @phba: Pointer to HBA context object. |
1856 | * @qno: HBQ queue number. | |
1857 | * | |
1858 | * This function is called from SLI initialization code path with | |
1859 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1860 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1861 | **/ |
a6ababd2 | 1862 | static int |
92d7f7b0 JS |
1863 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1864 | { | |
def9c7a9 JS |
1865 | if (phba->sli_rev == LPFC_SLI_REV4) |
1866 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1867 | lpfc_hbq_defs[qno]->entry_count); | |
1868 | else | |
1869 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1870 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1871 | } |
1872 | ||
3772a991 JS |
1873 | /** |
1874 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1875 | * @phba: Pointer to HBA context object. | |
1876 | * @hbqno: HBQ number. | |
1877 | * | |
1878 | * This function removes the first hbq buffer on an hbq list and returns a | |
1879 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1880 | **/ | |
1881 | static struct hbq_dmabuf * | |
1882 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1883 | { | |
1884 | struct lpfc_dmabuf *d_buf; | |
1885 | ||
1886 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1887 | if (!d_buf) | |
1888 | return NULL; | |
1889 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1890 | } | |
1891 | ||
e59058c4 | 1892 | /** |
3621a710 | 1893 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1894 | * @phba: Pointer to HBA context object. |
1895 | * @tag: Tag of the hbq buffer. | |
1896 | * | |
1897 | * This function is called with hbalock held. This function searches | |
1898 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1899 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1900 | * it returns NULL. | |
1901 | **/ | |
a6ababd2 | 1902 | static struct hbq_dmabuf * |
92d7f7b0 | 1903 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1904 | { |
92d7f7b0 JS |
1905 | struct lpfc_dmabuf *d_buf; |
1906 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1907 | uint32_t hbqno; |
1908 | ||
1909 | hbqno = tag >> 16; | |
a0a74e45 | 1910 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1911 | return NULL; |
ed957684 | 1912 | |
3772a991 | 1913 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1914 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1915 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1916 | if (hbq_buf->tag == tag) { |
3772a991 | 1917 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1918 | return hbq_buf; |
ed957684 JS |
1919 | } |
1920 | } | |
3772a991 | 1921 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1922 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1923 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1924 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1925 | return NULL; |
ed957684 JS |
1926 | } |
1927 | ||
e59058c4 | 1928 | /** |
3621a710 | 1929 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1930 | * @phba: Pointer to HBA context object. |
1931 | * @hbq_buffer: Pointer to HBQ buffer. | |
1932 | * | |
1933 | * This function is called with hbalock. This function gives back | |
1934 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1935 | * post the buffer, it will free the buffer. | |
1936 | **/ | |
ed957684 | 1937 | void |
51ef4c26 | 1938 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
1939 | { |
1940 | uint32_t hbqno; | |
1941 | ||
51ef4c26 JS |
1942 | if (hbq_buffer) { |
1943 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 1944 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 1945 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
1946 | } |
1947 | } | |
1948 | ||
e59058c4 | 1949 | /** |
3621a710 | 1950 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
1951 | * @mbxCommand: mailbox command code. |
1952 | * | |
1953 | * This function is called by the mailbox event handler function to verify | |
1954 | * that the completed mailbox command is a legitimate mailbox command. If the | |
1955 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
1956 | * and the mailbox event handler will take the HBA offline. | |
1957 | **/ | |
dea3101e JB |
1958 | static int |
1959 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
1960 | { | |
1961 | uint8_t ret; | |
1962 | ||
1963 | switch (mbxCommand) { | |
1964 | case MBX_LOAD_SM: | |
1965 | case MBX_READ_NV: | |
1966 | case MBX_WRITE_NV: | |
a8adb832 | 1967 | case MBX_WRITE_VPARMS: |
dea3101e JB |
1968 | case MBX_RUN_BIU_DIAG: |
1969 | case MBX_INIT_LINK: | |
1970 | case MBX_DOWN_LINK: | |
1971 | case MBX_CONFIG_LINK: | |
1972 | case MBX_CONFIG_RING: | |
1973 | case MBX_RESET_RING: | |
1974 | case MBX_READ_CONFIG: | |
1975 | case MBX_READ_RCONFIG: | |
1976 | case MBX_READ_SPARM: | |
1977 | case MBX_READ_STATUS: | |
1978 | case MBX_READ_RPI: | |
1979 | case MBX_READ_XRI: | |
1980 | case MBX_READ_REV: | |
1981 | case MBX_READ_LNK_STAT: | |
1982 | case MBX_REG_LOGIN: | |
1983 | case MBX_UNREG_LOGIN: | |
dea3101e JB |
1984 | case MBX_CLEAR_LA: |
1985 | case MBX_DUMP_MEMORY: | |
1986 | case MBX_DUMP_CONTEXT: | |
1987 | case MBX_RUN_DIAGS: | |
1988 | case MBX_RESTART: | |
1989 | case MBX_UPDATE_CFG: | |
1990 | case MBX_DOWN_LOAD: | |
1991 | case MBX_DEL_LD_ENTRY: | |
1992 | case MBX_RUN_PROGRAM: | |
1993 | case MBX_SET_MASK: | |
09372820 | 1994 | case MBX_SET_VARIABLE: |
dea3101e | 1995 | case MBX_UNREG_D_ID: |
41415862 | 1996 | case MBX_KILL_BOARD: |
dea3101e | 1997 | case MBX_CONFIG_FARP: |
41415862 | 1998 | case MBX_BEACON: |
dea3101e JB |
1999 | case MBX_LOAD_AREA: |
2000 | case MBX_RUN_BIU_DIAG64: | |
2001 | case MBX_CONFIG_PORT: | |
2002 | case MBX_READ_SPARM64: | |
2003 | case MBX_READ_RPI64: | |
2004 | case MBX_REG_LOGIN64: | |
76a95d75 | 2005 | case MBX_READ_TOPOLOGY: |
09372820 | 2006 | case MBX_WRITE_WWN: |
dea3101e JB |
2007 | case MBX_SET_DEBUG: |
2008 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2009 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2010 | case MBX_REG_VPI: |
2011 | case MBX_UNREG_VPI: | |
858c9f6c | 2012 | case MBX_HEARTBEAT: |
84774a4d JS |
2013 | case MBX_PORT_CAPABILITIES: |
2014 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2015 | case MBX_SLI4_CONFIG: |
2016 | case MBX_SLI4_REQ_FTRS: | |
2017 | case MBX_REG_FCFI: | |
2018 | case MBX_UNREG_FCFI: | |
2019 | case MBX_REG_VFI: | |
2020 | case MBX_UNREG_VFI: | |
2021 | case MBX_INIT_VPI: | |
2022 | case MBX_INIT_VFI: | |
2023 | case MBX_RESUME_RPI: | |
c7495937 JS |
2024 | case MBX_READ_EVENT_LOG_STATUS: |
2025 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2026 | case MBX_SECURITY_MGMT: |
2027 | case MBX_AUTH_PORT: | |
dea3101e JB |
2028 | ret = mbxCommand; |
2029 | break; | |
2030 | default: | |
2031 | ret = MBX_SHUTDOWN; | |
2032 | break; | |
2033 | } | |
2e0fef85 | 2034 | return ret; |
dea3101e | 2035 | } |
e59058c4 JS |
2036 | |
2037 | /** | |
3621a710 | 2038 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2039 | * @phba: Pointer to HBA context object. |
2040 | * @pmboxq: Pointer to mailbox command. | |
2041 | * | |
2042 | * This is completion handler function for mailbox commands issued from | |
2043 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2044 | * mailbox event handler function with no lock held. This function | |
2045 | * will wake up thread waiting on the wait queue pointed by context1 | |
2046 | * of the mailbox. | |
2047 | **/ | |
04c68496 | 2048 | void |
2e0fef85 | 2049 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
2050 | { |
2051 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2052 | unsigned long drvr_flag; |
dea3101e JB |
2053 | |
2054 | /* | |
2055 | * If pdone_q is empty, the driver thread gave up waiting and | |
2056 | * continued running. | |
2057 | */ | |
7054a606 | 2058 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2059 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
2060 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2061 | if (pdone_q) | |
2062 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2063 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
2064 | return; |
2065 | } | |
2066 | ||
e59058c4 JS |
2067 | |
2068 | /** | |
3621a710 | 2069 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2070 | * @phba: Pointer to HBA context object. |
2071 | * @pmb: Pointer to mailbox object. | |
2072 | * | |
2073 | * This function is the default mailbox completion handler. It | |
2074 | * frees the memory resources associated with the completed mailbox | |
2075 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2076 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2077 | **/ | |
dea3101e | 2078 | void |
2e0fef85 | 2079 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2080 | { |
d439d286 | 2081 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2082 | struct lpfc_dmabuf *mp; |
d439d286 | 2083 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2084 | struct Scsi_Host *shost; |
04c68496 | 2085 | uint16_t rpi, vpi; |
7054a606 JS |
2086 | int rc; |
2087 | ||
dea3101e | 2088 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2089 | |
dea3101e JB |
2090 | if (mp) { |
2091 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2092 | kfree(mp); | |
2093 | } | |
7054a606 JS |
2094 | |
2095 | /* | |
2096 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2097 | * is in re-discovery driver need to cleanup the RPI. | |
2098 | */ | |
2e0fef85 | 2099 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2100 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2101 | !pmb->u.mb.mbxStatus) { | |
2102 | rpi = pmb->u.mb.un.varWords[0]; | |
6d368e53 | 2103 | vpi = pmb->u.mb.un.varRegLogin.vpi; |
04c68496 | 2104 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
92d7f7b0 | 2105 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2106 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2107 | if (rc != MBX_NOT_FINISHED) | |
2108 | return; | |
2109 | } | |
2110 | ||
695a814e JS |
2111 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2112 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2113 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2114 | shost = lpfc_shost_from_vport(vport); |
2115 | spin_lock_irq(shost->host_lock); | |
2116 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2117 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2118 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2119 | } |
2120 | ||
d439d286 JS |
2121 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2122 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2123 | lpfc_nlp_put(ndlp); | |
2124 | pmb->context2 = NULL; | |
2125 | } | |
2126 | ||
dcf2a4e0 JS |
2127 | /* Check security permission status on INIT_LINK mailbox command */ |
2128 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2129 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2130 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2131 | "2860 SLI authentication is required " | |
2132 | "for INIT_LINK but has not done yet\n"); | |
2133 | ||
04c68496 JS |
2134 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2135 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2136 | else | |
2137 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e JB |
2138 | } |
2139 | ||
e59058c4 | 2140 | /** |
3621a710 | 2141 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2142 | * @phba: Pointer to HBA context object. |
2143 | * | |
2144 | * This function is called with no lock held. This function processes all | |
2145 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2146 | * service routine processes mailbox completion interrupt and adds completed | |
2147 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2148 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2149 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2150 | * function returns the mailbox commands to the upper layer by calling the | |
2151 | * completion handler function of each mailbox. | |
2152 | **/ | |
dea3101e | 2153 | int |
2e0fef85 | 2154 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2155 | { |
92d7f7b0 | 2156 | MAILBOX_t *pmbox; |
dea3101e | 2157 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2158 | int rc; |
2159 | LIST_HEAD(cmplq); | |
dea3101e JB |
2160 | |
2161 | phba->sli.slistat.mbox_event++; | |
2162 | ||
92d7f7b0 JS |
2163 | /* Get all completed mailboxe buffers into the cmplq */ |
2164 | spin_lock_irq(&phba->hbalock); | |
2165 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2166 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2167 | |
92d7f7b0 JS |
2168 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2169 | do { | |
2170 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2171 | if (pmb == NULL) | |
2172 | break; | |
2e0fef85 | 2173 | |
04c68496 | 2174 | pmbox = &pmb->u.mb; |
dea3101e | 2175 | |
858c9f6c JS |
2176 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2177 | if (pmb->vport) { | |
2178 | lpfc_debugfs_disc_trc(pmb->vport, | |
2179 | LPFC_DISC_TRC_MBOX_VPORT, | |
2180 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2181 | (uint32_t)pmbox->mbxCommand, | |
2182 | pmbox->un.varWords[0], | |
2183 | pmbox->un.varWords[1]); | |
2184 | } | |
2185 | else { | |
2186 | lpfc_debugfs_disc_trc(phba->pport, | |
2187 | LPFC_DISC_TRC_MBOX, | |
2188 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2189 | (uint32_t)pmbox->mbxCommand, | |
2190 | pmbox->un.varWords[0], | |
2191 | pmbox->un.varWords[1]); | |
2192 | } | |
2193 | } | |
2194 | ||
dea3101e JB |
2195 | /* |
2196 | * It is a fatal error if unknown mbox command completion. | |
2197 | */ | |
2198 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2199 | MBX_SHUTDOWN) { | |
af901ca1 | 2200 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2201 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2202 | "(%d):0323 Unknown Mailbox command " |
04c68496 | 2203 | "x%x (x%x) Cmpl\n", |
92d7f7b0 | 2204 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 JS |
2205 | pmbox->mbxCommand, |
2206 | lpfc_sli4_mbox_opcode_get(phba, pmb)); | |
2e0fef85 | 2207 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2208 | phba->work_hs = HS_FFER3; |
2209 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2210 | continue; |
dea3101e JB |
2211 | } |
2212 | ||
dea3101e JB |
2213 | if (pmbox->mbxStatus) { |
2214 | phba->sli.slistat.mbox_stat_err++; | |
2215 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2216 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 JS |
2217 | lpfc_printf_log(phba, KERN_INFO, |
2218 | LOG_MBOX | LOG_SLI, | |
e8b62011 | 2219 | "(%d):0305 Mbox cmd cmpl " |
92d7f7b0 | 2220 | "error - RETRYing Data: x%x " |
04c68496 | 2221 | "(x%x) x%x x%x x%x\n", |
92d7f7b0 JS |
2222 | pmb->vport ? pmb->vport->vpi :0, |
2223 | pmbox->mbxCommand, | |
04c68496 JS |
2224 | lpfc_sli4_mbox_opcode_get(phba, |
2225 | pmb), | |
92d7f7b0 JS |
2226 | pmbox->mbxStatus, |
2227 | pmbox->un.varWords[0], | |
2228 | pmb->vport->port_state); | |
dea3101e JB |
2229 | pmbox->mbxStatus = 0; |
2230 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2231 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2232 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2233 | continue; |
dea3101e JB |
2234 | } |
2235 | } | |
2236 | ||
2237 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2238 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
04c68496 | 2239 | "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p " |
dea3101e | 2240 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2241 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2242 | pmbox->mbxCommand, |
04c68496 | 2243 | lpfc_sli4_mbox_opcode_get(phba, pmb), |
dea3101e JB |
2244 | pmb->mbox_cmpl, |
2245 | *((uint32_t *) pmbox), | |
2246 | pmbox->un.varWords[0], | |
2247 | pmbox->un.varWords[1], | |
2248 | pmbox->un.varWords[2], | |
2249 | pmbox->un.varWords[3], | |
2250 | pmbox->un.varWords[4], | |
2251 | pmbox->un.varWords[5], | |
2252 | pmbox->un.varWords[6], | |
2253 | pmbox->un.varWords[7]); | |
2254 | ||
92d7f7b0 | 2255 | if (pmb->mbox_cmpl) |
dea3101e | 2256 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2257 | } while (1); |
2258 | return 0; | |
2259 | } | |
dea3101e | 2260 | |
e59058c4 | 2261 | /** |
3621a710 | 2262 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2263 | * @phba: Pointer to HBA context object. |
2264 | * @pring: Pointer to driver SLI ring object. | |
2265 | * @tag: buffer tag. | |
2266 | * | |
2267 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2268 | * is set in the tag the buffer is posted for a particular exchange, | |
2269 | * the function will return the buffer without replacing the buffer. | |
2270 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2271 | * returns the buffer and also posts another buffer to the firmware. | |
2272 | **/ | |
76bb24ef JS |
2273 | static struct lpfc_dmabuf * |
2274 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2275 | struct lpfc_sli_ring *pring, |
2276 | uint32_t tag) | |
76bb24ef | 2277 | { |
9f1e1b50 JS |
2278 | struct hbq_dmabuf *hbq_entry; |
2279 | ||
76bb24ef JS |
2280 | if (tag & QUE_BUFTAG_BIT) |
2281 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2282 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2283 | if (!hbq_entry) | |
2284 | return NULL; | |
2285 | return &hbq_entry->dbuf; | |
76bb24ef | 2286 | } |
57127f15 | 2287 | |
3772a991 JS |
2288 | /** |
2289 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2290 | * @phba: Pointer to HBA context object. | |
2291 | * @pring: Pointer to driver SLI ring object. | |
2292 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2293 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2294 | * @fch_type: the type for the first frame of the sequence. | |
2295 | * | |
2296 | * This function is called with no lock held. This function uses the r_ctl and | |
2297 | * type of the received sequence to find the correct callback function to call | |
2298 | * to process the sequence. | |
2299 | **/ | |
2300 | static int | |
2301 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2302 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2303 | uint32_t fch_type) | |
2304 | { | |
2305 | int i; | |
2306 | ||
2307 | /* unSolicited Responses */ | |
2308 | if (pring->prt[0].profile) { | |
2309 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2310 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2311 | saveq); | |
2312 | return 1; | |
2313 | } | |
2314 | /* We must search, based on rctl / type | |
2315 | for the right routine */ | |
2316 | for (i = 0; i < pring->num_mask; i++) { | |
2317 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2318 | (pring->prt[i].type == fch_type)) { | |
2319 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2320 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2321 | (phba, pring, saveq); | |
2322 | return 1; | |
2323 | } | |
2324 | } | |
2325 | return 0; | |
2326 | } | |
e59058c4 JS |
2327 | |
2328 | /** | |
3621a710 | 2329 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2330 | * @phba: Pointer to HBA context object. |
2331 | * @pring: Pointer to driver SLI ring object. | |
2332 | * @saveq: Pointer to the unsolicited iocb. | |
2333 | * | |
2334 | * This function is called with no lock held by the ring event handler | |
2335 | * when there is an unsolicited iocb posted to the response ring by the | |
2336 | * firmware. This function gets the buffer associated with the iocbs | |
2337 | * and calls the event handler for the ring. This function handles both | |
2338 | * qring buffers and hbq buffers. | |
2339 | * When the function returns 1 the caller can free the iocb object otherwise | |
2340 | * upper layer functions will free the iocb objects. | |
2341 | **/ | |
dea3101e JB |
2342 | static int |
2343 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2344 | struct lpfc_iocbq *saveq) | |
2345 | { | |
2346 | IOCB_t * irsp; | |
2347 | WORD5 * w5p; | |
2348 | uint32_t Rctl, Type; | |
3772a991 | 2349 | uint32_t match; |
76bb24ef | 2350 | struct lpfc_iocbq *iocbq; |
3163f725 | 2351 | struct lpfc_dmabuf *dmzbuf; |
dea3101e JB |
2352 | |
2353 | match = 0; | |
2354 | irsp = &(saveq->iocb); | |
57127f15 JS |
2355 | |
2356 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2357 | if (pring->lpfc_sli_rcv_async_status) | |
2358 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2359 | else | |
2360 | lpfc_printf_log(phba, | |
2361 | KERN_WARNING, | |
2362 | LOG_SLI, | |
2363 | "0316 Ring %d handler: unexpected " | |
2364 | "ASYNC_STATUS iocb received evt_code " | |
2365 | "0x%x\n", | |
2366 | pring->ringno, | |
2367 | irsp->un.asyncstat.evt_code); | |
2368 | return 1; | |
2369 | } | |
2370 | ||
3163f725 JS |
2371 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2372 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2373 | if (irsp->ulpBdeCount > 0) { | |
2374 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2375 | irsp->un.ulpWord[3]); | |
2376 | lpfc_in_buf_free(phba, dmzbuf); | |
2377 | } | |
2378 | ||
2379 | if (irsp->ulpBdeCount > 1) { | |
2380 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2381 | irsp->unsli3.sli3Words[3]); | |
2382 | lpfc_in_buf_free(phba, dmzbuf); | |
2383 | } | |
2384 | ||
2385 | if (irsp->ulpBdeCount > 2) { | |
2386 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2387 | irsp->unsli3.sli3Words[7]); | |
2388 | lpfc_in_buf_free(phba, dmzbuf); | |
2389 | } | |
2390 | ||
2391 | return 1; | |
2392 | } | |
2393 | ||
92d7f7b0 | 2394 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2395 | if (irsp->ulpBdeCount != 0) { |
2396 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2397 | irsp->un.ulpWord[3]); | |
2398 | if (!saveq->context2) | |
2399 | lpfc_printf_log(phba, | |
2400 | KERN_ERR, | |
2401 | LOG_SLI, | |
2402 | "0341 Ring %d Cannot find buffer for " | |
2403 | "an unsolicited iocb. tag 0x%x\n", | |
2404 | pring->ringno, | |
2405 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2406 | } |
2407 | if (irsp->ulpBdeCount == 2) { | |
2408 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2409 | irsp->unsli3.sli3Words[7]); | |
2410 | if (!saveq->context3) | |
2411 | lpfc_printf_log(phba, | |
2412 | KERN_ERR, | |
2413 | LOG_SLI, | |
2414 | "0342 Ring %d Cannot find buffer for an" | |
2415 | " unsolicited iocb. tag 0x%x\n", | |
2416 | pring->ringno, | |
2417 | irsp->unsli3.sli3Words[7]); | |
2418 | } | |
2419 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2420 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2421 | if (irsp->ulpBdeCount != 0) { |
2422 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2423 | irsp->un.ulpWord[3]); | |
9c2face6 | 2424 | if (!iocbq->context2) |
76bb24ef JS |
2425 | lpfc_printf_log(phba, |
2426 | KERN_ERR, | |
2427 | LOG_SLI, | |
2428 | "0343 Ring %d Cannot find " | |
2429 | "buffer for an unsolicited iocb" | |
2430 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2431 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2432 | } |
2433 | if (irsp->ulpBdeCount == 2) { | |
2434 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2435 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2436 | if (!iocbq->context3) |
76bb24ef JS |
2437 | lpfc_printf_log(phba, |
2438 | KERN_ERR, | |
2439 | LOG_SLI, | |
2440 | "0344 Ring %d Cannot find " | |
2441 | "buffer for an unsolicited " | |
2442 | "iocb. tag 0x%x\n", | |
2443 | pring->ringno, | |
2444 | irsp->unsli3.sli3Words[7]); | |
2445 | } | |
2446 | } | |
92d7f7b0 | 2447 | } |
9c2face6 JS |
2448 | if (irsp->ulpBdeCount != 0 && |
2449 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2450 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2451 | int found = 0; | |
2452 | ||
2453 | /* search continue save q for same XRI */ | |
2454 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
2455 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { | |
2456 | list_add_tail(&saveq->list, &iocbq->list); | |
2457 | found = 1; | |
2458 | break; | |
2459 | } | |
2460 | } | |
2461 | if (!found) | |
2462 | list_add_tail(&saveq->clist, | |
2463 | &pring->iocb_continue_saveq); | |
2464 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2465 | list_del_init(&iocbq->clist); | |
2466 | saveq = iocbq; | |
2467 | irsp = &(saveq->iocb); | |
2468 | } else | |
2469 | return 0; | |
2470 | } | |
2471 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2472 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2473 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2474 | Rctl = FC_RCTL_ELS_REQ; |
2475 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2476 | } else { |
2477 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2478 | Rctl = w5p->hcsw.Rctl; | |
2479 | Type = w5p->hcsw.Type; | |
2480 | ||
2481 | /* Firmware Workaround */ | |
2482 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2483 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2484 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2485 | Rctl = FC_RCTL_ELS_REQ; |
2486 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2487 | w5p->hcsw.Rctl = Rctl; |
2488 | w5p->hcsw.Type = Type; | |
2489 | } | |
2490 | } | |
92d7f7b0 | 2491 | |
3772a991 | 2492 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2493 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2494 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2495 | "Type x%x received\n", |
e8b62011 | 2496 | pring->ringno, Rctl, Type); |
3772a991 | 2497 | |
92d7f7b0 | 2498 | return 1; |
dea3101e JB |
2499 | } |
2500 | ||
e59058c4 | 2501 | /** |
3621a710 | 2502 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2503 | * @phba: Pointer to HBA context object. |
2504 | * @pring: Pointer to driver SLI ring object. | |
2505 | * @prspiocb: Pointer to response iocb object. | |
2506 | * | |
2507 | * This function looks up the iocb_lookup table to get the command iocb | |
2508 | * corresponding to the given response iocb using the iotag of the | |
2509 | * response iocb. This function is called with the hbalock held. | |
2510 | * This function returns the command iocb object if it finds the command | |
2511 | * iocb else returns NULL. | |
2512 | **/ | |
dea3101e | 2513 | static struct lpfc_iocbq * |
2e0fef85 JS |
2514 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2515 | struct lpfc_sli_ring *pring, | |
2516 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2517 | { |
dea3101e JB |
2518 | struct lpfc_iocbq *cmd_iocb = NULL; |
2519 | uint16_t iotag; | |
2520 | ||
604a3e30 JB |
2521 | iotag = prspiocb->iocb.ulpIoTag; |
2522 | ||
2523 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2524 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2525 | list_del_init(&cmd_iocb->list); |
2a9bf3d0 JS |
2526 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2527 | pring->txcmplq_cnt--; | |
2528 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2529 | } | |
604a3e30 | 2530 | return cmd_iocb; |
dea3101e JB |
2531 | } |
2532 | ||
dea3101e | 2533 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2534 | "0317 iotag x%x is out off " |
604a3e30 | 2535 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2536 | iotag, phba->sli.last_iotag, |
604a3e30 | 2537 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
2538 | return NULL; |
2539 | } | |
2540 | ||
3772a991 JS |
2541 | /** |
2542 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2543 | * @phba: Pointer to HBA context object. | |
2544 | * @pring: Pointer to driver SLI ring object. | |
2545 | * @iotag: IOCB tag. | |
2546 | * | |
2547 | * This function looks up the iocb_lookup table to get the command iocb | |
2548 | * corresponding to the given iotag. This function is called with the | |
2549 | * hbalock held. | |
2550 | * This function returns the command iocb object if it finds the command | |
2551 | * iocb else returns NULL. | |
2552 | **/ | |
2553 | static struct lpfc_iocbq * | |
2554 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2555 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2556 | { | |
2557 | struct lpfc_iocbq *cmd_iocb; | |
2558 | ||
2559 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2560 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
2561 | list_del_init(&cmd_iocb->list); | |
2a9bf3d0 JS |
2562 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2563 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2564 | pring->txcmplq_cnt--; | |
2565 | } | |
3772a991 JS |
2566 | return cmd_iocb; |
2567 | } | |
2568 | ||
2569 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2570 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2571 | iotag, phba->sli.last_iotag); | |
2572 | return NULL; | |
2573 | } | |
2574 | ||
e59058c4 | 2575 | /** |
3621a710 | 2576 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2577 | * @phba: Pointer to HBA context object. |
2578 | * @pring: Pointer to driver SLI ring object. | |
2579 | * @saveq: Pointer to the response iocb to be processed. | |
2580 | * | |
2581 | * This function is called by the ring event handler for non-fcp | |
2582 | * rings when there is a new response iocb in the response ring. | |
2583 | * The caller is not required to hold any locks. This function | |
2584 | * gets the command iocb associated with the response iocb and | |
2585 | * calls the completion handler for the command iocb. If there | |
2586 | * is no completion handler, the function will free the resources | |
2587 | * associated with command iocb. If the response iocb is for | |
2588 | * an already aborted command iocb, the status of the completion | |
2589 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2590 | * This function always returns 1. | |
2591 | **/ | |
dea3101e | 2592 | static int |
2e0fef85 | 2593 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
2594 | struct lpfc_iocbq *saveq) |
2595 | { | |
2e0fef85 | 2596 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
2597 | int rc = 1; |
2598 | unsigned long iflag; | |
2599 | ||
2600 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2601 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2602 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2603 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2604 | ||
dea3101e JB |
2605 | if (cmdiocbp) { |
2606 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2607 | /* |
2608 | * If an ELS command failed send an event to mgmt | |
2609 | * application. | |
2610 | */ | |
2611 | if (saveq->iocb.ulpStatus && | |
2612 | (pring->ringno == LPFC_ELS_RING) && | |
2613 | (cmdiocbp->iocb.ulpCommand == | |
2614 | CMD_ELS_REQUEST64_CR)) | |
2615 | lpfc_send_els_failure_event(phba, | |
2616 | cmdiocbp, saveq); | |
2617 | ||
dea3101e JB |
2618 | /* |
2619 | * Post all ELS completions to the worker thread. | |
2620 | * All other are passed to the completion callback. | |
2621 | */ | |
2622 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2623 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2624 | (cmdiocbp->iocb_flag & | |
2625 | LPFC_DRIVER_ABORTED)) { | |
2626 | spin_lock_irqsave(&phba->hbalock, | |
2627 | iflag); | |
07951076 JS |
2628 | cmdiocbp->iocb_flag &= |
2629 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2630 | spin_unlock_irqrestore(&phba->hbalock, |
2631 | iflag); | |
07951076 JS |
2632 | saveq->iocb.ulpStatus = |
2633 | IOSTAT_LOCAL_REJECT; | |
2634 | saveq->iocb.un.ulpWord[4] = | |
2635 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2636 | |
2637 | /* Firmware could still be in progress | |
2638 | * of DMAing payload, so don't free data | |
2639 | * buffer till after a hbeat. | |
2640 | */ | |
341af102 JS |
2641 | spin_lock_irqsave(&phba->hbalock, |
2642 | iflag); | |
0ff10d46 | 2643 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2644 | spin_unlock_irqrestore(&phba->hbalock, |
2645 | iflag); | |
2646 | } | |
0f65ff68 JS |
2647 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2648 | if (saveq->iocb_flag & | |
2649 | LPFC_EXCHANGE_BUSY) { | |
2650 | /* Set cmdiocb flag for the | |
2651 | * exchange busy so sgl (xri) | |
2652 | * will not be released until | |
2653 | * the abort xri is received | |
2654 | * from hba. | |
2655 | */ | |
2656 | spin_lock_irqsave( | |
2657 | &phba->hbalock, iflag); | |
2658 | cmdiocbp->iocb_flag |= | |
2659 | LPFC_EXCHANGE_BUSY; | |
2660 | spin_unlock_irqrestore( | |
2661 | &phba->hbalock, iflag); | |
2662 | } | |
2663 | if (cmdiocbp->iocb_flag & | |
2664 | LPFC_DRIVER_ABORTED) { | |
2665 | /* | |
2666 | * Clear LPFC_DRIVER_ABORTED | |
2667 | * bit in case it was driver | |
2668 | * initiated abort. | |
2669 | */ | |
2670 | spin_lock_irqsave( | |
2671 | &phba->hbalock, iflag); | |
2672 | cmdiocbp->iocb_flag &= | |
2673 | ~LPFC_DRIVER_ABORTED; | |
2674 | spin_unlock_irqrestore( | |
2675 | &phba->hbalock, iflag); | |
2676 | cmdiocbp->iocb.ulpStatus = | |
2677 | IOSTAT_LOCAL_REJECT; | |
2678 | cmdiocbp->iocb.un.ulpWord[4] = | |
2679 | IOERR_ABORT_REQUESTED; | |
2680 | /* | |
2681 | * For SLI4, irsiocb contains | |
2682 | * NO_XRI in sli_xritag, it | |
2683 | * shall not affect releasing | |
2684 | * sgl (xri) process. | |
2685 | */ | |
2686 | saveq->iocb.ulpStatus = | |
2687 | IOSTAT_LOCAL_REJECT; | |
2688 | saveq->iocb.un.ulpWord[4] = | |
2689 | IOERR_SLI_ABORTED; | |
2690 | spin_lock_irqsave( | |
2691 | &phba->hbalock, iflag); | |
2692 | saveq->iocb_flag |= | |
2693 | LPFC_DELAY_MEM_FREE; | |
2694 | spin_unlock_irqrestore( | |
2695 | &phba->hbalock, iflag); | |
2696 | } | |
07951076 | 2697 | } |
dea3101e | 2698 | } |
2e0fef85 | 2699 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2700 | } else |
2701 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
2702 | } else { |
2703 | /* | |
2704 | * Unknown initiating command based on the response iotag. | |
2705 | * This could be the case on the ELS ring because of | |
2706 | * lpfc_els_abort(). | |
2707 | */ | |
2708 | if (pring->ringno != LPFC_ELS_RING) { | |
2709 | /* | |
2710 | * Ring <ringno> handler: unexpected completion IoTag | |
2711 | * <IoTag> | |
2712 | */ | |
a257bf90 | 2713 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2714 | "0322 Ring %d handler: " |
2715 | "unexpected completion IoTag x%x " | |
2716 | "Data: x%x x%x x%x x%x\n", | |
2717 | pring->ringno, | |
2718 | saveq->iocb.ulpIoTag, | |
2719 | saveq->iocb.ulpStatus, | |
2720 | saveq->iocb.un.ulpWord[4], | |
2721 | saveq->iocb.ulpCommand, | |
2722 | saveq->iocb.ulpContext); | |
dea3101e JB |
2723 | } |
2724 | } | |
68876920 | 2725 | |
dea3101e JB |
2726 | return rc; |
2727 | } | |
2728 | ||
e59058c4 | 2729 | /** |
3621a710 | 2730 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2731 | * @phba: Pointer to HBA context object. |
2732 | * @pring: Pointer to driver SLI ring object. | |
2733 | * | |
2734 | * This function is called from the iocb ring event handlers when | |
2735 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2736 | * an error attention condition to the worker thread and the worker | |
2737 | * thread will transition the HBA to offline state. | |
2738 | **/ | |
2e0fef85 JS |
2739 | static void |
2740 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2741 | { |
34b02dcd | 2742 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2743 | /* |
025dfdaf | 2744 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2745 | * rsp ring <portRspMax> |
2746 | */ | |
2747 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2748 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2749 | "is bigger than rsp ring %d\n", |
e8b62011 | 2750 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
2751 | pring->numRiocb); |
2752 | ||
2e0fef85 | 2753 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2754 | |
2755 | /* | |
2756 | * All error attention handlers are posted to | |
2757 | * worker thread | |
2758 | */ | |
2759 | phba->work_ha |= HA_ERATT; | |
2760 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2761 | |
5e9d9b82 | 2762 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2763 | |
2764 | return; | |
2765 | } | |
2766 | ||
9399627f | 2767 | /** |
3621a710 | 2768 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2769 | * @ptr: Pointer to address of HBA context object. |
2770 | * | |
2771 | * This function is invoked by the Error Attention polling timer when the | |
2772 | * timer times out. It will check the SLI Error Attention register for | |
2773 | * possible attention events. If so, it will post an Error Attention event | |
2774 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2775 | * Error Attention polling timer for the next poll. | |
2776 | **/ | |
2777 | void lpfc_poll_eratt(unsigned long ptr) | |
2778 | { | |
2779 | struct lpfc_hba *phba; | |
2780 | uint32_t eratt = 0; | |
2781 | ||
2782 | phba = (struct lpfc_hba *)ptr; | |
2783 | ||
2784 | /* Check chip HA register for error event */ | |
2785 | eratt = lpfc_sli_check_eratt(phba); | |
2786 | ||
2787 | if (eratt) | |
2788 | /* Tell the worker thread there is work to do */ | |
2789 | lpfc_worker_wake_up(phba); | |
2790 | else | |
2791 | /* Restart the timer for next eratt poll */ | |
2792 | mod_timer(&phba->eratt_poll, jiffies + | |
2793 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2794 | return; | |
2795 | } | |
2796 | ||
875fbdfe | 2797 | |
e59058c4 | 2798 | /** |
3621a710 | 2799 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2800 | * @phba: Pointer to HBA context object. |
2801 | * @pring: Pointer to driver SLI ring object. | |
2802 | * @mask: Host attention register mask for this ring. | |
2803 | * | |
2804 | * This function is called from the interrupt context when there is a ring | |
2805 | * event for the fcp ring. The caller does not hold any lock. | |
2806 | * The function processes each response iocb in the response ring until it | |
25985edc | 2807 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2808 | * LE bit set. The function will call the completion handler of the command iocb |
2809 | * if the response iocb indicates a completion for a command iocb or it is | |
2810 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2811 | * function if this is an unsolicited iocb. | |
dea3101e | 2812 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2813 | * to check it explicitly. |
2814 | */ | |
2815 | int | |
2e0fef85 JS |
2816 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2817 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2818 | { |
34b02dcd | 2819 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2820 | IOCB_t *irsp = NULL; |
87f6eaff | 2821 | IOCB_t *entry = NULL; |
dea3101e JB |
2822 | struct lpfc_iocbq *cmdiocbq = NULL; |
2823 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
2824 | uint32_t status; |
2825 | uint32_t portRspPut, portRspMax; | |
2826 | int rc = 1; | |
2827 | lpfc_iocb_type type; | |
2828 | unsigned long iflag; | |
2829 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2830 | |
2e0fef85 | 2831 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2832 | pring->stats.iocb_event++; |
2833 | ||
dea3101e JB |
2834 | /* |
2835 | * The next available response entry should never exceed the maximum | |
2836 | * entries. If it does, treat it as an adapter hardware error. | |
2837 | */ | |
2838 | portRspMax = pring->numRiocb; | |
2839 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2840 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2841 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2842 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2843 | return 1; |
2844 | } | |
45ed1190 JS |
2845 | if (phba->fcp_ring_in_use) { |
2846 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2847 | return 1; | |
2848 | } else | |
2849 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
2850 | |
2851 | rmb(); | |
2852 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
2853 | /* |
2854 | * Fetch an entry off the ring and copy it into a local data | |
2855 | * structure. The copy involves a byte-swap since the | |
2856 | * network byte order and pci byte orders are different. | |
2857 | */ | |
ed957684 | 2858 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2859 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
2860 | |
2861 | if (++pring->rspidx >= portRspMax) | |
2862 | pring->rspidx = 0; | |
2863 | ||
87f6eaff JSEC |
2864 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2865 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2866 | phba->iocb_rsp_size); |
a4bc3379 | 2867 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2868 | irsp = &rspiocbq.iocb; |
2869 | ||
dea3101e JB |
2870 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2871 | pring->stats.iocb_rsp++; | |
2872 | rsp_cmpl++; | |
2873 | ||
2874 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2875 | /* |
2876 | * If resource errors reported from HBA, reduce | |
2877 | * queuedepths of the SCSI device. | |
2878 | */ | |
2879 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2880 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2881 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2882 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2883 | spin_lock_irqsave(&phba->hbalock, iflag); |
2884 | } | |
2885 | ||
dea3101e JB |
2886 | /* Rsp ring <ringno> error: IOCB */ |
2887 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2888 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2889 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2890 | pring->ringno, |
92d7f7b0 JS |
2891 | irsp->un.ulpWord[0], |
2892 | irsp->un.ulpWord[1], | |
2893 | irsp->un.ulpWord[2], | |
2894 | irsp->un.ulpWord[3], | |
2895 | irsp->un.ulpWord[4], | |
2896 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2897 | *(uint32_t *)&irsp->un1, |
2898 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
2899 | } |
2900 | ||
2901 | switch (type) { | |
2902 | case LPFC_ABORT_IOCB: | |
2903 | case LPFC_SOL_IOCB: | |
2904 | /* | |
2905 | * Idle exchange closed via ABTS from port. No iocb | |
2906 | * resources need to be recovered. | |
2907 | */ | |
2908 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2909 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2910 | "0333 IOCB cmd 0x%x" |
dca9479b | 2911 | " processed. Skipping" |
92d7f7b0 | 2912 | " completion\n", |
dca9479b | 2913 | irsp->ulpCommand); |
dea3101e JB |
2914 | break; |
2915 | } | |
2916 | ||
604a3e30 JB |
2917 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2918 | &rspiocbq); | |
0f65ff68 JS |
2919 | if (unlikely(!cmdiocbq)) |
2920 | break; | |
2921 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2922 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2923 | if (cmdiocbq->iocb_cmpl) { | |
2924 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2925 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2926 | &rspiocbq); | |
2927 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2928 | } | |
dea3101e | 2929 | break; |
a4bc3379 | 2930 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2931 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2932 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2933 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2934 | break; |
dea3101e JB |
2935 | default: |
2936 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2937 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2938 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2939 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2940 | MAX_MSG_DATA); | |
898eb71c JP |
2941 | dev_warn(&((phba->pcidev)->dev), |
2942 | "lpfc%d: %s\n", | |
dea3101e JB |
2943 | phba->brd_no, adaptermsg); |
2944 | } else { | |
2945 | /* Unknown IOCB command */ | |
2946 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2947 | "0334 Unknown IOCB command " |
92d7f7b0 | 2948 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2949 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2950 | irsp->ulpStatus, |
2951 | irsp->ulpIoTag, | |
2952 | irsp->ulpContext); | |
dea3101e JB |
2953 | } |
2954 | break; | |
2955 | } | |
2956 | ||
2957 | /* | |
2958 | * The response IOCB has been processed. Update the ring | |
2959 | * pointer in SLIM. If the port response put pointer has not | |
2960 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2961 | * response put pointer. | |
2962 | */ | |
ed957684 | 2963 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e JB |
2964 | |
2965 | if (pring->rspidx == portRspPut) | |
2966 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2967 | } | |
2968 | ||
2969 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
2970 | pring->stats.iocb_rsp_full++; | |
2971 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2972 | writel(status, phba->CAregaddr); | |
2973 | readl(phba->CAregaddr); | |
2974 | } | |
2975 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2976 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2977 | pring->stats.iocb_cmd_empty++; | |
2978 | ||
2979 | /* Force update of the local copy of cmdGetInx */ | |
2980 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2981 | lpfc_sli_resume_iocb(phba, pring); | |
2982 | ||
2983 | if ((pring->lpfc_sli_cmd_available)) | |
2984 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2985 | ||
2986 | } | |
2987 | ||
45ed1190 | 2988 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 2989 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2990 | return rc; |
2991 | } | |
2992 | ||
e59058c4 | 2993 | /** |
3772a991 JS |
2994 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
2995 | * @phba: Pointer to HBA context object. | |
2996 | * @pring: Pointer to driver SLI ring object. | |
2997 | * @rspiocbp: Pointer to driver response IOCB object. | |
2998 | * | |
2999 | * This function is called from the worker thread when there is a slow-path | |
3000 | * response IOCB to process. This function chains all the response iocbs until | |
3001 | * seeing the iocb with the LE bit set. The function will call | |
3002 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3003 | * completion of a command iocb. The function will call the | |
3004 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3005 | * The function frees the resources or calls the completion handler if this | |
3006 | * iocb is an abort completion. The function returns NULL when the response | |
3007 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3008 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3009 | * response iocb passed in. | |
3010 | **/ | |
3011 | static struct lpfc_iocbq * | |
3012 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3013 | struct lpfc_iocbq *rspiocbp) | |
3014 | { | |
3015 | struct lpfc_iocbq *saveq; | |
3016 | struct lpfc_iocbq *cmdiocbp; | |
3017 | struct lpfc_iocbq *next_iocb; | |
3018 | IOCB_t *irsp = NULL; | |
3019 | uint32_t free_saveq; | |
3020 | uint8_t iocb_cmd_type; | |
3021 | lpfc_iocb_type type; | |
3022 | unsigned long iflag; | |
3023 | int rc; | |
3024 | ||
3025 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3026 | /* First add the response iocb to the countinueq list */ | |
3027 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3028 | pring->iocb_continueq_cnt++; | |
3029 | ||
70f23fd6 | 3030 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3031 | irsp = &rspiocbp->iocb; |
3032 | if (irsp->ulpLe) { | |
3033 | /* | |
3034 | * By default, the driver expects to free all resources | |
3035 | * associated with this iocb completion. | |
3036 | */ | |
3037 | free_saveq = 1; | |
3038 | saveq = list_get_first(&pring->iocb_continueq, | |
3039 | struct lpfc_iocbq, list); | |
3040 | irsp = &(saveq->iocb); | |
3041 | list_del_init(&pring->iocb_continueq); | |
3042 | pring->iocb_continueq_cnt = 0; | |
3043 | ||
3044 | pring->stats.iocb_rsp++; | |
3045 | ||
3046 | /* | |
3047 | * If resource errors reported from HBA, reduce | |
3048 | * queuedepths of the SCSI device. | |
3049 | */ | |
3050 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3051 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3052 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3053 | phba->lpfc_rampdown_queue_depth(phba); | |
3054 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3055 | } | |
3056 | ||
3057 | if (irsp->ulpStatus) { | |
3058 | /* Rsp ring <ringno> error: IOCB */ | |
3059 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3060 | "0328 Rsp Ring %d error: " | |
3061 | "IOCB Data: " | |
3062 | "x%x x%x x%x x%x " | |
3063 | "x%x x%x x%x x%x " | |
3064 | "x%x x%x x%x x%x " | |
3065 | "x%x x%x x%x x%x\n", | |
3066 | pring->ringno, | |
3067 | irsp->un.ulpWord[0], | |
3068 | irsp->un.ulpWord[1], | |
3069 | irsp->un.ulpWord[2], | |
3070 | irsp->un.ulpWord[3], | |
3071 | irsp->un.ulpWord[4], | |
3072 | irsp->un.ulpWord[5], | |
3073 | *(((uint32_t *) irsp) + 6), | |
3074 | *(((uint32_t *) irsp) + 7), | |
3075 | *(((uint32_t *) irsp) + 8), | |
3076 | *(((uint32_t *) irsp) + 9), | |
3077 | *(((uint32_t *) irsp) + 10), | |
3078 | *(((uint32_t *) irsp) + 11), | |
3079 | *(((uint32_t *) irsp) + 12), | |
3080 | *(((uint32_t *) irsp) + 13), | |
3081 | *(((uint32_t *) irsp) + 14), | |
3082 | *(((uint32_t *) irsp) + 15)); | |
3083 | } | |
3084 | ||
3085 | /* | |
3086 | * Fetch the IOCB command type and call the correct completion | |
3087 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3088 | * get freed back to the lpfc_iocb_list by the discovery | |
3089 | * kernel thread. | |
3090 | */ | |
3091 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3092 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3093 | switch (type) { | |
3094 | case LPFC_SOL_IOCB: | |
3095 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3096 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3097 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3098 | break; | |
3099 | ||
3100 | case LPFC_UNSOL_IOCB: | |
3101 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3102 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3103 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3104 | if (!rc) | |
3105 | free_saveq = 0; | |
3106 | break; | |
3107 | ||
3108 | case LPFC_ABORT_IOCB: | |
3109 | cmdiocbp = NULL; | |
3110 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3111 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3112 | saveq); | |
3113 | if (cmdiocbp) { | |
3114 | /* Call the specified completion routine */ | |
3115 | if (cmdiocbp->iocb_cmpl) { | |
3116 | spin_unlock_irqrestore(&phba->hbalock, | |
3117 | iflag); | |
3118 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3119 | saveq); | |
3120 | spin_lock_irqsave(&phba->hbalock, | |
3121 | iflag); | |
3122 | } else | |
3123 | __lpfc_sli_release_iocbq(phba, | |
3124 | cmdiocbp); | |
3125 | } | |
3126 | break; | |
3127 | ||
3128 | case LPFC_UNKNOWN_IOCB: | |
3129 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3130 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3131 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3132 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3133 | MAX_MSG_DATA); | |
3134 | dev_warn(&((phba->pcidev)->dev), | |
3135 | "lpfc%d: %s\n", | |
3136 | phba->brd_no, adaptermsg); | |
3137 | } else { | |
3138 | /* Unknown IOCB command */ | |
3139 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3140 | "0335 Unknown IOCB " | |
3141 | "command Data: x%x " | |
3142 | "x%x x%x x%x\n", | |
3143 | irsp->ulpCommand, | |
3144 | irsp->ulpStatus, | |
3145 | irsp->ulpIoTag, | |
3146 | irsp->ulpContext); | |
3147 | } | |
3148 | break; | |
3149 | } | |
3150 | ||
3151 | if (free_saveq) { | |
3152 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3153 | &saveq->list, list) { | |
3154 | list_del(&rspiocbp->list); | |
3155 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3156 | } | |
3157 | __lpfc_sli_release_iocbq(phba, saveq); | |
3158 | } | |
3159 | rspiocbp = NULL; | |
3160 | } | |
3161 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3162 | return rspiocbp; | |
3163 | } | |
3164 | ||
3165 | /** | |
3166 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3167 | * @phba: Pointer to HBA context object. |
3168 | * @pring: Pointer to driver SLI ring object. | |
3169 | * @mask: Host attention register mask for this ring. | |
3170 | * | |
3772a991 JS |
3171 | * This routine wraps the actual slow_ring event process routine from the |
3172 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3173 | **/ |
3772a991 | 3174 | void |
2e0fef85 JS |
3175 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3176 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3177 | { |
3178 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3179 | } | |
3180 | ||
3181 | /** | |
3182 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3183 | * @phba: Pointer to HBA context object. | |
3184 | * @pring: Pointer to driver SLI ring object. | |
3185 | * @mask: Host attention register mask for this ring. | |
3186 | * | |
3187 | * This function is called from the worker thread when there is a ring event | |
3188 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3189 | * remove each response iocb in the response ring and calls the handle | |
3190 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3191 | **/ | |
3192 | static void | |
3193 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3194 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3195 | { |
34b02dcd | 3196 | struct lpfc_pgp *pgp; |
dea3101e JB |
3197 | IOCB_t *entry; |
3198 | IOCB_t *irsp = NULL; | |
3199 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3200 | uint32_t portRspPut, portRspMax; |
dea3101e | 3201 | unsigned long iflag; |
3772a991 | 3202 | uint32_t status; |
dea3101e | 3203 | |
34b02dcd | 3204 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3205 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3206 | pring->stats.iocb_event++; |
3207 | ||
dea3101e JB |
3208 | /* |
3209 | * The next available response entry should never exceed the maximum | |
3210 | * entries. If it does, treat it as an adapter hardware error. | |
3211 | */ | |
3212 | portRspMax = pring->numRiocb; | |
3213 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3214 | if (portRspPut >= portRspMax) { | |
3215 | /* | |
025dfdaf | 3216 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
3217 | * rsp ring <portRspMax> |
3218 | */ | |
ed957684 | 3219 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3220 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3221 | "is bigger than rsp ring %d\n", |
e8b62011 | 3222 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3223 | |
2e0fef85 JS |
3224 | phba->link_state = LPFC_HBA_ERROR; |
3225 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
3226 | |
3227 | phba->work_hs = HS_FFER3; | |
3228 | lpfc_handle_eratt(phba); | |
3229 | ||
3772a991 | 3230 | return; |
dea3101e JB |
3231 | } |
3232 | ||
3233 | rmb(); | |
dea3101e JB |
3234 | while (pring->rspidx != portRspPut) { |
3235 | /* | |
3236 | * Build a completion list and call the appropriate handler. | |
3237 | * The process is to get the next available response iocb, get | |
3238 | * a free iocb from the list, copy the response data into the | |
3239 | * free iocb, insert to the continuation list, and update the | |
3240 | * next response index to slim. This process makes response | |
3241 | * iocb's in the ring available to DMA as fast as possible but | |
3242 | * pays a penalty for a copy operation. Since the iocb is | |
3243 | * only 32 bytes, this penalty is considered small relative to | |
3244 | * the PCI reads for register values and a slim write. When | |
3245 | * the ulpLe field is set, the entire Command has been | |
3246 | * received. | |
3247 | */ | |
ed957684 JS |
3248 | entry = lpfc_resp_iocb(phba, pring); |
3249 | ||
858c9f6c | 3250 | phba->last_completion_time = jiffies; |
2e0fef85 | 3251 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
3252 | if (rspiocbp == NULL) { |
3253 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3254 | "completion.\n", __func__); |
dea3101e JB |
3255 | break; |
3256 | } | |
3257 | ||
ed957684 JS |
3258 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3259 | phba->iocb_rsp_size); | |
dea3101e JB |
3260 | irsp = &rspiocbp->iocb; |
3261 | ||
3262 | if (++pring->rspidx >= portRspMax) | |
3263 | pring->rspidx = 0; | |
3264 | ||
a58cbd52 JS |
3265 | if (pring->ringno == LPFC_ELS_RING) { |
3266 | lpfc_debugfs_slow_ring_trc(phba, | |
3267 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3268 | *(((uint32_t *) irsp) + 4), | |
3269 | *(((uint32_t *) irsp) + 6), | |
3270 | *(((uint32_t *) irsp) + 7)); | |
3271 | } | |
3272 | ||
ed957684 | 3273 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 3274 | |
3772a991 JS |
3275 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3276 | /* Handle the response IOCB */ | |
3277 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3278 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
3279 | |
3280 | /* | |
3281 | * If the port response put pointer has not been updated, sync | |
3282 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3283 | * response put pointer. | |
3284 | */ | |
3285 | if (pring->rspidx == portRspPut) { | |
3286 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3287 | } | |
3288 | } /* while (pring->rspidx != portRspPut) */ | |
3289 | ||
92d7f7b0 | 3290 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
3291 | /* At least one response entry has been freed */ |
3292 | pring->stats.iocb_rsp_full++; | |
3293 | /* SET RxRE_RSP in Chip Att register */ | |
3294 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3295 | writel(status, phba->CAregaddr); | |
3296 | readl(phba->CAregaddr); /* flush */ | |
3297 | } | |
3298 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3299 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3300 | pring->stats.iocb_cmd_empty++; | |
3301 | ||
3302 | /* Force update of the local copy of cmdGetInx */ | |
3303 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3304 | lpfc_sli_resume_iocb(phba, pring); | |
3305 | ||
3306 | if ((pring->lpfc_sli_cmd_available)) | |
3307 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3308 | ||
3309 | } | |
3310 | ||
2e0fef85 | 3311 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3312 | return; |
dea3101e JB |
3313 | } |
3314 | ||
4f774513 JS |
3315 | /** |
3316 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3317 | * @phba: Pointer to HBA context object. | |
3318 | * @pring: Pointer to driver SLI ring object. | |
3319 | * @mask: Host attention register mask for this ring. | |
3320 | * | |
3321 | * This function is called from the worker thread when there is a pending | |
3322 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3323 | * queue. The caller does not hold any lock. The function will remove each | |
3324 | * response iocb from the response worker queue and calls the handle | |
3325 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3326 | **/ | |
3327 | static void | |
3328 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3329 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3330 | { | |
3331 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3332 | struct hbq_dmabuf *dmabuf; |
3333 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3334 | unsigned long iflag; |
3335 | ||
45ed1190 JS |
3336 | spin_lock_irqsave(&phba->hbalock, iflag); |
3337 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3338 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3339 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3340 | /* Get the response iocb from the head of work queue */ |
3341 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3342 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3343 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3344 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3345 | |
3346 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3347 | case CQE_CODE_COMPL_WQE: | |
3348 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3349 | cq_event); | |
45ed1190 JS |
3350 | /* Translate ELS WCQE to response IOCBQ */ |
3351 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3352 | irspiocbq); | |
3353 | if (irspiocbq) | |
3354 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3355 | irspiocbq); | |
4d9ab994 JS |
3356 | break; |
3357 | case CQE_CODE_RECEIVE: | |
3358 | dmabuf = container_of(cq_event, struct hbq_dmabuf, | |
3359 | cq_event); | |
3360 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3361 | break; | |
3362 | default: | |
3363 | break; | |
3364 | } | |
4f774513 JS |
3365 | } |
3366 | } | |
3367 | ||
e59058c4 | 3368 | /** |
3621a710 | 3369 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3370 | * @phba: Pointer to HBA context object. |
3371 | * @pring: Pointer to driver SLI ring object. | |
3372 | * | |
3373 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3374 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3375 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3376 | * the return of this function. The caller is not required to hold any locks. | |
3377 | **/ | |
2e0fef85 | 3378 | void |
dea3101e JB |
3379 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3380 | { | |
2534ba75 | 3381 | LIST_HEAD(completions); |
dea3101e | 3382 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3383 | |
92d7f7b0 JS |
3384 | if (pring->ringno == LPFC_ELS_RING) { |
3385 | lpfc_fabric_abort_hba(phba); | |
3386 | } | |
3387 | ||
dea3101e JB |
3388 | /* Error everything on txq and txcmplq |
3389 | * First do the txq. | |
3390 | */ | |
2e0fef85 | 3391 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3392 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3393 | pring->txq_cnt = 0; |
dea3101e JB |
3394 | |
3395 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3396 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3397 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3398 | |
2e0fef85 | 3399 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3400 | |
a257bf90 JS |
3401 | /* Cancel all the IOCBs from the completions list */ |
3402 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3403 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3404 | } |
3405 | ||
a8e497d5 | 3406 | /** |
3621a710 | 3407 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3408 | * @phba: Pointer to HBA context object. |
3409 | * | |
3410 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3411 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3412 | * for all the iocb commands in txcmplq, they will just be returned with | |
3413 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3414 | * slot has been permanently disabled. | |
3415 | **/ | |
3416 | void | |
3417 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3418 | { | |
3419 | LIST_HEAD(txq); | |
3420 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3421 | struct lpfc_sli *psli = &phba->sli; |
3422 | struct lpfc_sli_ring *pring; | |
3423 | ||
3424 | /* Currently, only one fcp ring */ | |
3425 | pring = &psli->ring[psli->fcp_ring]; | |
3426 | ||
3427 | spin_lock_irq(&phba->hbalock); | |
3428 | /* Retrieve everything on txq */ | |
3429 | list_splice_init(&pring->txq, &txq); | |
3430 | pring->txq_cnt = 0; | |
3431 | ||
3432 | /* Retrieve everything on the txcmplq */ | |
3433 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3434 | pring->txcmplq_cnt = 0; | |
3435 | spin_unlock_irq(&phba->hbalock); | |
3436 | ||
3437 | /* Flush the txq */ | |
a257bf90 JS |
3438 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3439 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3440 | |
3441 | /* Flush the txcmpq */ | |
a257bf90 JS |
3442 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3443 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3444 | } |
3445 | ||
e59058c4 | 3446 | /** |
3772a991 | 3447 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3448 | * @phba: Pointer to HBA context object. |
3449 | * @mask: Bit mask to be checked. | |
3450 | * | |
3451 | * This function reads the host status register and compares | |
3452 | * with the provided bit mask to check if HBA completed | |
3453 | * the restart. This function will wait in a loop for the | |
3454 | * HBA to complete restart. If the HBA does not restart within | |
3455 | * 15 iterations, the function will reset the HBA again. The | |
3456 | * function returns 1 when HBA fail to restart otherwise returns | |
3457 | * zero. | |
3458 | **/ | |
3772a991 JS |
3459 | static int |
3460 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3461 | { |
41415862 JW |
3462 | uint32_t status; |
3463 | int i = 0; | |
3464 | int retval = 0; | |
dea3101e | 3465 | |
41415862 | 3466 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3467 | if (lpfc_readl(phba->HSregaddr, &status)) |
3468 | return 1; | |
dea3101e | 3469 | |
41415862 JW |
3470 | /* |
3471 | * Check status register every 100ms for 5 retries, then every | |
3472 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3473 | * every 2.5 sec for 4. | |
3474 | * Break our of the loop if errors occurred during init. | |
3475 | */ | |
3476 | while (((status & mask) != mask) && | |
3477 | !(status & HS_FFERM) && | |
3478 | i++ < 20) { | |
dea3101e | 3479 | |
41415862 JW |
3480 | if (i <= 5) |
3481 | msleep(10); | |
3482 | else if (i <= 10) | |
3483 | msleep(500); | |
3484 | else | |
3485 | msleep(2500); | |
dea3101e | 3486 | |
41415862 | 3487 | if (i == 15) { |
2e0fef85 | 3488 | /* Do post */ |
92d7f7b0 | 3489 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3490 | lpfc_sli_brdrestart(phba); |
3491 | } | |
3492 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3493 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3494 | retval = 1; | |
3495 | break; | |
3496 | } | |
41415862 | 3497 | } |
dea3101e | 3498 | |
41415862 JW |
3499 | /* Check to see if any errors occurred during init */ |
3500 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3502 | "2751 Adapter failed to restart, " | |
3503 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3504 | status, | |
3505 | readl(phba->MBslimaddr + 0xa8), | |
3506 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3507 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3508 | retval = 1; |
dea3101e | 3509 | } |
dea3101e | 3510 | |
41415862 JW |
3511 | return retval; |
3512 | } | |
dea3101e | 3513 | |
da0436e9 JS |
3514 | /** |
3515 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3516 | * @phba: Pointer to HBA context object. | |
3517 | * @mask: Bit mask to be checked. | |
3518 | * | |
3519 | * This function checks the host status register to check if HBA is | |
3520 | * ready. This function will wait in a loop for the HBA to be ready | |
3521 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3522 | * function again. The function returns 1 when HBA fail to be ready | |
3523 | * otherwise returns zero. | |
3524 | **/ | |
3525 | static int | |
3526 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3527 | { | |
3528 | uint32_t status; | |
3529 | int retval = 0; | |
3530 | ||
3531 | /* Read the HBA Host Status Register */ | |
3532 | status = lpfc_sli4_post_status_check(phba); | |
3533 | ||
3534 | if (status) { | |
3535 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3536 | lpfc_sli_brdrestart(phba); | |
3537 | status = lpfc_sli4_post_status_check(phba); | |
3538 | } | |
3539 | ||
3540 | /* Check to see if any errors occurred during init */ | |
3541 | if (status) { | |
3542 | phba->link_state = LPFC_HBA_ERROR; | |
3543 | retval = 1; | |
3544 | } else | |
3545 | phba->sli4_hba.intr_enable = 0; | |
3546 | ||
3547 | return retval; | |
3548 | } | |
3549 | ||
3550 | /** | |
3551 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3552 | * @phba: Pointer to HBA context object. | |
3553 | * @mask: Bit mask to be checked. | |
3554 | * | |
3555 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3556 | * from the API jump table function pointer from the lpfc_hba struct. | |
3557 | **/ | |
3558 | int | |
3559 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3560 | { | |
3561 | return phba->lpfc_sli_brdready(phba, mask); | |
3562 | } | |
3563 | ||
9290831f JS |
3564 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3565 | ||
e59058c4 | 3566 | /** |
3621a710 | 3567 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3568 | * @phba: Pointer to HBA context object. |
3569 | * | |
3570 | * This function is called before resetting an HBA. This | |
3571 | * function requests HBA to quiesce DMAs before a reset. | |
3572 | **/ | |
2e0fef85 | 3573 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3574 | { |
65a29c16 JS |
3575 | uint32_t __iomem *resp_buf; |
3576 | uint32_t __iomem *mbox_buf; | |
9290831f | 3577 | volatile uint32_t mbox; |
9940b97b | 3578 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3579 | int i; |
3580 | uint8_t hdrtype; | |
3581 | ||
3582 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3583 | if (hdrtype != 0x80 || | |
3584 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3585 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3586 | return; | |
3587 | ||
3588 | /* | |
3589 | * Tell the other part of the chip to suspend temporarily all | |
3590 | * its DMA activity. | |
3591 | */ | |
65a29c16 | 3592 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3593 | |
3594 | /* Disable the error attention */ | |
9940b97b JS |
3595 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3596 | return; | |
9290831f JS |
3597 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3598 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3599 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3600 | |
9940b97b JS |
3601 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3602 | return; | |
3603 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3604 | /* Clear Chip error bit */ |
3605 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3606 | phba->pport->stopped = 1; |
9290831f JS |
3607 | } |
3608 | ||
3609 | mbox = 0; | |
3610 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3611 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3612 | ||
3613 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3614 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3615 | writel(mbox, mbox_buf); |
3616 | ||
9940b97b JS |
3617 | for (i = 0; i < 50; i++) { |
3618 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3619 | return; | |
3620 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3621 | mdelay(1); | |
3622 | else | |
3623 | break; | |
3624 | } | |
3625 | resp_data = 0; | |
3626 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3627 | return; | |
3628 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3629 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3630 | phba->pport->stopped) |
9290831f JS |
3631 | goto restore_hc; |
3632 | else | |
3633 | goto clear_errat; | |
3634 | } | |
3635 | ||
3636 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3637 | resp_data = 0; |
3638 | for (i = 0; i < 500; i++) { | |
3639 | if (lpfc_readl(resp_buf, &resp_data)) | |
3640 | return; | |
3641 | if (resp_data != mbox) | |
3642 | mdelay(1); | |
3643 | else | |
3644 | break; | |
3645 | } | |
9290831f JS |
3646 | |
3647 | clear_errat: | |
3648 | ||
9940b97b JS |
3649 | while (++i < 500) { |
3650 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3651 | return; | |
3652 | if (!(ha_copy & HA_ERATT)) | |
3653 | mdelay(1); | |
3654 | else | |
3655 | break; | |
3656 | } | |
9290831f JS |
3657 | |
3658 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3659 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3660 | phba->pport->stopped = 1; |
9290831f JS |
3661 | } |
3662 | ||
3663 | restore_hc: | |
2e0fef85 | 3664 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3665 | writel(hc_copy, phba->HCregaddr); |
3666 | readl(phba->HCregaddr); /* flush */ | |
3667 | } | |
3668 | ||
e59058c4 | 3669 | /** |
3621a710 | 3670 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3671 | * @phba: Pointer to HBA context object. |
3672 | * | |
3673 | * This function issues a kill_board mailbox command and waits for | |
3674 | * the error attention interrupt. This function is called for stopping | |
3675 | * the firmware processing. The caller is not required to hold any | |
3676 | * locks. This function calls lpfc_hba_down_post function to free | |
3677 | * any pending commands after the kill. The function will return 1 when it | |
3678 | * fails to kill the board else will return 0. | |
3679 | **/ | |
41415862 | 3680 | int |
2e0fef85 | 3681 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3682 | { |
3683 | struct lpfc_sli *psli; | |
3684 | LPFC_MBOXQ_t *pmb; | |
3685 | uint32_t status; | |
3686 | uint32_t ha_copy; | |
3687 | int retval; | |
3688 | int i = 0; | |
dea3101e | 3689 | |
41415862 | 3690 | psli = &phba->sli; |
dea3101e | 3691 | |
41415862 | 3692 | /* Kill HBA */ |
ed957684 | 3693 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3694 | "0329 Kill HBA Data: x%x x%x\n", |
3695 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3696 | |
98c9ea5c JS |
3697 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3698 | if (!pmb) | |
41415862 | 3699 | return 1; |
41415862 JW |
3700 | |
3701 | /* Disable the error attention */ | |
2e0fef85 | 3702 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3703 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3704 | spin_unlock_irq(&phba->hbalock); | |
3705 | mempool_free(pmb, phba->mbox_mem_pool); | |
3706 | return 1; | |
3707 | } | |
41415862 JW |
3708 | status &= ~HC_ERINT_ENA; |
3709 | writel(status, phba->HCregaddr); | |
3710 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3711 | phba->link_flag |= LS_IGNORE_ERATT; |
3712 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3713 | |
3714 | lpfc_kill_board(phba, pmb); | |
3715 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3716 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3717 | ||
3718 | if (retval != MBX_SUCCESS) { | |
3719 | if (retval != MBX_BUSY) | |
3720 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3721 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3722 | "2752 KILL_BOARD command failed retval %d\n", | |
3723 | retval); | |
2e0fef85 JS |
3724 | spin_lock_irq(&phba->hbalock); |
3725 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3726 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3727 | return 1; |
3728 | } | |
3729 | ||
f4b4c68f JS |
3730 | spin_lock_irq(&phba->hbalock); |
3731 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3732 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3733 | |
41415862 JW |
3734 | mempool_free(pmb, phba->mbox_mem_pool); |
3735 | ||
3736 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3737 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3738 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3739 | * board is now undefined. | |
3740 | */ | |
9940b97b JS |
3741 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3742 | return 1; | |
41415862 JW |
3743 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3744 | mdelay(100); | |
9940b97b JS |
3745 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3746 | return 1; | |
41415862 JW |
3747 | } |
3748 | ||
3749 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3750 | if (ha_copy & HA_ERATT) { |
3751 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3752 | phba->pport->stopped = 1; |
9290831f | 3753 | } |
2e0fef85 | 3754 | spin_lock_irq(&phba->hbalock); |
41415862 | 3755 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3756 | psli->mbox_active = NULL; |
2e0fef85 JS |
3757 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3758 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3759 | |
41415862 | 3760 | lpfc_hba_down_post(phba); |
2e0fef85 | 3761 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3762 | |
2e0fef85 | 3763 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
3764 | } |
3765 | ||
e59058c4 | 3766 | /** |
3772a991 | 3767 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3768 | * @phba: Pointer to HBA context object. |
3769 | * | |
3770 | * This function resets the HBA by writing HC_INITFF to the control | |
3771 | * register. After the HBA resets, this function resets all the iocb ring | |
3772 | * indices. This function disables PCI layer parity checking during | |
3773 | * the reset. | |
3774 | * This function returns 0 always. | |
3775 | * The caller is not required to hold any locks. | |
3776 | **/ | |
41415862 | 3777 | int |
2e0fef85 | 3778 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3779 | { |
41415862 | 3780 | struct lpfc_sli *psli; |
dea3101e | 3781 | struct lpfc_sli_ring *pring; |
41415862 | 3782 | uint16_t cfg_value; |
dea3101e | 3783 | int i; |
dea3101e | 3784 | |
41415862 | 3785 | psli = &phba->sli; |
dea3101e | 3786 | |
41415862 JW |
3787 | /* Reset HBA */ |
3788 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3789 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3790 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
3791 | |
3792 | /* perform board reset */ | |
3793 | phba->fc_eventTag = 0; | |
4d9ab994 | 3794 | phba->link_events = 0; |
2e0fef85 JS |
3795 | phba->pport->fc_myDID = 0; |
3796 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3797 | |
41415862 JW |
3798 | /* Turn off parity checking and serr during the physical reset */ |
3799 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3800 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3801 | (cfg_value & | |
3802 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3803 | ||
3772a991 JS |
3804 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3805 | ||
41415862 JW |
3806 | /* Now toggle INITFF bit in the Host Control Register */ |
3807 | writel(HC_INITFF, phba->HCregaddr); | |
3808 | mdelay(1); | |
3809 | readl(phba->HCregaddr); /* flush */ | |
3810 | writel(0, phba->HCregaddr); | |
3811 | readl(phba->HCregaddr); /* flush */ | |
3812 | ||
3813 | /* Restore PCI cmd register */ | |
3814 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
3815 | |
3816 | /* Initialize relevant SLI info */ | |
41415862 JW |
3817 | for (i = 0; i < psli->num_rings; i++) { |
3818 | pring = &psli->ring[i]; | |
dea3101e JB |
3819 | pring->flag = 0; |
3820 | pring->rspidx = 0; | |
3821 | pring->next_cmdidx = 0; | |
3822 | pring->local_getidx = 0; | |
3823 | pring->cmdidx = 0; | |
3824 | pring->missbufcnt = 0; | |
3825 | } | |
dea3101e | 3826 | |
2e0fef85 | 3827 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3828 | return 0; |
3829 | } | |
3830 | ||
e59058c4 | 3831 | /** |
da0436e9 JS |
3832 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3833 | * @phba: Pointer to HBA context object. | |
3834 | * | |
3835 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3836 | * checking during resets the device. The caller is not required to hold | |
3837 | * any locks. | |
3838 | * | |
3839 | * This function returns 0 always. | |
3840 | **/ | |
3841 | int | |
3842 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3843 | { | |
3844 | struct lpfc_sli *psli = &phba->sli; | |
3845 | uint16_t cfg_value; | |
3846 | uint8_t qindx; | |
3847 | ||
3848 | /* Reset HBA */ | |
3849 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3850 | "0295 Reset HBA Data: x%x x%x\n", | |
3851 | phba->pport->port_state, psli->sli_flag); | |
3852 | ||
3853 | /* perform board reset */ | |
3854 | phba->fc_eventTag = 0; | |
4d9ab994 | 3855 | phba->link_events = 0; |
da0436e9 JS |
3856 | phba->pport->fc_myDID = 0; |
3857 | phba->pport->fc_prevDID = 0; | |
3858 | ||
da0436e9 JS |
3859 | spin_lock_irq(&phba->hbalock); |
3860 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3861 | phba->fcf.fcf_flag = 0; | |
3862 | /* Clean up the child queue list for the CQs */ | |
3863 | list_del_init(&phba->sli4_hba.mbx_wq->list); | |
3864 | list_del_init(&phba->sli4_hba.els_wq->list); | |
3865 | list_del_init(&phba->sli4_hba.hdr_rq->list); | |
3866 | list_del_init(&phba->sli4_hba.dat_rq->list); | |
3867 | list_del_init(&phba->sli4_hba.mbx_cq->list); | |
3868 | list_del_init(&phba->sli4_hba.els_cq->list); | |
da0436e9 JS |
3869 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
3870 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | |
0558056c JS |
3871 | qindx = 0; |
3872 | do | |
da0436e9 | 3873 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); |
0558056c | 3874 | while (++qindx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
3875 | spin_unlock_irq(&phba->hbalock); |
3876 | ||
3877 | /* Now physically reset the device */ | |
3878 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3879 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
3880 | |
3881 | /* Turn off parity checking and serr during the physical reset */ | |
3882 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3883 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
3884 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3885 | ||
da0436e9 JS |
3886 | /* Perform FCoE PCI function reset */ |
3887 | lpfc_pci_function_reset(phba); | |
3888 | ||
be858b65 JS |
3889 | /* Restore PCI cmd register */ |
3890 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
3891 | ||
da0436e9 JS |
3892 | return 0; |
3893 | } | |
3894 | ||
3895 | /** | |
3896 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3897 | * @phba: Pointer to HBA context object. |
3898 | * | |
3899 | * This function is called in the SLI initialization code path to | |
3900 | * restart the HBA. The caller is not required to hold any lock. | |
3901 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3902 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3903 | * function to free any pending commands. The function enables | |
3904 | * POST only during the first initialization. The function returns zero. | |
3905 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3906 | * command before the return of this function. | |
3907 | **/ | |
da0436e9 JS |
3908 | static int |
3909 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3910 | { |
3911 | MAILBOX_t *mb; | |
3912 | struct lpfc_sli *psli; | |
41415862 JW |
3913 | volatile uint32_t word0; |
3914 | void __iomem *to_slim; | |
0d878419 | 3915 | uint32_t hba_aer_enabled; |
41415862 | 3916 | |
2e0fef85 | 3917 | spin_lock_irq(&phba->hbalock); |
41415862 | 3918 | |
0d878419 JS |
3919 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3920 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3921 | ||
41415862 JW |
3922 | psli = &phba->sli; |
3923 | ||
3924 | /* Restart HBA */ | |
3925 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3926 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3927 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3928 | |
3929 | word0 = 0; | |
3930 | mb = (MAILBOX_t *) &word0; | |
3931 | mb->mbxCommand = MBX_RESTART; | |
3932 | mb->mbxHc = 1; | |
3933 | ||
9290831f JS |
3934 | lpfc_reset_barrier(phba); |
3935 | ||
41415862 JW |
3936 | to_slim = phba->MBslimaddr; |
3937 | writel(*(uint32_t *) mb, to_slim); | |
3938 | readl(to_slim); /* flush */ | |
3939 | ||
3940 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3941 | if (phba->pport->port_state) |
41415862 | 3942 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 3943 | else |
41415862 | 3944 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 3945 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
3946 | writel(*(uint32_t *) mb, to_slim); |
3947 | readl(to_slim); /* flush */ | |
dea3101e | 3948 | |
41415862 | 3949 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
3950 | phba->pport->stopped = 0; |
3951 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 3952 | phba->hba_flag = 0; |
2e0fef85 | 3953 | spin_unlock_irq(&phba->hbalock); |
41415862 | 3954 | |
64ba8818 JS |
3955 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
3956 | psli->stats_start = get_seconds(); | |
3957 | ||
eaf15d5b JS |
3958 | /* Give the INITFF and Post time to settle. */ |
3959 | mdelay(100); | |
41415862 | 3960 | |
0d878419 JS |
3961 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3962 | if (hba_aer_enabled) | |
3963 | pci_disable_pcie_error_reporting(phba->pcidev); | |
3964 | ||
41415862 | 3965 | lpfc_hba_down_post(phba); |
dea3101e JB |
3966 | |
3967 | return 0; | |
3968 | } | |
3969 | ||
da0436e9 JS |
3970 | /** |
3971 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
3972 | * @phba: Pointer to HBA context object. | |
3973 | * | |
3974 | * This function is called in the SLI initialization code path to restart | |
3975 | * a SLI4 HBA. The caller is not required to hold any lock. | |
3976 | * At the end of the function, it calls lpfc_hba_down_post function to | |
3977 | * free any pending commands. | |
3978 | **/ | |
3979 | static int | |
3980 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
3981 | { | |
3982 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 3983 | uint32_t hba_aer_enabled; |
da0436e9 JS |
3984 | |
3985 | /* Restart HBA */ | |
3986 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3987 | "0296 Restart HBA Data: x%x x%x\n", | |
3988 | phba->pport->port_state, psli->sli_flag); | |
3989 | ||
75baf696 JS |
3990 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3991 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3992 | ||
da0436e9 JS |
3993 | lpfc_sli4_brdreset(phba); |
3994 | ||
3995 | spin_lock_irq(&phba->hbalock); | |
3996 | phba->pport->stopped = 0; | |
3997 | phba->link_state = LPFC_INIT_START; | |
3998 | phba->hba_flag = 0; | |
3999 | spin_unlock_irq(&phba->hbalock); | |
4000 | ||
4001 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4002 | psli->stats_start = get_seconds(); | |
4003 | ||
75baf696 JS |
4004 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4005 | if (hba_aer_enabled) | |
4006 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4007 | ||
da0436e9 JS |
4008 | lpfc_hba_down_post(phba); |
4009 | ||
4010 | return 0; | |
4011 | } | |
4012 | ||
4013 | /** | |
4014 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4015 | * @phba: Pointer to HBA context object. | |
4016 | * | |
4017 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4018 | * API jump table function pointer from the lpfc_hba struct. | |
4019 | **/ | |
4020 | int | |
4021 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4022 | { | |
4023 | return phba->lpfc_sli_brdrestart(phba); | |
4024 | } | |
4025 | ||
e59058c4 | 4026 | /** |
3621a710 | 4027 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4028 | * @phba: Pointer to HBA context object. |
4029 | * | |
4030 | * This function is called after a HBA restart to wait for successful | |
4031 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4032 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4033 | * iteration, the function will restart the HBA again. The function returns | |
4034 | * zero if HBA successfully restarted else returns negative error code. | |
4035 | **/ | |
dea3101e JB |
4036 | static int |
4037 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4038 | { | |
4039 | uint32_t status, i = 0; | |
4040 | ||
4041 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4042 | if (lpfc_readl(phba->HSregaddr, &status)) |
4043 | return -EIO; | |
dea3101e JB |
4044 | |
4045 | /* Check status register to see what current state is */ | |
4046 | i = 0; | |
4047 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4048 | ||
dcf2a4e0 JS |
4049 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4050 | * retries, then every 1 sec for 50 retires for a total of | |
4051 | * ~60 seconds before reset the board again and check every | |
4052 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4053 | * board ready is required by the Falcon FIPS zeroization | |
4054 | * complete, and any reset the board in between shall cause | |
4055 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4056 | */ |
dcf2a4e0 | 4057 | if (i++ >= 200) { |
dea3101e JB |
4058 | /* Adapter failed to init, timeout, status reg |
4059 | <status> */ | |
ed957684 | 4060 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4061 | "0436 Adapter failed to init, " |
09372820 JS |
4062 | "timeout, status reg x%x, " |
4063 | "FW Data: A8 x%x AC x%x\n", status, | |
4064 | readl(phba->MBslimaddr + 0xa8), | |
4065 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4066 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4067 | return -ETIMEDOUT; |
4068 | } | |
4069 | ||
4070 | /* Check to see if any errors occurred during init */ | |
4071 | if (status & HS_FFERM) { | |
4072 | /* ERROR: During chipset initialization */ | |
4073 | /* Adapter failed to init, chipset, status reg | |
4074 | <status> */ | |
ed957684 | 4075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4076 | "0437 Adapter failed to init, " |
09372820 JS |
4077 | "chipset, status reg x%x, " |
4078 | "FW Data: A8 x%x AC x%x\n", status, | |
4079 | readl(phba->MBslimaddr + 0xa8), | |
4080 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4081 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4082 | return -EIO; |
4083 | } | |
4084 | ||
dcf2a4e0 | 4085 | if (i <= 10) |
dea3101e | 4086 | msleep(10); |
dcf2a4e0 JS |
4087 | else if (i <= 100) |
4088 | msleep(100); | |
4089 | else | |
4090 | msleep(1000); | |
dea3101e | 4091 | |
dcf2a4e0 JS |
4092 | if (i == 150) { |
4093 | /* Do post */ | |
92d7f7b0 | 4094 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4095 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4096 | } |
4097 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4098 | if (lpfc_readl(phba->HSregaddr, &status)) |
4099 | return -EIO; | |
dea3101e JB |
4100 | } |
4101 | ||
4102 | /* Check to see if any errors occurred during init */ | |
4103 | if (status & HS_FFERM) { | |
4104 | /* ERROR: During chipset initialization */ | |
4105 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4106 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4107 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4108 | "status reg x%x, " |
4109 | "FW Data: A8 x%x AC x%x\n", status, | |
4110 | readl(phba->MBslimaddr + 0xa8), | |
4111 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4112 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4113 | return -EIO; |
4114 | } | |
4115 | ||
4116 | /* Clear all interrupt enable conditions */ | |
4117 | writel(0, phba->HCregaddr); | |
4118 | readl(phba->HCregaddr); /* flush */ | |
4119 | ||
4120 | /* setup host attn register */ | |
4121 | writel(0xffffffff, phba->HAregaddr); | |
4122 | readl(phba->HAregaddr); /* flush */ | |
4123 | return 0; | |
4124 | } | |
4125 | ||
e59058c4 | 4126 | /** |
3621a710 | 4127 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4128 | * |
4129 | * This function calculates and returns the number of HBQs required to be | |
4130 | * configured. | |
4131 | **/ | |
78b2d852 | 4132 | int |
ed957684 JS |
4133 | lpfc_sli_hbq_count(void) |
4134 | { | |
92d7f7b0 | 4135 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4136 | } |
4137 | ||
e59058c4 | 4138 | /** |
3621a710 | 4139 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4140 | * |
4141 | * This function adds the number of hbq entries in every HBQ to get | |
4142 | * the total number of hbq entries required for the HBA and returns | |
4143 | * the total count. | |
4144 | **/ | |
ed957684 JS |
4145 | static int |
4146 | lpfc_sli_hbq_entry_count(void) | |
4147 | { | |
4148 | int hbq_count = lpfc_sli_hbq_count(); | |
4149 | int count = 0; | |
4150 | int i; | |
4151 | ||
4152 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4153 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4154 | return count; |
4155 | } | |
4156 | ||
e59058c4 | 4157 | /** |
3621a710 | 4158 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4159 | * |
4160 | * This function calculates amount of memory required for all hbq entries | |
4161 | * to be configured and returns the total memory required. | |
4162 | **/ | |
dea3101e | 4163 | int |
ed957684 JS |
4164 | lpfc_sli_hbq_size(void) |
4165 | { | |
4166 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4167 | } | |
4168 | ||
e59058c4 | 4169 | /** |
3621a710 | 4170 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4171 | * @phba: Pointer to HBA context object. |
4172 | * | |
4173 | * This function is called during the SLI initialization to configure | |
4174 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4175 | * required to hold any locks. This function will return zero if successful | |
4176 | * else it will return negative error code. | |
4177 | **/ | |
ed957684 JS |
4178 | static int |
4179 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4180 | { | |
4181 | int hbq_count = lpfc_sli_hbq_count(); | |
4182 | LPFC_MBOXQ_t *pmb; | |
4183 | MAILBOX_t *pmbox; | |
4184 | uint32_t hbqno; | |
4185 | uint32_t hbq_entry_index; | |
ed957684 | 4186 | |
92d7f7b0 JS |
4187 | /* Get a Mailbox buffer to setup mailbox |
4188 | * commands for HBA initialization | |
4189 | */ | |
ed957684 JS |
4190 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4191 | ||
4192 | if (!pmb) | |
4193 | return -ENOMEM; | |
4194 | ||
04c68496 | 4195 | pmbox = &pmb->u.mb; |
ed957684 JS |
4196 | |
4197 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4198 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4199 | phba->hbq_in_use = 1; |
ed957684 JS |
4200 | |
4201 | hbq_entry_index = 0; | |
4202 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4203 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4204 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4205 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4206 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4207 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4208 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4209 | hbq_entry_index, pmb); | |
ed957684 JS |
4210 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4211 | ||
4212 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4213 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4214 | mbxStatus <status>, ring <num> */ | |
4215 | ||
4216 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4217 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4218 | "1805 Adapter failed to init. " |
ed957684 | 4219 | "Data: x%x x%x x%x\n", |
e8b62011 | 4220 | pmbox->mbxCommand, |
ed957684 JS |
4221 | pmbox->mbxStatus, hbqno); |
4222 | ||
4223 | phba->link_state = LPFC_HBA_ERROR; | |
4224 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4225 | return -ENXIO; |
ed957684 JS |
4226 | } |
4227 | } | |
4228 | phba->hbq_count = hbq_count; | |
4229 | ||
ed957684 JS |
4230 | mempool_free(pmb, phba->mbox_mem_pool); |
4231 | ||
92d7f7b0 | 4232 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4233 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4234 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4235 | return 0; |
4236 | } | |
4237 | ||
4f774513 JS |
4238 | /** |
4239 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4240 | * @phba: Pointer to HBA context object. | |
4241 | * | |
4242 | * This function is called during the SLI initialization to configure | |
4243 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4244 | * required to hold any locks. This function will return zero if successful | |
4245 | * else it will return negative error code. | |
4246 | **/ | |
4247 | static int | |
4248 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4249 | { | |
4250 | phba->hbq_in_use = 1; | |
4251 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4252 | phba->hbq_count = 1; | |
4253 | /* Initially populate or replenish the HBQs */ | |
4254 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4255 | return 0; | |
4256 | } | |
4257 | ||
e59058c4 | 4258 | /** |
3621a710 | 4259 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4260 | * @phba: Pointer to HBA context object. |
4261 | * @sli_mode: sli mode - 2/3 | |
4262 | * | |
4263 | * This function is called by the sli intialization code path | |
4264 | * to issue config_port mailbox command. This function restarts the | |
4265 | * HBA firmware and issues a config_port mailbox command to configure | |
4266 | * the SLI interface in the sli mode specified by sli_mode | |
4267 | * variable. The caller is not required to hold any locks. | |
4268 | * The function returns 0 if successful, else returns negative error | |
4269 | * code. | |
4270 | **/ | |
9399627f JS |
4271 | int |
4272 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
4273 | { |
4274 | LPFC_MBOXQ_t *pmb; | |
4275 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4276 | ||
4277 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4278 | if (!pmb) { | |
2e0fef85 | 4279 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4280 | return -ENOMEM; |
4281 | } | |
4282 | ||
ed957684 | 4283 | phba->sli_rev = sli_mode; |
dea3101e | 4284 | while (resetcount < 2 && !done) { |
2e0fef85 | 4285 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4286 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4287 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4288 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4289 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4290 | rc = lpfc_sli_chipset_init(phba); |
4291 | if (rc) | |
4292 | break; | |
4293 | ||
2e0fef85 | 4294 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4295 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4296 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4297 | resetcount++; |
4298 | ||
ed957684 JS |
4299 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4300 | * value of 0 means the call was successful. Any other | |
4301 | * nonzero value is a failure, but if ERESTART is returned, | |
4302 | * the driver may reset the HBA and try again. | |
4303 | */ | |
dea3101e JB |
4304 | rc = lpfc_config_port_prep(phba); |
4305 | if (rc == -ERESTART) { | |
ed957684 | 4306 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4307 | continue; |
34b02dcd | 4308 | } else if (rc) |
dea3101e | 4309 | break; |
6d368e53 | 4310 | |
2e0fef85 | 4311 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
4312 | lpfc_config_port(phba, pmb); |
4313 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4314 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4315 | LPFC_SLI3_HBQ_ENABLED | | |
4316 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4317 | LPFC_SLI3_BG_ENABLED | |
4318 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4319 | if (rc != MBX_SUCCESS) { |
dea3101e | 4320 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4321 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4322 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4323 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4324 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4325 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4326 | spin_unlock_irq(&phba->hbalock); |
4327 | rc = -ENXIO; | |
04c68496 JS |
4328 | } else { |
4329 | /* Allow asynchronous mailbox command to go through */ | |
4330 | spin_lock_irq(&phba->hbalock); | |
4331 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4332 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4333 | done = 1; |
04c68496 | 4334 | } |
dea3101e | 4335 | } |
ed957684 JS |
4336 | if (!done) { |
4337 | rc = -EINVAL; | |
4338 | goto do_prep_failed; | |
4339 | } | |
04c68496 JS |
4340 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4341 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4342 | rc = -ENXIO; |
4343 | goto do_prep_failed; | |
4344 | } | |
04c68496 | 4345 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4346 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4347 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4348 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4349 | phba->max_vpi : phba->max_vports; | |
4350 | ||
34b02dcd JS |
4351 | } else |
4352 | phba->max_vpi = 0; | |
bc73905a JS |
4353 | phba->fips_level = 0; |
4354 | phba->fips_spec_rev = 0; | |
4355 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4356 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4357 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4358 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4359 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4360 | "2850 Security Crypto Active. FIPS x%d " | |
4361 | "(Spec Rev: x%d)", | |
4362 | phba->fips_level, phba->fips_spec_rev); | |
4363 | } | |
4364 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4365 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4366 | "2856 Config Port Security Crypto " | |
4367 | "Error: x%x ", | |
4368 | pmb->u.mb.un.varCfgPort.sec_err); | |
4369 | } | |
04c68496 | 4370 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4371 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4372 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4373 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4374 | |
4375 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4376 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4377 | |
4378 | if (phba->cfg_enable_bg) { | |
04c68496 | 4379 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4380 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4381 | else | |
4382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4383 | "0443 Adapter did not grant " | |
4384 | "BlockGuard\n"); | |
4385 | } | |
34b02dcd | 4386 | } else { |
8f34f4ce | 4387 | phba->hbq_get = NULL; |
34b02dcd | 4388 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4389 | phba->max_vpi = 0; |
ed957684 | 4390 | } |
92d7f7b0 | 4391 | do_prep_failed: |
ed957684 JS |
4392 | mempool_free(pmb, phba->mbox_mem_pool); |
4393 | return rc; | |
4394 | } | |
4395 | ||
e59058c4 JS |
4396 | |
4397 | /** | |
3621a710 | 4398 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4399 | * @phba: Pointer to HBA context object. |
4400 | * | |
4401 | * This function is the main SLI intialization function. This function | |
4402 | * is called by the HBA intialization code, HBA reset code and HBA | |
4403 | * error attention handler code. Caller is not required to hold any | |
4404 | * locks. This function issues config_port mailbox command to configure | |
4405 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4406 | * calls the config_port_post function to issue init_link mailbox | |
4407 | * command and to start the discovery. The function will return zero | |
4408 | * if successful, else it will return negative error code. | |
4409 | **/ | |
ed957684 JS |
4410 | int |
4411 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4412 | { | |
4413 | uint32_t rc; | |
6d368e53 JS |
4414 | int mode = 3, i; |
4415 | int longs; | |
ed957684 JS |
4416 | |
4417 | switch (lpfc_sli_mode) { | |
4418 | case 2: | |
78b2d852 | 4419 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4420 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4421 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4422 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4423 | lpfc_sli_mode); |
92d7f7b0 JS |
4424 | break; |
4425 | } | |
ed957684 JS |
4426 | mode = 2; |
4427 | break; | |
4428 | case 0: | |
4429 | case 3: | |
4430 | break; | |
4431 | default: | |
92d7f7b0 | 4432 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4433 | "1819 Unrecognized lpfc_sli_mode " |
4434 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4435 | |
4436 | break; | |
4437 | } | |
4438 | ||
9399627f JS |
4439 | rc = lpfc_sli_config_port(phba, mode); |
4440 | ||
ed957684 | 4441 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4443 | "1820 Unable to select SLI-3. " |
4444 | "Not supported by adapter.\n"); | |
ed957684 | 4445 | if (rc && mode != 2) |
9399627f | 4446 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4447 | if (rc) |
dea3101e JB |
4448 | goto lpfc_sli_hba_setup_error; |
4449 | ||
0d878419 JS |
4450 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4451 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4452 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4453 | if (!rc) { | |
4454 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4455 | "2709 This device supports " | |
4456 | "Advanced Error Reporting (AER)\n"); | |
4457 | spin_lock_irq(&phba->hbalock); | |
4458 | phba->hba_flag |= HBA_AER_ENABLED; | |
4459 | spin_unlock_irq(&phba->hbalock); | |
4460 | } else { | |
4461 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4462 | "2708 This device does not support " | |
4463 | "Advanced Error Reporting (AER)\n"); | |
4464 | phba->cfg_aer_support = 0; | |
4465 | } | |
4466 | } | |
4467 | ||
ed957684 JS |
4468 | if (phba->sli_rev == 3) { |
4469 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4470 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4471 | } else { |
4472 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4473 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4474 | phba->sli3_options = 0; |
ed957684 JS |
4475 | } |
4476 | ||
4477 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4478 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4479 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4480 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
4481 | |
4482 | if (rc) | |
4483 | goto lpfc_sli_hba_setup_error; | |
4484 | ||
6d368e53 JS |
4485 | /* Initialize VPIs. */ |
4486 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
4487 | /* | |
4488 | * The VPI bitmask and physical ID array are allocated | |
4489 | * and initialized once only - at driver load. A port | |
4490 | * reset doesn't need to reinitialize this memory. | |
4491 | */ | |
4492 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
4493 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
4494 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4495 | GFP_KERNEL); | |
4496 | if (!phba->vpi_bmask) { | |
4497 | rc = -ENOMEM; | |
4498 | goto lpfc_sli_hba_setup_error; | |
4499 | } | |
4500 | ||
4501 | phba->vpi_ids = kzalloc( | |
4502 | (phba->max_vpi+1) * sizeof(uint16_t), | |
4503 | GFP_KERNEL); | |
4504 | if (!phba->vpi_ids) { | |
4505 | kfree(phba->vpi_bmask); | |
4506 | rc = -ENOMEM; | |
4507 | goto lpfc_sli_hba_setup_error; | |
4508 | } | |
4509 | for (i = 0; i < phba->max_vpi; i++) | |
4510 | phba->vpi_ids[i] = i; | |
4511 | } | |
4512 | } | |
4513 | ||
9399627f | 4514 | /* Init HBQs */ |
ed957684 JS |
4515 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4516 | rc = lpfc_sli_hbq_setup(phba); | |
4517 | if (rc) | |
4518 | goto lpfc_sli_hba_setup_error; | |
4519 | } | |
04c68496 | 4520 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4521 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4522 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4523 | |
4524 | rc = lpfc_config_port_post(phba); | |
4525 | if (rc) | |
4526 | goto lpfc_sli_hba_setup_error; | |
4527 | ||
ed957684 JS |
4528 | return rc; |
4529 | ||
92d7f7b0 | 4530 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4531 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4533 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
4534 | return rc; |
4535 | } | |
4536 | ||
e59058c4 | 4537 | /** |
da0436e9 JS |
4538 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4539 | * @phba: Pointer to HBA context object. | |
4540 | * @mboxq: mailbox pointer. | |
4541 | * This function issue a dump mailbox command to read config region | |
4542 | * 23 and parse the records in the region and populate driver | |
4543 | * data structure. | |
e59058c4 | 4544 | **/ |
da0436e9 JS |
4545 | static int |
4546 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, | |
4547 | LPFC_MBOXQ_t *mboxq) | |
dea3101e | 4548 | { |
da0436e9 JS |
4549 | struct lpfc_dmabuf *mp; |
4550 | struct lpfc_mqe *mqe; | |
4551 | uint32_t data_length; | |
4552 | int rc; | |
dea3101e | 4553 | |
da0436e9 JS |
4554 | /* Program the default value of vlan_id and fc_map */ |
4555 | phba->valid_vlan = 0; | |
4556 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4557 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4558 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4559 | |
da0436e9 JS |
4560 | mqe = &mboxq->u.mqe; |
4561 | if (lpfc_dump_fcoe_param(phba, mboxq)) | |
4562 | return -ENOMEM; | |
4563 | ||
4564 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4565 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4566 | ||
4567 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4568 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4569 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4570 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4571 | "CQ: x%x x%x x%x x%x\n", | |
4572 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4573 | bf_get(lpfc_mqe_command, mqe), | |
4574 | bf_get(lpfc_mqe_status, mqe), | |
4575 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4576 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4577 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4578 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4579 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4580 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4581 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4582 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4583 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4584 | mboxq->mcqe.word0, | |
4585 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4586 | mboxq->mcqe.trailer); | |
4587 | ||
4588 | if (rc) { | |
4589 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4590 | kfree(mp); | |
4591 | return -EIO; | |
4592 | } | |
4593 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4594 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4595 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4596 | kfree(mp); | |
da0436e9 | 4597 | return -EIO; |
d11e31dd | 4598 | } |
dea3101e | 4599 | |
da0436e9 JS |
4600 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4601 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4602 | kfree(mp); | |
4603 | return 0; | |
4604 | } | |
e59058c4 JS |
4605 | |
4606 | /** | |
da0436e9 JS |
4607 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4608 | * @phba: pointer to lpfc hba data structure. | |
4609 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4610 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4611 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4612 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4613 | * |
da0436e9 JS |
4614 | * This routine executes a READ_REV SLI4 mailbox command. In |
4615 | * addition, this routine gets the port vpd data. | |
4616 | * | |
4617 | * Return codes | |
af901ca1 | 4618 | * 0 - successful |
d439d286 | 4619 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4620 | **/ |
da0436e9 JS |
4621 | static int |
4622 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4623 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4624 | { |
da0436e9 JS |
4625 | int rc = 0; |
4626 | uint32_t dma_size; | |
4627 | struct lpfc_dmabuf *dmabuf; | |
4628 | struct lpfc_mqe *mqe; | |
dea3101e | 4629 | |
da0436e9 JS |
4630 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4631 | if (!dmabuf) | |
4632 | return -ENOMEM; | |
4633 | ||
4634 | /* | |
4635 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4636 | * mailbox command. | |
a257bf90 | 4637 | */ |
da0436e9 JS |
4638 | dma_size = *vpd_size; |
4639 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4640 | dma_size, | |
4641 | &dmabuf->phys, | |
4642 | GFP_KERNEL); | |
4643 | if (!dmabuf->virt) { | |
4644 | kfree(dmabuf); | |
4645 | return -ENOMEM; | |
a257bf90 | 4646 | } |
da0436e9 | 4647 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4648 | |
da0436e9 JS |
4649 | /* |
4650 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4651 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4652 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4653 | */ |
da0436e9 JS |
4654 | lpfc_read_rev(phba, mboxq); |
4655 | mqe = &mboxq->u.mqe; | |
4656 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4657 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4658 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4659 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4660 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4661 | ||
4662 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4663 | if (rc) { | |
4664 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4665 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4666 | kfree(dmabuf); |
da0436e9 JS |
4667 | return -EIO; |
4668 | } | |
1dcb58e5 | 4669 | |
da0436e9 JS |
4670 | /* |
4671 | * The available vpd length cannot be bigger than the | |
4672 | * DMA buffer passed to the port. Catch the less than | |
4673 | * case and update the caller's size. | |
4674 | */ | |
4675 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4676 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4677 | |
d7c47992 JS |
4678 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4679 | ||
da0436e9 JS |
4680 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4681 | dmabuf->virt, dmabuf->phys); | |
4682 | kfree(dmabuf); | |
4683 | return 0; | |
dea3101e JB |
4684 | } |
4685 | ||
e59058c4 | 4686 | /** |
da0436e9 JS |
4687 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4688 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4689 | * |
da0436e9 JS |
4690 | * This routine is called to explicitly arm the SLI4 device's completion and |
4691 | * event queues | |
4692 | **/ | |
4693 | static void | |
4694 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4695 | { | |
4696 | uint8_t fcp_eqidx; | |
4697 | ||
4698 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4699 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
0558056c JS |
4700 | fcp_eqidx = 0; |
4701 | do | |
da0436e9 JS |
4702 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
4703 | LPFC_QUEUE_REARM); | |
0558056c | 4704 | while (++fcp_eqidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
4705 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
4706 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | |
4707 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | |
4708 | LPFC_QUEUE_REARM); | |
4709 | } | |
4710 | ||
6d368e53 JS |
4711 | /** |
4712 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
4713 | * @phba: Pointer to HBA context object. | |
4714 | * @type: The resource extent type. | |
4715 | * | |
4716 | * This function allocates all SLI4 resource identifiers. | |
4717 | **/ | |
4718 | static int | |
4719 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, | |
4720 | uint16_t *extnt_count, uint16_t *extnt_size) | |
4721 | { | |
4722 | int rc = 0; | |
4723 | uint32_t length; | |
4724 | uint32_t mbox_tmo; | |
4725 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
4726 | LPFC_MBOXQ_t *mbox; | |
4727 | ||
4728 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4729 | if (!mbox) | |
4730 | return -ENOMEM; | |
4731 | ||
4732 | /* Find out how many extents are available for this resource type */ | |
4733 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
4734 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
4735 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4736 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
4737 | length, LPFC_SLI4_MBX_EMBED); | |
4738 | ||
4739 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
4740 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
4741 | LPFC_SLI4_MBX_EMBED); | |
4742 | if (unlikely(rc)) { | |
4743 | rc = -EIO; | |
4744 | goto err_exit; | |
4745 | } | |
4746 | ||
4747 | if (!phba->sli4_hba.intr_enable) | |
4748 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
4749 | else { | |
4750 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
4751 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
4752 | } | |
4753 | if (unlikely(rc)) { | |
4754 | rc = -EIO; | |
4755 | goto err_exit; | |
4756 | } | |
4757 | ||
4758 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
4759 | if (bf_get(lpfc_mbox_hdr_status, | |
4760 | &rsrc_info->header.cfg_shdr.response)) { | |
4761 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
4762 | "2930 Failed to get resource extents " | |
4763 | "Status 0x%x Add'l Status 0x%x\n", | |
4764 | bf_get(lpfc_mbox_hdr_status, | |
4765 | &rsrc_info->header.cfg_shdr.response), | |
4766 | bf_get(lpfc_mbox_hdr_add_status, | |
4767 | &rsrc_info->header.cfg_shdr.response)); | |
4768 | rc = -EIO; | |
4769 | goto err_exit; | |
4770 | } | |
4771 | ||
4772 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
4773 | &rsrc_info->u.rsp); | |
4774 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
4775 | &rsrc_info->u.rsp); | |
4776 | err_exit: | |
4777 | mempool_free(mbox, phba->mbox_mem_pool); | |
4778 | return rc; | |
4779 | } | |
4780 | ||
4781 | /** | |
4782 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
4783 | * @phba: Pointer to HBA context object. | |
4784 | * @type: The extent type to check. | |
4785 | * | |
4786 | * This function reads the current available extents from the port and checks | |
4787 | * if the extent count or extent size has changed since the last access. | |
4788 | * Callers use this routine post port reset to understand if there is a | |
4789 | * extent reprovisioning requirement. | |
4790 | * | |
4791 | * Returns: | |
4792 | * -Error: error indicates problem. | |
4793 | * 1: Extent count or size has changed. | |
4794 | * 0: No changes. | |
4795 | **/ | |
4796 | static int | |
4797 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
4798 | { | |
4799 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
4800 | uint16_t size_diff, rsrc_ext_size; | |
4801 | int rc = 0; | |
4802 | struct lpfc_rsrc_blks *rsrc_entry; | |
4803 | struct list_head *rsrc_blk_list = NULL; | |
4804 | ||
4805 | size_diff = 0; | |
4806 | curr_ext_cnt = 0; | |
4807 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
4808 | &rsrc_ext_cnt, | |
4809 | &rsrc_ext_size); | |
4810 | if (unlikely(rc)) | |
4811 | return -EIO; | |
4812 | ||
4813 | switch (type) { | |
4814 | case LPFC_RSC_TYPE_FCOE_RPI: | |
4815 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
4816 | break; | |
4817 | case LPFC_RSC_TYPE_FCOE_VPI: | |
4818 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
4819 | break; | |
4820 | case LPFC_RSC_TYPE_FCOE_XRI: | |
4821 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
4822 | break; | |
4823 | case LPFC_RSC_TYPE_FCOE_VFI: | |
4824 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
4825 | break; | |
4826 | default: | |
4827 | break; | |
4828 | } | |
4829 | ||
4830 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
4831 | curr_ext_cnt++; | |
4832 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
4833 | size_diff++; | |
4834 | } | |
4835 | ||
4836 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
4837 | rc = 1; | |
4838 | ||
4839 | return rc; | |
4840 | } | |
4841 | ||
4842 | /** | |
4843 | * lpfc_sli4_cfg_post_extnts - | |
4844 | * @phba: Pointer to HBA context object. | |
4845 | * @extnt_cnt - number of available extents. | |
4846 | * @type - the extent type (rpi, xri, vfi, vpi). | |
4847 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
4848 | * @mbox - pointer to the caller's allocated mailbox structure. | |
4849 | * | |
4850 | * This function executes the extents allocation request. It also | |
4851 | * takes care of the amount of memory needed to allocate or get the | |
4852 | * allocated extents. It is the caller's responsibility to evaluate | |
4853 | * the response. | |
4854 | * | |
4855 | * Returns: | |
4856 | * -Error: Error value describes the condition found. | |
4857 | * 0: if successful | |
4858 | **/ | |
4859 | static int | |
4860 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt, | |
4861 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) | |
4862 | { | |
4863 | int rc = 0; | |
4864 | uint32_t req_len; | |
4865 | uint32_t emb_len; | |
4866 | uint32_t alloc_len, mbox_tmo; | |
4867 | ||
4868 | /* Calculate the total requested length of the dma memory */ | |
4869 | req_len = *extnt_cnt * sizeof(uint16_t); | |
4870 | ||
4871 | /* | |
4872 | * Calculate the size of an embedded mailbox. The uint32_t | |
4873 | * accounts for extents-specific word. | |
4874 | */ | |
4875 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
4876 | sizeof(uint32_t); | |
4877 | ||
4878 | /* | |
4879 | * Presume the allocation and response will fit into an embedded | |
4880 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
4881 | */ | |
4882 | *emb = LPFC_SLI4_MBX_EMBED; | |
4883 | if (req_len > emb_len) { | |
4884 | req_len = *extnt_cnt * sizeof(uint16_t) + | |
4885 | sizeof(union lpfc_sli4_cfg_shdr) + | |
4886 | sizeof(uint32_t); | |
4887 | *emb = LPFC_SLI4_MBX_NEMBED; | |
4888 | } | |
4889 | ||
4890 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4891 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
4892 | req_len, *emb); | |
4893 | if (alloc_len < req_len) { | |
4894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4895 | "9000 Allocated DMA memory size (x%x) is " | |
4896 | "less than the requested DMA memory " | |
4897 | "size (x%x)\n", alloc_len, req_len); | |
4898 | return -ENOMEM; | |
4899 | } | |
4900 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb); | |
4901 | if (unlikely(rc)) | |
4902 | return -EIO; | |
4903 | ||
4904 | if (!phba->sli4_hba.intr_enable) | |
4905 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
4906 | else { | |
4907 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
4908 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
4909 | } | |
4910 | ||
4911 | if (unlikely(rc)) | |
4912 | rc = -EIO; | |
4913 | return rc; | |
4914 | } | |
4915 | ||
4916 | /** | |
4917 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
4918 | * @phba: Pointer to HBA context object. | |
4919 | * @type: The resource extent type to allocate. | |
4920 | * | |
4921 | * This function allocates the number of elements for the specified | |
4922 | * resource type. | |
4923 | **/ | |
4924 | static int | |
4925 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
4926 | { | |
4927 | bool emb = false; | |
4928 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
4929 | uint16_t rsrc_id, rsrc_start, j, k; | |
4930 | uint16_t *ids; | |
4931 | int i, rc; | |
4932 | unsigned long longs; | |
4933 | unsigned long *bmask; | |
4934 | struct lpfc_rsrc_blks *rsrc_blks; | |
4935 | LPFC_MBOXQ_t *mbox; | |
4936 | uint32_t length; | |
4937 | struct lpfc_id_range *id_array = NULL; | |
4938 | void *virtaddr = NULL; | |
4939 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
4940 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
4941 | struct list_head *ext_blk_list; | |
4942 | ||
4943 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
4944 | &rsrc_cnt, | |
4945 | &rsrc_size); | |
4946 | if (unlikely(rc)) | |
4947 | return -EIO; | |
4948 | ||
4949 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
4950 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
4951 | "3009 No available Resource Extents " | |
4952 | "for resource type 0x%x: Count: 0x%x, " | |
4953 | "Size 0x%x\n", type, rsrc_cnt, | |
4954 | rsrc_size); | |
4955 | return -ENOMEM; | |
4956 | } | |
4957 | ||
4958 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT, | |
4959 | "2903 Available Resource Extents " | |
4960 | "for resource type 0x%x: Count: 0x%x, " | |
4961 | "Size 0x%x\n", type, rsrc_cnt, | |
4962 | rsrc_size); | |
4963 | ||
4964 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4965 | if (!mbox) | |
4966 | return -ENOMEM; | |
4967 | ||
4968 | rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox); | |
4969 | if (unlikely(rc)) { | |
4970 | rc = -EIO; | |
4971 | goto err_exit; | |
4972 | } | |
4973 | ||
4974 | /* | |
4975 | * Figure out where the response is located. Then get local pointers | |
4976 | * to the response data. The port does not guarantee to respond to | |
4977 | * all extents counts request so update the local variable with the | |
4978 | * allocated count from the port. | |
4979 | */ | |
4980 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
4981 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
4982 | id_array = &rsrc_ext->u.rsp.id[0]; | |
4983 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
4984 | } else { | |
4985 | virtaddr = mbox->sge_array->addr[0]; | |
4986 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
4987 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
4988 | id_array = &n_rsrc->id; | |
4989 | } | |
4990 | ||
4991 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
4992 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
4993 | ||
4994 | /* | |
4995 | * Based on the resource size and count, correct the base and max | |
4996 | * resource values. | |
4997 | */ | |
4998 | length = sizeof(struct lpfc_rsrc_blks); | |
4999 | switch (type) { | |
5000 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5001 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5002 | sizeof(unsigned long), | |
5003 | GFP_KERNEL); | |
5004 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5005 | rc = -ENOMEM; | |
5006 | goto err_exit; | |
5007 | } | |
5008 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * | |
5009 | sizeof(uint16_t), | |
5010 | GFP_KERNEL); | |
5011 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5012 | kfree(phba->sli4_hba.rpi_bmask); | |
5013 | rc = -ENOMEM; | |
5014 | goto err_exit; | |
5015 | } | |
5016 | ||
5017 | /* | |
5018 | * The next_rpi was initialized with the maximum available | |
5019 | * count but the port may allocate a smaller number. Catch | |
5020 | * that case and update the next_rpi. | |
5021 | */ | |
5022 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5023 | ||
5024 | /* Initialize local ptrs for common extent processing later. */ | |
5025 | bmask = phba->sli4_hba.rpi_bmask; | |
5026 | ids = phba->sli4_hba.rpi_ids; | |
5027 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5028 | break; | |
5029 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5030 | phba->vpi_bmask = kzalloc(longs * | |
5031 | sizeof(unsigned long), | |
5032 | GFP_KERNEL); | |
5033 | if (unlikely(!phba->vpi_bmask)) { | |
5034 | rc = -ENOMEM; | |
5035 | goto err_exit; | |
5036 | } | |
5037 | phba->vpi_ids = kzalloc(rsrc_id_cnt * | |
5038 | sizeof(uint16_t), | |
5039 | GFP_KERNEL); | |
5040 | if (unlikely(!phba->vpi_ids)) { | |
5041 | kfree(phba->vpi_bmask); | |
5042 | rc = -ENOMEM; | |
5043 | goto err_exit; | |
5044 | } | |
5045 | ||
5046 | /* Initialize local ptrs for common extent processing later. */ | |
5047 | bmask = phba->vpi_bmask; | |
5048 | ids = phba->vpi_ids; | |
5049 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5050 | break; | |
5051 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5052 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5053 | sizeof(unsigned long), | |
5054 | GFP_KERNEL); | |
5055 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5056 | rc = -ENOMEM; | |
5057 | goto err_exit; | |
5058 | } | |
5059 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * | |
5060 | sizeof(uint16_t), | |
5061 | GFP_KERNEL); | |
5062 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5063 | kfree(phba->sli4_hba.xri_bmask); | |
5064 | rc = -ENOMEM; | |
5065 | goto err_exit; | |
5066 | } | |
5067 | ||
5068 | /* Initialize local ptrs for common extent processing later. */ | |
5069 | bmask = phba->sli4_hba.xri_bmask; | |
5070 | ids = phba->sli4_hba.xri_ids; | |
5071 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5072 | break; | |
5073 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5074 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5075 | sizeof(unsigned long), | |
5076 | GFP_KERNEL); | |
5077 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5078 | rc = -ENOMEM; | |
5079 | goto err_exit; | |
5080 | } | |
5081 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * | |
5082 | sizeof(uint16_t), | |
5083 | GFP_KERNEL); | |
5084 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5085 | kfree(phba->sli4_hba.vfi_bmask); | |
5086 | rc = -ENOMEM; | |
5087 | goto err_exit; | |
5088 | } | |
5089 | ||
5090 | /* Initialize local ptrs for common extent processing later. */ | |
5091 | bmask = phba->sli4_hba.vfi_bmask; | |
5092 | ids = phba->sli4_hba.vfi_ids; | |
5093 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5094 | break; | |
5095 | default: | |
5096 | /* Unsupported Opcode. Fail call. */ | |
5097 | id_array = NULL; | |
5098 | bmask = NULL; | |
5099 | ids = NULL; | |
5100 | ext_blk_list = NULL; | |
5101 | goto err_exit; | |
5102 | } | |
5103 | ||
5104 | /* | |
5105 | * Complete initializing the extent configuration with the | |
5106 | * allocated ids assigned to this function. The bitmask serves | |
5107 | * as an index into the array and manages the available ids. The | |
5108 | * array just stores the ids communicated to the port via the wqes. | |
5109 | */ | |
5110 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
5111 | if ((i % 2) == 0) | |
5112 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
5113 | &id_array[k]); | |
5114 | else | |
5115 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
5116 | &id_array[k]); | |
5117 | ||
5118 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
5119 | if (unlikely(!rsrc_blks)) { | |
5120 | rc = -ENOMEM; | |
5121 | kfree(bmask); | |
5122 | kfree(ids); | |
5123 | goto err_exit; | |
5124 | } | |
5125 | rsrc_blks->rsrc_start = rsrc_id; | |
5126 | rsrc_blks->rsrc_size = rsrc_size; | |
5127 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
5128 | rsrc_start = rsrc_id; | |
5129 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) | |
5130 | phba->sli4_hba.scsi_xri_start = rsrc_start + | |
5131 | lpfc_sli4_get_els_iocb_cnt(phba); | |
5132 | ||
5133 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
5134 | ids[j] = rsrc_id; | |
5135 | rsrc_id++; | |
5136 | j++; | |
5137 | } | |
5138 | /* Entire word processed. Get next word.*/ | |
5139 | if ((i % 2) == 1) | |
5140 | k++; | |
5141 | } | |
5142 | err_exit: | |
5143 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5144 | return rc; | |
5145 | } | |
5146 | ||
5147 | /** | |
5148 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
5149 | * @phba: Pointer to HBA context object. | |
5150 | * @type: the extent's type. | |
5151 | * | |
5152 | * This function deallocates all extents of a particular resource type. | |
5153 | * SLI4 does not allow for deallocating a particular extent range. It | |
5154 | * is the caller's responsibility to release all kernel memory resources. | |
5155 | **/ | |
5156 | static int | |
5157 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5158 | { | |
5159 | int rc; | |
5160 | uint32_t length, mbox_tmo = 0; | |
5161 | LPFC_MBOXQ_t *mbox; | |
5162 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
5163 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
5164 | ||
5165 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5166 | if (!mbox) | |
5167 | return -ENOMEM; | |
5168 | ||
5169 | /* | |
5170 | * This function sends an embedded mailbox because it only sends the | |
5171 | * the resource type. All extents of this type are released by the | |
5172 | * port. | |
5173 | */ | |
5174 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
5175 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5176 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5177 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
5178 | length, LPFC_SLI4_MBX_EMBED); | |
5179 | ||
5180 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
5181 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5182 | LPFC_SLI4_MBX_EMBED); | |
5183 | if (unlikely(rc)) { | |
5184 | rc = -EIO; | |
5185 | goto out_free_mbox; | |
5186 | } | |
5187 | if (!phba->sli4_hba.intr_enable) | |
5188 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5189 | else { | |
5190 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox_tmo); | |
5191 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
5192 | } | |
5193 | if (unlikely(rc)) { | |
5194 | rc = -EIO; | |
5195 | goto out_free_mbox; | |
5196 | } | |
5197 | ||
5198 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
5199 | if (bf_get(lpfc_mbox_hdr_status, | |
5200 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
5201 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5202 | "2919 Failed to release resource extents " | |
5203 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
5204 | "Resource memory not released.\n", | |
5205 | type, | |
5206 | bf_get(lpfc_mbox_hdr_status, | |
5207 | &dealloc_rsrc->header.cfg_shdr.response), | |
5208 | bf_get(lpfc_mbox_hdr_add_status, | |
5209 | &dealloc_rsrc->header.cfg_shdr.response)); | |
5210 | rc = -EIO; | |
5211 | goto out_free_mbox; | |
5212 | } | |
5213 | ||
5214 | /* Release kernel memory resources for the specific type. */ | |
5215 | switch (type) { | |
5216 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5217 | kfree(phba->vpi_bmask); | |
5218 | kfree(phba->vpi_ids); | |
5219 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5220 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5221 | &phba->lpfc_vpi_blk_list, list) { | |
5222 | list_del_init(&rsrc_blk->list); | |
5223 | kfree(rsrc_blk); | |
5224 | } | |
5225 | break; | |
5226 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5227 | kfree(phba->sli4_hba.xri_bmask); | |
5228 | kfree(phba->sli4_hba.xri_ids); | |
5229 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5230 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5231 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
5232 | list_del_init(&rsrc_blk->list); | |
5233 | kfree(rsrc_blk); | |
5234 | } | |
5235 | break; | |
5236 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5237 | kfree(phba->sli4_hba.vfi_bmask); | |
5238 | kfree(phba->sli4_hba.vfi_ids); | |
5239 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5240 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5241 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
5242 | list_del_init(&rsrc_blk->list); | |
5243 | kfree(rsrc_blk); | |
5244 | } | |
5245 | break; | |
5246 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5247 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
5248 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5249 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
5250 | list_del_init(&rsrc_blk->list); | |
5251 | kfree(rsrc_blk); | |
5252 | } | |
5253 | break; | |
5254 | default: | |
5255 | break; | |
5256 | } | |
5257 | ||
5258 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5259 | ||
5260 | out_free_mbox: | |
5261 | mempool_free(mbox, phba->mbox_mem_pool); | |
5262 | return rc; | |
5263 | } | |
5264 | ||
5265 | /** | |
5266 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
5267 | * @phba: Pointer to HBA context object. | |
5268 | * | |
5269 | * This function allocates all SLI4 resource identifiers. | |
5270 | **/ | |
5271 | int | |
5272 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
5273 | { | |
5274 | int i, rc, error = 0; | |
5275 | uint16_t count, base; | |
5276 | unsigned long longs; | |
5277 | ||
5278 | if (phba->sli4_hba.extents_in_use) { | |
5279 | /* | |
5280 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
5281 | * resource extent count must be read and allocated before | |
5282 | * provisioning the resource id arrays. | |
5283 | */ | |
5284 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5285 | LPFC_IDX_RSRC_RDY) { | |
5286 | /* | |
5287 | * Extent-based resources are set - the driver could | |
5288 | * be in a port reset. Figure out if any corrective | |
5289 | * actions need to be taken. | |
5290 | */ | |
5291 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5292 | LPFC_RSC_TYPE_FCOE_VFI); | |
5293 | if (rc != 0) | |
5294 | error++; | |
5295 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5296 | LPFC_RSC_TYPE_FCOE_VPI); | |
5297 | if (rc != 0) | |
5298 | error++; | |
5299 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5300 | LPFC_RSC_TYPE_FCOE_XRI); | |
5301 | if (rc != 0) | |
5302 | error++; | |
5303 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5304 | LPFC_RSC_TYPE_FCOE_RPI); | |
5305 | if (rc != 0) | |
5306 | error++; | |
5307 | ||
5308 | /* | |
5309 | * It's possible that the number of resources | |
5310 | * provided to this port instance changed between | |
5311 | * resets. Detect this condition and reallocate | |
5312 | * resources. Otherwise, there is no action. | |
5313 | */ | |
5314 | if (error) { | |
5315 | lpfc_printf_log(phba, KERN_INFO, | |
5316 | LOG_MBOX | LOG_INIT, | |
5317 | "2931 Detected extent resource " | |
5318 | "change. Reallocating all " | |
5319 | "extents.\n"); | |
5320 | rc = lpfc_sli4_dealloc_extent(phba, | |
5321 | LPFC_RSC_TYPE_FCOE_VFI); | |
5322 | rc = lpfc_sli4_dealloc_extent(phba, | |
5323 | LPFC_RSC_TYPE_FCOE_VPI); | |
5324 | rc = lpfc_sli4_dealloc_extent(phba, | |
5325 | LPFC_RSC_TYPE_FCOE_XRI); | |
5326 | rc = lpfc_sli4_dealloc_extent(phba, | |
5327 | LPFC_RSC_TYPE_FCOE_RPI); | |
5328 | } else | |
5329 | return 0; | |
5330 | } | |
5331 | ||
5332 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5333 | if (unlikely(rc)) | |
5334 | goto err_exit; | |
5335 | ||
5336 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5337 | if (unlikely(rc)) | |
5338 | goto err_exit; | |
5339 | ||
5340 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5341 | if (unlikely(rc)) | |
5342 | goto err_exit; | |
5343 | ||
5344 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5345 | if (unlikely(rc)) | |
5346 | goto err_exit; | |
5347 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5348 | LPFC_IDX_RSRC_RDY); | |
5349 | return rc; | |
5350 | } else { | |
5351 | /* | |
5352 | * The port does not support resource extents. The XRI, VPI, | |
5353 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
5354 | * Just allocate the bitmasks and provision the resource id | |
5355 | * arrays. If a port reset is active, the resources don't | |
5356 | * need any action - just exit. | |
5357 | */ | |
5358 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5359 | LPFC_IDX_RSRC_RDY) | |
5360 | return 0; | |
5361 | ||
5362 | /* RPIs. */ | |
5363 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
5364 | base = phba->sli4_hba.max_cfg_param.rpi_base; | |
5365 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5366 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5367 | sizeof(unsigned long), | |
5368 | GFP_KERNEL); | |
5369 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5370 | rc = -ENOMEM; | |
5371 | goto err_exit; | |
5372 | } | |
5373 | phba->sli4_hba.rpi_ids = kzalloc(count * | |
5374 | sizeof(uint16_t), | |
5375 | GFP_KERNEL); | |
5376 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5377 | rc = -ENOMEM; | |
5378 | goto free_rpi_bmask; | |
5379 | } | |
5380 | ||
5381 | for (i = 0; i < count; i++) | |
5382 | phba->sli4_hba.rpi_ids[i] = base + i; | |
5383 | ||
5384 | /* VPIs. */ | |
5385 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
5386 | base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5387 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5388 | phba->vpi_bmask = kzalloc(longs * | |
5389 | sizeof(unsigned long), | |
5390 | GFP_KERNEL); | |
5391 | if (unlikely(!phba->vpi_bmask)) { | |
5392 | rc = -ENOMEM; | |
5393 | goto free_rpi_ids; | |
5394 | } | |
5395 | phba->vpi_ids = kzalloc(count * | |
5396 | sizeof(uint16_t), | |
5397 | GFP_KERNEL); | |
5398 | if (unlikely(!phba->vpi_ids)) { | |
5399 | rc = -ENOMEM; | |
5400 | goto free_vpi_bmask; | |
5401 | } | |
5402 | ||
5403 | for (i = 0; i < count; i++) | |
5404 | phba->vpi_ids[i] = base + i; | |
5405 | ||
5406 | /* XRIs. */ | |
5407 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
5408 | base = phba->sli4_hba.max_cfg_param.xri_base; | |
5409 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5410 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5411 | sizeof(unsigned long), | |
5412 | GFP_KERNEL); | |
5413 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5414 | rc = -ENOMEM; | |
5415 | goto free_vpi_ids; | |
5416 | } | |
5417 | phba->sli4_hba.xri_ids = kzalloc(count * | |
5418 | sizeof(uint16_t), | |
5419 | GFP_KERNEL); | |
5420 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5421 | rc = -ENOMEM; | |
5422 | goto free_xri_bmask; | |
5423 | } | |
5424 | ||
5425 | for (i = 0; i < count; i++) | |
5426 | phba->sli4_hba.xri_ids[i] = base + i; | |
5427 | ||
5428 | /* VFIs. */ | |
5429 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
5430 | base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5431 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5432 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5433 | sizeof(unsigned long), | |
5434 | GFP_KERNEL); | |
5435 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5436 | rc = -ENOMEM; | |
5437 | goto free_xri_ids; | |
5438 | } | |
5439 | phba->sli4_hba.vfi_ids = kzalloc(count * | |
5440 | sizeof(uint16_t), | |
5441 | GFP_KERNEL); | |
5442 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5443 | rc = -ENOMEM; | |
5444 | goto free_vfi_bmask; | |
5445 | } | |
5446 | ||
5447 | for (i = 0; i < count; i++) | |
5448 | phba->sli4_hba.vfi_ids[i] = base + i; | |
5449 | ||
5450 | /* | |
5451 | * Mark all resources ready. An HBA reset doesn't need | |
5452 | * to reset the initialization. | |
5453 | */ | |
5454 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5455 | LPFC_IDX_RSRC_RDY); | |
5456 | return 0; | |
5457 | } | |
5458 | ||
5459 | free_vfi_bmask: | |
5460 | kfree(phba->sli4_hba.vfi_bmask); | |
5461 | free_xri_ids: | |
5462 | kfree(phba->sli4_hba.xri_ids); | |
5463 | free_xri_bmask: | |
5464 | kfree(phba->sli4_hba.xri_bmask); | |
5465 | free_vpi_ids: | |
5466 | kfree(phba->vpi_ids); | |
5467 | free_vpi_bmask: | |
5468 | kfree(phba->vpi_bmask); | |
5469 | free_rpi_ids: | |
5470 | kfree(phba->sli4_hba.rpi_ids); | |
5471 | free_rpi_bmask: | |
5472 | kfree(phba->sli4_hba.rpi_bmask); | |
5473 | err_exit: | |
5474 | return rc; | |
5475 | } | |
5476 | ||
5477 | /** | |
5478 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
5479 | * @phba: Pointer to HBA context object. | |
5480 | * | |
5481 | * This function allocates the number of elements for the specified | |
5482 | * resource type. | |
5483 | **/ | |
5484 | int | |
5485 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
5486 | { | |
5487 | if (phba->sli4_hba.extents_in_use) { | |
5488 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5489 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5490 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5491 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5492 | } else { | |
5493 | kfree(phba->vpi_bmask); | |
5494 | kfree(phba->vpi_ids); | |
5495 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5496 | kfree(phba->sli4_hba.xri_bmask); | |
5497 | kfree(phba->sli4_hba.xri_ids); | |
5498 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5499 | kfree(phba->sli4_hba.vfi_bmask); | |
5500 | kfree(phba->sli4_hba.vfi_ids); | |
5501 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5502 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5503 | } | |
5504 | ||
5505 | return 0; | |
5506 | } | |
5507 | ||
da0436e9 JS |
5508 | /** |
5509 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
5510 | * @phba: Pointer to HBA context object. | |
5511 | * | |
5512 | * This function is the main SLI4 device intialization PCI function. This | |
5513 | * function is called by the HBA intialization code, HBA reset code and | |
5514 | * HBA error attention handler code. Caller is not required to hold any | |
5515 | * locks. | |
5516 | **/ | |
5517 | int | |
5518 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
5519 | { | |
5520 | int rc; | |
5521 | LPFC_MBOXQ_t *mboxq; | |
5522 | struct lpfc_mqe *mqe; | |
5523 | uint8_t *vpd; | |
5524 | uint32_t vpd_size; | |
5525 | uint32_t ftr_rsp = 0; | |
5526 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
5527 | struct lpfc_vport *vport = phba->pport; | |
5528 | struct lpfc_dmabuf *mp; | |
5529 | ||
5530 | /* Perform a PCI function reset to start from clean */ | |
5531 | rc = lpfc_pci_function_reset(phba); | |
5532 | if (unlikely(rc)) | |
5533 | return -ENODEV; | |
5534 | ||
5535 | /* Check the HBA Host Status Register for readyness */ | |
5536 | rc = lpfc_sli4_post_status_check(phba); | |
5537 | if (unlikely(rc)) | |
5538 | return -ENODEV; | |
5539 | else { | |
5540 | spin_lock_irq(&phba->hbalock); | |
5541 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
5542 | spin_unlock_irq(&phba->hbalock); | |
5543 | } | |
5544 | ||
5545 | /* | |
5546 | * Allocate a single mailbox container for initializing the | |
5547 | * port. | |
5548 | */ | |
5549 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5550 | if (!mboxq) | |
5551 | return -ENOMEM; | |
5552 | ||
5553 | /* | |
5554 | * Continue initialization with default values even if driver failed | |
5555 | * to read FCoE param config regions | |
5556 | */ | |
5557 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) | |
0558056c | 5558 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, |
e4e74273 | 5559 | "2570 Failed to read FCoE parameters\n"); |
da0436e9 JS |
5560 | |
5561 | /* Issue READ_REV to collect vpd and FW information. */ | |
49198b37 | 5562 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
5563 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
5564 | if (!vpd) { | |
5565 | rc = -ENOMEM; | |
5566 | goto out_free_mbox; | |
5567 | } | |
5568 | ||
5569 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
5570 | if (unlikely(rc)) { |
5571 | kfree(vpd); | |
5572 | goto out_free_mbox; | |
5573 | } | |
da0436e9 | 5574 | mqe = &mboxq->u.mqe; |
f1126688 JS |
5575 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
5576 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
5577 | phba->hba_flag |= HBA_FCOE_MODE; |
5578 | else | |
5579 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
5580 | |
5581 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
5582 | LPFC_DCBX_CEE_MODE) | |
5583 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
5584 | else | |
5585 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
5586 | ||
c31098ce | 5587 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
5588 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5589 | "0376 READ_REV Error. SLI Level %d " | |
5590 | "FCoE enabled %d\n", | |
76a95d75 | 5591 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 5592 | rc = -EIO; |
76a95d75 JS |
5593 | kfree(vpd); |
5594 | goto out_free_mbox; | |
da0436e9 | 5595 | } |
da0436e9 JS |
5596 | /* |
5597 | * Evaluate the read rev and vpd data. Populate the driver | |
5598 | * state with the results. If this routine fails, the failure | |
5599 | * is not fatal as the driver will use generic values. | |
5600 | */ | |
5601 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
5602 | if (unlikely(!rc)) { | |
5603 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5604 | "0377 Error %d parsing vpd. " | |
5605 | "Using defaults.\n", rc); | |
5606 | rc = 0; | |
5607 | } | |
76a95d75 | 5608 | kfree(vpd); |
da0436e9 | 5609 | |
f1126688 JS |
5610 | /* Save information as VPD data */ |
5611 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
5612 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
5613 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
5614 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
5615 | &mqe->un.read_rev); | |
5616 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
5617 | &mqe->un.read_rev); | |
5618 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
5619 | &mqe->un.read_rev); | |
5620 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
5621 | &mqe->un.read_rev); | |
5622 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
5623 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
5624 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
5625 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
5626 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
5627 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
5628 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5629 | "(%d):0380 READ_REV Status x%x " | |
5630 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
5631 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5632 | bf_get(lpfc_mqe_status, mqe), | |
5633 | phba->vpd.rev.opFwName, | |
5634 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
5635 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
5636 | |
5637 | /* | |
5638 | * Discover the port's supported feature set and match it against the | |
5639 | * hosts requests. | |
5640 | */ | |
5641 | lpfc_request_features(phba, mboxq); | |
5642 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5643 | if (unlikely(rc)) { | |
5644 | rc = -EIO; | |
76a95d75 | 5645 | goto out_free_mbox; |
da0436e9 JS |
5646 | } |
5647 | ||
5648 | /* | |
5649 | * The port must support FCP initiator mode as this is the | |
5650 | * only mode running in the host. | |
5651 | */ | |
5652 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
5653 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
5654 | "0378 No support for fcpi mode.\n"); | |
5655 | ftr_rsp++; | |
5656 | } | |
fedd3b7b JS |
5657 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
5658 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
5659 | else | |
5660 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
5661 | /* |
5662 | * If the port cannot support the host's requested features | |
5663 | * then turn off the global config parameters to disable the | |
5664 | * feature in the driver. This is not a fatal error. | |
5665 | */ | |
5666 | if ((phba->cfg_enable_bg) && | |
5667 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
5668 | ftr_rsp++; | |
5669 | ||
5670 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
5671 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
5672 | ftr_rsp++; | |
5673 | ||
5674 | if (ftr_rsp) { | |
5675 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
5676 | "0379 Feature Mismatch Data: x%08x %08x " | |
5677 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
5678 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
5679 | phba->cfg_enable_npiv, phba->max_vpi); | |
5680 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
5681 | phba->cfg_enable_bg = 0; | |
5682 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
5683 | phba->cfg_enable_npiv = 0; | |
5684 | } | |
5685 | ||
5686 | /* These SLI3 features are assumed in SLI4 */ | |
5687 | spin_lock_irq(&phba->hbalock); | |
5688 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
5689 | spin_unlock_irq(&phba->hbalock); | |
5690 | ||
6d368e53 JS |
5691 | /* |
5692 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
5693 | * calls depends on these resources to complete port setup. | |
5694 | */ | |
5695 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
5696 | if (rc) { | |
5697 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5698 | "2920 Failed to alloc Resource IDs " | |
5699 | "rc = x%x\n", rc); | |
5700 | goto out_free_mbox; | |
5701 | } | |
5702 | ||
da0436e9 | 5703 | /* Read the port's service parameters. */ |
9f1177a3 JS |
5704 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
5705 | if (rc) { | |
5706 | phba->link_state = LPFC_HBA_ERROR; | |
5707 | rc = -ENOMEM; | |
76a95d75 | 5708 | goto out_free_mbox; |
9f1177a3 JS |
5709 | } |
5710 | ||
da0436e9 JS |
5711 | mboxq->vport = vport; |
5712 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5713 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
5714 | if (rc == MBX_SUCCESS) { | |
5715 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
5716 | rc = 0; | |
5717 | } | |
5718 | ||
5719 | /* | |
5720 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
5721 | * it to the mbuf pool. | |
5722 | */ | |
5723 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
5724 | kfree(mp); | |
5725 | mboxq->context1 = NULL; | |
5726 | if (unlikely(rc)) { | |
5727 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5728 | "0382 READ_SPARAM command failed " | |
5729 | "status %d, mbxStatus x%x\n", | |
5730 | rc, bf_get(lpfc_mqe_status, mqe)); | |
5731 | phba->link_state = LPFC_HBA_ERROR; | |
5732 | rc = -EIO; | |
76a95d75 | 5733 | goto out_free_mbox; |
da0436e9 JS |
5734 | } |
5735 | ||
0558056c | 5736 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
5737 | |
5738 | /* Update the fc_host data structures with new wwn. */ | |
5739 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
5740 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
5741 | ||
5742 | /* Register SGL pool to the device using non-embedded mailbox command */ | |
6d368e53 JS |
5743 | if (!phba->sli4_hba.extents_in_use) { |
5744 | rc = lpfc_sli4_post_els_sgl_list(phba); | |
5745 | if (unlikely(rc)) { | |
5746 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5747 | "0582 Error %d during els sgl post " | |
5748 | "operation\n", rc); | |
5749 | rc = -ENODEV; | |
5750 | goto out_free_mbox; | |
5751 | } | |
5752 | } else { | |
5753 | rc = lpfc_sli4_post_els_sgl_list_ext(phba); | |
5754 | if (unlikely(rc)) { | |
5755 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5756 | "2560 Error %d during els sgl post " | |
5757 | "operation\n", rc); | |
5758 | rc = -ENODEV; | |
5759 | goto out_free_mbox; | |
5760 | } | |
da0436e9 JS |
5761 | } |
5762 | ||
5763 | /* Register SCSI SGL pool to the device */ | |
5764 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
5765 | if (unlikely(rc)) { | |
6d368e53 | 5766 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6a9c52cf JS |
5767 | "0383 Error %d during scsi sgl post " |
5768 | "operation\n", rc); | |
da0436e9 JS |
5769 | /* Some Scsi buffers were moved to the abort scsi list */ |
5770 | /* A pci function reset will repost them */ | |
5771 | rc = -ENODEV; | |
76a95d75 | 5772 | goto out_free_mbox; |
da0436e9 JS |
5773 | } |
5774 | ||
5775 | /* Post the rpi header region to the device. */ | |
5776 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
5777 | if (unlikely(rc)) { | |
5778 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5779 | "0393 Error %d during rpi post operation\n", | |
5780 | rc); | |
5781 | rc = -ENODEV; | |
76a95d75 | 5782 | goto out_free_mbox; |
da0436e9 | 5783 | } |
da0436e9 JS |
5784 | |
5785 | /* Set up all the queues to the device */ | |
5786 | rc = lpfc_sli4_queue_setup(phba); | |
5787 | if (unlikely(rc)) { | |
5788 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5789 | "0381 Error %d during queue setup.\n ", rc); | |
5790 | goto out_stop_timers; | |
5791 | } | |
5792 | ||
5793 | /* Arm the CQs and then EQs on device */ | |
5794 | lpfc_sli4_arm_cqeq_intr(phba); | |
5795 | ||
5796 | /* Indicate device interrupt mode */ | |
5797 | phba->sli4_hba.intr_enable = 1; | |
5798 | ||
5799 | /* Allow asynchronous mailbox command to go through */ | |
5800 | spin_lock_irq(&phba->hbalock); | |
5801 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5802 | spin_unlock_irq(&phba->hbalock); | |
5803 | ||
5804 | /* Post receive buffers to the device */ | |
5805 | lpfc_sli4_rb_setup(phba); | |
5806 | ||
fc2b989b JS |
5807 | /* Reset HBA FCF states after HBA reset */ |
5808 | phba->fcf.fcf_flag = 0; | |
5809 | phba->fcf.current_rec.flag = 0; | |
5810 | ||
da0436e9 | 5811 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
5812 | mod_timer(&vport->els_tmofunc, |
5813 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
5814 | |
5815 | /* Start heart beat timer */ | |
5816 | mod_timer(&phba->hb_tmofunc, | |
5817 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
5818 | phba->hb_outstanding = 0; | |
5819 | phba->last_completion_time = jiffies; | |
5820 | ||
5821 | /* Start error attention (ERATT) polling timer */ | |
5822 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
5823 | ||
75baf696 JS |
5824 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
5825 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
5826 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
5827 | if (!rc) { | |
5828 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5829 | "2829 This device supports " | |
5830 | "Advanced Error Reporting (AER)\n"); | |
5831 | spin_lock_irq(&phba->hbalock); | |
5832 | phba->hba_flag |= HBA_AER_ENABLED; | |
5833 | spin_unlock_irq(&phba->hbalock); | |
5834 | } else { | |
5835 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5836 | "2830 This device does not support " | |
5837 | "Advanced Error Reporting (AER)\n"); | |
5838 | phba->cfg_aer_support = 0; | |
5839 | } | |
5840 | } | |
5841 | ||
76a95d75 JS |
5842 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
5843 | /* | |
5844 | * The FC Port needs to register FCFI (index 0) | |
5845 | */ | |
5846 | lpfc_reg_fcfi(phba, mboxq); | |
5847 | mboxq->vport = phba->pport; | |
5848 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 5849 | if (rc != MBX_SUCCESS) |
76a95d75 | 5850 | goto out_unset_queue; |
9589b062 JS |
5851 | rc = 0; |
5852 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
5853 | &mboxq->u.mqe.un.reg_fcfi); | |
76a95d75 | 5854 | } |
da0436e9 JS |
5855 | /* |
5856 | * The port is ready, set the host's link state to LINK_DOWN | |
5857 | * in preparation for link interrupts. | |
5858 | */ | |
da0436e9 JS |
5859 | spin_lock_irq(&phba->hbalock); |
5860 | phba->link_state = LPFC_LINK_DOWN; | |
5861 | spin_unlock_irq(&phba->hbalock); | |
fedd3b7b JS |
5862 | if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) |
5863 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
76a95d75 | 5864 | out_unset_queue: |
da0436e9 JS |
5865 | /* Unset all the queues set up in this routine when error out */ |
5866 | if (rc) | |
5867 | lpfc_sli4_queue_unset(phba); | |
da0436e9 JS |
5868 | out_stop_timers: |
5869 | if (rc) | |
5870 | lpfc_stop_hba_timers(phba); | |
da0436e9 JS |
5871 | out_free_mbox: |
5872 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5873 | return rc; | |
5874 | } | |
5875 | ||
5876 | /** | |
5877 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
5878 | * @ptr: context object - pointer to hba structure. | |
5879 | * | |
5880 | * This is the callback function for mailbox timer. The mailbox | |
5881 | * timer is armed when a new mailbox command is issued and the timer | |
5882 | * is deleted when the mailbox complete. The function is called by | |
5883 | * the kernel timer code when a mailbox does not complete within | |
5884 | * expected time. This function wakes up the worker thread to | |
5885 | * process the mailbox timeout and returns. All the processing is | |
5886 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
5887 | **/ | |
5888 | void | |
5889 | lpfc_mbox_timeout(unsigned long ptr) | |
5890 | { | |
5891 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
5892 | unsigned long iflag; | |
5893 | uint32_t tmo_posted; | |
5894 | ||
5895 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
5896 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
5897 | if (!tmo_posted) | |
5898 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
5899 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
5900 | ||
5901 | if (!tmo_posted) | |
5902 | lpfc_worker_wake_up(phba); | |
5903 | return; | |
5904 | } | |
5905 | ||
5906 | ||
5907 | /** | |
5908 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
5909 | * @phba: Pointer to HBA context object. | |
5910 | * | |
5911 | * This function is called from worker thread when a mailbox command times out. | |
5912 | * The caller is not required to hold any locks. This function will reset the | |
5913 | * HBA and recover all the pending commands. | |
5914 | **/ | |
5915 | void | |
5916 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
5917 | { | |
5918 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 5919 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
5920 | struct lpfc_sli *psli = &phba->sli; |
5921 | struct lpfc_sli_ring *pring; | |
5922 | ||
5923 | /* Check the pmbox pointer first. There is a race condition | |
5924 | * between the mbox timeout handler getting executed in the | |
5925 | * worklist and the mailbox actually completing. When this | |
5926 | * race condition occurs, the mbox_active will be NULL. | |
5927 | */ | |
5928 | spin_lock_irq(&phba->hbalock); | |
5929 | if (pmbox == NULL) { | |
5930 | lpfc_printf_log(phba, KERN_WARNING, | |
5931 | LOG_MBOX | LOG_SLI, | |
5932 | "0353 Active Mailbox cleared - mailbox timeout " | |
5933 | "exiting\n"); | |
5934 | spin_unlock_irq(&phba->hbalock); | |
5935 | return; | |
5936 | } | |
5937 | ||
5938 | /* Mbox cmd <mbxCommand> timeout */ | |
5939 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5940 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
5941 | mb->mbxCommand, | |
5942 | phba->pport->port_state, | |
5943 | phba->sli.sli_flag, | |
5944 | phba->sli.mbox_active); | |
5945 | spin_unlock_irq(&phba->hbalock); | |
5946 | ||
5947 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
5948 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 5949 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
5950 | */ |
5951 | spin_lock_irq(&phba->pport->work_port_lock); | |
5952 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
5953 | spin_unlock_irq(&phba->pport->work_port_lock); | |
5954 | spin_lock_irq(&phba->hbalock); | |
5955 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 5956 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
5957 | spin_unlock_irq(&phba->hbalock); |
5958 | ||
5959 | pring = &psli->ring[psli->fcp_ring]; | |
5960 | lpfc_sli_abort_iocb_ring(phba, pring); | |
5961 | ||
5962 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5963 | "0345 Resetting board due to mailbox timeout\n"); | |
5964 | ||
5965 | /* Reset the HBA device */ | |
5966 | lpfc_reset_hba(phba); | |
5967 | } | |
5968 | ||
5969 | /** | |
5970 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
5971 | * @phba: Pointer to HBA context object. | |
5972 | * @pmbox: Pointer to mailbox object. | |
5973 | * @flag: Flag indicating how the mailbox need to be processed. | |
5974 | * | |
5975 | * This function is called by discovery code and HBA management code | |
5976 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
5977 | * function gets the hbalock to protect the data structures. | |
5978 | * The mailbox command can be submitted in polling mode, in which case | |
5979 | * this function will wait in a polling loop for the completion of the | |
5980 | * mailbox. | |
5981 | * If the mailbox is submitted in no_wait mode (not polling) the | |
5982 | * function will submit the command and returns immediately without waiting | |
5983 | * for the mailbox completion. The no_wait is supported only when HBA | |
5984 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
5985 | * The SLI interface allows only one mailbox pending at a time. If the | |
5986 | * mailbox is issued in polling mode and there is already a mailbox | |
5987 | * pending, then the function will return an error. If the mailbox is issued | |
5988 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
5989 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
5990 | * The sli layer owns the mailbox object until the completion of mailbox | |
5991 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
5992 | * return codes the caller owns the mailbox command after the return of | |
5993 | * the function. | |
e59058c4 | 5994 | **/ |
3772a991 JS |
5995 | static int |
5996 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
5997 | uint32_t flag) | |
dea3101e | 5998 | { |
dea3101e | 5999 | MAILBOX_t *mb; |
2e0fef85 | 6000 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6001 | uint32_t status, evtctr; |
9940b97b | 6002 | uint32_t ha_copy, hc_copy; |
dea3101e | 6003 | int i; |
09372820 | 6004 | unsigned long timeout; |
dea3101e | 6005 | unsigned long drvr_flag = 0; |
34b02dcd | 6006 | uint32_t word0, ldata; |
dea3101e | 6007 | void __iomem *to_slim; |
58da1ffb JS |
6008 | int processing_queue = 0; |
6009 | ||
6010 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6011 | if (!pmbox) { | |
8568a4d2 | 6012 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 6013 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
6014 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
6015 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6016 | return MBX_SUCCESS; | |
6017 | } | |
58da1ffb | 6018 | processing_queue = 1; |
58da1ffb JS |
6019 | pmbox = lpfc_mbox_get(phba); |
6020 | if (!pmbox) { | |
6021 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6022 | return MBX_SUCCESS; | |
6023 | } | |
6024 | } | |
dea3101e | 6025 | |
ed957684 | 6026 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 6027 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 6028 | if(!pmbox->vport) { |
58da1ffb | 6029 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 6030 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 6031 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 6032 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 6033 | pmbox->u.mb.mbxCommand); |
ed957684 | 6034 | dump_stack(); |
58da1ffb | 6035 | goto out_not_finished; |
ed957684 JS |
6036 | } |
6037 | } | |
6038 | ||
8d63f375 | 6039 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
6040 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
6041 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6042 | goto out_not_finished; | |
6043 | } | |
8d63f375 | 6044 | |
a257bf90 JS |
6045 | /* If HBA has a deferred error attention, fail the iocb. */ |
6046 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
6047 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6048 | goto out_not_finished; | |
6049 | } | |
6050 | ||
dea3101e | 6051 | psli = &phba->sli; |
92d7f7b0 | 6052 | |
3772a991 | 6053 | mb = &pmbox->u.mb; |
dea3101e JB |
6054 | status = MBX_SUCCESS; |
6055 | ||
2e0fef85 JS |
6056 | if (phba->link_state == LPFC_HBA_ERROR) { |
6057 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
6058 | |
6059 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6060 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6061 | "(%d):0311 Mailbox command x%x cannot " | |
6062 | "issue Data: x%x x%x\n", | |
6063 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6064 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 6065 | goto out_not_finished; |
41415862 JW |
6066 | } |
6067 | ||
9940b97b JS |
6068 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
6069 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || | |
6070 | !(hc_copy & HC_MBINT_ENA)) { | |
6071 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6072 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
6073 | "(%d):2528 Mailbox command x%x cannot " |
6074 | "issue Data: x%x x%x\n", | |
6075 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6076 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
6077 | goto out_not_finished; |
6078 | } | |
9290831f JS |
6079 | } |
6080 | ||
dea3101e JB |
6081 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
6082 | /* Polling for a mbox command when another one is already active | |
6083 | * is not allowed in SLI. Also, the driver must have established | |
6084 | * SLI2 mode to queue and process multiple mbox commands. | |
6085 | */ | |
6086 | ||
6087 | if (flag & MBX_POLL) { | |
2e0fef85 | 6088 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
6089 | |
6090 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6091 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6092 | "(%d):2529 Mailbox command x%x " | |
6093 | "cannot issue Data: x%x x%x\n", | |
6094 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6095 | pmbox->u.mb.mbxCommand, | |
6096 | psli->sli_flag, flag); | |
58da1ffb | 6097 | goto out_not_finished; |
dea3101e JB |
6098 | } |
6099 | ||
3772a991 | 6100 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 6101 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6102 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6103 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6104 | "(%d):2530 Mailbox command x%x " | |
6105 | "cannot issue Data: x%x x%x\n", | |
6106 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6107 | pmbox->u.mb.mbxCommand, | |
6108 | psli->sli_flag, flag); | |
58da1ffb | 6109 | goto out_not_finished; |
dea3101e JB |
6110 | } |
6111 | ||
dea3101e JB |
6112 | /* Another mailbox command is still being processed, queue this |
6113 | * command to be processed later. | |
6114 | */ | |
6115 | lpfc_mbox_put(phba, pmbox); | |
6116 | ||
6117 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 6118 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6119 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 6120 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
6121 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
6122 | mb->mbxCommand, phba->pport->port_state, | |
6123 | psli->sli_flag, flag); | |
dea3101e JB |
6124 | |
6125 | psli->slistat.mbox_busy++; | |
2e0fef85 | 6126 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6127 | |
858c9f6c JS |
6128 | if (pmbox->vport) { |
6129 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6130 | LPFC_DISC_TRC_MBOX_VPORT, | |
6131 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
6132 | (uint32_t)mb->mbxCommand, | |
6133 | mb->un.varWords[0], mb->un.varWords[1]); | |
6134 | } | |
6135 | else { | |
6136 | lpfc_debugfs_disc_trc(phba->pport, | |
6137 | LPFC_DISC_TRC_MBOX, | |
6138 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
6139 | (uint32_t)mb->mbxCommand, | |
6140 | mb->un.varWords[0], mb->un.varWords[1]); | |
6141 | } | |
6142 | ||
2e0fef85 | 6143 | return MBX_BUSY; |
dea3101e JB |
6144 | } |
6145 | ||
dea3101e JB |
6146 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
6147 | ||
6148 | /* If we are not polling, we MUST be in SLI2 mode */ | |
6149 | if (flag != MBX_POLL) { | |
3772a991 | 6150 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 6151 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 6152 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6153 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6154 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6155 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6156 | "(%d):2531 Mailbox command x%x " | |
6157 | "cannot issue Data: x%x x%x\n", | |
6158 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6159 | pmbox->u.mb.mbxCommand, | |
6160 | psli->sli_flag, flag); | |
58da1ffb | 6161 | goto out_not_finished; |
dea3101e JB |
6162 | } |
6163 | /* timeout active mbox command */ | |
a309a6b6 JS |
6164 | mod_timer(&psli->mbox_tmo, (jiffies + |
6165 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | |
dea3101e JB |
6166 | } |
6167 | ||
6168 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 6169 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6170 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 6171 | "x%x\n", |
e8b62011 | 6172 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
6173 | mb->mbxCommand, phba->pport->port_state, |
6174 | psli->sli_flag, flag); | |
dea3101e | 6175 | |
858c9f6c JS |
6176 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
6177 | if (pmbox->vport) { | |
6178 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6179 | LPFC_DISC_TRC_MBOX_VPORT, | |
6180 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
6181 | (uint32_t)mb->mbxCommand, | |
6182 | mb->un.varWords[0], mb->un.varWords[1]); | |
6183 | } | |
6184 | else { | |
6185 | lpfc_debugfs_disc_trc(phba->pport, | |
6186 | LPFC_DISC_TRC_MBOX, | |
6187 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
6188 | (uint32_t)mb->mbxCommand, | |
6189 | mb->un.varWords[0], mb->un.varWords[1]); | |
6190 | } | |
6191 | } | |
6192 | ||
dea3101e JB |
6193 | psli->slistat.mbox_cmd++; |
6194 | evtctr = psli->slistat.mbox_event; | |
6195 | ||
6196 | /* next set own bit for the adapter and copy over command word */ | |
6197 | mb->mbxOwner = OWN_CHIP; | |
6198 | ||
3772a991 | 6199 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
6200 | /* Populate mbox extension offset word. */ |
6201 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
6202 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6203 | = (uint8_t *)phba->mbox_ext | |
6204 | - (uint8_t *)phba->mbox; | |
6205 | } | |
6206 | ||
6207 | /* Copy the mailbox extension data */ | |
6208 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6209 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
6210 | (uint8_t *)phba->mbox_ext, | |
6211 | pmbox->in_ext_byte_len); | |
6212 | } | |
6213 | /* Copy command data to host SLIM area */ | |
34b02dcd | 6214 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 6215 | } else { |
7a470277 JS |
6216 | /* Populate mbox extension offset word. */ |
6217 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
6218 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6219 | = MAILBOX_HBA_EXT_OFFSET; | |
6220 | ||
6221 | /* Copy the mailbox extension data */ | |
6222 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6223 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
6224 | MAILBOX_HBA_EXT_OFFSET, | |
6225 | pmbox->context2, pmbox->in_ext_byte_len); | |
6226 | ||
6227 | } | |
9290831f | 6228 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 6229 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 6230 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e JB |
6231 | } |
6232 | ||
6233 | /* First copy mbox command data to HBA SLIM, skip past first | |
6234 | word */ | |
6235 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
6236 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
6237 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
6238 | ||
6239 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 6240 | ldata = *((uint32_t *)mb); |
dea3101e JB |
6241 | to_slim = phba->MBslimaddr; |
6242 | writel(ldata, to_slim); | |
6243 | readl(to_slim); /* flush */ | |
6244 | ||
6245 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6246 | /* switch over to host mailbox */ | |
3772a991 | 6247 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
6248 | } |
6249 | } | |
6250 | ||
6251 | wmb(); | |
dea3101e JB |
6252 | |
6253 | switch (flag) { | |
6254 | case MBX_NOWAIT: | |
09372820 | 6255 | /* Set up reference to mailbox command */ |
dea3101e | 6256 | psli->mbox_active = pmbox; |
09372820 JS |
6257 | /* Interrupt board to do it */ |
6258 | writel(CA_MBATT, phba->CAregaddr); | |
6259 | readl(phba->CAregaddr); /* flush */ | |
6260 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
6261 | break; |
6262 | ||
6263 | case MBX_POLL: | |
09372820 | 6264 | /* Set up null reference to mailbox command */ |
dea3101e | 6265 | psli->mbox_active = NULL; |
09372820 JS |
6266 | /* Interrupt board to do it */ |
6267 | writel(CA_MBATT, phba->CAregaddr); | |
6268 | readl(phba->CAregaddr); /* flush */ | |
6269 | ||
3772a991 | 6270 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6271 | /* First read mbox status word */ |
34b02dcd | 6272 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
6273 | word0 = le32_to_cpu(word0); |
6274 | } else { | |
6275 | /* First read mbox status word */ | |
9940b97b JS |
6276 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
6277 | spin_unlock_irqrestore(&phba->hbalock, | |
6278 | drvr_flag); | |
6279 | goto out_not_finished; | |
6280 | } | |
dea3101e JB |
6281 | } |
6282 | ||
6283 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6284 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6285 | spin_unlock_irqrestore(&phba->hbalock, | |
6286 | drvr_flag); | |
6287 | goto out_not_finished; | |
6288 | } | |
09372820 JS |
6289 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
6290 | mb->mbxCommand) * | |
6291 | 1000) + jiffies; | |
6292 | i = 0; | |
dea3101e | 6293 | /* Wait for command to complete */ |
41415862 JW |
6294 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
6295 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 6296 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 6297 | if (time_after(jiffies, timeout)) { |
dea3101e | 6298 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6299 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 6300 | drvr_flag); |
58da1ffb | 6301 | goto out_not_finished; |
dea3101e JB |
6302 | } |
6303 | ||
6304 | /* Check if we took a mbox interrupt while we were | |
6305 | polling */ | |
6306 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
6307 | && (evtctr != psli->slistat.mbox_event)) | |
6308 | break; | |
6309 | ||
09372820 JS |
6310 | if (i++ > 10) { |
6311 | spin_unlock_irqrestore(&phba->hbalock, | |
6312 | drvr_flag); | |
6313 | msleep(1); | |
6314 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6315 | } | |
dea3101e | 6316 | |
3772a991 | 6317 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6318 | /* First copy command data */ |
34b02dcd | 6319 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
6320 | word0 = le32_to_cpu(word0); |
6321 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6322 | MAILBOX_t *slimmb; | |
34b02dcd | 6323 | uint32_t slimword0; |
dea3101e JB |
6324 | /* Check real SLIM for any errors */ |
6325 | slimword0 = readl(phba->MBslimaddr); | |
6326 | slimmb = (MAILBOX_t *) & slimword0; | |
6327 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
6328 | && slimmb->mbxStatus) { | |
6329 | psli->sli_flag &= | |
3772a991 | 6330 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
6331 | word0 = slimword0; |
6332 | } | |
6333 | } | |
6334 | } else { | |
6335 | /* First copy command data */ | |
6336 | word0 = readl(phba->MBslimaddr); | |
6337 | } | |
6338 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6339 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6340 | spin_unlock_irqrestore(&phba->hbalock, | |
6341 | drvr_flag); | |
6342 | goto out_not_finished; | |
6343 | } | |
dea3101e JB |
6344 | } |
6345 | ||
3772a991 | 6346 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6347 | /* copy results back to user */ |
34b02dcd | 6348 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
6349 | /* Copy the mailbox extension data */ |
6350 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6351 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
6352 | pmbox->context2, | |
6353 | pmbox->out_ext_byte_len); | |
6354 | } | |
dea3101e JB |
6355 | } else { |
6356 | /* First copy command data */ | |
6357 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
6358 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
6359 | /* Copy the mailbox extension data */ |
6360 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6361 | lpfc_memcpy_from_slim(pmbox->context2, | |
6362 | phba->MBslimaddr + | |
6363 | MAILBOX_HBA_EXT_OFFSET, | |
6364 | pmbox->out_ext_byte_len); | |
dea3101e JB |
6365 | } |
6366 | } | |
6367 | ||
6368 | writel(HA_MBATT, phba->HAregaddr); | |
6369 | readl(phba->HAregaddr); /* flush */ | |
6370 | ||
6371 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6372 | status = mb->mbxStatus; | |
6373 | } | |
6374 | ||
2e0fef85 JS |
6375 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
6376 | return status; | |
58da1ffb JS |
6377 | |
6378 | out_not_finished: | |
6379 | if (processing_queue) { | |
da0436e9 | 6380 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
6381 | lpfc_mbox_cmpl_put(phba, pmbox); |
6382 | } | |
6383 | return MBX_NOT_FINISHED; | |
dea3101e JB |
6384 | } |
6385 | ||
f1126688 JS |
6386 | /** |
6387 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
6388 | * @phba: Pointer to HBA context object. | |
6389 | * | |
6390 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
6391 | * the driver internal pending mailbox queue. It will then try to wait out the | |
6392 | * possible outstanding mailbox command before return. | |
6393 | * | |
6394 | * Returns: | |
6395 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
6396 | * the outstanding mailbox command timed out. | |
6397 | **/ | |
6398 | static int | |
6399 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
6400 | { | |
6401 | struct lpfc_sli *psli = &phba->sli; | |
6402 | uint8_t actcmd = MBX_HEARTBEAT; | |
6403 | int rc = 0; | |
6404 | unsigned long timeout; | |
6405 | ||
6406 | /* Mark the asynchronous mailbox command posting as blocked */ | |
6407 | spin_lock_irq(&phba->hbalock); | |
6408 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
6409 | if (phba->sli.mbox_active) | |
6410 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
6411 | spin_unlock_irq(&phba->hbalock); | |
6412 | /* Determine how long we might wait for the active mailbox | |
6413 | * command to be gracefully completed by firmware. | |
6414 | */ | |
6415 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
6416 | jiffies; | |
6417 | /* Wait for the outstnading mailbox command to complete */ | |
6418 | while (phba->sli.mbox_active) { | |
6419 | /* Check active mailbox complete status every 2ms */ | |
6420 | msleep(2); | |
6421 | if (time_after(jiffies, timeout)) { | |
6422 | /* Timeout, marked the outstanding cmd not complete */ | |
6423 | rc = 1; | |
6424 | break; | |
6425 | } | |
6426 | } | |
6427 | ||
6428 | /* Can not cleanly block async mailbox command, fails it */ | |
6429 | if (rc) { | |
6430 | spin_lock_irq(&phba->hbalock); | |
6431 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6432 | spin_unlock_irq(&phba->hbalock); | |
6433 | } | |
6434 | return rc; | |
6435 | } | |
6436 | ||
6437 | /** | |
6438 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
6439 | * @phba: Pointer to HBA context object. | |
6440 | * | |
6441 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
6442 | * commands from the driver internal pending mailbox queue. It makes sure | |
6443 | * that there is no outstanding mailbox command before resuming posting | |
6444 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
6445 | * mailbox command, it will try to wait it out before resuming asynchronous | |
6446 | * mailbox command posting. | |
6447 | **/ | |
6448 | static void | |
6449 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
6450 | { | |
6451 | struct lpfc_sli *psli = &phba->sli; | |
6452 | ||
6453 | spin_lock_irq(&phba->hbalock); | |
6454 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
6455 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
6456 | spin_unlock_irq(&phba->hbalock); | |
6457 | return; | |
6458 | } | |
6459 | ||
6460 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
6461 | * successful or timeout, after timing-out the outstanding mailbox | |
6462 | * command shall always be removed, so just unblock posting async | |
6463 | * mailbox command and resume | |
6464 | */ | |
6465 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6466 | spin_unlock_irq(&phba->hbalock); | |
6467 | ||
6468 | /* wake up worker thread to post asynchronlous mailbox command */ | |
6469 | lpfc_worker_wake_up(phba); | |
6470 | } | |
6471 | ||
da0436e9 JS |
6472 | /** |
6473 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
6474 | * @phba: Pointer to HBA context object. | |
6475 | * @mboxq: Pointer to mailbox object. | |
6476 | * | |
6477 | * The function posts a mailbox to the port. The mailbox is expected | |
6478 | * to be comletely filled in and ready for the port to operate on it. | |
6479 | * This routine executes a synchronous completion operation on the | |
6480 | * mailbox by polling for its completion. | |
6481 | * | |
6482 | * The caller must not be holding any locks when calling this routine. | |
6483 | * | |
6484 | * Returns: | |
6485 | * MBX_SUCCESS - mailbox posted successfully | |
6486 | * Any of the MBX error values. | |
6487 | **/ | |
6488 | static int | |
6489 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
6490 | { | |
6491 | int rc = MBX_SUCCESS; | |
6492 | unsigned long iflag; | |
6493 | uint32_t db_ready; | |
6494 | uint32_t mcqe_status; | |
6495 | uint32_t mbx_cmnd; | |
6496 | unsigned long timeout; | |
6497 | struct lpfc_sli *psli = &phba->sli; | |
6498 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
6499 | struct lpfc_bmbx_create *mbox_rgn; | |
6500 | struct dma_address *dma_address; | |
6501 | struct lpfc_register bmbx_reg; | |
6502 | ||
6503 | /* | |
6504 | * Only one mailbox can be active to the bootstrap mailbox region | |
6505 | * at a time and there is no queueing provided. | |
6506 | */ | |
6507 | spin_lock_irqsave(&phba->hbalock, iflag); | |
6508 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
6509 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6510 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6511 | "(%d):2532 Mailbox command x%x (x%x) " | |
6512 | "cannot issue Data: x%x x%x\n", | |
6513 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6514 | mboxq->u.mb.mbxCommand, | |
6515 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6516 | psli->sli_flag, MBX_POLL); | |
6517 | return MBXERR_ERROR; | |
6518 | } | |
6519 | /* The server grabs the token and owns it until release */ | |
6520 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
6521 | phba->sli.mbox_active = mboxq; | |
6522 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6523 | ||
6524 | /* | |
6525 | * Initialize the bootstrap memory region to avoid stale data areas | |
6526 | * in the mailbox post. Then copy the caller's mailbox contents to | |
6527 | * the bmbx mailbox region. | |
6528 | */ | |
6529 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
6530 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
6531 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
6532 | sizeof(struct lpfc_mqe)); | |
6533 | ||
6534 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
6535 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
6536 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
6537 | ||
6538 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
6539 | * 1000) + jiffies; | |
6540 | do { | |
6541 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
6542 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
6543 | if (!db_ready) | |
6544 | msleep(2); | |
6545 | ||
6546 | if (time_after(jiffies, timeout)) { | |
6547 | rc = MBXERR_ERROR; | |
6548 | goto exit; | |
6549 | } | |
6550 | } while (!db_ready); | |
6551 | ||
6552 | /* Post the low mailbox dma address to the port. */ | |
6553 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
6554 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
6555 | * 1000) + jiffies; | |
6556 | do { | |
6557 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
6558 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
6559 | if (!db_ready) | |
6560 | msleep(2); | |
6561 | ||
6562 | if (time_after(jiffies, timeout)) { | |
6563 | rc = MBXERR_ERROR; | |
6564 | goto exit; | |
6565 | } | |
6566 | } while (!db_ready); | |
6567 | ||
6568 | /* | |
6569 | * Read the CQ to ensure the mailbox has completed. | |
6570 | * If so, update the mailbox status so that the upper layers | |
6571 | * can complete the request normally. | |
6572 | */ | |
6573 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
6574 | sizeof(struct lpfc_mqe)); | |
6575 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
6576 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
6577 | sizeof(struct lpfc_mcqe)); | |
6578 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
0558056c JS |
6579 | /* |
6580 | * When the CQE status indicates a failure and the mailbox status | |
6581 | * indicates success then copy the CQE status into the mailbox status | |
6582 | * (and prefix it with x4000). | |
6583 | */ | |
da0436e9 | 6584 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
6585 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
6586 | bf_set(lpfc_mqe_status, mb, | |
6587 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 6588 | rc = MBXERR_ERROR; |
d7c47992 JS |
6589 | } else |
6590 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
6591 | |
6592 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6593 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " | |
6594 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" | |
6595 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
6596 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6597 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6598 | bf_get(lpfc_mqe_status, mb), | |
6599 | mb->un.mb_words[0], mb->un.mb_words[1], | |
6600 | mb->un.mb_words[2], mb->un.mb_words[3], | |
6601 | mb->un.mb_words[4], mb->un.mb_words[5], | |
6602 | mb->un.mb_words[6], mb->un.mb_words[7], | |
6603 | mb->un.mb_words[8], mb->un.mb_words[9], | |
6604 | mb->un.mb_words[10], mb->un.mb_words[11], | |
6605 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
6606 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
6607 | mboxq->mcqe.trailer); | |
6608 | exit: | |
6609 | /* We are holding the token, no needed for lock when release */ | |
6610 | spin_lock_irqsave(&phba->hbalock, iflag); | |
6611 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6612 | phba->sli.mbox_active = NULL; | |
6613 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6614 | return rc; | |
6615 | } | |
6616 | ||
6617 | /** | |
6618 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
6619 | * @phba: Pointer to HBA context object. | |
6620 | * @pmbox: Pointer to mailbox object. | |
6621 | * @flag: Flag indicating how the mailbox need to be processed. | |
6622 | * | |
6623 | * This function is called by discovery code and HBA management code to submit | |
6624 | * a mailbox command to firmware with SLI-4 interface spec. | |
6625 | * | |
6626 | * Return codes the caller owns the mailbox command after the return of the | |
6627 | * function. | |
6628 | **/ | |
6629 | static int | |
6630 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
6631 | uint32_t flag) | |
6632 | { | |
6633 | struct lpfc_sli *psli = &phba->sli; | |
6634 | unsigned long iflags; | |
6635 | int rc; | |
6636 | ||
8fa38513 JS |
6637 | rc = lpfc_mbox_dev_check(phba); |
6638 | if (unlikely(rc)) { | |
6639 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6640 | "(%d):2544 Mailbox command x%x (x%x) " | |
6641 | "cannot issue Data: x%x x%x\n", | |
6642 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6643 | mboxq->u.mb.mbxCommand, | |
6644 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6645 | psli->sli_flag, flag); | |
6646 | goto out_not_finished; | |
6647 | } | |
6648 | ||
da0436e9 JS |
6649 | /* Detect polling mode and jump to a handler */ |
6650 | if (!phba->sli4_hba.intr_enable) { | |
6651 | if (flag == MBX_POLL) | |
6652 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
6653 | else | |
6654 | rc = -EIO; | |
6655 | if (rc != MBX_SUCCESS) | |
0558056c | 6656 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 JS |
6657 | "(%d):2541 Mailbox command x%x " |
6658 | "(x%x) cannot issue Data: x%x x%x\n", | |
6659 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6660 | mboxq->u.mb.mbxCommand, | |
6661 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6662 | psli->sli_flag, flag); | |
6663 | return rc; | |
6664 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
6665 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
6666 | "(%d):2542 Try to issue mailbox command " | |
6667 | "x%x (x%x) synchronously ahead of async" | |
6668 | "mailbox command queue: x%x x%x\n", | |
da0436e9 JS |
6669 | mboxq->vport ? mboxq->vport->vpi : 0, |
6670 | mboxq->u.mb.mbxCommand, | |
6671 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6672 | psli->sli_flag, flag); | |
f1126688 JS |
6673 | /* Try to block the asynchronous mailbox posting */ |
6674 | rc = lpfc_sli4_async_mbox_block(phba); | |
6675 | if (!rc) { | |
6676 | /* Successfully blocked, now issue sync mbox cmd */ | |
6677 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
6678 | if (rc != MBX_SUCCESS) | |
6679 | lpfc_printf_log(phba, KERN_ERR, | |
6680 | LOG_MBOX | LOG_SLI, | |
6681 | "(%d):2597 Mailbox command " | |
6682 | "x%x (x%x) cannot issue " | |
6683 | "Data: x%x x%x\n", | |
6684 | mboxq->vport ? | |
6685 | mboxq->vport->vpi : 0, | |
6686 | mboxq->u.mb.mbxCommand, | |
6687 | lpfc_sli4_mbox_opcode_get(phba, | |
6688 | mboxq), | |
6689 | psli->sli_flag, flag); | |
6690 | /* Unblock the async mailbox posting afterward */ | |
6691 | lpfc_sli4_async_mbox_unblock(phba); | |
6692 | } | |
6693 | return rc; | |
da0436e9 JS |
6694 | } |
6695 | ||
6696 | /* Now, interrupt mode asynchrous mailbox command */ | |
6697 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
6698 | if (rc) { | |
6699 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6700 | "(%d):2543 Mailbox command x%x (x%x) " | |
6701 | "cannot issue Data: x%x x%x\n", | |
6702 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6703 | mboxq->u.mb.mbxCommand, | |
6704 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6705 | psli->sli_flag, flag); | |
6706 | goto out_not_finished; | |
6707 | } | |
da0436e9 JS |
6708 | |
6709 | /* Put the mailbox command to the driver internal FIFO */ | |
6710 | psli->slistat.mbox_busy++; | |
6711 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6712 | lpfc_mbox_put(phba, mboxq); | |
6713 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6714 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6715 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
6716 | "x%x (x%x) x%x x%x x%x\n", | |
6717 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, | |
6718 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
6719 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6720 | phba->pport->port_state, | |
6721 | psli->sli_flag, MBX_NOWAIT); | |
6722 | /* Wake up worker thread to transport mailbox command from head */ | |
6723 | lpfc_worker_wake_up(phba); | |
6724 | ||
6725 | return MBX_BUSY; | |
6726 | ||
6727 | out_not_finished: | |
6728 | return MBX_NOT_FINISHED; | |
6729 | } | |
6730 | ||
6731 | /** | |
6732 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
6733 | * @phba: Pointer to HBA context object. | |
6734 | * | |
6735 | * This function is called by worker thread to send a mailbox command to | |
6736 | * SLI4 HBA firmware. | |
6737 | * | |
6738 | **/ | |
6739 | int | |
6740 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
6741 | { | |
6742 | struct lpfc_sli *psli = &phba->sli; | |
6743 | LPFC_MBOXQ_t *mboxq; | |
6744 | int rc = MBX_SUCCESS; | |
6745 | unsigned long iflags; | |
6746 | struct lpfc_mqe *mqe; | |
6747 | uint32_t mbx_cmnd; | |
6748 | ||
6749 | /* Check interrupt mode before post async mailbox command */ | |
6750 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
6751 | return MBX_NOT_FINISHED; | |
6752 | ||
6753 | /* Check for mailbox command service token */ | |
6754 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6755 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
6756 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6757 | return MBX_NOT_FINISHED; | |
6758 | } | |
6759 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
6760 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6761 | return MBX_NOT_FINISHED; | |
6762 | } | |
6763 | if (unlikely(phba->sli.mbox_active)) { | |
6764 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6765 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6766 | "0384 There is pending active mailbox cmd\n"); | |
6767 | return MBX_NOT_FINISHED; | |
6768 | } | |
6769 | /* Take the mailbox command service token */ | |
6770 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
6771 | ||
6772 | /* Get the next mailbox command from head of queue */ | |
6773 | mboxq = lpfc_mbox_get(phba); | |
6774 | ||
6775 | /* If no more mailbox command waiting for post, we're done */ | |
6776 | if (!mboxq) { | |
6777 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6778 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6779 | return MBX_SUCCESS; | |
6780 | } | |
6781 | phba->sli.mbox_active = mboxq; | |
6782 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6783 | ||
6784 | /* Check device readiness for posting mailbox command */ | |
6785 | rc = lpfc_mbox_dev_check(phba); | |
6786 | if (unlikely(rc)) | |
6787 | /* Driver clean routine will clean up pending mailbox */ | |
6788 | goto out_not_finished; | |
6789 | ||
6790 | /* Prepare the mbox command to be posted */ | |
6791 | mqe = &mboxq->u.mqe; | |
6792 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
6793 | ||
6794 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
6795 | mod_timer(&psli->mbox_tmo, (jiffies + | |
6796 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); | |
6797 | ||
6798 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
6799 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " | |
6800 | "x%x x%x\n", | |
6801 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
6802 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6803 | phba->pport->port_state, psli->sli_flag); | |
6804 | ||
6805 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
6806 | if (mboxq->vport) { | |
6807 | lpfc_debugfs_disc_trc(mboxq->vport, | |
6808 | LPFC_DISC_TRC_MBOX_VPORT, | |
6809 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
6810 | mbx_cmnd, mqe->un.mb_words[0], | |
6811 | mqe->un.mb_words[1]); | |
6812 | } else { | |
6813 | lpfc_debugfs_disc_trc(phba->pport, | |
6814 | LPFC_DISC_TRC_MBOX, | |
6815 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
6816 | mbx_cmnd, mqe->un.mb_words[0], | |
6817 | mqe->un.mb_words[1]); | |
6818 | } | |
6819 | } | |
6820 | psli->slistat.mbox_cmd++; | |
6821 | ||
6822 | /* Post the mailbox command to the port */ | |
6823 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
6824 | if (rc != MBX_SUCCESS) { | |
6825 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6826 | "(%d):2533 Mailbox command x%x (x%x) " | |
6827 | "cannot issue Data: x%x x%x\n", | |
6828 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6829 | mboxq->u.mb.mbxCommand, | |
6830 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
6831 | psli->sli_flag, MBX_NOWAIT); | |
6832 | goto out_not_finished; | |
6833 | } | |
6834 | ||
6835 | return rc; | |
6836 | ||
6837 | out_not_finished: | |
6838 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6839 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
6840 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
6841 | /* Release the token */ | |
6842 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6843 | phba->sli.mbox_active = NULL; | |
6844 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6845 | ||
6846 | return MBX_NOT_FINISHED; | |
6847 | } | |
6848 | ||
6849 | /** | |
6850 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
6851 | * @phba: Pointer to HBA context object. | |
6852 | * @pmbox: Pointer to mailbox object. | |
6853 | * @flag: Flag indicating how the mailbox need to be processed. | |
6854 | * | |
6855 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
6856 | * the API jump table function pointer from the lpfc_hba struct. | |
6857 | * | |
6858 | * Return codes the caller owns the mailbox command after the return of the | |
6859 | * function. | |
6860 | **/ | |
6861 | int | |
6862 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
6863 | { | |
6864 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
6865 | } | |
6866 | ||
6867 | /** | |
25985edc | 6868 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
6869 | * @phba: The hba struct for which this call is being executed. |
6870 | * @dev_grp: The HBA PCI-Device group number. | |
6871 | * | |
6872 | * This routine sets up the mbox interface API function jump table in @phba | |
6873 | * struct. | |
6874 | * Returns: 0 - success, -ENODEV - failure. | |
6875 | **/ | |
6876 | int | |
6877 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6878 | { | |
6879 | ||
6880 | switch (dev_grp) { | |
6881 | case LPFC_PCI_DEV_LP: | |
6882 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
6883 | phba->lpfc_sli_handle_slow_ring_event = | |
6884 | lpfc_sli_handle_slow_ring_event_s3; | |
6885 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
6886 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
6887 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
6888 | break; | |
6889 | case LPFC_PCI_DEV_OC: | |
6890 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
6891 | phba->lpfc_sli_handle_slow_ring_event = | |
6892 | lpfc_sli_handle_slow_ring_event_s4; | |
6893 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
6894 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
6895 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
6896 | break; | |
6897 | default: | |
6898 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6899 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
6900 | dev_grp); | |
6901 | return -ENODEV; | |
6902 | break; | |
6903 | } | |
6904 | return 0; | |
6905 | } | |
6906 | ||
e59058c4 | 6907 | /** |
3621a710 | 6908 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
6909 | * @phba: Pointer to HBA context object. |
6910 | * @pring: Pointer to driver SLI ring object. | |
6911 | * @piocb: Pointer to address of newly added command iocb. | |
6912 | * | |
6913 | * This function is called with hbalock held to add a command | |
6914 | * iocb to the txq when SLI layer cannot submit the command iocb | |
6915 | * to the ring. | |
6916 | **/ | |
2a9bf3d0 | 6917 | void |
92d7f7b0 | 6918 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 6919 | struct lpfc_iocbq *piocb) |
dea3101e JB |
6920 | { |
6921 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
6922 | list_add_tail(&piocb->list, &pring->txq); | |
6923 | pring->txq_cnt++; | |
dea3101e JB |
6924 | } |
6925 | ||
e59058c4 | 6926 | /** |
3621a710 | 6927 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
6928 | * @phba: Pointer to HBA context object. |
6929 | * @pring: Pointer to driver SLI ring object. | |
6930 | * @piocb: Pointer to address of newly added command iocb. | |
6931 | * | |
6932 | * This function is called with hbalock held before a new | |
6933 | * iocb is submitted to the firmware. This function checks | |
6934 | * txq to flush the iocbs in txq to Firmware before | |
6935 | * submitting new iocbs to the Firmware. | |
6936 | * If there are iocbs in the txq which need to be submitted | |
6937 | * to firmware, lpfc_sli_next_iocb returns the first element | |
6938 | * of the txq after dequeuing it from txq. | |
6939 | * If there is no iocb in the txq then the function will return | |
6940 | * *piocb and *piocb is set to NULL. Caller needs to check | |
6941 | * *piocb to find if there are more commands in the txq. | |
6942 | **/ | |
dea3101e JB |
6943 | static struct lpfc_iocbq * |
6944 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 6945 | struct lpfc_iocbq **piocb) |
dea3101e JB |
6946 | { |
6947 | struct lpfc_iocbq * nextiocb; | |
6948 | ||
6949 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
6950 | if (!nextiocb) { | |
6951 | nextiocb = *piocb; | |
6952 | *piocb = NULL; | |
6953 | } | |
6954 | ||
6955 | return nextiocb; | |
6956 | } | |
6957 | ||
e59058c4 | 6958 | /** |
3772a991 | 6959 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 6960 | * @phba: Pointer to HBA context object. |
3772a991 | 6961 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
6962 | * @piocb: Pointer to command iocb. |
6963 | * @flag: Flag indicating if this command can be put into txq. | |
6964 | * | |
3772a991 JS |
6965 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
6966 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
6967 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
6968 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
6969 | * this function allows only iocbs for posting buffers. This function finds | |
6970 | * next available slot in the command ring and posts the command to the | |
6971 | * available slot and writes the port attention register to request HBA start | |
6972 | * processing new iocb. If there is no slot available in the ring and | |
6973 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
6974 | * the function returns IOCB_BUSY. | |
e59058c4 | 6975 | * |
3772a991 JS |
6976 | * This function is called with hbalock held. The function will return success |
6977 | * after it successfully submit the iocb to firmware or after adding to the | |
6978 | * txq. | |
e59058c4 | 6979 | **/ |
98c9ea5c | 6980 | static int |
3772a991 | 6981 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
6982 | struct lpfc_iocbq *piocb, uint32_t flag) |
6983 | { | |
6984 | struct lpfc_iocbq *nextiocb; | |
6985 | IOCB_t *iocb; | |
3772a991 | 6986 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 6987 | |
92d7f7b0 JS |
6988 | if (piocb->iocb_cmpl && (!piocb->vport) && |
6989 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
6990 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
6991 | lpfc_printf_log(phba, KERN_ERR, | |
6992 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 6993 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
6994 | piocb->iocb.ulpCommand); |
6995 | dump_stack(); | |
6996 | return IOCB_ERROR; | |
6997 | } | |
6998 | ||
6999 | ||
8d63f375 LV |
7000 | /* If the PCI channel is in offline state, do not post iocbs. */ |
7001 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
7002 | return IOCB_ERROR; | |
7003 | ||
a257bf90 JS |
7004 | /* If HBA has a deferred error attention, fail the iocb. */ |
7005 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
7006 | return IOCB_ERROR; | |
7007 | ||
dea3101e JB |
7008 | /* |
7009 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
7010 | */ | |
2e0fef85 | 7011 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
7012 | return IOCB_ERROR; |
7013 | ||
7014 | /* | |
7015 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 7016 | * outstanding event. |
dea3101e | 7017 | */ |
0b727fea | 7018 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
7019 | goto iocb_busy; |
7020 | ||
2e0fef85 | 7021 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 7022 | /* |
2680eeaa | 7023 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
7024 | * can be issued if the link is not up. |
7025 | */ | |
7026 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
7027 | case CMD_GEN_REQUEST64_CR: |
7028 | case CMD_GEN_REQUEST64_CX: | |
7029 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
7030 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 7031 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
7032 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
7033 | MENLO_TRANSPORT_TYPE)) | |
7034 | ||
7035 | goto iocb_busy; | |
7036 | break; | |
dea3101e JB |
7037 | case CMD_QUE_RING_BUF_CN: |
7038 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
7039 | /* |
7040 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
7041 | * completion, iocb_cmpl MUST be 0. | |
7042 | */ | |
7043 | if (piocb->iocb_cmpl) | |
7044 | piocb->iocb_cmpl = NULL; | |
7045 | /*FALLTHROUGH*/ | |
7046 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
7047 | case CMD_CLOSE_XRI_CN: |
7048 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
7049 | break; |
7050 | default: | |
7051 | goto iocb_busy; | |
7052 | } | |
7053 | ||
7054 | /* | |
7055 | * For FCP commands, we must be in a state where we can process link | |
7056 | * attention events. | |
7057 | */ | |
7058 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 7059 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 7060 | goto iocb_busy; |
92d7f7b0 | 7061 | } |
dea3101e | 7062 | |
dea3101e JB |
7063 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
7064 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
7065 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
7066 | ||
7067 | if (iocb) | |
7068 | lpfc_sli_update_ring(phba, pring); | |
7069 | else | |
7070 | lpfc_sli_update_full_ring(phba, pring); | |
7071 | ||
7072 | if (!piocb) | |
7073 | return IOCB_SUCCESS; | |
7074 | ||
7075 | goto out_busy; | |
7076 | ||
7077 | iocb_busy: | |
7078 | pring->stats.iocb_cmd_delay++; | |
7079 | ||
7080 | out_busy: | |
7081 | ||
7082 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 7083 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
7084 | return IOCB_SUCCESS; |
7085 | } | |
7086 | ||
7087 | return IOCB_BUSY; | |
7088 | } | |
7089 | ||
3772a991 | 7090 | /** |
4f774513 JS |
7091 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
7092 | * @phba: Pointer to HBA context object. | |
7093 | * @piocb: Pointer to command iocb. | |
7094 | * @sglq: Pointer to the scatter gather queue object. | |
7095 | * | |
7096 | * This routine converts the bpl or bde that is in the IOCB | |
7097 | * to a sgl list for the sli4 hardware. The physical address | |
7098 | * of the bpl/bde is converted back to a virtual address. | |
7099 | * If the IOCB contains a BPL then the list of BDE's is | |
7100 | * converted to sli4_sge's. If the IOCB contains a single | |
7101 | * BDE then it is converted to a single sli_sge. | |
7102 | * The IOCB is still in cpu endianess so the contents of | |
7103 | * the bpl can be used without byte swapping. | |
7104 | * | |
7105 | * Returns valid XRI = Success, NO_XRI = Failure. | |
7106 | **/ | |
7107 | static uint16_t | |
7108 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
7109 | struct lpfc_sglq *sglq) | |
3772a991 | 7110 | { |
4f774513 JS |
7111 | uint16_t xritag = NO_XRI; |
7112 | struct ulp_bde64 *bpl = NULL; | |
7113 | struct ulp_bde64 bde; | |
7114 | struct sli4_sge *sgl = NULL; | |
7115 | IOCB_t *icmd; | |
7116 | int numBdes = 0; | |
7117 | int i = 0; | |
63e801ce JS |
7118 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
7119 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 7120 | |
4f774513 JS |
7121 | if (!piocbq || !sglq) |
7122 | return xritag; | |
7123 | ||
7124 | sgl = (struct sli4_sge *)sglq->sgl; | |
7125 | icmd = &piocbq->iocb; | |
7126 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
7127 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
7128 | sizeof(struct ulp_bde64); | |
7129 | /* The addrHigh and addrLow fields within the IOCB | |
7130 | * have not been byteswapped yet so there is no | |
7131 | * need to swap them back. | |
7132 | */ | |
7133 | bpl = (struct ulp_bde64 *) | |
7134 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | |
7135 | ||
7136 | if (!bpl) | |
7137 | return xritag; | |
7138 | ||
7139 | for (i = 0; i < numBdes; i++) { | |
7140 | /* Should already be byte swapped. */ | |
28baac74 JS |
7141 | sgl->addr_hi = bpl->addrHigh; |
7142 | sgl->addr_lo = bpl->addrLow; | |
7143 | ||
0558056c | 7144 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7145 | if ((i+1) == numBdes) |
7146 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
7147 | else | |
7148 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
7149 | /* swap the size field back to the cpu so we |
7150 | * can assign it to the sgl. | |
7151 | */ | |
7152 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
7153 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
7154 | /* The offsets in the sgl need to be accumulated |
7155 | * separately for the request and reply lists. | |
7156 | * The request is always first, the reply follows. | |
7157 | */ | |
7158 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
7159 | /* add up the reply sg entries */ | |
7160 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
7161 | inbound++; | |
7162 | /* first inbound? reset the offset */ | |
7163 | if (inbound == 1) | |
7164 | offset = 0; | |
7165 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
7166 | offset += bde.tus.f.bdeSize; | |
7167 | } | |
546fc854 | 7168 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
7169 | bpl++; |
7170 | sgl++; | |
7171 | } | |
7172 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
7173 | /* The addrHigh and addrLow fields of the BDE have not | |
7174 | * been byteswapped yet so they need to be swapped | |
7175 | * before putting them in the sgl. | |
7176 | */ | |
7177 | sgl->addr_hi = | |
7178 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
7179 | sgl->addr_lo = | |
7180 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 7181 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7182 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
7183 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
7184 | sgl->sge_len = |
7185 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
7186 | } |
7187 | return sglq->sli4_xritag; | |
3772a991 | 7188 | } |
92d7f7b0 | 7189 | |
e59058c4 | 7190 | /** |
4f774513 | 7191 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 7192 | * @phba: Pointer to HBA context object. |
e59058c4 | 7193 | * |
a93ff37a | 7194 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
7195 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
7196 | * held. | |
4f774513 JS |
7197 | * |
7198 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 7199 | **/ |
4f774513 | 7200 | static uint32_t |
8fa38513 | 7201 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 7202 | { |
8fa38513 JS |
7203 | ++phba->fcp_qidx; |
7204 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) | |
7205 | phba->fcp_qidx = 0; | |
92d7f7b0 | 7206 | |
8fa38513 | 7207 | return phba->fcp_qidx; |
92d7f7b0 JS |
7208 | } |
7209 | ||
e59058c4 | 7210 | /** |
4f774513 | 7211 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 7212 | * @phba: Pointer to HBA context object. |
4f774513 JS |
7213 | * @piocb: Pointer to command iocb. |
7214 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 7215 | * |
4f774513 JS |
7216 | * This routine converts the iocb command to its Work Queue Entry |
7217 | * equivalent. The wqe pointer should not have any fields set when | |
7218 | * this routine is called because it will memcpy over them. | |
7219 | * This routine does not set the CQ_ID or the WQEC bits in the | |
7220 | * wqe. | |
e59058c4 | 7221 | * |
4f774513 | 7222 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 7223 | **/ |
cf5bf97e | 7224 | static int |
4f774513 JS |
7225 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
7226 | union lpfc_wqe *wqe) | |
cf5bf97e | 7227 | { |
5ffc266e | 7228 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
7229 | uint8_t ct = 0; |
7230 | uint32_t fip; | |
7231 | uint32_t abort_tag; | |
7232 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
7233 | uint8_t cmnd; | |
7234 | uint16_t xritag; | |
dcf2a4e0 JS |
7235 | uint16_t abrt_iotag; |
7236 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 7237 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 7238 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
7239 | int numBdes, i; |
7240 | struct ulp_bde64 bde; | |
c31098ce | 7241 | struct lpfc_nodelist *ndlp; |
4f774513 | 7242 | |
45ed1190 | 7243 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 7244 | /* The fcp commands will set command type */ |
0c287589 | 7245 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 7246 | command_type = FCP_COMMAND; |
c868595d | 7247 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
7248 | command_type = ELS_COMMAND_FIP; |
7249 | else | |
7250 | command_type = ELS_COMMAND_NON_FIP; | |
7251 | ||
4f774513 JS |
7252 | /* Some of the fields are in the right position already */ |
7253 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
7254 | abort_tag = (uint32_t) iocbq->iotag; | |
7255 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 7256 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
7257 | /* words0-2 bpl convert bde */ |
7258 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
7259 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
7260 | sizeof(struct ulp_bde64); | |
4f774513 JS |
7261 | bpl = (struct ulp_bde64 *) |
7262 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
7263 | if (!bpl) | |
7264 | return IOCB_ERROR; | |
cf5bf97e | 7265 | |
4f774513 JS |
7266 | /* Should already be byte swapped. */ |
7267 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
7268 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
7269 | /* swap the size field back to the cpu so we | |
7270 | * can assign it to the sgl. | |
7271 | */ | |
7272 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
7273 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
7274 | total_len = 0; | |
7275 | for (i = 0; i < numBdes; i++) { | |
7276 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
7277 | total_len += bde.tus.f.bdeSize; | |
7278 | } | |
4f774513 | 7279 | } else |
5ffc266e | 7280 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 7281 | |
4f774513 JS |
7282 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
7283 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 7284 | |
4f774513 JS |
7285 | switch (iocbq->iocb.ulpCommand) { |
7286 | case CMD_ELS_REQUEST64_CR: | |
c31098ce | 7287 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 JS |
7288 | if (!iocbq->iocb.ulpLe) { |
7289 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7290 | "2007 Only Limited Edition cmd Format" | |
7291 | " supported 0x%x\n", | |
7292 | iocbq->iocb.ulpCommand); | |
7293 | return IOCB_ERROR; | |
7294 | } | |
5ffc266e | 7295 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
7296 | /* Els_reguest64 has a TMO */ |
7297 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
7298 | iocbq->iocb.ulpTimeout); | |
7299 | /* Need a VF for word 4 set the vf bit*/ | |
7300 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
7301 | /* And a VFID for word 12 */ | |
7302 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 7303 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
7304 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
7305 | iocbq->iocb.ulpContext); | |
7306 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
7307 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 7308 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
c868595d JS |
7309 | if (command_type == ELS_COMMAND_FIP) { |
7310 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) | |
7311 | >> LPFC_FIP_ELS_ID_SHIFT); | |
7312 | } | |
6d368e53 JS |
7313 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
7314 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
7315 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
7316 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
7317 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
7318 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
7319 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
7320 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
4f774513 | 7321 | break; |
5ffc266e | 7322 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
7323 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
7324 | iocbq->iocb.un.ulpWord[3]); | |
7325 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7326 | iocbq->iocb.ulpContext); | |
5ffc266e JS |
7327 | /* The entire sequence is transmitted for this IOCB */ |
7328 | xmit_len = total_len; | |
7329 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
4f774513 | 7330 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
7331 | /* word3 iocb=io_tag32 wqe=reserved */ |
7332 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
7333 | /* word4 relative_offset memcpy */ |
7334 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
7335 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
7336 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
7337 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
7338 | LPFC_WQE_IOD_WRITE); | |
7339 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
7340 | LPFC_WQE_LENLOC_WORD12); | |
7341 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
7342 | wqe->xmit_sequence.xmit_len = xmit_len; |
7343 | command_type = OTHER_COMMAND; | |
4f774513 JS |
7344 | break; |
7345 | case CMD_XMIT_BCAST64_CN: | |
f0d9bccc JS |
7346 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
7347 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
7348 | /* word4 iocb=rsvd wqe=rsvd */ |
7349 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
7350 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 7351 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 7352 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
7353 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
7354 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
7355 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
7356 | LPFC_WQE_LENLOC_WORD3); | |
7357 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
4f774513 JS |
7358 | break; |
7359 | case CMD_FCP_IWRITE64_CR: | |
7360 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
7361 | /* word3 iocb=iotag wqe=payload_offset_len */ |
7362 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
7363 | wqe->fcp_iwrite.payload_offset_len = | |
7364 | xmit_len + sizeof(struct fcp_rsp); | |
7365 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
7366 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
7367 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
7368 | iocbq->iocb.ulpFCP2Rcvy); | |
7369 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
7370 | /* Always open the exchange */ | |
7371 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
7372 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
7373 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); | |
7374 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
7375 | LPFC_WQE_LENLOC_WORD4); | |
7376 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
7377 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
7378 | break; | |
4f774513 | 7379 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
7380 | /* word3 iocb=iotag wqe=payload_offset_len */ |
7381 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
7382 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 7383 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
7384 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
7385 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
7386 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
7387 | iocbq->iocb.ulpFCP2Rcvy); | |
7388 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
7389 | /* Always open the exchange */ |
7390 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
7391 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
7392 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); | |
7393 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
7394 | LPFC_WQE_LENLOC_WORD4); | |
7395 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
7396 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
7397 | break; | |
4f774513 | 7398 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
7399 | /* word3 iocb=IO_TAG wqe=reserved */ |
7400 | wqe->fcp_icmd.rsrvd3 = 0; | |
7401 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 7402 | /* Always open the exchange */ |
f0d9bccc JS |
7403 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
7404 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
7405 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
7406 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
7407 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
7408 | LPFC_WQE_LENLOC_NONE); | |
7409 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 JS |
7410 | break; |
7411 | case CMD_GEN_REQUEST64_CR: | |
63e801ce JS |
7412 | /* For this command calculate the xmit length of the |
7413 | * request bde. | |
7414 | */ | |
7415 | xmit_len = 0; | |
7416 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
7417 | sizeof(struct ulp_bde64); | |
7418 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 7419 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
7420 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
7421 | break; | |
63e801ce JS |
7422 | xmit_len += bde.tus.f.bdeSize; |
7423 | } | |
f0d9bccc JS |
7424 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
7425 | wqe->gen_req.request_payload_len = xmit_len; | |
7426 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
7427 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
7428 | /* word6 context tag copied in memcpy */ |
7429 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
7430 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
7431 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7432 | "2015 Invalid CT %x command 0x%x\n", | |
7433 | ct, iocbq->iocb.ulpCommand); | |
7434 | return IOCB_ERROR; | |
7435 | } | |
f0d9bccc JS |
7436 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
7437 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
7438 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
7439 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
7440 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
7441 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
7442 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
7443 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 JS |
7444 | command_type = OTHER_COMMAND; |
7445 | break; | |
7446 | case CMD_XMIT_ELS_RSP64_CX: | |
c31098ce | 7447 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 7448 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
7449 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
7450 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
4f774513 | 7451 | /* word4 iocb=did wge=rsvd. */ |
f0d9bccc | 7452 | wqe->xmit_els_rsp.rsvd4 = 0; |
4f774513 JS |
7453 | /* word5 iocb=rsvd wge=did */ |
7454 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
7455 | iocbq->iocb.un.elsreq64.remoteID); | |
f0d9bccc JS |
7456 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
7457 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
7458 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
7459 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7460 | iocbq->iocb.ulpContext); | |
4f774513 | 7461 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 7462 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 7463 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
7464 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
7465 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
7466 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
7467 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
7468 | LPFC_WQE_LENLOC_WORD3); | |
7469 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
7470 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
7471 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
4f774513 JS |
7472 | command_type = OTHER_COMMAND; |
7473 | break; | |
7474 | case CMD_CLOSE_XRI_CN: | |
7475 | case CMD_ABORT_XRI_CN: | |
7476 | case CMD_ABORT_XRI_CX: | |
7477 | /* words 0-2 memcpy should be 0 rserved */ | |
7478 | /* port will send abts */ | |
dcf2a4e0 JS |
7479 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
7480 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
7481 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
7482 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
7483 | } else | |
7484 | fip = 0; | |
7485 | ||
7486 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 7487 | /* |
dcf2a4e0 JS |
7488 | * The link is down, or the command was ELS_FIP |
7489 | * so the fw does not need to send abts | |
4f774513 JS |
7490 | * on the wire. |
7491 | */ | |
7492 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
7493 | else | |
7494 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
7495 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
7496 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
7497 | wqe->abort_cmd.rsrvd5 = 0; | |
7498 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
7499 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
7500 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
7501 | /* |
7502 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
7503 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
7504 | */ | |
f0d9bccc JS |
7505 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
7506 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
7507 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
7508 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
7509 | cmnd = CMD_ABORT_XRI_CX; |
7510 | command_type = OTHER_COMMAND; | |
7511 | xritag = 0; | |
7512 | break; | |
6669f9bb | 7513 | case CMD_XMIT_BLS_RSP64_CX: |
546fc854 | 7514 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
7515 | * we re-construct this WQE here based on information in |
7516 | * iocbq from scratch. | |
7517 | */ | |
7518 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 7519 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 7520 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
7521 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
7522 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
7523 | LPFC_ABTS_UNSOL_INT) { |
7524 | /* ABTS sent by initiator to CT exchange, the | |
7525 | * RX_ID field will be filled with the newly | |
7526 | * allocated responder XRI. | |
7527 | */ | |
7528 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
7529 | iocbq->sli4_xritag); | |
7530 | } else { | |
7531 | /* ABTS sent by responder to CT exchange, the | |
7532 | * RX_ID field will be filled with the responder | |
7533 | * RX_ID from ABTS. | |
7534 | */ | |
7535 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 7536 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 7537 | } |
6669f9bb JS |
7538 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
7539 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
7540 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, | |
7541 | iocbq->iocb.ulpContext); | |
f0d9bccc JS |
7542 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
7543 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
7544 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
7545 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
7546 | command_type = OTHER_COMMAND; | |
546fc854 JS |
7547 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
7548 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
7549 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
7550 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
7551 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
7552 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
7553 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
7554 | } | |
7555 | ||
6669f9bb | 7556 | break; |
4f774513 JS |
7557 | case CMD_XRI_ABORTED_CX: |
7558 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
7559 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
7560 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
7561 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
7562 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
7563 | default: | |
7564 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7565 | "2014 Invalid command 0x%x\n", | |
7566 | iocbq->iocb.ulpCommand); | |
7567 | return IOCB_ERROR; | |
7568 | break; | |
4f774513 | 7569 | } |
6d368e53 | 7570 | |
f0d9bccc JS |
7571 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
7572 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
7573 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
7574 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
7575 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
7576 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
7577 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
7578 | return 0; |
7579 | } | |
7580 | ||
7581 | /** | |
7582 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
7583 | * @phba: Pointer to HBA context object. | |
7584 | * @ring_number: SLI ring number to issue iocb on. | |
7585 | * @piocb: Pointer to command iocb. | |
7586 | * @flag: Flag indicating if this command can be put into txq. | |
7587 | * | |
7588 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
7589 | * an iocb command to an HBA with SLI-4 interface spec. | |
7590 | * | |
7591 | * This function is called with hbalock held. The function will return success | |
7592 | * after it successfully submit the iocb to firmware or after adding to the | |
7593 | * txq. | |
7594 | **/ | |
7595 | static int | |
7596 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
7597 | struct lpfc_iocbq *piocb, uint32_t flag) | |
7598 | { | |
7599 | struct lpfc_sglq *sglq; | |
4f774513 JS |
7600 | union lpfc_wqe wqe; |
7601 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
7602 | |
7603 | if (piocb->sli4_xritag == NO_XRI) { | |
7604 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
546fc854 JS |
7605 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
7606 | piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX) | |
4f774513 JS |
7607 | sglq = NULL; |
7608 | else { | |
2a9bf3d0 JS |
7609 | if (pring->txq_cnt) { |
7610 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
7611 | __lpfc_sli_ringtx_put(phba, | |
7612 | pring, piocb); | |
7613 | return IOCB_SUCCESS; | |
7614 | } else { | |
7615 | return IOCB_BUSY; | |
7616 | } | |
7617 | } else { | |
6d368e53 | 7618 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
7619 | if (!sglq) { |
7620 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
7621 | __lpfc_sli_ringtx_put(phba, | |
7622 | pring, | |
7623 | piocb); | |
7624 | return IOCB_SUCCESS; | |
7625 | } else | |
7626 | return IOCB_BUSY; | |
7627 | } | |
7628 | } | |
4f774513 JS |
7629 | } |
7630 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6d368e53 JS |
7631 | /* These IO's already have an XRI and a mapped sgl. */ |
7632 | sglq = NULL; | |
4f774513 | 7633 | } else { |
6d368e53 JS |
7634 | /* |
7635 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
7636 | * sglq is on the active list |
7637 | */ | |
7638 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
7639 | if (!sglq) | |
7640 | return IOCB_ERROR; | |
7641 | } | |
7642 | ||
7643 | if (sglq) { | |
6d368e53 | 7644 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 7645 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 7646 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
7647 | return IOCB_ERROR; |
7648 | } | |
7649 | ||
7650 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
7651 | return IOCB_ERROR; | |
7652 | ||
341af102 JS |
7653 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
7654 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
7655 | /* |
7656 | * For FCP command IOCB, get a new WQ index to distribute | |
7657 | * WQE across the WQsr. On the other hand, for abort IOCB, | |
7658 | * it carries the same WQ index to the original command | |
7659 | * IOCB. | |
7660 | */ | |
341af102 | 7661 | if (piocb->iocb_flag & LPFC_IO_FCP) |
5ffc266e JS |
7662 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
7663 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], | |
7664 | &wqe)) | |
4f774513 JS |
7665 | return IOCB_ERROR; |
7666 | } else { | |
7667 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
7668 | return IOCB_ERROR; | |
7669 | } | |
7670 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
7671 | ||
7672 | return 0; | |
7673 | } | |
7674 | ||
7675 | /** | |
7676 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
7677 | * | |
7678 | * This routine wraps the actual lockless version for issusing IOCB function | |
7679 | * pointer from the lpfc_hba struct. | |
7680 | * | |
7681 | * Return codes: | |
7682 | * IOCB_ERROR - Error | |
7683 | * IOCB_SUCCESS - Success | |
7684 | * IOCB_BUSY - Busy | |
7685 | **/ | |
2a9bf3d0 | 7686 | int |
4f774513 JS |
7687 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
7688 | struct lpfc_iocbq *piocb, uint32_t flag) | |
7689 | { | |
7690 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
7691 | } | |
7692 | ||
7693 | /** | |
25985edc | 7694 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
7695 | * @phba: The hba struct for which this call is being executed. |
7696 | * @dev_grp: The HBA PCI-Device group number. | |
7697 | * | |
7698 | * This routine sets up the SLI interface API function jump table in @phba | |
7699 | * struct. | |
7700 | * Returns: 0 - success, -ENODEV - failure. | |
7701 | **/ | |
7702 | int | |
7703 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
7704 | { | |
7705 | ||
7706 | switch (dev_grp) { | |
7707 | case LPFC_PCI_DEV_LP: | |
7708 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
7709 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
7710 | break; | |
7711 | case LPFC_PCI_DEV_OC: | |
7712 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
7713 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
7714 | break; | |
7715 | default: | |
7716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7717 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
7718 | dev_grp); | |
7719 | return -ENODEV; | |
7720 | break; | |
7721 | } | |
7722 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
7723 | return 0; | |
7724 | } | |
7725 | ||
7726 | /** | |
7727 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
7728 | * @phba: Pointer to HBA context object. | |
7729 | * @pring: Pointer to driver SLI ring object. | |
7730 | * @piocb: Pointer to command iocb. | |
7731 | * @flag: Flag indicating if this command can be put into txq. | |
7732 | * | |
7733 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
7734 | * function. This function gets the hbalock and calls | |
7735 | * __lpfc_sli_issue_iocb function and will return the error returned | |
7736 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
7737 | * functions which do not hold hbalock. | |
7738 | **/ | |
7739 | int | |
7740 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
7741 | struct lpfc_iocbq *piocb, uint32_t flag) | |
7742 | { | |
7743 | unsigned long iflags; | |
7744 | int rc; | |
7745 | ||
7746 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7747 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
7748 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7749 | ||
7750 | return rc; | |
7751 | } | |
7752 | ||
7753 | /** | |
7754 | * lpfc_extra_ring_setup - Extra ring setup function | |
7755 | * @phba: Pointer to HBA context object. | |
7756 | * | |
7757 | * This function is called while driver attaches with the | |
7758 | * HBA to setup the extra ring. The extra ring is used | |
7759 | * only when driver needs to support target mode functionality | |
7760 | * or IP over FC functionalities. | |
7761 | * | |
7762 | * This function is called with no lock held. | |
7763 | **/ | |
7764 | static int | |
7765 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
7766 | { | |
7767 | struct lpfc_sli *psli; | |
7768 | struct lpfc_sli_ring *pring; | |
7769 | ||
7770 | psli = &phba->sli; | |
7771 | ||
7772 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
7773 | ||
7774 | /* Take some away from the FCP ring */ | |
7775 | pring = &psli->ring[psli->fcp_ring]; | |
7776 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
7777 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
cf5bf97e JW |
7778 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
7779 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
7780 | ||
a4bc3379 JS |
7781 | /* and give them to the extra ring */ |
7782 | pring = &psli->ring[psli->extra_ring]; | |
7783 | ||
cf5bf97e JW |
7784 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
7785 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
7786 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
7787 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
7788 | ||
7789 | /* Setup default profile for this ring */ | |
7790 | pring->iotag_max = 4096; | |
7791 | pring->num_mask = 1; | |
7792 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
7793 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
7794 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
7795 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
7796 | return 0; | |
7797 | } | |
7798 | ||
e59058c4 | 7799 | /** |
3621a710 | 7800 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
7801 | * @phba: Pointer to HBA context object. |
7802 | * @pring: Pointer to driver SLI ring object. | |
7803 | * @iocbq: Pointer to iocb object. | |
7804 | * | |
7805 | * This function is called by the slow ring event handler | |
7806 | * function when there is an ASYNC event iocb in the ring. | |
7807 | * This function is called with no lock held. | |
7808 | * Currently this function handles only temperature related | |
7809 | * ASYNC events. The function decodes the temperature sensor | |
7810 | * event message and posts events for the management applications. | |
7811 | **/ | |
98c9ea5c | 7812 | static void |
57127f15 JS |
7813 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
7814 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
7815 | { | |
7816 | IOCB_t *icmd; | |
7817 | uint16_t evt_code; | |
7818 | uint16_t temp; | |
7819 | struct temp_event temp_event_data; | |
7820 | struct Scsi_Host *shost; | |
a257bf90 | 7821 | uint32_t *iocb_w; |
57127f15 JS |
7822 | |
7823 | icmd = &iocbq->iocb; | |
7824 | evt_code = icmd->un.asyncstat.evt_code; | |
7825 | temp = icmd->ulpContext; | |
7826 | ||
7827 | if ((evt_code != ASYNC_TEMP_WARN) && | |
7828 | (evt_code != ASYNC_TEMP_SAFE)) { | |
a257bf90 | 7829 | iocb_w = (uint32_t *) icmd; |
57127f15 JS |
7830 | lpfc_printf_log(phba, |
7831 | KERN_ERR, | |
7832 | LOG_SLI, | |
76bb24ef | 7833 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 7834 | " evt_code 0x%x\n" |
a257bf90 JS |
7835 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
7836 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
7837 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
7838 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
57127f15 | 7839 | pring->ringno, |
a257bf90 JS |
7840 | icmd->un.asyncstat.evt_code, |
7841 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], | |
7842 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
7843 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
7844 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
7845 | ||
57127f15 JS |
7846 | return; |
7847 | } | |
7848 | temp_event_data.data = (uint32_t)temp; | |
7849 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
7850 | if (evt_code == ASYNC_TEMP_WARN) { | |
7851 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
7852 | lpfc_printf_log(phba, | |
09372820 | 7853 | KERN_ERR, |
57127f15 | 7854 | LOG_TEMP, |
76bb24ef | 7855 | "0347 Adapter is very hot, please take " |
57127f15 JS |
7856 | "corrective action. temperature : %d Celsius\n", |
7857 | temp); | |
7858 | } | |
7859 | if (evt_code == ASYNC_TEMP_SAFE) { | |
7860 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
7861 | lpfc_printf_log(phba, | |
09372820 | 7862 | KERN_ERR, |
57127f15 JS |
7863 | LOG_TEMP, |
7864 | "0340 Adapter temperature is OK now. " | |
7865 | "temperature : %d Celsius\n", | |
7866 | temp); | |
7867 | } | |
7868 | ||
7869 | /* Send temperature change event to applications */ | |
7870 | shost = lpfc_shost_from_vport(phba->pport); | |
7871 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
7872 | sizeof(temp_event_data), (char *) &temp_event_data, | |
ddcc50f0 | 7873 | LPFC_NL_VENDOR_ID); |
57127f15 JS |
7874 | |
7875 | } | |
7876 | ||
7877 | ||
e59058c4 | 7878 | /** |
3621a710 | 7879 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
7880 | * @phba: Pointer to HBA context object. |
7881 | * | |
7882 | * lpfc_sli_setup sets up rings of the SLI interface with | |
7883 | * number of iocbs per ring and iotags. This function is | |
7884 | * called while driver attach to the HBA and before the | |
7885 | * interrupts are enabled. So there is no need for locking. | |
7886 | * | |
7887 | * This function always returns 0. | |
7888 | **/ | |
dea3101e JB |
7889 | int |
7890 | lpfc_sli_setup(struct lpfc_hba *phba) | |
7891 | { | |
ed957684 | 7892 | int i, totiocbsize = 0; |
dea3101e JB |
7893 | struct lpfc_sli *psli = &phba->sli; |
7894 | struct lpfc_sli_ring *pring; | |
7895 | ||
7896 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
7897 | psli->sli_flag = 0; | |
7898 | psli->fcp_ring = LPFC_FCP_RING; | |
7899 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 7900 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 7901 | |
604a3e30 JB |
7902 | psli->iocbq_lookup = NULL; |
7903 | psli->iocbq_lookup_len = 0; | |
7904 | psli->last_iotag = 0; | |
7905 | ||
dea3101e JB |
7906 | for (i = 0; i < psli->num_rings; i++) { |
7907 | pring = &psli->ring[i]; | |
7908 | switch (i) { | |
7909 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
7910 | /* numCiocb and numRiocb are used in config_port */ | |
7911 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
7912 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
7913 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
7914 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
7915 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
7916 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 7917 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7918 | SLI3_IOCB_CMD_SIZE : |
7919 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7920 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7921 | SLI3_IOCB_RSP_SIZE : |
7922 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
7923 | pring->iotag_ctr = 0; |
7924 | pring->iotag_max = | |
92d7f7b0 | 7925 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
7926 | pring->fast_iotag = pring->iotag_max; |
7927 | pring->num_mask = 0; | |
7928 | break; | |
a4bc3379 | 7929 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e JB |
7930 | /* numCiocb and numRiocb are used in config_port */ |
7931 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
7932 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 7933 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7934 | SLI3_IOCB_CMD_SIZE : |
7935 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7936 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7937 | SLI3_IOCB_RSP_SIZE : |
7938 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 7939 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
7940 | pring->num_mask = 0; |
7941 | break; | |
7942 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
7943 | /* numCiocb and numRiocb are used in config_port */ | |
7944 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
7945 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 7946 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7947 | SLI3_IOCB_CMD_SIZE : |
7948 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7949 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7950 | SLI3_IOCB_RSP_SIZE : |
7951 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
7952 | pring->fast_iotag = 0; |
7953 | pring->iotag_ctr = 0; | |
7954 | pring->iotag_max = 4096; | |
57127f15 JS |
7955 | pring->lpfc_sli_rcv_async_status = |
7956 | lpfc_sli_async_event_handler; | |
6669f9bb | 7957 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 7958 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
7959 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
7960 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 7961 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7962 | lpfc_els_unsol_event; |
dea3101e | 7963 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
7964 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
7965 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 7966 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7967 | lpfc_els_unsol_event; |
dea3101e JB |
7968 | pring->prt[2].profile = 0; /* Mask 2 */ |
7969 | /* NameServer Inquiry */ | |
6a9c52cf | 7970 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 7971 | /* NameServer */ |
6a9c52cf | 7972 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 7973 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7974 | lpfc_ct_unsol_event; |
dea3101e JB |
7975 | pring->prt[3].profile = 0; /* Mask 3 */ |
7976 | /* NameServer response */ | |
6a9c52cf | 7977 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 7978 | /* NameServer */ |
6a9c52cf | 7979 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 7980 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7981 | lpfc_ct_unsol_event; |
6669f9bb JS |
7982 | /* abort unsolicited sequence */ |
7983 | pring->prt[4].profile = 0; /* Mask 4 */ | |
7984 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
7985 | pring->prt[4].type = FC_TYPE_BLS; | |
7986 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
7987 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e JB |
7988 | break; |
7989 | } | |
ed957684 | 7990 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 7991 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 7992 | } |
ed957684 | 7993 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 7994 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
7995 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
7996 | "SLI2 SLIM Data: x%x x%lx\n", | |
7997 | phba->brd_no, totiocbsize, | |
7998 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 7999 | } |
cf5bf97e JW |
8000 | if (phba->cfg_multi_ring_support == 2) |
8001 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
8002 | |
8003 | return 0; | |
8004 | } | |
8005 | ||
e59058c4 | 8006 | /** |
3621a710 | 8007 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
8008 | * @phba: Pointer to HBA context object. |
8009 | * | |
8010 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
8011 | * ring. This function also initializes ring indices of each ring. | |
8012 | * This function is called during the initialization of the SLI | |
8013 | * interface of an HBA. | |
8014 | * This function is called with no lock held and always returns | |
8015 | * 1. | |
8016 | **/ | |
dea3101e | 8017 | int |
2e0fef85 | 8018 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
8019 | { |
8020 | struct lpfc_sli *psli; | |
8021 | struct lpfc_sli_ring *pring; | |
604a3e30 | 8022 | int i; |
dea3101e JB |
8023 | |
8024 | psli = &phba->sli; | |
2e0fef85 | 8025 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8026 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 8027 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
8028 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
8029 | for (i = 0; i < psli->num_rings; i++) { | |
8030 | pring = &psli->ring[i]; | |
8031 | pring->ringno = i; | |
8032 | pring->next_cmdidx = 0; | |
8033 | pring->local_getidx = 0; | |
8034 | pring->cmdidx = 0; | |
8035 | INIT_LIST_HEAD(&pring->txq); | |
8036 | INIT_LIST_HEAD(&pring->txcmplq); | |
8037 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 8038 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 8039 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 8040 | } |
2e0fef85 JS |
8041 | spin_unlock_irq(&phba->hbalock); |
8042 | return 1; | |
dea3101e JB |
8043 | } |
8044 | ||
04c68496 JS |
8045 | /** |
8046 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
8047 | * @phba: Pointer to HBA context object. | |
8048 | * | |
8049 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
8050 | * flush all the mailbox commands in the three possible stages in the mailbox | |
8051 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
8052 | * command; and completed mailbox command queue. It is caller's responsibility | |
8053 | * to make sure that the driver is in the proper state to flush the mailbox | |
8054 | * command sub-system. Namely, the posting of mailbox commands into the | |
8055 | * pending mailbox command queue from the various clients must be stopped; | |
8056 | * either the HBA is in a state that it will never works on the outstanding | |
8057 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
8058 | * mailbox command has been completed. | |
8059 | **/ | |
8060 | static void | |
8061 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
8062 | { | |
8063 | LIST_HEAD(completions); | |
8064 | struct lpfc_sli *psli = &phba->sli; | |
8065 | LPFC_MBOXQ_t *pmb; | |
8066 | unsigned long iflag; | |
8067 | ||
8068 | /* Flush all the mailbox commands in the mbox system */ | |
8069 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8070 | /* The pending mailbox command queue */ | |
8071 | list_splice_init(&phba->sli.mboxq, &completions); | |
8072 | /* The outstanding active mailbox command */ | |
8073 | if (psli->mbox_active) { | |
8074 | list_add_tail(&psli->mbox_active->list, &completions); | |
8075 | psli->mbox_active = NULL; | |
8076 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8077 | } | |
8078 | /* The completed mailbox command queue */ | |
8079 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
8080 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8081 | ||
8082 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
8083 | while (!list_empty(&completions)) { | |
8084 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
8085 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8086 | if (pmb->mbox_cmpl) | |
8087 | pmb->mbox_cmpl(phba, pmb); | |
8088 | } | |
8089 | } | |
8090 | ||
e59058c4 | 8091 | /** |
3621a710 | 8092 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
8093 | * @vport: Pointer to virtual port object. |
8094 | * | |
8095 | * lpfc_sli_host_down is called to clean up the resources | |
8096 | * associated with a vport before destroying virtual | |
8097 | * port data structures. | |
8098 | * This function does following operations: | |
8099 | * - Free discovery resources associated with this virtual | |
8100 | * port. | |
8101 | * - Free iocbs associated with this virtual port in | |
8102 | * the txq. | |
8103 | * - Send abort for all iocb commands associated with this | |
8104 | * vport in txcmplq. | |
8105 | * | |
8106 | * This function is called with no lock held and always returns 1. | |
8107 | **/ | |
92d7f7b0 JS |
8108 | int |
8109 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
8110 | { | |
858c9f6c | 8111 | LIST_HEAD(completions); |
92d7f7b0 JS |
8112 | struct lpfc_hba *phba = vport->phba; |
8113 | struct lpfc_sli *psli = &phba->sli; | |
8114 | struct lpfc_sli_ring *pring; | |
8115 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
8116 | int i; |
8117 | unsigned long flags = 0; | |
8118 | uint16_t prev_pring_flag; | |
8119 | ||
8120 | lpfc_cleanup_discovery_resources(vport); | |
8121 | ||
8122 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
8123 | for (i = 0; i < psli->num_rings; i++) { |
8124 | pring = &psli->ring[i]; | |
8125 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
8126 | /* Only slow rings */ |
8127 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 8128 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
8129 | /* Set the lpfc data pending flag */ |
8130 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
8131 | } | |
92d7f7b0 JS |
8132 | /* |
8133 | * Error everything on the txq since these iocbs have not been | |
8134 | * given to the FW yet. | |
8135 | */ | |
92d7f7b0 JS |
8136 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
8137 | if (iocb->vport != vport) | |
8138 | continue; | |
858c9f6c | 8139 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 8140 | pring->txq_cnt--; |
92d7f7b0 JS |
8141 | } |
8142 | ||
8143 | /* Next issue ABTS for everything on the txcmplq */ | |
8144 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
8145 | list) { | |
8146 | if (iocb->vport != vport) | |
8147 | continue; | |
8148 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
8149 | } | |
8150 | ||
8151 | pring->flag = prev_pring_flag; | |
8152 | } | |
8153 | ||
8154 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
8155 | ||
a257bf90 JS |
8156 | /* Cancel all the IOCBs from the completions list */ |
8157 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8158 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
8159 | return 1; |
8160 | } | |
8161 | ||
e59058c4 | 8162 | /** |
3621a710 | 8163 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
8164 | * @phba: Pointer to HBA context object. |
8165 | * | |
8166 | * This function cleans up all iocb, buffers, mailbox commands | |
8167 | * while shutting down the HBA. This function is called with no | |
8168 | * lock held and always returns 1. | |
8169 | * This function does the following to cleanup driver resources: | |
8170 | * - Free discovery resources for each virtual port | |
8171 | * - Cleanup any pending fabric iocbs | |
8172 | * - Iterate through the iocb txq and free each entry | |
8173 | * in the list. | |
8174 | * - Free up any buffer posted to the HBA | |
8175 | * - Free mailbox commands in the mailbox queue. | |
8176 | **/ | |
dea3101e | 8177 | int |
2e0fef85 | 8178 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 8179 | { |
2534ba75 | 8180 | LIST_HEAD(completions); |
2e0fef85 | 8181 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 8182 | struct lpfc_sli_ring *pring; |
0ff10d46 | 8183 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 8184 | unsigned long flags = 0; |
04c68496 JS |
8185 | int i; |
8186 | ||
8187 | /* Shutdown the mailbox command sub-system */ | |
8188 | lpfc_sli_mbox_sys_shutdown(phba); | |
dea3101e | 8189 | |
dea3101e JB |
8190 | lpfc_hba_down_prep(phba); |
8191 | ||
92d7f7b0 JS |
8192 | lpfc_fabric_abort_hba(phba); |
8193 | ||
2e0fef85 | 8194 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
8195 | for (i = 0; i < psli->num_rings; i++) { |
8196 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
8197 | /* Only slow rings */ |
8198 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 8199 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
8200 | /* Set the lpfc data pending flag */ |
8201 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
8202 | } | |
dea3101e JB |
8203 | |
8204 | /* | |
8205 | * Error everything on the txq since these iocbs have not been | |
8206 | * given to the FW yet. | |
8207 | */ | |
2534ba75 | 8208 | list_splice_init(&pring->txq, &completions); |
dea3101e JB |
8209 | pring->txq_cnt = 0; |
8210 | ||
2534ba75 | 8211 | } |
2e0fef85 | 8212 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 8213 | |
a257bf90 JS |
8214 | /* Cancel all the IOCBs from the completions list */ |
8215 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8216 | IOERR_SLI_DOWN); | |
dea3101e | 8217 | |
0ff10d46 JS |
8218 | spin_lock_irqsave(&phba->hbalock, flags); |
8219 | list_splice_init(&phba->elsbuf, &completions); | |
8220 | phba->elsbuf_cnt = 0; | |
8221 | phba->elsbuf_prev_cnt = 0; | |
8222 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
8223 | ||
8224 | while (!list_empty(&completions)) { | |
8225 | list_remove_head(&completions, buf_ptr, | |
8226 | struct lpfc_dmabuf, list); | |
8227 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
8228 | kfree(buf_ptr); | |
8229 | } | |
8230 | ||
dea3101e JB |
8231 | /* Return any active mbox cmds */ |
8232 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 8233 | |
da0436e9 | 8234 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 8235 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 8236 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 8237 | |
da0436e9 JS |
8238 | return 1; |
8239 | } | |
8240 | ||
e59058c4 | 8241 | /** |
3621a710 | 8242 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
8243 | * @srcp: Source memory pointer. |
8244 | * @destp: Destination memory pointer. | |
8245 | * @cnt: Number of words required to be copied. | |
8246 | * | |
8247 | * This function is used for copying data between driver memory | |
8248 | * and the SLI memory. This function also changes the endianness | |
8249 | * of each word if native endianness is different from SLI | |
8250 | * endianness. This function can be called with or without | |
8251 | * lock. | |
8252 | **/ | |
dea3101e JB |
8253 | void |
8254 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
8255 | { | |
8256 | uint32_t *src = srcp; | |
8257 | uint32_t *dest = destp; | |
8258 | uint32_t ldata; | |
8259 | int i; | |
8260 | ||
8261 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
8262 | ldata = *src; | |
8263 | ldata = le32_to_cpu(ldata); | |
8264 | *dest = ldata; | |
8265 | src++; | |
8266 | dest++; | |
8267 | } | |
8268 | } | |
8269 | ||
e59058c4 | 8270 | |
a0c87cbd JS |
8271 | /** |
8272 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
8273 | * @srcp: Source memory pointer. | |
8274 | * @destp: Destination memory pointer. | |
8275 | * @cnt: Number of words required to be copied. | |
8276 | * | |
8277 | * This function is used for copying data between a data structure | |
8278 | * with big endian representation to local endianness. | |
8279 | * This function can be called with or without lock. | |
8280 | **/ | |
8281 | void | |
8282 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
8283 | { | |
8284 | uint32_t *src = srcp; | |
8285 | uint32_t *dest = destp; | |
8286 | uint32_t ldata; | |
8287 | int i; | |
8288 | ||
8289 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
8290 | ldata = *src; | |
8291 | ldata = be32_to_cpu(ldata); | |
8292 | *dest = ldata; | |
8293 | src++; | |
8294 | dest++; | |
8295 | } | |
8296 | } | |
8297 | ||
e59058c4 | 8298 | /** |
3621a710 | 8299 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
8300 | * @phba: Pointer to HBA context object. |
8301 | * @pring: Pointer to driver SLI ring object. | |
8302 | * @mp: Pointer to driver buffer object. | |
8303 | * | |
8304 | * This function is called with no lock held. | |
8305 | * It always return zero after adding the buffer to the postbufq | |
8306 | * buffer list. | |
8307 | **/ | |
dea3101e | 8308 | int |
2e0fef85 JS |
8309 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
8310 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
8311 | { |
8312 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
8313 | later */ | |
2e0fef85 | 8314 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8315 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 8316 | pring->postbufq_cnt++; |
2e0fef85 | 8317 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
8318 | return 0; |
8319 | } | |
8320 | ||
e59058c4 | 8321 | /** |
3621a710 | 8322 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
8323 | * @phba: Pointer to HBA context object. |
8324 | * | |
8325 | * When HBQ is enabled, buffers are searched based on tags. This function | |
8326 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
8327 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
8328 | * does not conflict with tags of buffer posted for unsolicited events. | |
8329 | * The function returns the allocated tag. The function is called with | |
8330 | * no locks held. | |
8331 | **/ | |
76bb24ef JS |
8332 | uint32_t |
8333 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
8334 | { | |
8335 | spin_lock_irq(&phba->hbalock); | |
8336 | phba->buffer_tag_count++; | |
8337 | /* | |
8338 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
8339 | * a tag assigned by HBQ. | |
8340 | */ | |
8341 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
8342 | spin_unlock_irq(&phba->hbalock); | |
8343 | return phba->buffer_tag_count; | |
8344 | } | |
8345 | ||
e59058c4 | 8346 | /** |
3621a710 | 8347 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
8348 | * @phba: Pointer to HBA context object. |
8349 | * @pring: Pointer to driver SLI ring object. | |
8350 | * @tag: Buffer tag. | |
8351 | * | |
8352 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
8353 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
8354 | * iocb is posted to the response ring with the tag of the buffer. | |
8355 | * This function searches the pring->postbufq list using the tag | |
8356 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
8357 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
8358 | * buffer is returned to the caller else NULL is returned. | |
8359 | * This function is called with no lock held. | |
8360 | **/ | |
76bb24ef JS |
8361 | struct lpfc_dmabuf * |
8362 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
8363 | uint32_t tag) | |
8364 | { | |
8365 | struct lpfc_dmabuf *mp, *next_mp; | |
8366 | struct list_head *slp = &pring->postbufq; | |
8367 | ||
25985edc | 8368 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
8369 | spin_lock_irq(&phba->hbalock); |
8370 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
8371 | if (mp->buffer_tag == tag) { | |
8372 | list_del_init(&mp->list); | |
8373 | pring->postbufq_cnt--; | |
8374 | spin_unlock_irq(&phba->hbalock); | |
8375 | return mp; | |
8376 | } | |
8377 | } | |
8378 | ||
8379 | spin_unlock_irq(&phba->hbalock); | |
8380 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 8381 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
8382 | "ring %d Data x%lx x%p x%p x%x\n", |
8383 | pring->ringno, (unsigned long) tag, | |
8384 | slp->next, slp->prev, pring->postbufq_cnt); | |
8385 | ||
8386 | return NULL; | |
8387 | } | |
dea3101e | 8388 | |
e59058c4 | 8389 | /** |
3621a710 | 8390 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
8391 | * @phba: Pointer to HBA context object. |
8392 | * @pring: Pointer to driver SLI ring object. | |
8393 | * @phys: DMA address of the buffer. | |
8394 | * | |
8395 | * This function searches the buffer list using the dma_address | |
8396 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
8397 | * corresponding to the dma_address. The function returns the | |
8398 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
8399 | * This function is called by the ct and els unsolicited event | |
8400 | * handlers to get the buffer associated with the unsolicited | |
8401 | * event. | |
8402 | * | |
8403 | * This function is called with no lock held. | |
8404 | **/ | |
dea3101e JB |
8405 | struct lpfc_dmabuf * |
8406 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
8407 | dma_addr_t phys) | |
8408 | { | |
8409 | struct lpfc_dmabuf *mp, *next_mp; | |
8410 | struct list_head *slp = &pring->postbufq; | |
8411 | ||
25985edc | 8412 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 8413 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
8414 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
8415 | if (mp->phys == phys) { | |
8416 | list_del_init(&mp->list); | |
8417 | pring->postbufq_cnt--; | |
2e0fef85 | 8418 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
8419 | return mp; |
8420 | } | |
8421 | } | |
8422 | ||
2e0fef85 | 8423 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 8424 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 8425 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 8426 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 8427 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
8428 | slp->next, slp->prev, pring->postbufq_cnt); |
8429 | return NULL; | |
8430 | } | |
8431 | ||
e59058c4 | 8432 | /** |
3621a710 | 8433 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
8434 | * @phba: Pointer to HBA context object. |
8435 | * @cmdiocb: Pointer to driver command iocb object. | |
8436 | * @rspiocb: Pointer to driver response iocb object. | |
8437 | * | |
8438 | * This function is the completion handler for the abort iocbs for | |
8439 | * ELS commands. This function is called from the ELS ring event | |
8440 | * handler with no lock held. This function frees memory resources | |
8441 | * associated with the abort iocb. | |
8442 | **/ | |
dea3101e | 8443 | static void |
2e0fef85 JS |
8444 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
8445 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 8446 | { |
2e0fef85 | 8447 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 8448 | uint16_t abort_iotag, abort_context; |
92d7f7b0 | 8449 | struct lpfc_iocbq *abort_iocb; |
2680eeaa JS |
8450 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
8451 | ||
8452 | abort_iocb = NULL; | |
2680eeaa JS |
8453 | |
8454 | if (irsp->ulpStatus) { | |
8455 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | |
8456 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
8457 | ||
2e0fef85 | 8458 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
8459 | if (phba->sli_rev < LPFC_SLI_REV4) { |
8460 | if (abort_iotag != 0 && | |
8461 | abort_iotag <= phba->sli.last_iotag) | |
8462 | abort_iocb = | |
8463 | phba->sli.iocbq_lookup[abort_iotag]; | |
8464 | } else | |
8465 | /* For sli4 the abort_tag is the XRI, | |
8466 | * so the abort routine puts the iotag of the iocb | |
8467 | * being aborted in the context field of the abort | |
8468 | * IOCB. | |
8469 | */ | |
8470 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 8471 | |
58da1ffb JS |
8472 | /* |
8473 | * If the iocb is not found in Firmware queue the iocb | |
8474 | * might have completed already. Do not free it again. | |
8475 | */ | |
9b379605 | 8476 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
45ed1190 JS |
8477 | if (irsp->un.ulpWord[4] != IOERR_NO_XRI) { |
8478 | spin_unlock_irq(&phba->hbalock); | |
8479 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
8480 | return; | |
8481 | } | |
8482 | /* For SLI4 the ulpContext field for abort IOCB | |
8483 | * holds the iotag of the IOCB being aborted so | |
8484 | * the local abort_context needs to be reset to | |
8485 | * match the aborted IOCBs ulpContext. | |
8486 | */ | |
8487 | if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4) | |
8488 | abort_context = abort_iocb->iocb.ulpContext; | |
58da1ffb | 8489 | } |
2a9bf3d0 JS |
8490 | |
8491 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, | |
8492 | "0327 Cannot abort els iocb %p " | |
8493 | "with tag %x context %x, abort status %x, " | |
8494 | "abort code %x\n", | |
8495 | abort_iocb, abort_iotag, abort_context, | |
8496 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
2680eeaa JS |
8497 | /* |
8498 | * make sure we have the right iocbq before taking it | |
8499 | * off the txcmplq and try to call completion routine. | |
8500 | */ | |
2e0fef85 JS |
8501 | if (!abort_iocb || |
8502 | abort_iocb->iocb.ulpContext != abort_context || | |
8503 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | |
8504 | spin_unlock_irq(&phba->hbalock); | |
341af102 JS |
8505 | else if (phba->sli_rev < LPFC_SLI_REV4) { |
8506 | /* | |
8507 | * leave the SLI4 aborted command on the txcmplq | |
8508 | * list and the command complete WCQE's XB bit | |
8509 | * will tell whether the SGL (XRI) can be released | |
8510 | * immediately or to the aborted SGL list for the | |
8511 | * following abort XRI from the HBA. | |
8512 | */ | |
92d7f7b0 | 8513 | list_del_init(&abort_iocb->list); |
2a9bf3d0 JS |
8514 | if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) { |
8515 | abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
8516 | pring->txcmplq_cnt--; | |
8517 | } | |
2680eeaa | 8518 | |
0ff10d46 JS |
8519 | /* Firmware could still be in progress of DMAing |
8520 | * payload, so don't free data buffer till after | |
8521 | * a hbeat. | |
8522 | */ | |
8523 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
92d7f7b0 | 8524 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
341af102 JS |
8525 | spin_unlock_irq(&phba->hbalock); |
8526 | ||
92d7f7b0 | 8527 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
341af102 | 8528 | abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED; |
92d7f7b0 | 8529 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
49198b37 JS |
8530 | } else |
8531 | spin_unlock_irq(&phba->hbalock); | |
2680eeaa JS |
8532 | } |
8533 | ||
604a3e30 | 8534 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
8535 | return; |
8536 | } | |
8537 | ||
e59058c4 | 8538 | /** |
3621a710 | 8539 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
8540 | * @phba: Pointer to HBA context object. |
8541 | * @cmdiocb: Pointer to driver command iocb object. | |
8542 | * @rspiocb: Pointer to driver response iocb object. | |
8543 | * | |
8544 | * The function is called from SLI ring event handler with no | |
8545 | * lock held. This function is the completion handler for ELS commands | |
8546 | * which are aborted. The function frees memory resources used for | |
8547 | * the aborted ELS commands. | |
8548 | **/ | |
92d7f7b0 JS |
8549 | static void |
8550 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
8551 | struct lpfc_iocbq *rspiocb) | |
8552 | { | |
8553 | IOCB_t *irsp = &rspiocb->iocb; | |
8554 | ||
8555 | /* ELS cmd tag <ulpIoTag> completes */ | |
8556 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 8557 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 8558 | "x%x x%x x%x\n", |
e8b62011 | 8559 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 8560 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
8561 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
8562 | lpfc_ct_free_iocb(phba, cmdiocb); | |
8563 | else | |
8564 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
8565 | return; |
8566 | } | |
8567 | ||
e59058c4 | 8568 | /** |
5af5eee7 | 8569 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
8570 | * @phba: Pointer to HBA context object. |
8571 | * @pring: Pointer to driver SLI ring object. | |
8572 | * @cmdiocb: Pointer to driver command iocb object. | |
8573 | * | |
5af5eee7 JS |
8574 | * This function issues an abort iocb for the provided command iocb down to |
8575 | * the port. Other than the case the outstanding command iocb is an abort | |
8576 | * request, this function issues abort out unconditionally. This function is | |
8577 | * called with hbalock held. The function returns 0 when it fails due to | |
8578 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 8579 | **/ |
5af5eee7 JS |
8580 | static int |
8581 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 8582 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 8583 | { |
2e0fef85 | 8584 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 8585 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
8586 | IOCB_t *icmd = NULL; |
8587 | IOCB_t *iabt = NULL; | |
5af5eee7 | 8588 | int retval; |
07951076 | 8589 | |
92d7f7b0 JS |
8590 | /* |
8591 | * There are certain command types we don't want to abort. And we | |
8592 | * don't want to abort commands that are already in the process of | |
8593 | * being aborted. | |
07951076 JS |
8594 | */ |
8595 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 8596 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
8597 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
8598 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
8599 | return 0; |
8600 | ||
dea3101e | 8601 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 8602 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
8603 | if (abtsiocbp == NULL) |
8604 | return 0; | |
dea3101e | 8605 | |
07951076 | 8606 | /* This signals the response to set the correct status |
341af102 | 8607 | * before calling the completion handler |
07951076 JS |
8608 | */ |
8609 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
8610 | ||
dea3101e | 8611 | iabt = &abtsiocbp->iocb; |
07951076 JS |
8612 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
8613 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 8614 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 8615 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
8616 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
8617 | } | |
da0436e9 JS |
8618 | else |
8619 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
8620 | iabt->ulpLe = 1; |
8621 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 8622 | |
5ffc266e JS |
8623 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
8624 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
8625 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
8626 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 8627 | |
2e0fef85 | 8628 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
8629 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
8630 | else | |
8631 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 8632 | |
07951076 | 8633 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 8634 | |
e8b62011 JS |
8635 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
8636 | "0339 Abort xri x%x, original iotag x%x, " | |
8637 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 8638 | iabt->un.acxri.abortIoTag, |
e8b62011 | 8639 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 8640 | abtsiocbp->iotag); |
da0436e9 | 8641 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
dea3101e | 8642 | |
d7c255b2 JS |
8643 | if (retval) |
8644 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
8645 | |
8646 | /* | |
8647 | * Caller to this routine should check for IOCB_ERROR | |
8648 | * and handle it properly. This routine no longer removes | |
8649 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
8650 | */ | |
8651 | return retval; | |
8652 | } | |
8653 | ||
8654 | /** | |
8655 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
8656 | * @phba: Pointer to HBA context object. | |
8657 | * @pring: Pointer to driver SLI ring object. | |
8658 | * @cmdiocb: Pointer to driver command iocb object. | |
8659 | * | |
8660 | * This function issues an abort iocb for the provided command iocb. In case | |
8661 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
8662 | * ring. Instead, the callback function shall be changed to those commands | |
8663 | * so that nothing happens when them finishes. This function is called with | |
8664 | * hbalock held. The function returns 0 when the command iocb is an abort | |
8665 | * request. | |
8666 | **/ | |
8667 | int | |
8668 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
8669 | struct lpfc_iocbq *cmdiocb) | |
8670 | { | |
8671 | struct lpfc_vport *vport = cmdiocb->vport; | |
8672 | int retval = IOCB_ERROR; | |
8673 | IOCB_t *icmd = NULL; | |
8674 | ||
8675 | /* | |
8676 | * There are certain command types we don't want to abort. And we | |
8677 | * don't want to abort commands that are already in the process of | |
8678 | * being aborted. | |
8679 | */ | |
8680 | icmd = &cmdiocb->iocb; | |
8681 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
8682 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
8683 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
8684 | return 0; | |
8685 | ||
8686 | /* | |
8687 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
8688 | * the callback so that nothing happens when it finishes. | |
8689 | */ | |
8690 | if ((vport->load_flag & FC_UNLOADING) && | |
8691 | (pring->ringno == LPFC_ELS_RING)) { | |
8692 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
8693 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
8694 | else | |
8695 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
8696 | goto abort_iotag_exit; | |
8697 | } | |
8698 | ||
8699 | /* Now, we try to issue the abort to the cmdiocb out */ | |
8700 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
8701 | ||
07951076 | 8702 | abort_iotag_exit: |
2e0fef85 JS |
8703 | /* |
8704 | * Caller to this routine should check for IOCB_ERROR | |
8705 | * and handle it properly. This routine no longer removes | |
8706 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 8707 | */ |
2e0fef85 | 8708 | return retval; |
dea3101e JB |
8709 | } |
8710 | ||
5af5eee7 JS |
8711 | /** |
8712 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
8713 | * @phba: Pointer to HBA context object. | |
8714 | * @pring: Pointer to driver SLI ring object. | |
8715 | * | |
8716 | * This function aborts all iocbs in the given ring and frees all the iocb | |
8717 | * objects in txq. This function issues abort iocbs unconditionally for all | |
8718 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
8719 | * to complete before the return of this function. The caller is not required | |
8720 | * to hold any locks. | |
8721 | **/ | |
8722 | static void | |
8723 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
8724 | { | |
8725 | LIST_HEAD(completions); | |
8726 | struct lpfc_iocbq *iocb, *next_iocb; | |
8727 | ||
8728 | if (pring->ringno == LPFC_ELS_RING) | |
8729 | lpfc_fabric_abort_hba(phba); | |
8730 | ||
8731 | spin_lock_irq(&phba->hbalock); | |
8732 | ||
8733 | /* Take off all the iocbs on txq for cancelling */ | |
8734 | list_splice_init(&pring->txq, &completions); | |
8735 | pring->txq_cnt = 0; | |
8736 | ||
8737 | /* Next issue ABTS for everything on the txcmplq */ | |
8738 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
8739 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
8740 | ||
8741 | spin_unlock_irq(&phba->hbalock); | |
8742 | ||
8743 | /* Cancel all the IOCBs from the completions list */ | |
8744 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8745 | IOERR_SLI_ABORTED); | |
8746 | } | |
8747 | ||
8748 | /** | |
8749 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
8750 | * @phba: pointer to lpfc HBA data structure. | |
8751 | * | |
8752 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
8753 | **/ | |
8754 | void | |
8755 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
8756 | { | |
8757 | struct lpfc_sli *psli = &phba->sli; | |
8758 | struct lpfc_sli_ring *pring; | |
8759 | int i; | |
8760 | ||
8761 | for (i = 0; i < psli->num_rings; i++) { | |
8762 | pring = &psli->ring[i]; | |
8763 | lpfc_sli_iocb_ring_abort(phba, pring); | |
8764 | } | |
8765 | } | |
8766 | ||
e59058c4 | 8767 | /** |
3621a710 | 8768 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
8769 | * @iocbq: Pointer to driver iocb object. |
8770 | * @vport: Pointer to driver virtual port object. | |
8771 | * @tgt_id: SCSI ID of the target. | |
8772 | * @lun_id: LUN ID of the scsi device. | |
8773 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
8774 | * | |
3621a710 | 8775 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
8776 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
8777 | * 0 if the filtering criteria is met for the given iocb and will return | |
8778 | * 1 if the filtering criteria is not met. | |
8779 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
8780 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
8781 | * lun_id parameter. | |
8782 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
8783 | * given iocb is for the SCSI target specified by vport and tgt_id | |
8784 | * parameters. | |
8785 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
8786 | * given iocb is for the SCSI host associated with the given vport. | |
8787 | * This function is called with no locks held. | |
8788 | **/ | |
dea3101e | 8789 | static int |
51ef4c26 JS |
8790 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
8791 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 8792 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 8793 | { |
0bd4ca25 | 8794 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
8795 | int rc = 1; |
8796 | ||
0bd4ca25 JSEC |
8797 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
8798 | return rc; | |
8799 | ||
51ef4c26 JS |
8800 | if (iocbq->vport != vport) |
8801 | return rc; | |
8802 | ||
0bd4ca25 | 8803 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 8804 | |
495a714c | 8805 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
8806 | return rc; |
8807 | ||
8808 | switch (ctx_cmd) { | |
8809 | case LPFC_CTX_LUN: | |
495a714c JS |
8810 | if ((lpfc_cmd->rdata->pnode) && |
8811 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
8812 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
8813 | rc = 0; |
8814 | break; | |
8815 | case LPFC_CTX_TGT: | |
495a714c JS |
8816 | if ((lpfc_cmd->rdata->pnode) && |
8817 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
8818 | rc = 0; |
8819 | break; | |
dea3101e JB |
8820 | case LPFC_CTX_HOST: |
8821 | rc = 0; | |
8822 | break; | |
8823 | default: | |
8824 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 8825 | __func__, ctx_cmd); |
dea3101e JB |
8826 | break; |
8827 | } | |
8828 | ||
8829 | return rc; | |
8830 | } | |
8831 | ||
e59058c4 | 8832 | /** |
3621a710 | 8833 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
8834 | * @vport: Pointer to virtual port. |
8835 | * @tgt_id: SCSI ID of the target. | |
8836 | * @lun_id: LUN ID of the scsi device. | |
8837 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
8838 | * | |
8839 | * This function returns number of FCP commands pending for the vport. | |
8840 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
8841 | * commands pending on the vport associated with SCSI device specified | |
8842 | * by tgt_id and lun_id parameters. | |
8843 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
8844 | * commands pending on the vport associated with SCSI target specified | |
8845 | * by tgt_id parameter. | |
8846 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
8847 | * commands pending on the vport. | |
8848 | * This function returns the number of iocbs which satisfy the filter. | |
8849 | * This function is called without any lock held. | |
8850 | **/ | |
dea3101e | 8851 | int |
51ef4c26 JS |
8852 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
8853 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 8854 | { |
51ef4c26 | 8855 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
8856 | struct lpfc_iocbq *iocbq; |
8857 | int sum, i; | |
dea3101e | 8858 | |
0bd4ca25 JSEC |
8859 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
8860 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 8861 | |
51ef4c26 JS |
8862 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
8863 | ctx_cmd) == 0) | |
0bd4ca25 | 8864 | sum++; |
dea3101e | 8865 | } |
0bd4ca25 | 8866 | |
dea3101e JB |
8867 | return sum; |
8868 | } | |
8869 | ||
e59058c4 | 8870 | /** |
3621a710 | 8871 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
8872 | * @phba: Pointer to HBA context object |
8873 | * @cmdiocb: Pointer to command iocb object. | |
8874 | * @rspiocb: Pointer to response iocb object. | |
8875 | * | |
8876 | * This function is called when an aborted FCP iocb completes. This | |
8877 | * function is called by the ring event handler with no lock held. | |
8878 | * This function frees the iocb. | |
8879 | **/ | |
5eb95af0 | 8880 | void |
2e0fef85 JS |
8881 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
8882 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 8883 | { |
604a3e30 | 8884 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
8885 | return; |
8886 | } | |
8887 | ||
e59058c4 | 8888 | /** |
3621a710 | 8889 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
8890 | * @vport: Pointer to virtual port. |
8891 | * @pring: Pointer to driver SLI ring object. | |
8892 | * @tgt_id: SCSI ID of the target. | |
8893 | * @lun_id: LUN ID of the scsi device. | |
8894 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
8895 | * | |
8896 | * This function sends an abort command for every SCSI command | |
8897 | * associated with the given virtual port pending on the ring | |
8898 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
8899 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
8900 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
8901 | * parameters | |
8902 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
8903 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
8904 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
8905 | * FCP iocbs associated with virtual port. | |
8906 | * This function returns number of iocbs it failed to abort. | |
8907 | * This function is called with no locks held. | |
8908 | **/ | |
dea3101e | 8909 | int |
51ef4c26 JS |
8910 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
8911 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 8912 | { |
51ef4c26 | 8913 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
8914 | struct lpfc_iocbq *iocbq; |
8915 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 8916 | IOCB_t *cmd = NULL; |
dea3101e | 8917 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 8918 | int i; |
dea3101e | 8919 | |
0bd4ca25 JSEC |
8920 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
8921 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 8922 | |
51ef4c26 | 8923 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 8924 | abort_cmd) != 0) |
dea3101e JB |
8925 | continue; |
8926 | ||
8927 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 8928 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
8929 | if (abtsiocb == NULL) { |
8930 | errcnt++; | |
8931 | continue; | |
8932 | } | |
dea3101e | 8933 | |
0bd4ca25 | 8934 | cmd = &iocbq->iocb; |
dea3101e JB |
8935 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
8936 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
8937 | if (phba->sli_rev == LPFC_SLI_REV4) |
8938 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
8939 | else | |
8940 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
8941 | abtsiocb->iocb.ulpLe = 1; |
8942 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 8943 | abtsiocb->vport = phba->pport; |
dea3101e | 8944 | |
5ffc266e JS |
8945 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
8946 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
8947 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
8948 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 8949 | |
2e0fef85 | 8950 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
8951 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
8952 | else | |
8953 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
8954 | ||
5eb95af0 JSEC |
8955 | /* Setup callback routine and issue the command. */ |
8956 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
8957 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
8958 | abtsiocb, 0); | |
dea3101e | 8959 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 8960 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
8961 | errcnt++; |
8962 | continue; | |
8963 | } | |
8964 | } | |
8965 | ||
8966 | return errcnt; | |
8967 | } | |
8968 | ||
e59058c4 | 8969 | /** |
3621a710 | 8970 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
8971 | * @phba: Pointer to HBA context object. |
8972 | * @cmdiocbq: Pointer to command iocb. | |
8973 | * @rspiocbq: Pointer to response iocb. | |
8974 | * | |
8975 | * This function is the completion handler for iocbs issued using | |
8976 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
8977 | * ring event handler function without any lock held. This function | |
8978 | * can be called from both worker thread context and interrupt | |
8979 | * context. This function also can be called from other thread which | |
8980 | * cleans up the SLI layer objects. | |
8981 | * This function copy the contents of the response iocb to the | |
8982 | * response iocb memory object provided by the caller of | |
8983 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
8984 | * sleeps for the iocb completion. | |
8985 | **/ | |
68876920 JSEC |
8986 | static void |
8987 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
8988 | struct lpfc_iocbq *cmdiocbq, | |
8989 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 8990 | { |
68876920 JSEC |
8991 | wait_queue_head_t *pdone_q; |
8992 | unsigned long iflags; | |
0f65ff68 | 8993 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 8994 | |
2e0fef85 | 8995 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
8996 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
8997 | if (cmdiocbq->context2 && rspiocbq) | |
8998 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
8999 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
9000 | ||
0f65ff68 JS |
9001 | /* Set the exchange busy flag for task management commands */ |
9002 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
9003 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
9004 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
9005 | cur_iocbq); | |
9006 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
9007 | } | |
9008 | ||
68876920 | 9009 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
9010 | if (pdone_q) |
9011 | wake_up(pdone_q); | |
858c9f6c | 9012 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
9013 | return; |
9014 | } | |
9015 | ||
d11e31dd JS |
9016 | /** |
9017 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
9018 | * @phba: Pointer to HBA context object.. | |
9019 | * @piocbq: Pointer to command iocb. | |
9020 | * @flag: Flag to test. | |
9021 | * | |
9022 | * This routine grabs the hbalock and then test the iocb_flag to | |
9023 | * see if the passed in flag is set. | |
9024 | * Returns: | |
9025 | * 1 if flag is set. | |
9026 | * 0 if flag is not set. | |
9027 | **/ | |
9028 | static int | |
9029 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
9030 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
9031 | { | |
9032 | unsigned long iflags; | |
9033 | int ret; | |
9034 | ||
9035 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9036 | ret = piocbq->iocb_flag & flag; | |
9037 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9038 | return ret; | |
9039 | ||
9040 | } | |
9041 | ||
e59058c4 | 9042 | /** |
3621a710 | 9043 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
9044 | * @phba: Pointer to HBA context object.. |
9045 | * @pring: Pointer to sli ring. | |
9046 | * @piocb: Pointer to command iocb. | |
9047 | * @prspiocbq: Pointer to response iocb. | |
9048 | * @timeout: Timeout in number of seconds. | |
9049 | * | |
9050 | * This function issues the iocb to firmware and waits for the | |
9051 | * iocb to complete. If the iocb command is not | |
9052 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
9053 | * Caller should not free the iocb resources if this function | |
9054 | * returns IOCB_TIMEDOUT. | |
9055 | * The function waits for the iocb completion using an | |
9056 | * non-interruptible wait. | |
9057 | * This function will sleep while waiting for iocb completion. | |
9058 | * So, this function should not be called from any context which | |
9059 | * does not allow sleeping. Due to the same reason, this function | |
9060 | * cannot be called with interrupt disabled. | |
9061 | * This function assumes that the iocb completions occur while | |
9062 | * this function sleep. So, this function cannot be called from | |
9063 | * the thread which process iocb completion for this ring. | |
9064 | * This function clears the iocb_flag of the iocb object before | |
9065 | * issuing the iocb and the iocb completion handler sets this | |
9066 | * flag and wakes this thread when the iocb completes. | |
9067 | * The contents of the response iocb will be copied to prspiocbq | |
9068 | * by the completion handler when the command completes. | |
9069 | * This function returns IOCB_SUCCESS when success. | |
9070 | * This function is called with no lock held. | |
9071 | **/ | |
dea3101e | 9072 | int |
2e0fef85 | 9073 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 9074 | uint32_t ring_number, |
2e0fef85 JS |
9075 | struct lpfc_iocbq *piocb, |
9076 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 9077 | uint32_t timeout) |
dea3101e | 9078 | { |
7259f0d0 | 9079 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
9080 | long timeleft, timeout_req = 0; |
9081 | int retval = IOCB_SUCCESS; | |
875fbdfe | 9082 | uint32_t creg_val; |
2a9bf3d0 | 9083 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 9084 | /* |
68876920 JSEC |
9085 | * If the caller has provided a response iocbq buffer, then context2 |
9086 | * is NULL or its an error. | |
dea3101e | 9087 | */ |
68876920 JSEC |
9088 | if (prspiocbq) { |
9089 | if (piocb->context2) | |
9090 | return IOCB_ERROR; | |
9091 | piocb->context2 = prspiocbq; | |
dea3101e JB |
9092 | } |
9093 | ||
68876920 JSEC |
9094 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
9095 | piocb->context_un.wait_queue = &done_q; | |
9096 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 9097 | |
875fbdfe | 9098 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9099 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9100 | return IOCB_ERROR; | |
875fbdfe JSEC |
9101 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
9102 | writel(creg_val, phba->HCregaddr); | |
9103 | readl(phba->HCregaddr); /* flush */ | |
9104 | } | |
9105 | ||
2a9bf3d0 JS |
9106 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
9107 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
9108 | if (retval == IOCB_SUCCESS) { |
9109 | timeout_req = timeout * HZ; | |
68876920 | 9110 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 9111 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 9112 | timeout_req); |
dea3101e | 9113 | |
7054a606 JS |
9114 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
9115 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 9116 | "0331 IOCB wake signaled\n"); |
7054a606 | 9117 | } else if (timeleft == 0) { |
68876920 | 9118 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9119 | "0338 IOCB wait timeout error - no " |
9120 | "wake response Data x%x\n", timeout); | |
68876920 | 9121 | retval = IOCB_TIMEDOUT; |
7054a606 | 9122 | } else { |
68876920 | 9123 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9124 | "0330 IOCB wake NOT set, " |
9125 | "Data x%x x%lx\n", | |
68876920 JSEC |
9126 | timeout, (timeleft / jiffies)); |
9127 | retval = IOCB_TIMEDOUT; | |
dea3101e | 9128 | } |
2a9bf3d0 JS |
9129 | } else if (retval == IOCB_BUSY) { |
9130 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9131 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
9132 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
9133 | return retval; | |
68876920 JSEC |
9134 | } else { |
9135 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 9136 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 9137 | retval); |
68876920 | 9138 | retval = IOCB_ERROR; |
dea3101e JB |
9139 | } |
9140 | ||
875fbdfe | 9141 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9142 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9143 | return IOCB_ERROR; | |
875fbdfe JSEC |
9144 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
9145 | writel(creg_val, phba->HCregaddr); | |
9146 | readl(phba->HCregaddr); /* flush */ | |
9147 | } | |
9148 | ||
68876920 JSEC |
9149 | if (prspiocbq) |
9150 | piocb->context2 = NULL; | |
9151 | ||
9152 | piocb->context_un.wait_queue = NULL; | |
9153 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
9154 | return retval; |
9155 | } | |
68876920 | 9156 | |
e59058c4 | 9157 | /** |
3621a710 | 9158 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
9159 | * @phba: Pointer to HBA context object. |
9160 | * @pmboxq: Pointer to driver mailbox object. | |
9161 | * @timeout: Timeout in number of seconds. | |
9162 | * | |
9163 | * This function issues the mailbox to firmware and waits for the | |
9164 | * mailbox command to complete. If the mailbox command is not | |
9165 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
9166 | * The function waits for the mailbox completion using an | |
9167 | * interruptible wait. If the thread is woken up due to a | |
9168 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
9169 | * should not free the mailbox resources, if this function returns | |
9170 | * MBX_TIMEOUT. | |
9171 | * This function will sleep while waiting for mailbox completion. | |
9172 | * So, this function should not be called from any context which | |
9173 | * does not allow sleeping. Due to the same reason, this function | |
9174 | * cannot be called with interrupt disabled. | |
9175 | * This function assumes that the mailbox completion occurs while | |
9176 | * this function sleep. So, this function cannot be called from | |
9177 | * the worker thread which processes mailbox completion. | |
9178 | * This function is called in the context of HBA management | |
9179 | * applications. | |
9180 | * This function returns MBX_SUCCESS when successful. | |
9181 | * This function is called with no lock held. | |
9182 | **/ | |
dea3101e | 9183 | int |
2e0fef85 | 9184 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
9185 | uint32_t timeout) |
9186 | { | |
7259f0d0 | 9187 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 9188 | int retval; |
858c9f6c | 9189 | unsigned long flag; |
dea3101e JB |
9190 | |
9191 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 9192 | if (pmboxq->context1) |
2e0fef85 | 9193 | return MBX_NOT_FINISHED; |
dea3101e | 9194 | |
495a714c | 9195 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
9196 | /* setup wake call as IOCB callback */ |
9197 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
9198 | /* setup context field to pass wait_queue pointer to wake function */ | |
9199 | pmboxq->context1 = &done_q; | |
9200 | ||
dea3101e JB |
9201 | /* now issue the command */ |
9202 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
9203 | ||
9204 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | |
7054a606 JS |
9205 | wait_event_interruptible_timeout(done_q, |
9206 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
9207 | timeout * HZ); | |
9208 | ||
858c9f6c | 9209 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 9210 | pmboxq->context1 = NULL; |
7054a606 JS |
9211 | /* |
9212 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
9213 | * else do not free the resources. | |
9214 | */ | |
d7c47992 | 9215 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 9216 | retval = MBX_SUCCESS; |
d7c47992 JS |
9217 | lpfc_sli4_swap_str(phba, pmboxq); |
9218 | } else { | |
7054a606 | 9219 | retval = MBX_TIMEOUT; |
858c9f6c JS |
9220 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
9221 | } | |
9222 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e JB |
9223 | } |
9224 | ||
dea3101e JB |
9225 | return retval; |
9226 | } | |
9227 | ||
e59058c4 | 9228 | /** |
3772a991 | 9229 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
9230 | * @phba: Pointer to HBA context. |
9231 | * | |
3772a991 JS |
9232 | * This function is called to shutdown the driver's mailbox sub-system. |
9233 | * It first marks the mailbox sub-system is in a block state to prevent | |
9234 | * the asynchronous mailbox command from issued off the pending mailbox | |
9235 | * command queue. If the mailbox command sub-system shutdown is due to | |
9236 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
9237 | * the mailbox sub-system flush routine to forcefully bring down the | |
9238 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
9239 | * as with offline or HBA function reset), this routine will wait for the | |
9240 | * outstanding mailbox command to complete before invoking the mailbox | |
9241 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 9242 | **/ |
3772a991 JS |
9243 | void |
9244 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) | |
b4c02652 | 9245 | { |
3772a991 JS |
9246 | struct lpfc_sli *psli = &phba->sli; |
9247 | uint8_t actcmd = MBX_HEARTBEAT; | |
9248 | unsigned long timeout; | |
b4c02652 | 9249 | |
3772a991 JS |
9250 | spin_lock_irq(&phba->hbalock); |
9251 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
9252 | spin_unlock_irq(&phba->hbalock); | |
b4c02652 | 9253 | |
3772a991 | 9254 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
ed957684 | 9255 | spin_lock_irq(&phba->hbalock); |
3772a991 JS |
9256 | if (phba->sli.mbox_active) |
9257 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
ed957684 | 9258 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
9259 | /* Determine how long we might wait for the active mailbox |
9260 | * command to be gracefully completed by firmware. | |
9261 | */ | |
9262 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * | |
9263 | 1000) + jiffies; | |
9264 | while (phba->sli.mbox_active) { | |
9265 | /* Check active mailbox complete status every 2ms */ | |
9266 | msleep(2); | |
9267 | if (time_after(jiffies, timeout)) | |
9268 | /* Timeout, let the mailbox flush routine to | |
9269 | * forcefully release active mailbox command | |
9270 | */ | |
9271 | break; | |
9272 | } | |
9273 | } | |
9274 | lpfc_sli_mbox_sys_flush(phba); | |
9275 | } | |
ed957684 | 9276 | |
3772a991 JS |
9277 | /** |
9278 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
9279 | * @phba: Pointer to HBA context. | |
9280 | * | |
9281 | * This function is called to read the SLI3 device error attention registers | |
9282 | * for possible error attention events. The caller must hold the hostlock | |
9283 | * with spin_lock_irq(). | |
9284 | * | |
25985edc | 9285 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
9286 | * Register and returns 0 otherwise. |
9287 | **/ | |
9288 | static int | |
9289 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
9290 | { | |
9291 | uint32_t ha_copy; | |
b4c02652 | 9292 | |
3772a991 | 9293 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
9294 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
9295 | goto unplug_err; | |
9296 | ||
3772a991 JS |
9297 | if (ha_copy & HA_ERATT) { |
9298 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
9299 | if (lpfc_sli_read_hs(phba)) |
9300 | goto unplug_err; | |
b4c02652 | 9301 | |
3772a991 JS |
9302 | /* Check if there is a deferred error condition is active */ |
9303 | if ((HS_FFER1 & phba->work_hs) && | |
9304 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 9305 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 9306 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
9307 | /* Clear all interrupt enable conditions */ |
9308 | writel(0, phba->HCregaddr); | |
9309 | readl(phba->HCregaddr); | |
9310 | } | |
9311 | ||
9312 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
9313 | phba->work_ha |= HA_ERATT; |
9314 | /* Indicate polling handles this ERATT */ | |
9315 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
9316 | return 1; |
9317 | } | |
9318 | return 0; | |
9940b97b JS |
9319 | |
9320 | unplug_err: | |
9321 | /* Set the driver HS work bitmap */ | |
9322 | phba->work_hs |= UNPLUG_ERR; | |
9323 | /* Set the driver HA work bitmap */ | |
9324 | phba->work_ha |= HA_ERATT; | |
9325 | /* Indicate polling handles this ERATT */ | |
9326 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9327 | return 1; | |
b4c02652 JS |
9328 | } |
9329 | ||
da0436e9 JS |
9330 | /** |
9331 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
9332 | * @phba: Pointer to HBA context. | |
9333 | * | |
9334 | * This function is called to read the SLI4 device error attention registers | |
9335 | * for possible error attention events. The caller must hold the hostlock | |
9336 | * with spin_lock_irq(). | |
9337 | * | |
25985edc | 9338 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
9339 | * Register and returns 0 otherwise. |
9340 | **/ | |
9341 | static int | |
9342 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
9343 | { | |
9344 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
9345 | uint32_t if_type, portsmphr; |
9346 | struct lpfc_register portstat_reg; | |
da0436e9 | 9347 | |
2fcee4bf JS |
9348 | /* |
9349 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
9350 | * registers for error attention. This can be changed later. |
9351 | */ | |
2fcee4bf JS |
9352 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
9353 | switch (if_type) { | |
9354 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
9355 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
9356 | &uerr_sta_lo) || | |
9357 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
9358 | &uerr_sta_hi)) { | |
9359 | phba->work_hs |= UNPLUG_ERR; | |
9360 | phba->work_ha |= HA_ERATT; | |
9361 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9362 | return 1; | |
9363 | } | |
2fcee4bf JS |
9364 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
9365 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
9366 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9367 | "1423 HBA Unrecoverable error: " | |
9368 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
9369 | "ue_mask_lo_reg=0x%x, " | |
9370 | "ue_mask_hi_reg=0x%x\n", | |
9371 | uerr_sta_lo, uerr_sta_hi, | |
9372 | phba->sli4_hba.ue_mask_lo, | |
9373 | phba->sli4_hba.ue_mask_hi); | |
9374 | phba->work_status[0] = uerr_sta_lo; | |
9375 | phba->work_status[1] = uerr_sta_hi; | |
9376 | phba->work_ha |= HA_ERATT; | |
9377 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9378 | return 1; | |
9379 | } | |
9380 | break; | |
9381 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
9382 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
9383 | &portstat_reg.word0) || | |
9384 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
9385 | &portsmphr)){ | |
9386 | phba->work_hs |= UNPLUG_ERR; | |
9387 | phba->work_ha |= HA_ERATT; | |
9388 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9389 | return 1; | |
9390 | } | |
2fcee4bf JS |
9391 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
9392 | phba->work_status[0] = | |
9393 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
9394 | phba->work_status[1] = | |
9395 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
9396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9397 | "2885 Port Error Detected: " | |
9398 | "port status reg 0x%x, " | |
9399 | "port smphr reg 0x%x, " | |
9400 | "error 1=0x%x, error 2=0x%x\n", | |
9401 | portstat_reg.word0, | |
9402 | portsmphr, | |
9403 | phba->work_status[0], | |
9404 | phba->work_status[1]); | |
9405 | phba->work_ha |= HA_ERATT; | |
9406 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9407 | return 1; | |
9408 | } | |
9409 | break; | |
9410 | case LPFC_SLI_INTF_IF_TYPE_1: | |
9411 | default: | |
a747c9ce | 9412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
9413 | "2886 HBA Error Attention on unsupported " |
9414 | "if type %d.", if_type); | |
a747c9ce | 9415 | return 1; |
da0436e9 | 9416 | } |
2fcee4bf | 9417 | |
da0436e9 JS |
9418 | return 0; |
9419 | } | |
9420 | ||
e59058c4 | 9421 | /** |
3621a710 | 9422 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
9423 | * @phba: Pointer to HBA context. |
9424 | * | |
3772a991 | 9425 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
9426 | * error attention register bit for error attention events. |
9427 | * | |
25985edc | 9428 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
9429 | * Register and returns 0 otherwise. |
9430 | **/ | |
9431 | int | |
9432 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
9433 | { | |
9434 | uint32_t ha_copy; | |
9435 | ||
9436 | /* If somebody is waiting to handle an eratt, don't process it | |
9437 | * here. The brdkill function will do this. | |
9438 | */ | |
9439 | if (phba->link_flag & LS_IGNORE_ERATT) | |
9440 | return 0; | |
9441 | ||
9442 | /* Check if interrupt handler handles this ERATT */ | |
9443 | spin_lock_irq(&phba->hbalock); | |
9444 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
9445 | /* Interrupt handler has handled ERATT */ | |
9446 | spin_unlock_irq(&phba->hbalock); | |
9447 | return 0; | |
9448 | } | |
9449 | ||
a257bf90 JS |
9450 | /* |
9451 | * If there is deferred error attention, do not check for error | |
9452 | * attention | |
9453 | */ | |
9454 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
9455 | spin_unlock_irq(&phba->hbalock); | |
9456 | return 0; | |
9457 | } | |
9458 | ||
3772a991 JS |
9459 | /* If PCI channel is offline, don't process it */ |
9460 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 9461 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
9462 | return 0; |
9463 | } | |
9464 | ||
9465 | switch (phba->sli_rev) { | |
9466 | case LPFC_SLI_REV2: | |
9467 | case LPFC_SLI_REV3: | |
9468 | /* Read chip Host Attention (HA) register */ | |
9469 | ha_copy = lpfc_sli_eratt_read(phba); | |
9470 | break; | |
da0436e9 | 9471 | case LPFC_SLI_REV4: |
2fcee4bf | 9472 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
9473 | ha_copy = lpfc_sli4_eratt_read(phba); |
9474 | break; | |
3772a991 JS |
9475 | default: |
9476 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9477 | "0299 Invalid SLI revision (%d)\n", | |
9478 | phba->sli_rev); | |
9479 | ha_copy = 0; | |
9480 | break; | |
9399627f JS |
9481 | } |
9482 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
9483 | |
9484 | return ha_copy; | |
9485 | } | |
9486 | ||
9487 | /** | |
9488 | * lpfc_intr_state_check - Check device state for interrupt handling | |
9489 | * @phba: Pointer to HBA context. | |
9490 | * | |
9491 | * This inline routine checks whether a device or its PCI slot is in a state | |
9492 | * that the interrupt should be handled. | |
9493 | * | |
9494 | * This function returns 0 if the device or the PCI slot is in a state that | |
9495 | * interrupt should be handled, otherwise -EIO. | |
9496 | */ | |
9497 | static inline int | |
9498 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
9499 | { | |
9500 | /* If the pci channel is offline, ignore all the interrupts */ | |
9501 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
9502 | return -EIO; | |
9503 | ||
9504 | /* Update device level interrupt statistics */ | |
9505 | phba->sli.slistat.sli_intr++; | |
9506 | ||
9507 | /* Ignore all interrupts during initialization. */ | |
9508 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
9509 | return -EIO; | |
9510 | ||
9399627f JS |
9511 | return 0; |
9512 | } | |
9513 | ||
9514 | /** | |
3772a991 | 9515 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
9516 | * @irq: Interrupt number. |
9517 | * @dev_id: The device context pointer. | |
9518 | * | |
9399627f | 9519 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
9520 | * service routine when device with SLI-3 interface spec is enabled with |
9521 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
9522 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
9523 | * interrupt mode, this function is called as part of the device-level | |
9524 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
9525 | * is undergoing initialization, the interrupt handler will not process | |
9526 | * the interrupt. The link attention and ELS ring attention events are | |
9527 | * handled by the worker thread. The interrupt handler signals the worker | |
9528 | * thread and returns for these events. This function is called without | |
9529 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
9530 | * structures. |
9531 | * | |
9532 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
9533 | * returns IRQ_NONE. | |
e59058c4 | 9534 | **/ |
dea3101e | 9535 | irqreturn_t |
3772a991 | 9536 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 9537 | { |
2e0fef85 | 9538 | struct lpfc_hba *phba; |
a747c9ce | 9539 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
9540 | uint32_t work_ha_copy; |
9541 | unsigned long status; | |
5b75da2f | 9542 | unsigned long iflag; |
dea3101e JB |
9543 | uint32_t control; |
9544 | ||
92d7f7b0 | 9545 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
9546 | struct lpfc_vport *vport; |
9547 | struct lpfc_nodelist *ndlp; | |
9548 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
9549 | LPFC_MBOXQ_t *pmb; |
9550 | int rc; | |
9551 | ||
dea3101e JB |
9552 | /* |
9553 | * Get the driver's phba structure from the dev_id and | |
9554 | * assume the HBA is not interrupting. | |
9555 | */ | |
9399627f | 9556 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
9557 | |
9558 | if (unlikely(!phba)) | |
9559 | return IRQ_NONE; | |
9560 | ||
dea3101e | 9561 | /* |
9399627f JS |
9562 | * Stuff needs to be attented to when this function is invoked as an |
9563 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 9564 | */ |
9399627f | 9565 | if (phba->intr_type == MSIX) { |
3772a991 JS |
9566 | /* Check device state for handling interrupt */ |
9567 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
9568 | return IRQ_NONE; |
9569 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 9570 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
9571 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
9572 | goto unplug_error; | |
9399627f JS |
9573 | /* If somebody is waiting to handle an eratt don't process it |
9574 | * here. The brdkill function will do this. | |
9575 | */ | |
9576 | if (phba->link_flag & LS_IGNORE_ERATT) | |
9577 | ha_copy &= ~HA_ERATT; | |
9578 | /* Check the need for handling ERATT in interrupt handler */ | |
9579 | if (ha_copy & HA_ERATT) { | |
9580 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
9581 | /* ERATT polling has handled ERATT */ | |
9582 | ha_copy &= ~HA_ERATT; | |
9583 | else | |
9584 | /* Indicate interrupt handler handles ERATT */ | |
9585 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9586 | } | |
a257bf90 JS |
9587 | |
9588 | /* | |
9589 | * If there is deferred error attention, do not check for any | |
9590 | * interrupt. | |
9591 | */ | |
9592 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 9593 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
9594 | return IRQ_NONE; |
9595 | } | |
9596 | ||
9399627f | 9597 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
9598 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
9599 | goto unplug_error; | |
9600 | ||
a747c9ce JS |
9601 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
9602 | HC_LAINT_ENA | HC_ERINT_ENA), | |
9603 | phba->HCregaddr); | |
9399627f JS |
9604 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
9605 | phba->HAregaddr); | |
a747c9ce | 9606 | writel(hc_copy, phba->HCregaddr); |
9399627f | 9607 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 9608 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
9609 | } else |
9610 | ha_copy = phba->ha_copy; | |
dea3101e | 9611 | |
dea3101e JB |
9612 | work_ha_copy = ha_copy & phba->work_ha_mask; |
9613 | ||
9399627f | 9614 | if (work_ha_copy) { |
dea3101e JB |
9615 | if (work_ha_copy & HA_LATT) { |
9616 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
9617 | /* | |
9618 | * Turn off Link Attention interrupts | |
9619 | * until CLEAR_LA done | |
9620 | */ | |
5b75da2f | 9621 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 9622 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
9623 | if (lpfc_readl(phba->HCregaddr, &control)) |
9624 | goto unplug_error; | |
dea3101e JB |
9625 | control &= ~HC_LAINT_ENA; |
9626 | writel(control, phba->HCregaddr); | |
9627 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 9628 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
9629 | } |
9630 | else | |
9631 | work_ha_copy &= ~HA_LATT; | |
9632 | } | |
9633 | ||
9399627f | 9634 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
9635 | /* |
9636 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
9637 | * the only slow ring. | |
9638 | */ | |
9639 | status = (work_ha_copy & | |
9640 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
9641 | status >>= (4*LPFC_ELS_RING); | |
9642 | if (status & HA_RXMASK) { | |
5b75da2f | 9643 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
9644 | if (lpfc_readl(phba->HCregaddr, &control)) |
9645 | goto unplug_error; | |
a58cbd52 JS |
9646 | |
9647 | lpfc_debugfs_slow_ring_trc(phba, | |
9648 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
9649 | control, status, | |
9650 | (uint32_t)phba->sli.slistat.sli_intr); | |
9651 | ||
858c9f6c | 9652 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
9653 | lpfc_debugfs_slow_ring_trc(phba, |
9654 | "ISR Disable ring:" | |
9655 | "pwork:x%x hawork:x%x wait:x%x", | |
9656 | phba->work_ha, work_ha_copy, | |
9657 | (uint32_t)((unsigned long) | |
5e9d9b82 | 9658 | &phba->work_waitq)); |
a58cbd52 | 9659 | |
858c9f6c JS |
9660 | control &= |
9661 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
9662 | writel(control, phba->HCregaddr); |
9663 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 9664 | } |
a58cbd52 JS |
9665 | else { |
9666 | lpfc_debugfs_slow_ring_trc(phba, | |
9667 | "ISR slow ring: pwork:" | |
9668 | "x%x hawork:x%x wait:x%x", | |
9669 | phba->work_ha, work_ha_copy, | |
9670 | (uint32_t)((unsigned long) | |
5e9d9b82 | 9671 | &phba->work_waitq)); |
a58cbd52 | 9672 | } |
5b75da2f | 9673 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
9674 | } |
9675 | } | |
5b75da2f | 9676 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 9677 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
9678 | if (lpfc_sli_read_hs(phba)) |
9679 | goto unplug_error; | |
a257bf90 JS |
9680 | /* |
9681 | * Check if there is a deferred error condition | |
9682 | * is active | |
9683 | */ | |
9684 | if ((HS_FFER1 & phba->work_hs) && | |
9685 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
9686 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
9687 | phba->work_hs)) { | |
a257bf90 JS |
9688 | phba->hba_flag |= DEFER_ERATT; |
9689 | /* Clear all interrupt enable conditions */ | |
9690 | writel(0, phba->HCregaddr); | |
9691 | readl(phba->HCregaddr); | |
9692 | } | |
9693 | } | |
9694 | ||
9399627f | 9695 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 9696 | pmb = phba->sli.mbox_active; |
04c68496 | 9697 | pmbox = &pmb->u.mb; |
34b02dcd | 9698 | mbox = phba->mbox; |
858c9f6c | 9699 | vport = pmb->vport; |
92d7f7b0 JS |
9700 | |
9701 | /* First check out the status word */ | |
9702 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
9703 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 9704 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
9705 | /* |
9706 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
9707 | * mbxStatus <status> | |
9708 | */ | |
09372820 | 9709 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 9710 | LOG_SLI, |
e8b62011 | 9711 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
9712 | "Interrupt mbxCommand x%x " |
9713 | "mbxStatus x%x\n", | |
e8b62011 | 9714 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
9715 | pmbox->mbxCommand, |
9716 | pmbox->mbxStatus); | |
09372820 JS |
9717 | /* clear mailbox attention bit */ |
9718 | work_ha_copy &= ~HA_MBATT; | |
9719 | } else { | |
97eab634 | 9720 | phba->sli.mbox_active = NULL; |
5b75da2f | 9721 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
9722 | phba->last_completion_time = jiffies; |
9723 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
9724 | if (pmb->mbox_cmpl) { |
9725 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
9726 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
9727 | if (pmb->out_ext_byte_len && |
9728 | pmb->context2) | |
9729 | lpfc_sli_pcimem_bcopy( | |
9730 | phba->mbox_ext, | |
9731 | pmb->context2, | |
9732 | pmb->out_ext_byte_len); | |
09372820 JS |
9733 | } |
9734 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
9735 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
9736 | ||
9737 | lpfc_debugfs_disc_trc(vport, | |
9738 | LPFC_DISC_TRC_MBOX_VPORT, | |
9739 | "MBOX dflt rpi: : " | |
9740 | "status:x%x rpi:x%x", | |
9741 | (uint32_t)pmbox->mbxStatus, | |
9742 | pmbox->un.varWords[0], 0); | |
9743 | ||
9744 | if (!pmbox->mbxStatus) { | |
9745 | mp = (struct lpfc_dmabuf *) | |
9746 | (pmb->context1); | |
9747 | ndlp = (struct lpfc_nodelist *) | |
9748 | pmb->context2; | |
9749 | ||
9750 | /* Reg_LOGIN of dflt RPI was | |
9751 | * successful. new lets get | |
9752 | * rid of the RPI using the | |
9753 | * same mbox buffer. | |
9754 | */ | |
9755 | lpfc_unreg_login(phba, | |
9756 | vport->vpi, | |
9757 | pmbox->un.varWords[0], | |
9758 | pmb); | |
9759 | pmb->mbox_cmpl = | |
9760 | lpfc_mbx_cmpl_dflt_rpi; | |
9761 | pmb->context1 = mp; | |
9762 | pmb->context2 = ndlp; | |
9763 | pmb->vport = vport; | |
58da1ffb JS |
9764 | rc = lpfc_sli_issue_mbox(phba, |
9765 | pmb, | |
9766 | MBX_NOWAIT); | |
9767 | if (rc != MBX_BUSY) | |
9768 | lpfc_printf_log(phba, | |
9769 | KERN_ERR, | |
9770 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 9771 | "0350 rc should have" |
6a9c52cf | 9772 | "been MBX_BUSY\n"); |
3772a991 JS |
9773 | if (rc != MBX_NOT_FINISHED) |
9774 | goto send_current_mbox; | |
09372820 | 9775 | } |
858c9f6c | 9776 | } |
5b75da2f JS |
9777 | spin_lock_irqsave( |
9778 | &phba->pport->work_port_lock, | |
9779 | iflag); | |
09372820 JS |
9780 | phba->pport->work_port_events &= |
9781 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
9782 | spin_unlock_irqrestore( |
9783 | &phba->pport->work_port_lock, | |
9784 | iflag); | |
09372820 | 9785 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 9786 | } |
97eab634 | 9787 | } else |
5b75da2f | 9788 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 9789 | |
92d7f7b0 JS |
9790 | if ((work_ha_copy & HA_MBATT) && |
9791 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 9792 | send_current_mbox: |
92d7f7b0 | 9793 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
9794 | do { |
9795 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
9796 | MBX_NOWAIT); | |
9797 | } while (rc == MBX_NOT_FINISHED); | |
9798 | if (rc != MBX_SUCCESS) | |
9799 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
9800 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 9801 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
9802 | } |
9803 | ||
5b75da2f | 9804 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 9805 | phba->work_ha |= work_ha_copy; |
5b75da2f | 9806 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 9807 | lpfc_worker_wake_up(phba); |
dea3101e | 9808 | } |
9399627f | 9809 | return IRQ_HANDLED; |
9940b97b JS |
9810 | unplug_error: |
9811 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9812 | return IRQ_HANDLED; | |
dea3101e | 9813 | |
3772a991 | 9814 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
9815 | |
9816 | /** | |
3772a991 | 9817 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
9818 | * @irq: Interrupt number. |
9819 | * @dev_id: The device context pointer. | |
9820 | * | |
9821 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
9822 | * service routine when device with SLI-3 interface spec is enabled with |
9823 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
9824 | * ring event in the HBA. However, when the device is enabled with either | |
9825 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
9826 | * device-level interrupt handler. When the PCI slot is in error recovery | |
9827 | * or the HBA is undergoing initialization, the interrupt handler will not | |
9828 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
9829 | * the intrrupt context. This function is called without any lock held. | |
9830 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
9831 | * |
9832 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
9833 | * returns IRQ_NONE. | |
9834 | **/ | |
9835 | irqreturn_t | |
3772a991 | 9836 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
9837 | { |
9838 | struct lpfc_hba *phba; | |
9839 | uint32_t ha_copy; | |
9840 | unsigned long status; | |
5b75da2f | 9841 | unsigned long iflag; |
9399627f JS |
9842 | |
9843 | /* Get the driver's phba structure from the dev_id and | |
9844 | * assume the HBA is not interrupting. | |
9845 | */ | |
9846 | phba = (struct lpfc_hba *) dev_id; | |
9847 | ||
9848 | if (unlikely(!phba)) | |
9849 | return IRQ_NONE; | |
9850 | ||
9851 | /* | |
9852 | * Stuff needs to be attented to when this function is invoked as an | |
9853 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
9854 | */ | |
9855 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
9856 | /* Check device state for handling interrupt */ |
9857 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
9858 | return IRQ_NONE; |
9859 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
9860 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
9861 | return IRQ_HANDLED; | |
9399627f | 9862 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 9863 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
9864 | /* |
9865 | * If there is deferred error attention, do not check for | |
9866 | * any interrupt. | |
9867 | */ | |
9868 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 9869 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
9870 | return IRQ_NONE; |
9871 | } | |
9399627f JS |
9872 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
9873 | phba->HAregaddr); | |
9874 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 9875 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
9876 | } else |
9877 | ha_copy = phba->ha_copy; | |
dea3101e JB |
9878 | |
9879 | /* | |
9399627f | 9880 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 9881 | */ |
9399627f JS |
9882 | ha_copy &= ~(phba->work_ha_mask); |
9883 | ||
9884 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 9885 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 9886 | if (status & HA_RXMASK) |
dea3101e JB |
9887 | lpfc_sli_handle_fast_ring_event(phba, |
9888 | &phba->sli.ring[LPFC_FCP_RING], | |
9889 | status); | |
a4bc3379 JS |
9890 | |
9891 | if (phba->cfg_multi_ring_support == 2) { | |
9892 | /* | |
9399627f JS |
9893 | * Process all events on extra ring. Take the optimized path |
9894 | * for extra ring IO. | |
a4bc3379 | 9895 | */ |
9399627f | 9896 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 9897 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 9898 | if (status & HA_RXMASK) { |
a4bc3379 JS |
9899 | lpfc_sli_handle_fast_ring_event(phba, |
9900 | &phba->sli.ring[LPFC_EXTRA_RING], | |
9901 | status); | |
9902 | } | |
9903 | } | |
dea3101e | 9904 | return IRQ_HANDLED; |
3772a991 | 9905 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
9906 | |
9907 | /** | |
3772a991 | 9908 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
9909 | * @irq: Interrupt number. |
9910 | * @dev_id: The device context pointer. | |
9911 | * | |
3772a991 JS |
9912 | * This function is the HBA device-level interrupt handler to device with |
9913 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
9914 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
9915 | * requires driver attention. This function invokes the slow-path interrupt | |
9916 | * attention handling function and fast-path interrupt attention handling | |
9917 | * function in turn to process the relevant HBA attention events. This | |
9918 | * function is called without any lock held. It gets the hbalock to access | |
9919 | * and update SLI data structures. | |
9399627f JS |
9920 | * |
9921 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
9922 | * returns IRQ_NONE. | |
9923 | **/ | |
9924 | irqreturn_t | |
3772a991 | 9925 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
9926 | { |
9927 | struct lpfc_hba *phba; | |
9928 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
9929 | unsigned long status1, status2; | |
a747c9ce | 9930 | uint32_t hc_copy; |
9399627f JS |
9931 | |
9932 | /* | |
9933 | * Get the driver's phba structure from the dev_id and | |
9934 | * assume the HBA is not interrupting. | |
9935 | */ | |
9936 | phba = (struct lpfc_hba *) dev_id; | |
9937 | ||
9938 | if (unlikely(!phba)) | |
9939 | return IRQ_NONE; | |
9940 | ||
3772a991 JS |
9941 | /* Check device state for handling interrupt */ |
9942 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
9943 | return IRQ_NONE; |
9944 | ||
9945 | spin_lock(&phba->hbalock); | |
9940b97b JS |
9946 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
9947 | spin_unlock(&phba->hbalock); | |
9948 | return IRQ_HANDLED; | |
9949 | } | |
9950 | ||
9399627f JS |
9951 | if (unlikely(!phba->ha_copy)) { |
9952 | spin_unlock(&phba->hbalock); | |
9953 | return IRQ_NONE; | |
9954 | } else if (phba->ha_copy & HA_ERATT) { | |
9955 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
9956 | /* ERATT polling has handled ERATT */ | |
9957 | phba->ha_copy &= ~HA_ERATT; | |
9958 | else | |
9959 | /* Indicate interrupt handler handles ERATT */ | |
9960 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9961 | } | |
9962 | ||
a257bf90 JS |
9963 | /* |
9964 | * If there is deferred error attention, do not check for any interrupt. | |
9965 | */ | |
9966 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 9967 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
9968 | return IRQ_NONE; |
9969 | } | |
9970 | ||
9399627f | 9971 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
9972 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
9973 | spin_unlock(&phba->hbalock); | |
9974 | return IRQ_HANDLED; | |
9975 | } | |
a747c9ce JS |
9976 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
9977 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
9978 | phba->HCregaddr); | |
9399627f | 9979 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 9980 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
9981 | readl(phba->HAregaddr); /* flush */ |
9982 | spin_unlock(&phba->hbalock); | |
9983 | ||
9984 | /* | |
9985 | * Invokes slow-path host attention interrupt handling as appropriate. | |
9986 | */ | |
9987 | ||
9988 | /* status of events with mailbox and link attention */ | |
9989 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
9990 | ||
9991 | /* status of events with ELS ring */ | |
9992 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
9993 | status2 >>= (4*LPFC_ELS_RING); | |
9994 | ||
9995 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 9996 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
9997 | else |
9998 | sp_irq_rc = IRQ_NONE; | |
9999 | ||
10000 | /* | |
10001 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10002 | */ | |
10003 | ||
10004 | /* status of events with FCP ring */ | |
10005 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
10006 | status1 >>= (4*LPFC_FCP_RING); | |
10007 | ||
10008 | /* status of events with extra ring */ | |
10009 | if (phba->cfg_multi_ring_support == 2) { | |
10010 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
10011 | status2 >>= (4*LPFC_EXTRA_RING); | |
10012 | } else | |
10013 | status2 = 0; | |
10014 | ||
10015 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 10016 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
10017 | else |
10018 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 10019 | |
9399627f JS |
10020 | /* Return device-level interrupt handling status */ |
10021 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 10022 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
10023 | |
10024 | /** | |
10025 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
10026 | * @phba: pointer to lpfc hba data structure. | |
10027 | * | |
10028 | * This routine is invoked by the worker thread to process all the pending | |
10029 | * SLI4 FCP abort XRI events. | |
10030 | **/ | |
10031 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
10032 | { | |
10033 | struct lpfc_cq_event *cq_event; | |
10034 | ||
10035 | /* First, declare the fcp xri abort event has been handled */ | |
10036 | spin_lock_irq(&phba->hbalock); | |
10037 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
10038 | spin_unlock_irq(&phba->hbalock); | |
10039 | /* Now, handle all the fcp xri abort events */ | |
10040 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
10041 | /* Get the first event from the head of the event queue */ | |
10042 | spin_lock_irq(&phba->hbalock); | |
10043 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
10044 | cq_event, struct lpfc_cq_event, list); | |
10045 | spin_unlock_irq(&phba->hbalock); | |
10046 | /* Notify aborted XRI for FCP work queue */ | |
10047 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10048 | /* Free the event processed back to the free pool */ | |
10049 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10050 | } | |
10051 | } | |
10052 | ||
10053 | /** | |
10054 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
10055 | * @phba: pointer to lpfc hba data structure. | |
10056 | * | |
10057 | * This routine is invoked by the worker thread to process all the pending | |
10058 | * SLI4 els abort xri events. | |
10059 | **/ | |
10060 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
10061 | { | |
10062 | struct lpfc_cq_event *cq_event; | |
10063 | ||
10064 | /* First, declare the els xri abort event has been handled */ | |
10065 | spin_lock_irq(&phba->hbalock); | |
10066 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
10067 | spin_unlock_irq(&phba->hbalock); | |
10068 | /* Now, handle all the els xri abort events */ | |
10069 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
10070 | /* Get the first event from the head of the event queue */ | |
10071 | spin_lock_irq(&phba->hbalock); | |
10072 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
10073 | cq_event, struct lpfc_cq_event, list); | |
10074 | spin_unlock_irq(&phba->hbalock); | |
10075 | /* Notify aborted XRI for ELS work queue */ | |
10076 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10077 | /* Free the event processed back to the free pool */ | |
10078 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10079 | } | |
10080 | } | |
10081 | ||
341af102 JS |
10082 | /** |
10083 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
10084 | * @phba: pointer to lpfc hba data structure | |
10085 | * @pIocbIn: pointer to the rspiocbq | |
10086 | * @pIocbOut: pointer to the cmdiocbq | |
10087 | * @wcqe: pointer to the complete wcqe | |
10088 | * | |
10089 | * This routine transfers the fields of a command iocbq to a response iocbq | |
10090 | * by copying all the IOCB fields from command iocbq and transferring the | |
10091 | * completion status information from the complete wcqe. | |
10092 | **/ | |
4f774513 | 10093 | static void |
341af102 JS |
10094 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
10095 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
10096 | struct lpfc_iocbq *pIocbOut, |
10097 | struct lpfc_wcqe_complete *wcqe) | |
10098 | { | |
341af102 | 10099 | unsigned long iflags; |
4f774513 JS |
10100 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
10101 | ||
10102 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
10103 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 JS |
10104 | /* Map WCQE parameters into irspiocb parameters */ |
10105 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | |
10106 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | |
10107 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
10108 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
10109 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
10110 | wcqe->total_data_placed; | |
10111 | else | |
10112 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 10113 | else { |
4f774513 | 10114 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
10115 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
10116 | } | |
341af102 JS |
10117 | |
10118 | /* Pick up HBA exchange busy condition */ | |
10119 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
10120 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10121 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
10122 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10123 | } | |
4f774513 JS |
10124 | } |
10125 | ||
45ed1190 JS |
10126 | /** |
10127 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
10128 | * @phba: Pointer to HBA context object. | |
10129 | * @wcqe: Pointer to work-queue completion queue entry. | |
10130 | * | |
10131 | * This routine handles an ELS work-queue completion event and construct | |
10132 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
10133 | * discovery engine to handle. | |
10134 | * | |
10135 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
10136 | **/ | |
10137 | static struct lpfc_iocbq * | |
10138 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
10139 | struct lpfc_iocbq *irspiocbq) | |
10140 | { | |
10141 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
10142 | struct lpfc_iocbq *cmdiocbq; | |
10143 | struct lpfc_wcqe_complete *wcqe; | |
10144 | unsigned long iflags; | |
10145 | ||
10146 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
10147 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10148 | pring->stats.iocb_event++; | |
10149 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
10150 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
10151 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10152 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10153 | ||
10154 | if (unlikely(!cmdiocbq)) { | |
10155 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10156 | "0386 ELS complete with no corresponding " | |
10157 | "cmdiocb: iotag (%d)\n", | |
10158 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10159 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
10160 | return NULL; | |
10161 | } | |
10162 | ||
10163 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 10164 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
10165 | |
10166 | return irspiocbq; | |
10167 | } | |
10168 | ||
04c68496 JS |
10169 | /** |
10170 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
10171 | * @phba: Pointer to HBA context object. | |
10172 | * @cqe: Pointer to mailbox completion queue entry. | |
10173 | * | |
10174 | * This routine process a mailbox completion queue entry with asynchrous | |
10175 | * event. | |
10176 | * | |
10177 | * Return: true if work posted to worker thread, otherwise false. | |
10178 | **/ | |
10179 | static bool | |
10180 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
10181 | { | |
10182 | struct lpfc_cq_event *cq_event; | |
10183 | unsigned long iflags; | |
10184 | ||
10185 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
10186 | "0392 Async Event: word0:x%x, word1:x%x, " | |
10187 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
10188 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
10189 | ||
10190 | /* Allocate a new internal CQ_EVENT entry */ | |
10191 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
10192 | if (!cq_event) { | |
10193 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10194 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
10195 | return false; | |
10196 | } | |
10197 | ||
10198 | /* Move the CQE into an asynchronous event entry */ | |
10199 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
10200 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10201 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
10202 | /* Set the async event flag */ | |
10203 | phba->hba_flag |= ASYNC_EVENT; | |
10204 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10205 | ||
10206 | return true; | |
10207 | } | |
10208 | ||
10209 | /** | |
10210 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
10211 | * @phba: Pointer to HBA context object. | |
10212 | * @cqe: Pointer to mailbox completion queue entry. | |
10213 | * | |
10214 | * This routine process a mailbox completion queue entry with mailbox | |
10215 | * completion event. | |
10216 | * | |
10217 | * Return: true if work posted to worker thread, otherwise false. | |
10218 | **/ | |
10219 | static bool | |
10220 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
10221 | { | |
10222 | uint32_t mcqe_status; | |
10223 | MAILBOX_t *mbox, *pmbox; | |
10224 | struct lpfc_mqe *mqe; | |
10225 | struct lpfc_vport *vport; | |
10226 | struct lpfc_nodelist *ndlp; | |
10227 | struct lpfc_dmabuf *mp; | |
10228 | unsigned long iflags; | |
10229 | LPFC_MBOXQ_t *pmb; | |
10230 | bool workposted = false; | |
10231 | int rc; | |
10232 | ||
10233 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
10234 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
10235 | goto out_no_mqe_complete; | |
10236 | ||
10237 | /* Get the reference to the active mbox command */ | |
10238 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10239 | pmb = phba->sli.mbox_active; | |
10240 | if (unlikely(!pmb)) { | |
10241 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
10242 | "1832 No pending MBOX command to handle\n"); | |
10243 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10244 | goto out_no_mqe_complete; | |
10245 | } | |
10246 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10247 | mqe = &pmb->u.mqe; | |
10248 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
10249 | mbox = phba->mbox; | |
10250 | vport = pmb->vport; | |
10251 | ||
10252 | /* Reset heartbeat timer */ | |
10253 | phba->last_completion_time = jiffies; | |
10254 | del_timer(&phba->sli.mbox_tmo); | |
10255 | ||
10256 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
10257 | if (pmb->mbox_cmpl && mbox) | |
10258 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
10259 | /* Set the mailbox status with SLI4 range 0x4000 */ | |
10260 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
10261 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) | |
10262 | bf_set(lpfc_mqe_status, mqe, | |
10263 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
10264 | ||
10265 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
10266 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
10267 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
10268 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
10269 | mcqe_status, | |
10270 | pmbox->un.varWords[0], 0); | |
10271 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
10272 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
10273 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
10274 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
10275 | * RID of the PPI using the same mbox buffer. | |
10276 | */ | |
10277 | lpfc_unreg_login(phba, vport->vpi, | |
10278 | pmbox->un.varWords[0], pmb); | |
10279 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
10280 | pmb->context1 = mp; | |
10281 | pmb->context2 = ndlp; | |
10282 | pmb->vport = vport; | |
10283 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
10284 | if (rc != MBX_BUSY) | |
10285 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
10286 | LOG_SLI, "0385 rc should " | |
10287 | "have been MBX_BUSY\n"); | |
10288 | if (rc != MBX_NOT_FINISHED) | |
10289 | goto send_current_mbox; | |
10290 | } | |
10291 | } | |
10292 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
10293 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
10294 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
10295 | ||
10296 | /* There is mailbox completion work to do */ | |
10297 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10298 | __lpfc_mbox_cmpl_put(phba, pmb); | |
10299 | phba->work_ha |= HA_MBATT; | |
10300 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10301 | workposted = true; | |
10302 | ||
10303 | send_current_mbox: | |
10304 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10305 | /* Release the mailbox command posting token */ | |
10306 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
10307 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
10308 | phba->sli.mbox_active = NULL; | |
10309 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10310 | /* Wake up worker thread to post the next pending mailbox command */ | |
10311 | lpfc_worker_wake_up(phba); | |
10312 | out_no_mqe_complete: | |
10313 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
10314 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
10315 | return workposted; | |
10316 | } | |
10317 | ||
10318 | /** | |
10319 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
10320 | * @phba: Pointer to HBA context object. | |
10321 | * @cqe: Pointer to mailbox completion queue entry. | |
10322 | * | |
10323 | * This routine process a mailbox completion queue entry, it invokes the | |
10324 | * proper mailbox complete handling or asynchrous event handling routine | |
10325 | * according to the MCQE's async bit. | |
10326 | * | |
10327 | * Return: true if work posted to worker thread, otherwise false. | |
10328 | **/ | |
10329 | static bool | |
10330 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
10331 | { | |
10332 | struct lpfc_mcqe mcqe; | |
10333 | bool workposted; | |
10334 | ||
10335 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
10336 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
10337 | ||
10338 | /* Invoke the proper event handling routine */ | |
10339 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
10340 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
10341 | else | |
10342 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
10343 | return workposted; | |
10344 | } | |
10345 | ||
4f774513 JS |
10346 | /** |
10347 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
10348 | * @phba: Pointer to HBA context object. | |
10349 | * @wcqe: Pointer to work-queue completion queue entry. | |
10350 | * | |
10351 | * This routine handles an ELS work-queue completion event. | |
10352 | * | |
10353 | * Return: true if work posted to worker thread, otherwise false. | |
10354 | **/ | |
10355 | static bool | |
10356 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | |
10357 | struct lpfc_wcqe_complete *wcqe) | |
10358 | { | |
4f774513 JS |
10359 | struct lpfc_iocbq *irspiocbq; |
10360 | unsigned long iflags; | |
2a9bf3d0 | 10361 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
4f774513 | 10362 | |
45ed1190 | 10363 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
10364 | irspiocbq = lpfc_sli_get_iocbq(phba); |
10365 | if (!irspiocbq) { | |
10366 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
10367 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
10368 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
10369 | pring->txq_cnt, phba->iocb_cnt, | |
10370 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
10371 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 10372 | return false; |
4f774513 | 10373 | } |
4f774513 | 10374 | |
45ed1190 JS |
10375 | /* Save off the slow-path queue event for work thread to process */ |
10376 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 10377 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 10378 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
10379 | &phba->sli4_hba.sp_queue_event); |
10380 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 10381 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 10382 | |
45ed1190 | 10383 | return true; |
4f774513 JS |
10384 | } |
10385 | ||
10386 | /** | |
10387 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
10388 | * @phba: Pointer to HBA context object. | |
10389 | * @wcqe: Pointer to work-queue completion queue entry. | |
10390 | * | |
10391 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
10392 | * proper WQ release routine to the slow-path WQ. | |
10393 | **/ | |
10394 | static void | |
10395 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
10396 | struct lpfc_wcqe_release *wcqe) | |
10397 | { | |
10398 | /* Check for the slow-path ELS work queue */ | |
10399 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
10400 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
10401 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
10402 | else | |
10403 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10404 | "2579 Slow-path wqe consume event carries " | |
10405 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
10406 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
10407 | phba->sli4_hba.els_wq->queue_id); | |
10408 | } | |
10409 | ||
10410 | /** | |
10411 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
10412 | * @phba: Pointer to HBA context object. | |
10413 | * @cq: Pointer to a WQ completion queue. | |
10414 | * @wcqe: Pointer to work-queue completion queue entry. | |
10415 | * | |
10416 | * This routine handles an XRI abort event. | |
10417 | * | |
10418 | * Return: true if work posted to worker thread, otherwise false. | |
10419 | **/ | |
10420 | static bool | |
10421 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
10422 | struct lpfc_queue *cq, | |
10423 | struct sli4_wcqe_xri_aborted *wcqe) | |
10424 | { | |
10425 | bool workposted = false; | |
10426 | struct lpfc_cq_event *cq_event; | |
10427 | unsigned long iflags; | |
10428 | ||
10429 | /* Allocate a new internal CQ_EVENT entry */ | |
10430 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
10431 | if (!cq_event) { | |
10432 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10433 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
10434 | return false; | |
10435 | } | |
10436 | ||
10437 | /* Move the CQE into the proper xri abort event list */ | |
10438 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
10439 | switch (cq->subtype) { | |
10440 | case LPFC_FCP: | |
10441 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10442 | list_add_tail(&cq_event->list, | |
10443 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
10444 | /* Set the fcp xri abort event flag */ | |
10445 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
10446 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10447 | workposted = true; | |
10448 | break; | |
10449 | case LPFC_ELS: | |
10450 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10451 | list_add_tail(&cq_event->list, | |
10452 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
10453 | /* Set the els xri abort event flag */ | |
10454 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
10455 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10456 | workposted = true; | |
10457 | break; | |
10458 | default: | |
10459 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10460 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
10461 | cq->subtype); | |
10462 | workposted = false; | |
10463 | break; | |
10464 | } | |
10465 | return workposted; | |
10466 | } | |
10467 | ||
4f774513 JS |
10468 | /** |
10469 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
10470 | * @phba: Pointer to HBA context object. | |
10471 | * @rcqe: Pointer to receive-queue completion queue entry. | |
10472 | * | |
10473 | * This routine process a receive-queue completion queue entry. | |
10474 | * | |
10475 | * Return: true if work posted to worker thread, otherwise false. | |
10476 | **/ | |
10477 | static bool | |
4d9ab994 | 10478 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 10479 | { |
4f774513 JS |
10480 | bool workposted = false; |
10481 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
10482 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
10483 | struct hbq_dmabuf *dma_buf; | |
10484 | uint32_t status; | |
10485 | unsigned long iflags; | |
10486 | ||
4d9ab994 | 10487 | if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id) |
4f774513 JS |
10488 | goto out; |
10489 | ||
4d9ab994 | 10490 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
10491 | switch (status) { |
10492 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
10493 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10494 | "2537 Receive Frame Truncated!!\n"); | |
10495 | case FC_STATUS_RQ_SUCCESS: | |
5ffc266e | 10496 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
10497 | spin_lock_irqsave(&phba->hbalock, iflags); |
10498 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
10499 | if (!dma_buf) { | |
10500 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10501 | goto out; | |
10502 | } | |
4d9ab994 | 10503 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 10504 | /* save off the frame for the word thread to process */ |
4d9ab994 | 10505 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 10506 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 10507 | /* Frame received */ |
45ed1190 | 10508 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
10509 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
10510 | workposted = true; | |
10511 | break; | |
10512 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
10513 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
10514 | /* Post more buffers if possible */ | |
10515 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10516 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
10517 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10518 | workposted = true; | |
10519 | break; | |
10520 | } | |
10521 | out: | |
10522 | return workposted; | |
4f774513 JS |
10523 | } |
10524 | ||
4d9ab994 JS |
10525 | /** |
10526 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
10527 | * @phba: Pointer to HBA context object. | |
10528 | * @cq: Pointer to the completion queue. | |
10529 | * @wcqe: Pointer to a completion queue entry. | |
10530 | * | |
25985edc | 10531 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
10532 | * entry. |
10533 | * | |
10534 | * Return: true if work posted to worker thread, otherwise false. | |
10535 | **/ | |
10536 | static bool | |
10537 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
10538 | struct lpfc_cqe *cqe) | |
10539 | { | |
45ed1190 | 10540 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
10541 | bool workposted = false; |
10542 | ||
10543 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 10544 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
10545 | |
10546 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 10547 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 10548 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 10549 | /* Process the WQ/RQ complete event */ |
bc73905a | 10550 | phba->last_completion_time = jiffies; |
4d9ab994 | 10551 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
45ed1190 | 10552 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
10553 | break; |
10554 | case CQE_CODE_RELEASE_WQE: | |
10555 | /* Process the WQ release event */ | |
10556 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 10557 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
10558 | break; |
10559 | case CQE_CODE_XRI_ABORTED: | |
10560 | /* Process the WQ XRI abort event */ | |
bc73905a | 10561 | phba->last_completion_time = jiffies; |
4d9ab994 | 10562 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 10563 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
10564 | break; |
10565 | case CQE_CODE_RECEIVE: | |
10566 | /* Process the RQ event */ | |
bc73905a | 10567 | phba->last_completion_time = jiffies; |
4d9ab994 | 10568 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 10569 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
10570 | break; |
10571 | default: | |
10572 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10573 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 10574 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
10575 | break; |
10576 | } | |
10577 | return workposted; | |
10578 | } | |
10579 | ||
4f774513 JS |
10580 | /** |
10581 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
10582 | * @phba: Pointer to HBA context object. | |
10583 | * @eqe: Pointer to fast-path event queue entry. | |
10584 | * | |
10585 | * This routine process a event queue entry from the slow-path event queue. | |
10586 | * It will check the MajorCode and MinorCode to determine this is for a | |
10587 | * completion event on a completion queue, if not, an error shall be logged | |
10588 | * and just return. Otherwise, it will get to the corresponding completion | |
10589 | * queue and process all the entries on that completion queue, rearm the | |
10590 | * completion queue, and then return. | |
10591 | * | |
10592 | **/ | |
10593 | static void | |
10594 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
10595 | { | |
10596 | struct lpfc_queue *cq = NULL, *childq, *speq; | |
10597 | struct lpfc_cqe *cqe; | |
10598 | bool workposted = false; | |
10599 | int ecount = 0; | |
10600 | uint16_t cqid; | |
10601 | ||
cb5172ea | 10602 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
4f774513 JS |
10603 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
10604 | "0359 Not a valid slow-path completion " | |
10605 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
10606 | bf_get_le32(lpfc_eqe_major_code, eqe), |
10607 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
10608 | return; |
10609 | } | |
10610 | ||
10611 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 10612 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
10613 | |
10614 | /* Search for completion queue pointer matching this cqid */ | |
10615 | speq = phba->sli4_hba.sp_eq; | |
10616 | list_for_each_entry(childq, &speq->child_list, list) { | |
10617 | if (childq->queue_id == cqid) { | |
10618 | cq = childq; | |
10619 | break; | |
10620 | } | |
10621 | } | |
10622 | if (unlikely(!cq)) { | |
75baf696 JS |
10623 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
10624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10625 | "0365 Slow-path CQ identifier " | |
10626 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
10627 | return; |
10628 | } | |
10629 | ||
10630 | /* Process all the entries to the CQ */ | |
10631 | switch (cq->type) { | |
10632 | case LPFC_MCQ: | |
10633 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
10634 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
10635 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10636 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
10637 | } | |
10638 | break; | |
10639 | case LPFC_WCQ: | |
10640 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
0558056c JS |
10641 | if (cq->subtype == LPFC_FCP) |
10642 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, | |
10643 | cqe); | |
10644 | else | |
10645 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, | |
10646 | cqe); | |
4f774513 JS |
10647 | if (!(++ecount % LPFC_GET_QE_REL_INT)) |
10648 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
10649 | } | |
10650 | break; | |
10651 | default: | |
10652 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10653 | "0370 Invalid completion queue type (%d)\n", | |
10654 | cq->type); | |
10655 | return; | |
10656 | } | |
10657 | ||
10658 | /* Catch the no cq entry condition, log an error */ | |
10659 | if (unlikely(ecount == 0)) | |
10660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10661 | "0371 No entry from the CQ: identifier " | |
10662 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
10663 | ||
10664 | /* In any case, flash and re-arm the RCQ */ | |
10665 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
10666 | ||
10667 | /* wake up worker thread if there are works to be done */ | |
10668 | if (workposted) | |
10669 | lpfc_worker_wake_up(phba); | |
10670 | } | |
10671 | ||
10672 | /** | |
10673 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
10674 | * @eqe: Pointer to fast-path completion queue entry. | |
10675 | * | |
10676 | * This routine process a fast-path work queue completion entry from fast-path | |
10677 | * event queue for FCP command response completion. | |
10678 | **/ | |
10679 | static void | |
10680 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | |
10681 | struct lpfc_wcqe_complete *wcqe) | |
10682 | { | |
10683 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | |
10684 | struct lpfc_iocbq *cmdiocbq; | |
10685 | struct lpfc_iocbq irspiocbq; | |
10686 | unsigned long iflags; | |
10687 | ||
10688 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10689 | pring->stats.iocb_event++; | |
10690 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10691 | ||
10692 | /* Check for response status */ | |
10693 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
10694 | /* If resource errors reported from HBA, reduce queue | |
10695 | * depth of the SCSI device. | |
10696 | */ | |
10697 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
10698 | IOSTAT_LOCAL_REJECT) && | |
10699 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
10700 | phba->lpfc_rampdown_queue_depth(phba); | |
10701 | } | |
10702 | /* Log the error status */ | |
10703 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10704 | "0373 FCP complete error: status=x%x, " | |
10705 | "hw_status=x%x, total_data_specified=%d, " | |
10706 | "parameter=x%x, word3=x%x\n", | |
10707 | bf_get(lpfc_wcqe_c_status, wcqe), | |
10708 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
10709 | wcqe->total_data_placed, wcqe->parameter, | |
10710 | wcqe->word3); | |
10711 | } | |
10712 | ||
10713 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
10714 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10715 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
10716 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10717 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10718 | if (unlikely(!cmdiocbq)) { | |
10719 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10720 | "0374 FCP complete with no corresponding " | |
10721 | "cmdiocb: iotag (%d)\n", | |
10722 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10723 | return; | |
10724 | } | |
10725 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
10726 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10727 | "0375 FCP cmdiocb not callback function " | |
10728 | "iotag: (%d)\n", | |
10729 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10730 | return; | |
10731 | } | |
10732 | ||
10733 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 10734 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 10735 | |
0f65ff68 JS |
10736 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
10737 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10738 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
10739 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10740 | } | |
10741 | ||
4f774513 JS |
10742 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
10743 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
10744 | } | |
10745 | ||
10746 | /** | |
10747 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
10748 | * @phba: Pointer to HBA context object. | |
10749 | * @cq: Pointer to completion queue. | |
10750 | * @wcqe: Pointer to work-queue completion queue entry. | |
10751 | * | |
10752 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
10753 | * proper WQ release routine to the slow-path WQ. | |
10754 | **/ | |
10755 | static void | |
10756 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
10757 | struct lpfc_wcqe_release *wcqe) | |
10758 | { | |
10759 | struct lpfc_queue *childwq; | |
10760 | bool wqid_matched = false; | |
10761 | uint16_t fcp_wqid; | |
10762 | ||
10763 | /* Check for fast-path FCP work queue release */ | |
10764 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
10765 | list_for_each_entry(childwq, &cq->child_list, list) { | |
10766 | if (childwq->queue_id == fcp_wqid) { | |
10767 | lpfc_sli4_wq_release(childwq, | |
10768 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
10769 | wqid_matched = true; | |
10770 | break; | |
10771 | } | |
10772 | } | |
10773 | /* Report warning log message if no match found */ | |
10774 | if (wqid_matched != true) | |
10775 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10776 | "2580 Fast-path wqe consume event carries " | |
10777 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
10778 | } | |
10779 | ||
10780 | /** | |
10781 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
10782 | * @cq: Pointer to the completion queue. | |
10783 | * @eqe: Pointer to fast-path completion queue entry. | |
10784 | * | |
10785 | * This routine process a fast-path work queue completion entry from fast-path | |
10786 | * event queue for FCP command response completion. | |
10787 | **/ | |
10788 | static int | |
10789 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
10790 | struct lpfc_cqe *cqe) | |
10791 | { | |
10792 | struct lpfc_wcqe_release wcqe; | |
10793 | bool workposted = false; | |
10794 | ||
10795 | /* Copy the work queue CQE and convert endian order if needed */ | |
10796 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
10797 | ||
10798 | /* Check and process for different type of WCQE and dispatch */ | |
10799 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
10800 | case CQE_CODE_COMPL_WQE: | |
10801 | /* Process the WQ complete event */ | |
98fc5dd9 | 10802 | phba->last_completion_time = jiffies; |
4f774513 JS |
10803 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
10804 | (struct lpfc_wcqe_complete *)&wcqe); | |
10805 | break; | |
10806 | case CQE_CODE_RELEASE_WQE: | |
10807 | /* Process the WQ release event */ | |
10808 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
10809 | (struct lpfc_wcqe_release *)&wcqe); | |
10810 | break; | |
10811 | case CQE_CODE_XRI_ABORTED: | |
10812 | /* Process the WQ XRI abort event */ | |
bc73905a | 10813 | phba->last_completion_time = jiffies; |
4f774513 JS |
10814 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
10815 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
10816 | break; | |
10817 | default: | |
10818 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10819 | "0144 Not a valid WCQE code: x%x\n", | |
10820 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
10821 | break; | |
10822 | } | |
10823 | return workposted; | |
10824 | } | |
10825 | ||
10826 | /** | |
10827 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | |
10828 | * @phba: Pointer to HBA context object. | |
10829 | * @eqe: Pointer to fast-path event queue entry. | |
10830 | * | |
10831 | * This routine process a event queue entry from the fast-path event queue. | |
10832 | * It will check the MajorCode and MinorCode to determine this is for a | |
10833 | * completion event on a completion queue, if not, an error shall be logged | |
10834 | * and just return. Otherwise, it will get to the corresponding completion | |
10835 | * queue and process all the entries on the completion queue, rearm the | |
10836 | * completion queue, and then return. | |
10837 | **/ | |
10838 | static void | |
10839 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | |
10840 | uint32_t fcp_cqidx) | |
10841 | { | |
10842 | struct lpfc_queue *cq; | |
10843 | struct lpfc_cqe *cqe; | |
10844 | bool workposted = false; | |
10845 | uint16_t cqid; | |
10846 | int ecount = 0; | |
10847 | ||
cb5172ea | 10848 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 JS |
10849 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
10850 | "0366 Not a valid fast-path completion " | |
10851 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
10852 | bf_get_le32(lpfc_eqe_major_code, eqe), |
10853 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
10854 | return; |
10855 | } | |
10856 | ||
10857 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | |
10858 | if (unlikely(!cq)) { | |
75baf696 JS |
10859 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
10860 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10861 | "0367 Fast-path completion queue " | |
10862 | "does not exist\n"); | |
4f774513 JS |
10863 | return; |
10864 | } | |
10865 | ||
10866 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 10867 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
10868 | if (unlikely(cqid != cq->queue_id)) { |
10869 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10870 | "0368 Miss-matched fast-path completion " | |
10871 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
10872 | cqid, cq->queue_id); | |
10873 | return; | |
10874 | } | |
10875 | ||
10876 | /* Process all the entries to the CQ */ | |
10877 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
10878 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
10879 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10880 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
10881 | } | |
10882 | ||
10883 | /* Catch the no cq entry condition */ | |
10884 | if (unlikely(ecount == 0)) | |
10885 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10886 | "0369 No entry from fast-path completion " | |
10887 | "queue fcpcqid=%d\n", cq->queue_id); | |
10888 | ||
10889 | /* In any case, flash and re-arm the CQ */ | |
10890 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
10891 | ||
10892 | /* wake up worker thread if there are works to be done */ | |
10893 | if (workposted) | |
10894 | lpfc_worker_wake_up(phba); | |
10895 | } | |
10896 | ||
10897 | static void | |
10898 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
10899 | { | |
10900 | struct lpfc_eqe *eqe; | |
10901 | ||
10902 | /* walk all the EQ entries and drop on the floor */ | |
10903 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
10904 | ; | |
10905 | ||
10906 | /* Clear and re-arm the EQ */ | |
10907 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
10908 | } | |
10909 | ||
10910 | /** | |
10911 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | |
10912 | * @irq: Interrupt number. | |
10913 | * @dev_id: The device context pointer. | |
10914 | * | |
10915 | * This function is directly called from the PCI layer as an interrupt | |
10916 | * service routine when device with SLI-4 interface spec is enabled with | |
10917 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
10918 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
10919 | * interrupt mode, this function is called as part of the device-level | |
10920 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | |
10921 | * undergoing initialization, the interrupt handler will not process the | |
10922 | * interrupt. The link attention and ELS ring attention events are handled | |
10923 | * by the worker thread. The interrupt handler signals the worker thread | |
10924 | * and returns for these events. This function is called without any lock | |
10925 | * held. It gets the hbalock to access and update SLI data structures. | |
10926 | * | |
10927 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10928 | * returns IRQ_NONE. | |
10929 | **/ | |
10930 | irqreturn_t | |
10931 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | |
10932 | { | |
10933 | struct lpfc_hba *phba; | |
10934 | struct lpfc_queue *speq; | |
10935 | struct lpfc_eqe *eqe; | |
10936 | unsigned long iflag; | |
10937 | int ecount = 0; | |
10938 | ||
10939 | /* | |
10940 | * Get the driver's phba structure from the dev_id | |
10941 | */ | |
10942 | phba = (struct lpfc_hba *)dev_id; | |
10943 | ||
10944 | if (unlikely(!phba)) | |
10945 | return IRQ_NONE; | |
10946 | ||
10947 | /* Get to the EQ struct associated with this vector */ | |
10948 | speq = phba->sli4_hba.sp_eq; | |
10949 | ||
10950 | /* Check device state for handling interrupt */ | |
10951 | if (unlikely(lpfc_intr_state_check(phba))) { | |
10952 | /* Check again for link_state with lock held */ | |
10953 | spin_lock_irqsave(&phba->hbalock, iflag); | |
10954 | if (phba->link_state < LPFC_LINK_DOWN) | |
10955 | /* Flush, clear interrupt, and rearm the EQ */ | |
10956 | lpfc_sli4_eq_flush(phba, speq); | |
10957 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10958 | return IRQ_NONE; | |
10959 | } | |
10960 | ||
10961 | /* | |
10962 | * Process all the event on FCP slow-path EQ | |
10963 | */ | |
10964 | while ((eqe = lpfc_sli4_eq_get(speq))) { | |
10965 | lpfc_sli4_sp_handle_eqe(phba, eqe); | |
10966 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10967 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); | |
10968 | } | |
10969 | ||
10970 | /* Always clear and re-arm the slow-path EQ */ | |
10971 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | |
10972 | ||
10973 | /* Catch the no cq entry condition */ | |
10974 | if (unlikely(ecount == 0)) { | |
10975 | if (phba->intr_type == MSIX) | |
10976 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10977 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10978 | "0357 MSI-X interrupt with no EQE\n"); | |
10979 | else | |
10980 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10981 | return IRQ_NONE; | |
10982 | } | |
10983 | ||
10984 | return IRQ_HANDLED; | |
10985 | } /* lpfc_sli4_sp_intr_handler */ | |
10986 | ||
10987 | /** | |
10988 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | |
10989 | * @irq: Interrupt number. | |
10990 | * @dev_id: The device context pointer. | |
10991 | * | |
10992 | * This function is directly called from the PCI layer as an interrupt | |
10993 | * service routine when device with SLI-4 interface spec is enabled with | |
10994 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10995 | * ring event in the HBA. However, when the device is enabled with either | |
10996 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10997 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10998 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10999 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
11000 | * the intrrupt context. This function is called without any lock held. | |
11001 | * It gets the hbalock to access and update SLI data structures. Note that, | |
11002 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
11003 | * equal to that of FCP CQ index. | |
11004 | * | |
11005 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
11006 | * returns IRQ_NONE. | |
11007 | **/ | |
11008 | irqreturn_t | |
11009 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | |
11010 | { | |
11011 | struct lpfc_hba *phba; | |
11012 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
11013 | struct lpfc_queue *fpeq; | |
11014 | struct lpfc_eqe *eqe; | |
11015 | unsigned long iflag; | |
11016 | int ecount = 0; | |
11017 | uint32_t fcp_eqidx; | |
11018 | ||
11019 | /* Get the driver's phba structure from the dev_id */ | |
11020 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
11021 | phba = fcp_eq_hdl->phba; | |
11022 | fcp_eqidx = fcp_eq_hdl->idx; | |
11023 | ||
11024 | if (unlikely(!phba)) | |
11025 | return IRQ_NONE; | |
11026 | ||
11027 | /* Get to the EQ struct associated with this vector */ | |
11028 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | |
11029 | ||
11030 | /* Check device state for handling interrupt */ | |
11031 | if (unlikely(lpfc_intr_state_check(phba))) { | |
11032 | /* Check again for link_state with lock held */ | |
11033 | spin_lock_irqsave(&phba->hbalock, iflag); | |
11034 | if (phba->link_state < LPFC_LINK_DOWN) | |
11035 | /* Flush, clear interrupt, and rearm the EQ */ | |
11036 | lpfc_sli4_eq_flush(phba, fpeq); | |
11037 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
11038 | return IRQ_NONE; | |
11039 | } | |
11040 | ||
11041 | /* | |
11042 | * Process all the event on FCP fast-path EQ | |
11043 | */ | |
11044 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
11045 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | |
11046 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
11047 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); | |
11048 | } | |
11049 | ||
11050 | /* Always clear and re-arm the fast-path EQ */ | |
11051 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
11052 | ||
11053 | if (unlikely(ecount == 0)) { | |
11054 | if (phba->intr_type == MSIX) | |
11055 | /* MSI-X treated interrupt served as no EQ share INT */ | |
11056 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11057 | "0358 MSI-X interrupt with no EQE\n"); | |
11058 | else | |
11059 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
11060 | return IRQ_NONE; | |
11061 | } | |
11062 | ||
11063 | return IRQ_HANDLED; | |
11064 | } /* lpfc_sli4_fp_intr_handler */ | |
11065 | ||
11066 | /** | |
11067 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
11068 | * @irq: Interrupt number. | |
11069 | * @dev_id: The device context pointer. | |
11070 | * | |
11071 | * This function is the device-level interrupt handler to device with SLI-4 | |
11072 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
11073 | * interrupt mode is enabled and there is an event in the HBA which requires | |
11074 | * driver attention. This function invokes the slow-path interrupt attention | |
11075 | * handling function and fast-path interrupt attention handling function in | |
11076 | * turn to process the relevant HBA attention events. This function is called | |
11077 | * without any lock held. It gets the hbalock to access and update SLI data | |
11078 | * structures. | |
11079 | * | |
11080 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
11081 | * returns IRQ_NONE. | |
11082 | **/ | |
11083 | irqreturn_t | |
11084 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
11085 | { | |
11086 | struct lpfc_hba *phba; | |
11087 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
11088 | bool fp_handled = false; | |
11089 | uint32_t fcp_eqidx; | |
11090 | ||
11091 | /* Get the driver's phba structure from the dev_id */ | |
11092 | phba = (struct lpfc_hba *)dev_id; | |
11093 | ||
11094 | if (unlikely(!phba)) | |
11095 | return IRQ_NONE; | |
11096 | ||
11097 | /* | |
11098 | * Invokes slow-path host attention interrupt handling as appropriate. | |
11099 | */ | |
11100 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | |
11101 | ||
11102 | /* | |
11103 | * Invoke fast-path host attention interrupt handling as appropriate. | |
11104 | */ | |
11105 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
11106 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | |
11107 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | |
11108 | if (fp_irq_rc == IRQ_HANDLED) | |
11109 | fp_handled |= true; | |
11110 | } | |
11111 | ||
11112 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | |
11113 | } /* lpfc_sli4_intr_handler */ | |
11114 | ||
11115 | /** | |
11116 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
11117 | * @queue: The queue structure to free. | |
11118 | * | |
b595076a | 11119 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
11120 | * the host resident queue. This function must be called after destroying the |
11121 | * queue on the HBA. | |
11122 | **/ | |
11123 | void | |
11124 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
11125 | { | |
11126 | struct lpfc_dmabuf *dmabuf; | |
11127 | ||
11128 | if (!queue) | |
11129 | return; | |
11130 | ||
11131 | while (!list_empty(&queue->page_list)) { | |
11132 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
11133 | list); | |
49198b37 | 11134 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
11135 | dmabuf->virt, dmabuf->phys); |
11136 | kfree(dmabuf); | |
11137 | } | |
11138 | kfree(queue); | |
11139 | return; | |
11140 | } | |
11141 | ||
11142 | /** | |
11143 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
11144 | * @phba: The HBA that this queue is being created on. | |
11145 | * @entry_size: The size of each queue entry for this queue. | |
11146 | * @entry count: The number of entries that this queue will handle. | |
11147 | * | |
11148 | * This function allocates a queue structure and the DMAable memory used for | |
11149 | * the host resident queue. This function must be called before creating the | |
11150 | * queue on the HBA. | |
11151 | **/ | |
11152 | struct lpfc_queue * | |
11153 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
11154 | uint32_t entry_count) | |
11155 | { | |
11156 | struct lpfc_queue *queue; | |
11157 | struct lpfc_dmabuf *dmabuf; | |
11158 | int x, total_qe_count; | |
11159 | void *dma_pointer; | |
cb5172ea | 11160 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 11161 | |
cb5172ea JS |
11162 | if (!phba->sli4_hba.pc_sli4_params.supported) |
11163 | hw_page_size = SLI4_PAGE_SIZE; | |
11164 | ||
4f774513 JS |
11165 | queue = kzalloc(sizeof(struct lpfc_queue) + |
11166 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
11167 | if (!queue) | |
11168 | return NULL; | |
cb5172ea JS |
11169 | queue->page_count = (ALIGN(entry_size * entry_count, |
11170 | hw_page_size))/hw_page_size; | |
4f774513 JS |
11171 | INIT_LIST_HEAD(&queue->list); |
11172 | INIT_LIST_HEAD(&queue->page_list); | |
11173 | INIT_LIST_HEAD(&queue->child_list); | |
11174 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
11175 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
11176 | if (!dmabuf) | |
11177 | goto out_fail; | |
11178 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 11179 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
11180 | GFP_KERNEL); |
11181 | if (!dmabuf->virt) { | |
11182 | kfree(dmabuf); | |
11183 | goto out_fail; | |
11184 | } | |
cb5172ea | 11185 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11186 | dmabuf->buffer_tag = x; |
11187 | list_add_tail(&dmabuf->list, &queue->page_list); | |
11188 | /* initialize queue's entry array */ | |
11189 | dma_pointer = dmabuf->virt; | |
11190 | for (; total_qe_count < entry_count && | |
cb5172ea | 11191 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
11192 | total_qe_count++, dma_pointer += entry_size) { |
11193 | queue->qe[total_qe_count].address = dma_pointer; | |
11194 | } | |
11195 | } | |
11196 | queue->entry_size = entry_size; | |
11197 | queue->entry_count = entry_count; | |
11198 | queue->phba = phba; | |
11199 | ||
11200 | return queue; | |
11201 | out_fail: | |
11202 | lpfc_sli4_queue_free(queue); | |
11203 | return NULL; | |
11204 | } | |
11205 | ||
11206 | /** | |
11207 | * lpfc_eq_create - Create an Event Queue on the HBA | |
11208 | * @phba: HBA structure that indicates port to create a queue on. | |
11209 | * @eq: The queue structure to use to create the event queue. | |
11210 | * @imax: The maximum interrupt per second limit. | |
11211 | * | |
11212 | * This function creates an event queue, as detailed in @eq, on a port, | |
11213 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
11214 | * | |
11215 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
11216 | * is used to get the entry count and entry size that are necessary to | |
11217 | * determine the number of pages to allocate and use for this queue. This | |
11218 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
11219 | * event queue. This function is asynchronous and will wait for the mailbox | |
11220 | * command to finish before continuing. | |
11221 | * | |
11222 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11223 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11224 | * fails this function will return -ENXIO. | |
4f774513 JS |
11225 | **/ |
11226 | uint32_t | |
11227 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
11228 | { | |
11229 | struct lpfc_mbx_eq_create *eq_create; | |
11230 | LPFC_MBOXQ_t *mbox; | |
11231 | int rc, length, status = 0; | |
11232 | struct lpfc_dmabuf *dmabuf; | |
11233 | uint32_t shdr_status, shdr_add_status; | |
11234 | union lpfc_sli4_cfg_shdr *shdr; | |
11235 | uint16_t dmult; | |
49198b37 JS |
11236 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
11237 | ||
11238 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
11239 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
11240 | |
11241 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11242 | if (!mbox) | |
11243 | return -ENOMEM; | |
11244 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
11245 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11246 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11247 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
11248 | length, LPFC_SLI4_MBX_EMBED); | |
11249 | eq_create = &mbox->u.mqe.un.eq_create; | |
11250 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
11251 | eq->page_count); | |
11252 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
11253 | LPFC_EQE_SIZE); | |
11254 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
11255 | /* Calculate delay multiper from maximum interrupt per second */ | |
11256 | dmult = LPFC_DMULT_CONST/imax - 1; | |
11257 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
11258 | dmult); | |
11259 | switch (eq->entry_count) { | |
11260 | default: | |
11261 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11262 | "0360 Unsupported EQ count. (%d)\n", | |
11263 | eq->entry_count); | |
11264 | if (eq->entry_count < 256) | |
11265 | return -EINVAL; | |
11266 | /* otherwise default to smallest count (drop through) */ | |
11267 | case 256: | |
11268 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11269 | LPFC_EQ_CNT_256); | |
11270 | break; | |
11271 | case 512: | |
11272 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11273 | LPFC_EQ_CNT_512); | |
11274 | break; | |
11275 | case 1024: | |
11276 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11277 | LPFC_EQ_CNT_1024); | |
11278 | break; | |
11279 | case 2048: | |
11280 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11281 | LPFC_EQ_CNT_2048); | |
11282 | break; | |
11283 | case 4096: | |
11284 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11285 | LPFC_EQ_CNT_4096); | |
11286 | break; | |
11287 | } | |
11288 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 11289 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11290 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
11291 | putPaddrLow(dmabuf->phys); | |
11292 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11293 | putPaddrHigh(dmabuf->phys); | |
11294 | } | |
11295 | mbox->vport = phba->pport; | |
11296 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11297 | mbox->context1 = NULL; | |
11298 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11299 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
11300 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11301 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11302 | if (shdr_status || shdr_add_status || rc) { | |
11303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11304 | "2500 EQ_CREATE mailbox failed with " | |
11305 | "status x%x add_status x%x, mbx status x%x\n", | |
11306 | shdr_status, shdr_add_status, rc); | |
11307 | status = -ENXIO; | |
11308 | } | |
11309 | eq->type = LPFC_EQ; | |
11310 | eq->subtype = LPFC_NONE; | |
11311 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
11312 | if (eq->queue_id == 0xFFFF) | |
11313 | status = -ENXIO; | |
11314 | eq->host_index = 0; | |
11315 | eq->hba_index = 0; | |
11316 | ||
8fa38513 | 11317 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
11318 | return status; |
11319 | } | |
11320 | ||
11321 | /** | |
11322 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
11323 | * @phba: HBA structure that indicates port to create a queue on. | |
11324 | * @cq: The queue structure to use to create the completion queue. | |
11325 | * @eq: The event queue to bind this completion queue to. | |
11326 | * | |
11327 | * This function creates a completion queue, as detailed in @wq, on a port, | |
11328 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
11329 | * | |
11330 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
11331 | * is used to get the entry count and entry size that are necessary to | |
11332 | * determine the number of pages to allocate and use for this queue. The @eq | |
11333 | * is used to indicate which event queue to bind this completion queue to. This | |
11334 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
11335 | * completion queue. This function is asynchronous and will wait for the mailbox | |
11336 | * command to finish before continuing. | |
11337 | * | |
11338 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11339 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11340 | * fails this function will return -ENXIO. | |
4f774513 JS |
11341 | **/ |
11342 | uint32_t | |
11343 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11344 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
11345 | { | |
11346 | struct lpfc_mbx_cq_create *cq_create; | |
11347 | struct lpfc_dmabuf *dmabuf; | |
11348 | LPFC_MBOXQ_t *mbox; | |
11349 | int rc, length, status = 0; | |
11350 | uint32_t shdr_status, shdr_add_status; | |
11351 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
11352 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
11353 | ||
11354 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
11355 | hw_page_size = SLI4_PAGE_SIZE; | |
11356 | ||
4f774513 JS |
11357 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
11358 | if (!mbox) | |
11359 | return -ENOMEM; | |
11360 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
11361 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11362 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11363 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
11364 | length, LPFC_SLI4_MBX_EMBED); | |
11365 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 11366 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
11367 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
11368 | cq->page_count); | |
11369 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
11370 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
11371 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
11372 | phba->sli4_hba.pc_sli4_params.cqv); | |
11373 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
11374 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
11375 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
11376 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
11377 | eq->queue_id); | |
11378 | } else { | |
11379 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
11380 | eq->queue_id); | |
11381 | } | |
4f774513 JS |
11382 | switch (cq->entry_count) { |
11383 | default: | |
11384 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11385 | "0361 Unsupported CQ count. (%d)\n", | |
11386 | cq->entry_count); | |
11387 | if (cq->entry_count < 256) | |
11388 | return -EINVAL; | |
11389 | /* otherwise default to smallest count (drop through) */ | |
11390 | case 256: | |
11391 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
11392 | LPFC_CQ_CNT_256); | |
11393 | break; | |
11394 | case 512: | |
11395 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
11396 | LPFC_CQ_CNT_512); | |
11397 | break; | |
11398 | case 1024: | |
11399 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
11400 | LPFC_CQ_CNT_1024); | |
11401 | break; | |
11402 | } | |
11403 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 11404 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11405 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
11406 | putPaddrLow(dmabuf->phys); | |
11407 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11408 | putPaddrHigh(dmabuf->phys); | |
11409 | } | |
11410 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11411 | ||
11412 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
11413 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
11414 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11415 | if (shdr_status || shdr_add_status || rc) { | |
11416 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11417 | "2501 CQ_CREATE mailbox failed with " | |
11418 | "status x%x add_status x%x, mbx status x%x\n", | |
11419 | shdr_status, shdr_add_status, rc); | |
11420 | status = -ENXIO; | |
11421 | goto out; | |
11422 | } | |
11423 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
11424 | if (cq->queue_id == 0xFFFF) { | |
11425 | status = -ENXIO; | |
11426 | goto out; | |
11427 | } | |
11428 | /* link the cq onto the parent eq child list */ | |
11429 | list_add_tail(&cq->list, &eq->child_list); | |
11430 | /* Set up completion queue's type and subtype */ | |
11431 | cq->type = type; | |
11432 | cq->subtype = subtype; | |
11433 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 11434 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
11435 | cq->host_index = 0; |
11436 | cq->hba_index = 0; | |
4f774513 | 11437 | |
8fa38513 JS |
11438 | out: |
11439 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
11440 | return status; |
11441 | } | |
11442 | ||
b19a061a JS |
11443 | /** |
11444 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
11445 | * @phba: HBA structure that indicates port to create a queue on. | |
11446 | * @mq: The queue structure to use to create the mailbox queue. | |
11447 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
11448 | * @cq: The completion queue to associate with this cq. | |
11449 | * | |
11450 | * This function provides failback (fb) functionality when the | |
11451 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
11452 | * to mq_create_ext otherwise. | |
11453 | * | |
11454 | * This routine cannot fail as all attributes were previously accessed and | |
11455 | * initialized in mq_create_ext. | |
11456 | **/ | |
11457 | static void | |
11458 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
11459 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
11460 | { | |
11461 | struct lpfc_mbx_mq_create *mq_create; | |
11462 | struct lpfc_dmabuf *dmabuf; | |
11463 | int length; | |
11464 | ||
11465 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
11466 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11467 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11468 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
11469 | length, LPFC_SLI4_MBX_EMBED); | |
11470 | mq_create = &mbox->u.mqe.un.mq_create; | |
11471 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
11472 | mq->page_count); | |
11473 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
11474 | cq->queue_id); | |
11475 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
11476 | switch (mq->entry_count) { | |
11477 | case 16: | |
5a6f133e JS |
11478 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
11479 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
11480 | break; |
11481 | case 32: | |
5a6f133e JS |
11482 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
11483 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
11484 | break; |
11485 | case 64: | |
5a6f133e JS |
11486 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
11487 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
11488 | break; |
11489 | case 128: | |
5a6f133e JS |
11490 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
11491 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
11492 | break; |
11493 | } | |
11494 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
11495 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
11496 | putPaddrLow(dmabuf->phys); | |
11497 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11498 | putPaddrHigh(dmabuf->phys); | |
11499 | } | |
11500 | } | |
11501 | ||
04c68496 JS |
11502 | /** |
11503 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
11504 | * @phba: HBA structure that indicates port to create a queue on. | |
11505 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
11506 | * @cq: The completion queue to associate with this cq. |
11507 | * @subtype: The queue's subtype. | |
04c68496 JS |
11508 | * |
11509 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
11510 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
11511 | * | |
11512 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
11513 | * is used to get the entry count and entry size that are necessary to | |
11514 | * determine the number of pages to allocate and use for this queue. This | |
11515 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
11516 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
11517 | * command to finish before continuing. | |
11518 | * | |
11519 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11520 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11521 | * fails this function will return -ENXIO. | |
04c68496 | 11522 | **/ |
b19a061a | 11523 | int32_t |
04c68496 JS |
11524 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
11525 | struct lpfc_queue *cq, uint32_t subtype) | |
11526 | { | |
11527 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 11528 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
11529 | struct lpfc_dmabuf *dmabuf; |
11530 | LPFC_MBOXQ_t *mbox; | |
11531 | int rc, length, status = 0; | |
11532 | uint32_t shdr_status, shdr_add_status; | |
11533 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 11534 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 11535 | |
49198b37 JS |
11536 | if (!phba->sli4_hba.pc_sli4_params.supported) |
11537 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 11538 | |
04c68496 JS |
11539 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
11540 | if (!mbox) | |
11541 | return -ENOMEM; | |
b19a061a | 11542 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
11543 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
11544 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 11545 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 11546 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
11547 | |
11548 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 11549 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
11550 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
11551 | &mq_create_ext->u.request, mq->page_count); | |
11552 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
11553 | &mq_create_ext->u.request, 1); | |
11554 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
11555 | &mq_create_ext->u.request, 1); |
11556 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
11557 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
11558 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
11559 | &mq_create_ext->u.request, 1); | |
11560 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
11561 | &mq_create_ext->u.request, 1); | |
b19a061a | 11562 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
11563 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
11564 | phba->sli4_hba.pc_sli4_params.mqv); | |
11565 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
11566 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
11567 | cq->queue_id); | |
11568 | else | |
11569 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
11570 | cq->queue_id); | |
04c68496 JS |
11571 | switch (mq->entry_count) { |
11572 | default: | |
11573 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11574 | "0362 Unsupported MQ count. (%d)\n", | |
11575 | mq->entry_count); | |
11576 | if (mq->entry_count < 16) | |
11577 | return -EINVAL; | |
11578 | /* otherwise default to smallest count (drop through) */ | |
11579 | case 16: | |
5a6f133e JS |
11580 | bf_set(lpfc_mq_context_ring_size, |
11581 | &mq_create_ext->u.request.context, | |
11582 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
11583 | break; |
11584 | case 32: | |
5a6f133e JS |
11585 | bf_set(lpfc_mq_context_ring_size, |
11586 | &mq_create_ext->u.request.context, | |
11587 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
11588 | break; |
11589 | case 64: | |
5a6f133e JS |
11590 | bf_set(lpfc_mq_context_ring_size, |
11591 | &mq_create_ext->u.request.context, | |
11592 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
11593 | break; |
11594 | case 128: | |
5a6f133e JS |
11595 | bf_set(lpfc_mq_context_ring_size, |
11596 | &mq_create_ext->u.request.context, | |
11597 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
11598 | break; |
11599 | } | |
11600 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 11601 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 11602 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 11603 | putPaddrLow(dmabuf->phys); |
b19a061a | 11604 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
11605 | putPaddrHigh(dmabuf->phys); |
11606 | } | |
11607 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
11608 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
11609 | &mq_create_ext->u.response); | |
11610 | if (rc != MBX_SUCCESS) { | |
11611 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
11612 | "2795 MQ_CREATE_EXT failed with " | |
11613 | "status x%x. Failback to MQ_CREATE.\n", | |
11614 | rc); | |
11615 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
11616 | mq_create = &mbox->u.mqe.un.mq_create; | |
11617 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11618 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
11619 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
11620 | &mq_create->u.response); | |
11621 | } | |
11622 | ||
04c68496 | 11623 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
11624 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
11625 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11626 | if (shdr_status || shdr_add_status || rc) { | |
11627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11628 | "2502 MQ_CREATE mailbox failed with " | |
11629 | "status x%x add_status x%x, mbx status x%x\n", | |
11630 | shdr_status, shdr_add_status, rc); | |
11631 | status = -ENXIO; | |
11632 | goto out; | |
11633 | } | |
04c68496 JS |
11634 | if (mq->queue_id == 0xFFFF) { |
11635 | status = -ENXIO; | |
11636 | goto out; | |
11637 | } | |
11638 | mq->type = LPFC_MQ; | |
2a622bfb | 11639 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
11640 | mq->subtype = subtype; |
11641 | mq->host_index = 0; | |
11642 | mq->hba_index = 0; | |
11643 | ||
11644 | /* link the mq onto the parent cq child list */ | |
11645 | list_add_tail(&mq->list, &cq->child_list); | |
11646 | out: | |
8fa38513 | 11647 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
11648 | return status; |
11649 | } | |
11650 | ||
4f774513 JS |
11651 | /** |
11652 | * lpfc_wq_create - Create a Work Queue on the HBA | |
11653 | * @phba: HBA structure that indicates port to create a queue on. | |
11654 | * @wq: The queue structure to use to create the work queue. | |
11655 | * @cq: The completion queue to bind this work queue to. | |
11656 | * @subtype: The subtype of the work queue indicating its functionality. | |
11657 | * | |
11658 | * This function creates a work queue, as detailed in @wq, on a port, described | |
11659 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
11660 | * | |
11661 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
11662 | * is used to get the entry count and entry size that are necessary to | |
11663 | * determine the number of pages to allocate and use for this queue. The @cq | |
11664 | * is used to indicate which completion queue to bind this work queue to. This | |
11665 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
11666 | * work queue. This function is asynchronous and will wait for the mailbox | |
11667 | * command to finish before continuing. | |
11668 | * | |
11669 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11670 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11671 | * fails this function will return -ENXIO. | |
4f774513 JS |
11672 | **/ |
11673 | uint32_t | |
11674 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
11675 | struct lpfc_queue *cq, uint32_t subtype) | |
11676 | { | |
11677 | struct lpfc_mbx_wq_create *wq_create; | |
11678 | struct lpfc_dmabuf *dmabuf; | |
11679 | LPFC_MBOXQ_t *mbox; | |
11680 | int rc, length, status = 0; | |
11681 | uint32_t shdr_status, shdr_add_status; | |
11682 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 11683 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 11684 | struct dma_address *page; |
49198b37 JS |
11685 | |
11686 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
11687 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
11688 | |
11689 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11690 | if (!mbox) | |
11691 | return -ENOMEM; | |
11692 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
11693 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11694 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11695 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
11696 | length, LPFC_SLI4_MBX_EMBED); | |
11697 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 11698 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
11699 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
11700 | wq->page_count); | |
11701 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
11702 | cq->queue_id); | |
5a6f133e JS |
11703 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
11704 | phba->sli4_hba.pc_sli4_params.wqv); | |
11705 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { | |
11706 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, | |
11707 | wq->entry_count); | |
11708 | switch (wq->entry_size) { | |
11709 | default: | |
11710 | case 64: | |
11711 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
11712 | &wq_create->u.request_1, | |
11713 | LPFC_WQ_WQE_SIZE_64); | |
11714 | break; | |
11715 | case 128: | |
11716 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
11717 | &wq_create->u.request_1, | |
11718 | LPFC_WQ_WQE_SIZE_128); | |
11719 | break; | |
11720 | } | |
11721 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
11722 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
11723 | page = wq_create->u.request_1.page; | |
11724 | } else { | |
11725 | page = wq_create->u.request.page; | |
11726 | } | |
4f774513 | 11727 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 11728 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
11729 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
11730 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 JS |
11731 | } |
11732 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11733 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
11734 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
11735 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11736 | if (shdr_status || shdr_add_status || rc) { | |
11737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11738 | "2503 WQ_CREATE mailbox failed with " | |
11739 | "status x%x add_status x%x, mbx status x%x\n", | |
11740 | shdr_status, shdr_add_status, rc); | |
11741 | status = -ENXIO; | |
11742 | goto out; | |
11743 | } | |
11744 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
11745 | if (wq->queue_id == 0xFFFF) { | |
11746 | status = -ENXIO; | |
11747 | goto out; | |
11748 | } | |
11749 | wq->type = LPFC_WQ; | |
2a622bfb | 11750 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
11751 | wq->subtype = subtype; |
11752 | wq->host_index = 0; | |
11753 | wq->hba_index = 0; | |
11754 | ||
11755 | /* link the wq onto the parent cq child list */ | |
11756 | list_add_tail(&wq->list, &cq->child_list); | |
11757 | out: | |
8fa38513 | 11758 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
11759 | return status; |
11760 | } | |
11761 | ||
11762 | /** | |
11763 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
11764 | * @phba: HBA structure that indicates port to create a queue on. | |
11765 | * @hrq: The queue structure to use to create the header receive queue. | |
11766 | * @drq: The queue structure to use to create the data receive queue. | |
11767 | * @cq: The completion queue to bind this work queue to. | |
11768 | * | |
11769 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
11770 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
11771 | * to the HBA. | |
11772 | * | |
11773 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
11774 | * struct is used to get the entry count that is necessary to determine the | |
11775 | * number of pages to use for this queue. The @cq is used to indicate which | |
11776 | * completion queue to bind received buffers that are posted to these queues to. | |
11777 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
11778 | * receive queue pair. This function is asynchronous and will wait for the | |
11779 | * mailbox command to finish before continuing. | |
11780 | * | |
11781 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11782 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11783 | * fails this function will return -ENXIO. | |
4f774513 JS |
11784 | **/ |
11785 | uint32_t | |
11786 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
11787 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
11788 | { | |
11789 | struct lpfc_mbx_rq_create *rq_create; | |
11790 | struct lpfc_dmabuf *dmabuf; | |
11791 | LPFC_MBOXQ_t *mbox; | |
11792 | int rc, length, status = 0; | |
11793 | uint32_t shdr_status, shdr_add_status; | |
11794 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
11795 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
11796 | ||
11797 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
11798 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
11799 | |
11800 | if (hrq->entry_count != drq->entry_count) | |
11801 | return -EINVAL; | |
11802 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11803 | if (!mbox) | |
11804 | return -ENOMEM; | |
11805 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
11806 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11807 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11808 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
11809 | length, LPFC_SLI4_MBX_EMBED); | |
11810 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
11811 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
11812 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
11813 | phba->sli4_hba.pc_sli4_params.rqv); | |
11814 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
11815 | bf_set(lpfc_rq_context_rqe_count_1, | |
11816 | &rq_create->u.request.context, | |
11817 | hrq->entry_count); | |
11818 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
11819 | bf_set(lpfc_rq_context_rqe_size, |
11820 | &rq_create->u.request.context, | |
11821 | LPFC_RQE_SIZE_8); | |
11822 | bf_set(lpfc_rq_context_page_size, | |
11823 | &rq_create->u.request.context, | |
11824 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
11825 | } else { |
11826 | switch (hrq->entry_count) { | |
11827 | default: | |
11828 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11829 | "2535 Unsupported RQ count. (%d)\n", | |
11830 | hrq->entry_count); | |
11831 | if (hrq->entry_count < 512) | |
11832 | return -EINVAL; | |
11833 | /* otherwise default to smallest count (drop through) */ | |
11834 | case 512: | |
11835 | bf_set(lpfc_rq_context_rqe_count, | |
11836 | &rq_create->u.request.context, | |
11837 | LPFC_RQ_RING_SIZE_512); | |
11838 | break; | |
11839 | case 1024: | |
11840 | bf_set(lpfc_rq_context_rqe_count, | |
11841 | &rq_create->u.request.context, | |
11842 | LPFC_RQ_RING_SIZE_1024); | |
11843 | break; | |
11844 | case 2048: | |
11845 | bf_set(lpfc_rq_context_rqe_count, | |
11846 | &rq_create->u.request.context, | |
11847 | LPFC_RQ_RING_SIZE_2048); | |
11848 | break; | |
11849 | case 4096: | |
11850 | bf_set(lpfc_rq_context_rqe_count, | |
11851 | &rq_create->u.request.context, | |
11852 | LPFC_RQ_RING_SIZE_4096); | |
11853 | break; | |
11854 | } | |
11855 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
11856 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
11857 | } |
11858 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
11859 | cq->queue_id); | |
11860 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
11861 | hrq->page_count); | |
4f774513 | 11862 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 11863 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11864 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
11865 | putPaddrLow(dmabuf->phys); | |
11866 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11867 | putPaddrHigh(dmabuf->phys); | |
11868 | } | |
11869 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11870 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
11871 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
11872 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11873 | if (shdr_status || shdr_add_status || rc) { | |
11874 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11875 | "2504 RQ_CREATE mailbox failed with " | |
11876 | "status x%x add_status x%x, mbx status x%x\n", | |
11877 | shdr_status, shdr_add_status, rc); | |
11878 | status = -ENXIO; | |
11879 | goto out; | |
11880 | } | |
11881 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
11882 | if (hrq->queue_id == 0xFFFF) { | |
11883 | status = -ENXIO; | |
11884 | goto out; | |
11885 | } | |
11886 | hrq->type = LPFC_HRQ; | |
2a622bfb | 11887 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
11888 | hrq->subtype = subtype; |
11889 | hrq->host_index = 0; | |
11890 | hrq->hba_index = 0; | |
11891 | ||
11892 | /* now create the data queue */ | |
11893 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11894 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
11895 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
11896 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
11897 | phba->sli4_hba.pc_sli4_params.rqv); | |
11898 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
11899 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 11900 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 11901 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
11902 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
11903 | LPFC_RQE_SIZE_8); | |
11904 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
11905 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
11906 | } else { |
11907 | switch (drq->entry_count) { | |
11908 | default: | |
11909 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11910 | "2536 Unsupported RQ count. (%d)\n", | |
11911 | drq->entry_count); | |
11912 | if (drq->entry_count < 512) | |
11913 | return -EINVAL; | |
11914 | /* otherwise default to smallest count (drop through) */ | |
11915 | case 512: | |
11916 | bf_set(lpfc_rq_context_rqe_count, | |
11917 | &rq_create->u.request.context, | |
11918 | LPFC_RQ_RING_SIZE_512); | |
11919 | break; | |
11920 | case 1024: | |
11921 | bf_set(lpfc_rq_context_rqe_count, | |
11922 | &rq_create->u.request.context, | |
11923 | LPFC_RQ_RING_SIZE_1024); | |
11924 | break; | |
11925 | case 2048: | |
11926 | bf_set(lpfc_rq_context_rqe_count, | |
11927 | &rq_create->u.request.context, | |
11928 | LPFC_RQ_RING_SIZE_2048); | |
11929 | break; | |
11930 | case 4096: | |
11931 | bf_set(lpfc_rq_context_rqe_count, | |
11932 | &rq_create->u.request.context, | |
11933 | LPFC_RQ_RING_SIZE_4096); | |
11934 | break; | |
11935 | } | |
11936 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
11937 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
11938 | } |
11939 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
11940 | cq->queue_id); | |
11941 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
11942 | drq->page_count); | |
4f774513 JS |
11943 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
11944 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
11945 | putPaddrLow(dmabuf->phys); | |
11946 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11947 | putPaddrHigh(dmabuf->phys); | |
11948 | } | |
11949 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11950 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11951 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
11952 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11953 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11954 | if (shdr_status || shdr_add_status || rc) { | |
11955 | status = -ENXIO; | |
11956 | goto out; | |
11957 | } | |
11958 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
11959 | if (drq->queue_id == 0xFFFF) { | |
11960 | status = -ENXIO; | |
11961 | goto out; | |
11962 | } | |
11963 | drq->type = LPFC_DRQ; | |
2a622bfb | 11964 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
11965 | drq->subtype = subtype; |
11966 | drq->host_index = 0; | |
11967 | drq->hba_index = 0; | |
11968 | ||
11969 | /* link the header and data RQs onto the parent cq child list */ | |
11970 | list_add_tail(&hrq->list, &cq->child_list); | |
11971 | list_add_tail(&drq->list, &cq->child_list); | |
11972 | ||
11973 | out: | |
8fa38513 | 11974 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
11975 | return status; |
11976 | } | |
11977 | ||
11978 | /** | |
11979 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
11980 | * @eq: The queue structure associated with the queue to destroy. | |
11981 | * | |
11982 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
11983 | * command, specific to the type of queue, to the HBA. | |
11984 | * | |
11985 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
11986 | * | |
11987 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11988 | * command fails this function will return -ENXIO. |
4f774513 JS |
11989 | **/ |
11990 | uint32_t | |
11991 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
11992 | { | |
11993 | LPFC_MBOXQ_t *mbox; | |
11994 | int rc, length, status = 0; | |
11995 | uint32_t shdr_status, shdr_add_status; | |
11996 | union lpfc_sli4_cfg_shdr *shdr; | |
11997 | ||
11998 | if (!eq) | |
11999 | return -ENODEV; | |
12000 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
12001 | if (!mbox) | |
12002 | return -ENOMEM; | |
12003 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
12004 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12005 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12006 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
12007 | length, LPFC_SLI4_MBX_EMBED); | |
12008 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
12009 | eq->queue_id); | |
12010 | mbox->vport = eq->phba->pport; | |
12011 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12012 | ||
12013 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
12014 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12015 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12016 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
12017 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12018 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12019 | if (shdr_status || shdr_add_status || rc) { | |
12020 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12021 | "2505 EQ_DESTROY mailbox failed with " | |
12022 | "status x%x add_status x%x, mbx status x%x\n", | |
12023 | shdr_status, shdr_add_status, rc); | |
12024 | status = -ENXIO; | |
12025 | } | |
12026 | ||
12027 | /* Remove eq from any list */ | |
12028 | list_del_init(&eq->list); | |
8fa38513 | 12029 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
12030 | return status; |
12031 | } | |
12032 | ||
12033 | /** | |
12034 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
12035 | * @cq: The queue structure associated with the queue to destroy. | |
12036 | * | |
12037 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
12038 | * command, specific to the type of queue, to the HBA. | |
12039 | * | |
12040 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
12041 | * | |
12042 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12043 | * command fails this function will return -ENXIO. |
4f774513 JS |
12044 | **/ |
12045 | uint32_t | |
12046 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
12047 | { | |
12048 | LPFC_MBOXQ_t *mbox; | |
12049 | int rc, length, status = 0; | |
12050 | uint32_t shdr_status, shdr_add_status; | |
12051 | union lpfc_sli4_cfg_shdr *shdr; | |
12052 | ||
12053 | if (!cq) | |
12054 | return -ENODEV; | |
12055 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
12056 | if (!mbox) | |
12057 | return -ENOMEM; | |
12058 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
12059 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12060 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12061 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
12062 | length, LPFC_SLI4_MBX_EMBED); | |
12063 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
12064 | cq->queue_id); | |
12065 | mbox->vport = cq->phba->pport; | |
12066 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12067 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
12068 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12069 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12070 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
12071 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12072 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12073 | if (shdr_status || shdr_add_status || rc) { | |
12074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12075 | "2506 CQ_DESTROY mailbox failed with " | |
12076 | "status x%x add_status x%x, mbx status x%x\n", | |
12077 | shdr_status, shdr_add_status, rc); | |
12078 | status = -ENXIO; | |
12079 | } | |
12080 | /* Remove cq from any list */ | |
12081 | list_del_init(&cq->list); | |
8fa38513 | 12082 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
12083 | return status; |
12084 | } | |
12085 | ||
04c68496 JS |
12086 | /** |
12087 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
12088 | * @qm: The queue structure associated with the queue to destroy. | |
12089 | * | |
12090 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
12091 | * command, specific to the type of queue, to the HBA. | |
12092 | * | |
12093 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
12094 | * | |
12095 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12096 | * command fails this function will return -ENXIO. |
04c68496 JS |
12097 | **/ |
12098 | uint32_t | |
12099 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
12100 | { | |
12101 | LPFC_MBOXQ_t *mbox; | |
12102 | int rc, length, status = 0; | |
12103 | uint32_t shdr_status, shdr_add_status; | |
12104 | union lpfc_sli4_cfg_shdr *shdr; | |
12105 | ||
12106 | if (!mq) | |
12107 | return -ENODEV; | |
12108 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
12109 | if (!mbox) | |
12110 | return -ENOMEM; | |
12111 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
12112 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12113 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12114 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
12115 | length, LPFC_SLI4_MBX_EMBED); | |
12116 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
12117 | mq->queue_id); | |
12118 | mbox->vport = mq->phba->pport; | |
12119 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12120 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
12121 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12122 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12123 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
12124 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12125 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12126 | if (shdr_status || shdr_add_status || rc) { | |
12127 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12128 | "2507 MQ_DESTROY mailbox failed with " | |
12129 | "status x%x add_status x%x, mbx status x%x\n", | |
12130 | shdr_status, shdr_add_status, rc); | |
12131 | status = -ENXIO; | |
12132 | } | |
12133 | /* Remove mq from any list */ | |
12134 | list_del_init(&mq->list); | |
8fa38513 | 12135 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
12136 | return status; |
12137 | } | |
12138 | ||
4f774513 JS |
12139 | /** |
12140 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
12141 | * @wq: The queue structure associated with the queue to destroy. | |
12142 | * | |
12143 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
12144 | * command, specific to the type of queue, to the HBA. | |
12145 | * | |
12146 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
12147 | * | |
12148 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12149 | * command fails this function will return -ENXIO. |
4f774513 JS |
12150 | **/ |
12151 | uint32_t | |
12152 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
12153 | { | |
12154 | LPFC_MBOXQ_t *mbox; | |
12155 | int rc, length, status = 0; | |
12156 | uint32_t shdr_status, shdr_add_status; | |
12157 | union lpfc_sli4_cfg_shdr *shdr; | |
12158 | ||
12159 | if (!wq) | |
12160 | return -ENODEV; | |
12161 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
12162 | if (!mbox) | |
12163 | return -ENOMEM; | |
12164 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
12165 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12166 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12167 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
12168 | length, LPFC_SLI4_MBX_EMBED); | |
12169 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
12170 | wq->queue_id); | |
12171 | mbox->vport = wq->phba->pport; | |
12172 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12173 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
12174 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12175 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
12176 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12177 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12178 | if (shdr_status || shdr_add_status || rc) { | |
12179 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12180 | "2508 WQ_DESTROY mailbox failed with " | |
12181 | "status x%x add_status x%x, mbx status x%x\n", | |
12182 | shdr_status, shdr_add_status, rc); | |
12183 | status = -ENXIO; | |
12184 | } | |
12185 | /* Remove wq from any list */ | |
12186 | list_del_init(&wq->list); | |
8fa38513 | 12187 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
12188 | return status; |
12189 | } | |
12190 | ||
12191 | /** | |
12192 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
12193 | * @rq: The queue structure associated with the queue to destroy. | |
12194 | * | |
12195 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
12196 | * command, specific to the type of queue, to the HBA. | |
12197 | * | |
12198 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
12199 | * | |
12200 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12201 | * command fails this function will return -ENXIO. |
4f774513 JS |
12202 | **/ |
12203 | uint32_t | |
12204 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
12205 | struct lpfc_queue *drq) | |
12206 | { | |
12207 | LPFC_MBOXQ_t *mbox; | |
12208 | int rc, length, status = 0; | |
12209 | uint32_t shdr_status, shdr_add_status; | |
12210 | union lpfc_sli4_cfg_shdr *shdr; | |
12211 | ||
12212 | if (!hrq || !drq) | |
12213 | return -ENODEV; | |
12214 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
12215 | if (!mbox) | |
12216 | return -ENOMEM; | |
12217 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 12218 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
12219 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
12220 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
12221 | length, LPFC_SLI4_MBX_EMBED); | |
12222 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
12223 | hrq->queue_id); | |
12224 | mbox->vport = hrq->phba->pport; | |
12225 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12226 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
12227 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12228 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12229 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
12230 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12231 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12232 | if (shdr_status || shdr_add_status || rc) { | |
12233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12234 | "2509 RQ_DESTROY mailbox failed with " | |
12235 | "status x%x add_status x%x, mbx status x%x\n", | |
12236 | shdr_status, shdr_add_status, rc); | |
12237 | if (rc != MBX_TIMEOUT) | |
12238 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
12239 | return -ENXIO; | |
12240 | } | |
12241 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
12242 | drq->queue_id); | |
12243 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
12244 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12245 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
12246 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12247 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12248 | if (shdr_status || shdr_add_status || rc) { | |
12249 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12250 | "2510 RQ_DESTROY mailbox failed with " | |
12251 | "status x%x add_status x%x, mbx status x%x\n", | |
12252 | shdr_status, shdr_add_status, rc); | |
12253 | status = -ENXIO; | |
12254 | } | |
12255 | list_del_init(&hrq->list); | |
12256 | list_del_init(&drq->list); | |
8fa38513 | 12257 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
12258 | return status; |
12259 | } | |
12260 | ||
12261 | /** | |
12262 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
12263 | * @phba: The virtual port for which this call being executed. | |
12264 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
12265 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
12266 | * @xritag: the xritag that ties this io to the SGL pages. | |
12267 | * | |
12268 | * This routine will post the sgl pages for the IO that has the xritag | |
12269 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
12270 | * creation and persists for as long as the driver is loaded. | |
12271 | * if the caller has fewer than 256 scatter gather segments to map then | |
12272 | * pdma_phys_addr1 should be 0. | |
12273 | * If the caller needs to map more than 256 scatter gather segment then | |
12274 | * pdma_phys_addr1 should be a valid physical address. | |
12275 | * physical address for SGLs must be 64 byte aligned. | |
12276 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
12277 | * the second sgl can have between 1 and 256 entries. | |
12278 | * | |
12279 | * Return codes: | |
12280 | * 0 - Success | |
12281 | * -ENXIO, -ENOMEM - Failure | |
12282 | **/ | |
12283 | int | |
12284 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
12285 | dma_addr_t pdma_phys_addr0, | |
12286 | dma_addr_t pdma_phys_addr1, | |
12287 | uint16_t xritag) | |
12288 | { | |
12289 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
12290 | LPFC_MBOXQ_t *mbox; | |
12291 | int rc; | |
12292 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 12293 | uint32_t mbox_tmo; |
4f774513 JS |
12294 | union lpfc_sli4_cfg_shdr *shdr; |
12295 | ||
12296 | if (xritag == NO_XRI) { | |
12297 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12298 | "0364 Invalid param:\n"); | |
12299 | return -EINVAL; | |
12300 | } | |
12301 | ||
12302 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12303 | if (!mbox) | |
12304 | return -ENOMEM; | |
12305 | ||
12306 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12307 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
12308 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 12309 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
12310 | |
12311 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
12312 | &mbox->u.mqe.un.post_sgl_pages; | |
12313 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
12314 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
12315 | ||
12316 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
12317 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
12318 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
12319 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
12320 | ||
12321 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
12322 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
12323 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
12324 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
12325 | if (!phba->sli4_hba.intr_enable) | |
12326 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 JS |
12327 | else { |
12328 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12329 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
12330 | } | |
4f774513 JS |
12331 | /* The IOCTL status is embedded in the mailbox subheader. */ |
12332 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
12333 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12334 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12335 | if (rc != MBX_TIMEOUT) | |
12336 | mempool_free(mbox, phba->mbox_mem_pool); | |
12337 | if (shdr_status || shdr_add_status || rc) { | |
12338 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12339 | "2511 POST_SGL mailbox failed with " | |
12340 | "status x%x add_status x%x, mbx status x%x\n", | |
12341 | shdr_status, shdr_add_status, rc); | |
12342 | rc = -ENXIO; | |
12343 | } | |
12344 | return 0; | |
12345 | } | |
4f774513 | 12346 | |
6d368e53 | 12347 | /** |
88a2cfbb | 12348 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
12349 | * @phba: pointer to lpfc hba data structure. |
12350 | * | |
12351 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
12352 | * HBA consistent with the SLI-4 interface spec. This routine |
12353 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
12354 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 12355 | * |
88a2cfbb JS |
12356 | * Returns |
12357 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
12358 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
12359 | **/ | |
6d368e53 JS |
12360 | uint16_t |
12361 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) | |
12362 | { | |
12363 | unsigned long xri; | |
12364 | ||
12365 | /* | |
12366 | * Fetch the next logical xri. Because this index is logical, | |
12367 | * the driver starts at 0 each time. | |
12368 | */ | |
12369 | spin_lock_irq(&phba->hbalock); | |
12370 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
12371 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
12372 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
12373 | spin_unlock_irq(&phba->hbalock); | |
12374 | return NO_XRI; | |
12375 | } else { | |
12376 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
12377 | phba->sli4_hba.max_cfg_param.xri_used++; | |
12378 | phba->sli4_hba.xri_count++; | |
12379 | } | |
12380 | ||
12381 | spin_unlock_irq(&phba->hbalock); | |
12382 | return xri; | |
12383 | } | |
12384 | ||
12385 | /** | |
12386 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
12387 | * @phba: pointer to lpfc hba data structure. | |
12388 | * | |
12389 | * This routine is invoked to release an xri to the pool of | |
12390 | * available rpis maintained by the driver. | |
12391 | **/ | |
12392 | void | |
12393 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
12394 | { | |
12395 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
12396 | phba->sli4_hba.xri_count--; | |
12397 | phba->sli4_hba.max_cfg_param.xri_used--; | |
12398 | } | |
12399 | } | |
12400 | ||
12401 | /** | |
12402 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
12403 | * @phba: pointer to lpfc hba data structure. | |
12404 | * | |
12405 | * This routine is invoked to release an xri to the pool of | |
12406 | * available rpis maintained by the driver. | |
12407 | **/ | |
12408 | void | |
12409 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
12410 | { | |
12411 | spin_lock_irq(&phba->hbalock); | |
12412 | __lpfc_sli4_free_xri(phba, xri); | |
12413 | spin_unlock_irq(&phba->hbalock); | |
12414 | } | |
12415 | ||
4f774513 JS |
12416 | /** |
12417 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
12418 | * @phba: Pointer to HBA context object. | |
12419 | * | |
12420 | * This function gets an xritag for the iocb. If there is no unused xritag | |
12421 | * it will return 0xffff. | |
12422 | * The function returns the allocated xritag if successful, else returns zero. | |
12423 | * Zero is not a valid xritag. | |
12424 | * The caller is not required to hold any lock. | |
12425 | **/ | |
12426 | uint16_t | |
12427 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
12428 | { | |
6d368e53 | 12429 | uint16_t xri_index; |
4f774513 | 12430 | |
6d368e53 JS |
12431 | xri_index = lpfc_sli4_alloc_xri(phba); |
12432 | if (xri_index != NO_XRI) | |
12433 | return xri_index; | |
12434 | ||
12435 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4f774513 JS |
12436 | "2004 Failed to allocate XRI.last XRITAG is %d" |
12437 | " Max XRI is %d, Used XRI is %d\n", | |
6d368e53 | 12438 | xri_index, |
4f774513 JS |
12439 | phba->sli4_hba.max_cfg_param.max_xri, |
12440 | phba->sli4_hba.max_cfg_param.xri_used); | |
6d368e53 | 12441 | return NO_XRI; |
4f774513 JS |
12442 | } |
12443 | ||
12444 | /** | |
6d368e53 | 12445 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
4f774513 JS |
12446 | * @phba: pointer to lpfc hba data structure. |
12447 | * | |
12448 | * This routine is invoked to post a block of driver's sgl pages to the | |
12449 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
12450 | * is only called when the driver is loading and after all IO has been | |
12451 | * stopped. | |
12452 | **/ | |
12453 | int | |
6d368e53 | 12454 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba) |
4f774513 JS |
12455 | { |
12456 | struct lpfc_sglq *sglq_entry; | |
12457 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
12458 | struct sgl_page_pairs *sgl_pg_pairs; | |
12459 | void *viraddr; | |
12460 | LPFC_MBOXQ_t *mbox; | |
12461 | uint32_t reqlen, alloclen, pg_pairs; | |
12462 | uint32_t mbox_tmo; | |
6d368e53 | 12463 | uint16_t xritag_start = 0, lxri = 0; |
4f774513 JS |
12464 | int els_xri_cnt, rc = 0; |
12465 | uint32_t shdr_status, shdr_add_status; | |
12466 | union lpfc_sli4_cfg_shdr *shdr; | |
12467 | ||
12468 | /* The number of sgls to be posted */ | |
12469 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
12470 | ||
12471 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
12472 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 12473 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
12474 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
12475 | "2559 Block sgl registration required DMA " | |
12476 | "size (%d) great than a page\n", reqlen); | |
12477 | return -ENOMEM; | |
12478 | } | |
12479 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6d368e53 | 12480 | if (!mbox) |
4f774513 | 12481 | return -ENOMEM; |
4f774513 JS |
12482 | |
12483 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
12484 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12485 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
12486 | LPFC_SLI4_MBX_NEMBED); | |
12487 | ||
12488 | if (alloclen < reqlen) { | |
12489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12490 | "0285 Allocated DMA memory size (%d) is " | |
12491 | "less than the requested DMA memory " | |
12492 | "size (%d)\n", alloclen, reqlen); | |
12493 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12494 | return -ENOMEM; | |
12495 | } | |
4f774513 | 12496 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 12497 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
12498 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
12499 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
12500 | ||
12501 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | |
12502 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | |
6d368e53 JS |
12503 | |
12504 | /* | |
12505 | * Assign the sglq a physical xri only if the driver has not | |
12506 | * initialized those resources. A port reset only needs | |
12507 | * the sglq's posted. | |
12508 | */ | |
12509 | if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
12510 | LPFC_XRI_RSRC_RDY) { | |
12511 | lxri = lpfc_sli4_next_xritag(phba); | |
12512 | if (lxri == NO_XRI) { | |
12513 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12514 | return -ENOMEM; | |
12515 | } | |
12516 | sglq_entry->sli4_lxritag = lxri; | |
12517 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
12518 | } | |
12519 | ||
4f774513 JS |
12520 | /* Set up the sge entry */ |
12521 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
12522 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
12523 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
12524 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
12525 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
12526 | cpu_to_le32(putPaddrLow(0)); | |
12527 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
12528 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 12529 | |
4f774513 JS |
12530 | /* Keep the first xritag on the list */ |
12531 | if (pg_pairs == 0) | |
12532 | xritag_start = sglq_entry->sli4_xritag; | |
12533 | sgl_pg_pairs++; | |
12534 | } | |
6d368e53 JS |
12535 | |
12536 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 12537 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
6a9c52cf | 12538 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
4f774513 | 12539 | sgl->word0 = cpu_to_le32(sgl->word0); |
4f774513 JS |
12540 | if (!phba->sli4_hba.intr_enable) |
12541 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12542 | else { | |
12543 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12544 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
12545 | } | |
12546 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
12547 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12548 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12549 | if (rc != MBX_TIMEOUT) | |
12550 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12551 | if (shdr_status || shdr_add_status || rc) { | |
12552 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12553 | "2513 POST_SGL_BLOCK mailbox command failed " | |
12554 | "status x%x add_status x%x mbx status x%x\n", | |
12555 | shdr_status, shdr_add_status, rc); | |
12556 | rc = -ENXIO; | |
12557 | } | |
6d368e53 JS |
12558 | |
12559 | if (rc == 0) | |
12560 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
12561 | LPFC_XRI_RSRC_RDY); | |
12562 | return rc; | |
12563 | } | |
12564 | ||
12565 | /** | |
12566 | * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port. | |
12567 | * @phba: pointer to lpfc hba data structure. | |
12568 | * | |
12569 | * This routine is invoked to post a block of driver's sgl pages to the | |
12570 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
12571 | * is only called when the driver is loading and after all IO has been | |
12572 | * stopped. | |
12573 | **/ | |
12574 | int | |
12575 | lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) | |
12576 | { | |
12577 | struct lpfc_sglq *sglq_entry; | |
12578 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
12579 | struct sgl_page_pairs *sgl_pg_pairs; | |
12580 | void *viraddr; | |
12581 | LPFC_MBOXQ_t *mbox; | |
12582 | uint32_t reqlen, alloclen, index; | |
12583 | uint32_t mbox_tmo; | |
12584 | uint16_t rsrc_start, rsrc_size, els_xri_cnt; | |
12585 | uint16_t xritag_start = 0, lxri = 0; | |
12586 | struct lpfc_rsrc_blks *rsrc_blk; | |
12587 | int cnt, ttl_cnt, rc = 0; | |
12588 | int loop_cnt; | |
12589 | uint32_t shdr_status, shdr_add_status; | |
12590 | union lpfc_sli4_cfg_shdr *shdr; | |
12591 | ||
12592 | /* The number of sgls to be posted */ | |
12593 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
12594 | ||
12595 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
12596 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
12597 | if (reqlen > SLI4_PAGE_SIZE) { | |
12598 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
12599 | "2989 Block sgl registration required DMA " | |
12600 | "size (%d) great than a page\n", reqlen); | |
12601 | return -ENOMEM; | |
12602 | } | |
12603 | ||
12604 | cnt = 0; | |
12605 | ttl_cnt = 0; | |
12606 | list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, | |
12607 | list) { | |
12608 | rsrc_start = rsrc_blk->rsrc_start; | |
12609 | rsrc_size = rsrc_blk->rsrc_size; | |
12610 | ||
12611 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12612 | "3014 Working ELS Extent start %d, cnt %d\n", | |
12613 | rsrc_start, rsrc_size); | |
12614 | ||
12615 | loop_cnt = min(els_xri_cnt, rsrc_size); | |
12616 | if (ttl_cnt + loop_cnt >= els_xri_cnt) { | |
12617 | loop_cnt = els_xri_cnt - ttl_cnt; | |
12618 | ttl_cnt = els_xri_cnt; | |
12619 | } | |
12620 | ||
12621 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12622 | if (!mbox) | |
12623 | return -ENOMEM; | |
12624 | /* | |
12625 | * Allocate DMA memory and set up the non-embedded mailbox | |
12626 | * command. | |
12627 | */ | |
12628 | alloclen = lpfc_sli4_config(phba, mbox, | |
12629 | LPFC_MBOX_SUBSYSTEM_FCOE, | |
12630 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
12631 | reqlen, LPFC_SLI4_MBX_NEMBED); | |
12632 | if (alloclen < reqlen) { | |
12633 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12634 | "2987 Allocated DMA memory size (%d) " | |
12635 | "is less than the requested DMA memory " | |
12636 | "size (%d)\n", alloclen, reqlen); | |
12637 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12638 | return -ENOMEM; | |
12639 | } | |
12640 | ||
12641 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
12642 | viraddr = mbox->sge_array->addr[0]; | |
12643 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
12644 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
12645 | ||
12646 | /* | |
12647 | * The starting resource may not begin at zero. Control | |
12648 | * the loop variants via the block resource parameters, | |
12649 | * but handle the sge pointers with a zero-based index | |
12650 | * that doesn't get reset per loop pass. | |
12651 | */ | |
12652 | for (index = rsrc_start; | |
12653 | index < rsrc_start + loop_cnt; | |
12654 | index++) { | |
12655 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt]; | |
12656 | ||
12657 | /* | |
12658 | * Assign the sglq a physical xri only if the driver | |
12659 | * has not initialized those resources. A port reset | |
12660 | * only needs the sglq's posted. | |
12661 | */ | |
12662 | if (bf_get(lpfc_xri_rsrc_rdy, | |
12663 | &phba->sli4_hba.sli4_flags) != | |
12664 | LPFC_XRI_RSRC_RDY) { | |
12665 | lxri = lpfc_sli4_next_xritag(phba); | |
12666 | if (lxri == NO_XRI) { | |
12667 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12668 | rc = -ENOMEM; | |
12669 | goto err_exit; | |
12670 | } | |
12671 | sglq_entry->sli4_lxritag = lxri; | |
12672 | sglq_entry->sli4_xritag = | |
12673 | phba->sli4_hba.xri_ids[lxri]; | |
12674 | } | |
12675 | ||
12676 | /* Set up the sge entry */ | |
12677 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
12678 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
12679 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
12680 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
12681 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
12682 | cpu_to_le32(putPaddrLow(0)); | |
12683 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
12684 | cpu_to_le32(putPaddrHigh(0)); | |
12685 | ||
12686 | /* Track the starting physical XRI for the mailbox. */ | |
12687 | if (index == rsrc_start) | |
12688 | xritag_start = sglq_entry->sli4_xritag; | |
12689 | sgl_pg_pairs++; | |
12690 | cnt++; | |
12691 | } | |
12692 | ||
12693 | /* Complete initialization and perform endian conversion. */ | |
12694 | rsrc_blk->rsrc_used += loop_cnt; | |
12695 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
12696 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt); | |
12697 | sgl->word0 = cpu_to_le32(sgl->word0); | |
12698 | ||
12699 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12700 | "3015 Post ELS Extent SGL, start %d, " | |
12701 | "cnt %d, used %d\n", | |
12702 | xritag_start, loop_cnt, rsrc_blk->rsrc_used); | |
12703 | if (!phba->sli4_hba.intr_enable) | |
12704 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12705 | else { | |
12706 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12707 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
12708 | } | |
12709 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
12710 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
12711 | &shdr->response); | |
12712 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
12713 | &shdr->response); | |
12714 | if (rc != MBX_TIMEOUT) | |
12715 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12716 | if (shdr_status || shdr_add_status || rc) { | |
12717 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12718 | "2988 POST_SGL_BLOCK mailbox " | |
12719 | "command failed status x%x " | |
12720 | "add_status x%x mbx status x%x\n", | |
12721 | shdr_status, shdr_add_status, rc); | |
12722 | rc = -ENXIO; | |
12723 | goto err_exit; | |
12724 | } | |
12725 | if (ttl_cnt >= els_xri_cnt) | |
12726 | break; | |
12727 | } | |
12728 | ||
12729 | err_exit: | |
12730 | if (rc == 0) | |
12731 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
12732 | LPFC_XRI_RSRC_RDY); | |
4f774513 JS |
12733 | return rc; |
12734 | } | |
12735 | ||
12736 | /** | |
12737 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
12738 | * @phba: pointer to lpfc hba data structure. | |
12739 | * @sblist: pointer to scsi buffer list. | |
12740 | * @count: number of scsi buffers on the list. | |
12741 | * | |
12742 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
12743 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
12744 | * No Lock is held. | |
12745 | * | |
12746 | **/ | |
12747 | int | |
12748 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | |
12749 | int cnt) | |
12750 | { | |
12751 | struct lpfc_scsi_buf *psb; | |
12752 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
12753 | struct sgl_page_pairs *sgl_pg_pairs; | |
12754 | void *viraddr; | |
12755 | LPFC_MBOXQ_t *mbox; | |
12756 | uint32_t reqlen, alloclen, pg_pairs; | |
12757 | uint32_t mbox_tmo; | |
12758 | uint16_t xritag_start = 0; | |
12759 | int rc = 0; | |
12760 | uint32_t shdr_status, shdr_add_status; | |
12761 | dma_addr_t pdma_phys_bpl1; | |
12762 | union lpfc_sli4_cfg_shdr *shdr; | |
12763 | ||
12764 | /* Calculate the requested length of the dma memory */ | |
12765 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
12766 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 12767 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
12768 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
12769 | "0217 Block sgl registration required DMA " | |
12770 | "size (%d) great than a page\n", reqlen); | |
12771 | return -ENOMEM; | |
12772 | } | |
12773 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12774 | if (!mbox) { | |
12775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12776 | "0283 Failed to allocate mbox cmd memory\n"); | |
12777 | return -ENOMEM; | |
12778 | } | |
12779 | ||
12780 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
12781 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12782 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
12783 | LPFC_SLI4_MBX_NEMBED); | |
12784 | ||
12785 | if (alloclen < reqlen) { | |
12786 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12787 | "2561 Allocated DMA memory size (%d) is " | |
12788 | "less than the requested DMA memory " | |
12789 | "size (%d)\n", alloclen, reqlen); | |
12790 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12791 | return -ENOMEM; | |
12792 | } | |
6d368e53 | 12793 | |
4f774513 | 12794 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
12795 | viraddr = mbox->sge_array->addr[0]; |
12796 | ||
12797 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
12798 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
12799 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
12800 | ||
12801 | pg_pairs = 0; | |
12802 | list_for_each_entry(psb, sblist, list) { | |
12803 | /* Set up the sge entry */ | |
12804 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
12805 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
12806 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
12807 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
12808 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
12809 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
12810 | else | |
12811 | pdma_phys_bpl1 = 0; | |
12812 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
12813 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
12814 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
12815 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
12816 | /* Keep the first xritag on the list */ | |
12817 | if (pg_pairs == 0) | |
12818 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
12819 | sgl_pg_pairs++; | |
12820 | pg_pairs++; | |
12821 | } | |
12822 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
12823 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
12824 | /* Perform endian conversion if necessary */ | |
12825 | sgl->word0 = cpu_to_le32(sgl->word0); | |
12826 | ||
12827 | if (!phba->sli4_hba.intr_enable) | |
12828 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12829 | else { | |
12830 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12831 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
12832 | } | |
12833 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
12834 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12835 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12836 | if (rc != MBX_TIMEOUT) | |
12837 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12838 | if (shdr_status || shdr_add_status || rc) { | |
12839 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12840 | "2564 POST_SGL_BLOCK mailbox command failed " | |
12841 | "status x%x add_status x%x mbx status x%x\n", | |
12842 | shdr_status, shdr_add_status, rc); | |
12843 | rc = -ENXIO; | |
12844 | } | |
12845 | return rc; | |
12846 | } | |
12847 | ||
6d368e53 JS |
12848 | /** |
12849 | * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port. | |
12850 | * @phba: pointer to lpfc hba data structure. | |
12851 | * @sblist: pointer to scsi buffer list. | |
12852 | * @count: number of scsi buffers on the list. | |
12853 | * | |
12854 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
12855 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
12856 | * No Lock is held. | |
12857 | * | |
12858 | **/ | |
12859 | int | |
12860 | lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist, | |
12861 | int cnt) | |
12862 | { | |
12863 | struct lpfc_scsi_buf *psb = NULL; | |
12864 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
12865 | struct sgl_page_pairs *sgl_pg_pairs; | |
12866 | void *viraddr; | |
12867 | LPFC_MBOXQ_t *mbox; | |
12868 | uint32_t reqlen, alloclen, pg_pairs; | |
12869 | uint32_t mbox_tmo; | |
12870 | uint16_t xri_start = 0, scsi_xri_start; | |
12871 | uint16_t rsrc_range; | |
12872 | int rc = 0, avail_cnt; | |
12873 | uint32_t shdr_status, shdr_add_status; | |
12874 | dma_addr_t pdma_phys_bpl1; | |
12875 | union lpfc_sli4_cfg_shdr *shdr; | |
12876 | struct lpfc_rsrc_blks *rsrc_blk; | |
12877 | uint32_t xri_cnt = 0; | |
12878 | ||
12879 | /* Calculate the total requested length of the dma memory */ | |
12880 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
12881 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
12882 | if (reqlen > SLI4_PAGE_SIZE) { | |
12883 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
12884 | "2932 Block sgl registration required DMA " | |
12885 | "size (%d) great than a page\n", reqlen); | |
12886 | return -ENOMEM; | |
12887 | } | |
12888 | ||
12889 | /* | |
12890 | * The use of extents requires the driver to post the sgl headers | |
12891 | * in multiple postings to meet the contiguous resource assignment. | |
12892 | */ | |
12893 | psb = list_prepare_entry(psb, sblist, list); | |
12894 | scsi_xri_start = phba->sli4_hba.scsi_xri_start; | |
12895 | list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, | |
12896 | list) { | |
12897 | rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size; | |
12898 | if (rsrc_range < scsi_xri_start) | |
12899 | continue; | |
12900 | else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size) | |
12901 | continue; | |
12902 | else | |
12903 | avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used; | |
12904 | ||
12905 | reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) + | |
12906 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
12907 | /* | |
12908 | * Allocate DMA memory and set up the non-embedded mailbox | |
12909 | * command. The mbox is used to post an SGL page per loop | |
12910 | * but the DMA memory has a use-once semantic so the mailbox | |
12911 | * is used and freed per loop pass. | |
12912 | */ | |
12913 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12914 | if (!mbox) { | |
12915 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12916 | "2933 Failed to allocate mbox cmd " | |
12917 | "memory\n"); | |
12918 | return -ENOMEM; | |
12919 | } | |
12920 | alloclen = lpfc_sli4_config(phba, mbox, | |
12921 | LPFC_MBOX_SUBSYSTEM_FCOE, | |
12922 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
12923 | reqlen, | |
12924 | LPFC_SLI4_MBX_NEMBED); | |
12925 | if (alloclen < reqlen) { | |
12926 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12927 | "2934 Allocated DMA memory size (%d) " | |
12928 | "is less than the requested DMA memory " | |
12929 | "size (%d)\n", alloclen, reqlen); | |
12930 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12931 | return -ENOMEM; | |
12932 | } | |
12933 | ||
12934 | /* Get the first SGE entry from the non-embedded DMA memory */ | |
12935 | viraddr = mbox->sge_array->addr[0]; | |
12936 | ||
12937 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
12938 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
12939 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
12940 | ||
12941 | /* pg_pairs tracks posted SGEs per loop iteration. */ | |
12942 | pg_pairs = 0; | |
12943 | list_for_each_entry_continue(psb, sblist, list) { | |
12944 | /* Set up the sge entry */ | |
12945 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
12946 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
12947 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
12948 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
12949 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
12950 | pdma_phys_bpl1 = psb->dma_phys_bpl + | |
12951 | SGL_PAGE_SIZE; | |
12952 | else | |
12953 | pdma_phys_bpl1 = 0; | |
12954 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
12955 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
12956 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
12957 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
12958 | /* Keep the first xri for this extent. */ | |
12959 | if (pg_pairs == 0) | |
12960 | xri_start = psb->cur_iocbq.sli4_xritag; | |
12961 | sgl_pg_pairs++; | |
12962 | pg_pairs++; | |
12963 | xri_cnt++; | |
12964 | ||
12965 | /* | |
12966 | * Track two exit conditions - the loop has constructed | |
12967 | * all of the caller's SGE pairs or all available | |
12968 | * resource IDs in this extent are consumed. | |
12969 | */ | |
12970 | if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt)) | |
12971 | break; | |
12972 | } | |
12973 | rsrc_blk->rsrc_used += pg_pairs; | |
12974 | bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start); | |
12975 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
12976 | ||
12977 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12978 | "3016 Post SCSI Extent SGL, start %d, cnt %d " | |
12979 | "blk use %d\n", | |
12980 | xri_start, pg_pairs, rsrc_blk->rsrc_used); | |
12981 | /* Perform endian conversion if necessary */ | |
12982 | sgl->word0 = cpu_to_le32(sgl->word0); | |
12983 | if (!phba->sli4_hba.intr_enable) | |
12984 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12985 | else { | |
12986 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12987 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
12988 | } | |
12989 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
12990 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12991 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
12992 | &shdr->response); | |
12993 | if (rc != MBX_TIMEOUT) | |
12994 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
12995 | if (shdr_status || shdr_add_status || rc) { | |
12996 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12997 | "2935 POST_SGL_BLOCK mailbox command " | |
12998 | "failed status x%x add_status x%x " | |
12999 | "mbx status x%x\n", | |
13000 | shdr_status, shdr_add_status, rc); | |
13001 | return -ENXIO; | |
13002 | } | |
13003 | ||
13004 | /* Post only what is requested. */ | |
13005 | if (xri_cnt >= cnt) | |
13006 | break; | |
13007 | } | |
13008 | return rc; | |
13009 | } | |
13010 | ||
4f774513 JS |
13011 | /** |
13012 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
13013 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
13014 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13015 | * | |
13016 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
13017 | * valid type of frame that the LPFC driver will handle. This function will | |
13018 | * return a zero if the frame is a valid frame or a non zero value when the | |
13019 | * frame does not pass the check. | |
13020 | **/ | |
13021 | static int | |
13022 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
13023 | { | |
474ffb74 TH |
13024 | /* make rctl_names static to save stack space */ |
13025 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
13026 | char *type_names[] = FC_TYPE_NAMES_INIT; |
13027 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 13028 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
13029 | |
13030 | switch (fc_hdr->fh_r_ctl) { | |
13031 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
13032 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
13033 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
13034 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
13035 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
13036 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
13037 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
13038 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
13039 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
13040 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
13041 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
13042 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
13043 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
13044 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
13045 | case FC_RCTL_BA_RMC: /* remove connection */ | |
13046 | case FC_RCTL_BA_ACC: /* basic accept */ | |
13047 | case FC_RCTL_BA_RJT: /* basic reject */ | |
13048 | case FC_RCTL_BA_PRMT: | |
13049 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
13050 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
13051 | case FC_RCTL_P_RJT: /* port reject */ | |
13052 | case FC_RCTL_F_RJT: /* fabric reject */ | |
13053 | case FC_RCTL_P_BSY: /* port busy */ | |
13054 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
13055 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
13056 | case FC_RCTL_LCR: /* link credit reset */ | |
13057 | case FC_RCTL_END: /* end */ | |
13058 | break; | |
13059 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
13060 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13061 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
13062 | return lpfc_fc_frame_check(phba, fc_hdr); | |
13063 | default: | |
13064 | goto drop; | |
13065 | } | |
13066 | switch (fc_hdr->fh_type) { | |
13067 | case FC_TYPE_BLS: | |
13068 | case FC_TYPE_ELS: | |
13069 | case FC_TYPE_FCP: | |
13070 | case FC_TYPE_CT: | |
13071 | break; | |
13072 | case FC_TYPE_IP: | |
13073 | case FC_TYPE_ILS: | |
13074 | default: | |
13075 | goto drop; | |
13076 | } | |
546fc854 | 13077 | |
4f774513 | 13078 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
13079 | "2538 Received frame rctl:%s type:%s " |
13080 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", | |
4f774513 | 13081 | rctl_names[fc_hdr->fh_r_ctl], |
546fc854 JS |
13082 | type_names[fc_hdr->fh_type], |
13083 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), | |
13084 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
13085 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); | |
4f774513 JS |
13086 | return 0; |
13087 | drop: | |
13088 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
13089 | "2539 Dropped frame rctl:%s type:%s\n", | |
13090 | rctl_names[fc_hdr->fh_r_ctl], | |
13091 | type_names[fc_hdr->fh_type]); | |
13092 | return 1; | |
13093 | } | |
13094 | ||
13095 | /** | |
13096 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
13097 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13098 | * | |
13099 | * This function processes the FC header to retrieve the VFI from the VF | |
13100 | * header, if one exists. This function will return the VFI if one exists | |
13101 | * or 0 if no VSAN Header exists. | |
13102 | **/ | |
13103 | static uint32_t | |
13104 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
13105 | { | |
13106 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13107 | ||
13108 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
13109 | return 0; | |
13110 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
13111 | } | |
13112 | ||
13113 | /** | |
13114 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
13115 | * @phba: Pointer to the HBA structure to search for the vport on | |
13116 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13117 | * @fcfi: The FC Fabric ID that the frame came from | |
13118 | * | |
13119 | * This function searches the @phba for a vport that matches the content of the | |
13120 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
13121 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
13122 | * returns the matching vport pointer or NULL if unable to match frame to a | |
13123 | * vport. | |
13124 | **/ | |
13125 | static struct lpfc_vport * | |
13126 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
13127 | uint16_t fcfi) | |
13128 | { | |
13129 | struct lpfc_vport **vports; | |
13130 | struct lpfc_vport *vport = NULL; | |
13131 | int i; | |
13132 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
13133 | fc_hdr->fh_d_id[1] << 8 | | |
13134 | fc_hdr->fh_d_id[2]); | |
13135 | ||
13136 | vports = lpfc_create_vport_work_array(phba); | |
13137 | if (vports != NULL) | |
13138 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
13139 | if (phba->fcf.fcfi == fcfi && | |
13140 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
13141 | vports[i]->fc_myDID == did) { | |
13142 | vport = vports[i]; | |
13143 | break; | |
13144 | } | |
13145 | } | |
13146 | lpfc_destroy_vport_work_array(phba, vports); | |
13147 | return vport; | |
13148 | } | |
13149 | ||
45ed1190 JS |
13150 | /** |
13151 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
13152 | * @vport: The vport to work on. | |
13153 | * | |
13154 | * This function updates the receive sequence time stamp for this vport. The | |
13155 | * receive sequence time stamp indicates the time that the last frame of the | |
13156 | * the sequence that has been idle for the longest amount of time was received. | |
13157 | * the driver uses this time stamp to indicate if any received sequences have | |
13158 | * timed out. | |
13159 | **/ | |
13160 | void | |
13161 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
13162 | { | |
13163 | struct lpfc_dmabuf *h_buf; | |
13164 | struct hbq_dmabuf *dmabuf = NULL; | |
13165 | ||
13166 | /* get the oldest sequence on the rcv list */ | |
13167 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
13168 | struct lpfc_dmabuf, list); | |
13169 | if (!h_buf) | |
13170 | return; | |
13171 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13172 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
13173 | } | |
13174 | ||
13175 | /** | |
13176 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
13177 | * @vport: The vport that the received sequences were sent to. | |
13178 | * | |
13179 | * This function cleans up all outstanding received sequences. This is called | |
13180 | * by the driver when a link event or user action invalidates all the received | |
13181 | * sequences. | |
13182 | **/ | |
13183 | void | |
13184 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
13185 | { | |
13186 | struct lpfc_dmabuf *h_buf, *hnext; | |
13187 | struct lpfc_dmabuf *d_buf, *dnext; | |
13188 | struct hbq_dmabuf *dmabuf = NULL; | |
13189 | ||
13190 | /* start with the oldest sequence on the rcv list */ | |
13191 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13192 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13193 | list_del_init(&dmabuf->hbuf.list); | |
13194 | list_for_each_entry_safe(d_buf, dnext, | |
13195 | &dmabuf->dbuf.list, list) { | |
13196 | list_del_init(&d_buf->list); | |
13197 | lpfc_in_buf_free(vport->phba, d_buf); | |
13198 | } | |
13199 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13200 | } | |
13201 | } | |
13202 | ||
13203 | /** | |
13204 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
13205 | * @vport: The vport that the received sequences were sent to. | |
13206 | * | |
13207 | * This function determines whether any received sequences have timed out by | |
13208 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
13209 | * indicates that there is at least one timed out sequence this routine will | |
13210 | * go through the received sequences one at a time from most inactive to most | |
13211 | * active to determine which ones need to be cleaned up. Once it has determined | |
13212 | * that a sequence needs to be cleaned up it will simply free up the resources | |
13213 | * without sending an abort. | |
13214 | **/ | |
13215 | void | |
13216 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
13217 | { | |
13218 | struct lpfc_dmabuf *h_buf, *hnext; | |
13219 | struct lpfc_dmabuf *d_buf, *dnext; | |
13220 | struct hbq_dmabuf *dmabuf = NULL; | |
13221 | unsigned long timeout; | |
13222 | int abort_count = 0; | |
13223 | ||
13224 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13225 | vport->rcv_buffer_time_stamp); | |
13226 | if (list_empty(&vport->rcv_buffer_list) || | |
13227 | time_before(jiffies, timeout)) | |
13228 | return; | |
13229 | /* start with the oldest sequence on the rcv list */ | |
13230 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13231 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13232 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13233 | dmabuf->time_stamp); | |
13234 | if (time_before(jiffies, timeout)) | |
13235 | break; | |
13236 | abort_count++; | |
13237 | list_del_init(&dmabuf->hbuf.list); | |
13238 | list_for_each_entry_safe(d_buf, dnext, | |
13239 | &dmabuf->dbuf.list, list) { | |
13240 | list_del_init(&d_buf->list); | |
13241 | lpfc_in_buf_free(vport->phba, d_buf); | |
13242 | } | |
13243 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13244 | } | |
13245 | if (abort_count) | |
13246 | lpfc_update_rcv_time_stamp(vport); | |
13247 | } | |
13248 | ||
4f774513 JS |
13249 | /** |
13250 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
13251 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
13252 | * | |
13253 | * This function searches through the existing incomplete sequences that have | |
13254 | * been sent to this @vport. If the frame matches one of the incomplete | |
13255 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
13256 | * make up that sequence. If no sequence is found that matches this frame then | |
13257 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
13258 | * This function returns a pointer to the first dmabuf in the sequence list that | |
13259 | * the frame was linked to. | |
13260 | **/ | |
13261 | static struct hbq_dmabuf * | |
13262 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
13263 | { | |
13264 | struct fc_frame_header *new_hdr; | |
13265 | struct fc_frame_header *temp_hdr; | |
13266 | struct lpfc_dmabuf *d_buf; | |
13267 | struct lpfc_dmabuf *h_buf; | |
13268 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13269 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
13270 | ||
4d9ab994 | 13271 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 13272 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
13273 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
13274 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
13275 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13276 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13277 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13278 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13279 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13280 | continue; | |
13281 | /* found a pending sequence that matches this frame */ | |
13282 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13283 | break; | |
13284 | } | |
13285 | if (!seq_dmabuf) { | |
13286 | /* | |
13287 | * This indicates first frame received for this sequence. | |
13288 | * Queue the buffer on the vport's rcv_buffer_list. | |
13289 | */ | |
13290 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 13291 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13292 | return dmabuf; |
13293 | } | |
13294 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
13295 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
13296 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
13297 | list_del_init(&seq_dmabuf->hbuf.list); |
13298 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13299 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 13300 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13301 | return dmabuf; |
13302 | } | |
45ed1190 JS |
13303 | /* move this sequence to the tail to indicate a young sequence */ |
13304 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13305 | seq_dmabuf->time_stamp = jiffies; | |
13306 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
13307 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
13308 | temp_hdr = dmabuf->hbuf.virt; | |
13309 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
13310 | return seq_dmabuf; | |
13311 | } | |
4f774513 JS |
13312 | /* find the correct place in the sequence to insert this frame */ |
13313 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
13314 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
13315 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
13316 | /* | |
13317 | * If the frame's sequence count is greater than the frame on | |
13318 | * the list then insert the frame right after this frame | |
13319 | */ | |
eeead811 JS |
13320 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
13321 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
13322 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
13323 | return seq_dmabuf; | |
13324 | } | |
13325 | } | |
13326 | return NULL; | |
13327 | } | |
13328 | ||
6669f9bb JS |
13329 | /** |
13330 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
13331 | * @vport: pointer to a vitural port | |
13332 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13333 | * | |
13334 | * This function tries to abort from the partially assembed sequence, described | |
13335 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
13336 | * partially assembled sequence held by the driver. If so, it shall free up all | |
13337 | * the frames from the partially assembled sequence. | |
13338 | * | |
13339 | * Return | |
13340 | * true -- if there is matching partially assembled sequence present and all | |
13341 | * the frames freed with the sequence; | |
13342 | * false -- if there is no matching partially assembled sequence present so | |
13343 | * nothing got aborted in the lower layer driver | |
13344 | **/ | |
13345 | static bool | |
13346 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
13347 | struct hbq_dmabuf *dmabuf) | |
13348 | { | |
13349 | struct fc_frame_header *new_hdr; | |
13350 | struct fc_frame_header *temp_hdr; | |
13351 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
13352 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13353 | ||
13354 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
13355 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
13356 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
13357 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
13358 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13359 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13360 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13361 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13362 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13363 | continue; | |
13364 | /* found a pending sequence that matches this frame */ | |
13365 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13366 | break; | |
13367 | } | |
13368 | ||
13369 | /* Free up all the frames from the partially assembled sequence */ | |
13370 | if (seq_dmabuf) { | |
13371 | list_for_each_entry_safe(d_buf, n_buf, | |
13372 | &seq_dmabuf->dbuf.list, list) { | |
13373 | list_del_init(&d_buf->list); | |
13374 | lpfc_in_buf_free(vport->phba, d_buf); | |
13375 | } | |
13376 | return true; | |
13377 | } | |
13378 | return false; | |
13379 | } | |
13380 | ||
13381 | /** | |
546fc854 | 13382 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
13383 | * @phba: Pointer to HBA context object. |
13384 | * @cmd_iocbq: pointer to the command iocbq structure. | |
13385 | * @rsp_iocbq: pointer to the response iocbq structure. | |
13386 | * | |
546fc854 | 13387 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
13388 | * event. It properly releases the memory allocated to the sequence abort |
13389 | * accept iocb. | |
13390 | **/ | |
13391 | static void | |
546fc854 | 13392 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
13393 | struct lpfc_iocbq *cmd_iocbq, |
13394 | struct lpfc_iocbq *rsp_iocbq) | |
13395 | { | |
13396 | if (cmd_iocbq) | |
13397 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
13398 | } | |
13399 | ||
6d368e53 JS |
13400 | /** |
13401 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
13402 | * @phba: Pointer to HBA context object. | |
13403 | * @xri: xri id in transaction. | |
13404 | * | |
13405 | * This function validates the xri maps to the known range of XRIs allocated an | |
13406 | * used by the driver. | |
13407 | **/ | |
13408 | static uint16_t | |
13409 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, | |
13410 | uint16_t xri) | |
13411 | { | |
13412 | int i; | |
13413 | ||
13414 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
13415 | if (xri == phba->sli4_hba.xri_ids[i]) | |
13416 | return i; | |
13417 | } | |
13418 | return NO_XRI; | |
13419 | } | |
13420 | ||
13421 | ||
6669f9bb | 13422 | /** |
546fc854 | 13423 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
13424 | * @phba: Pointer to HBA context object. |
13425 | * @fc_hdr: pointer to a FC frame header. | |
13426 | * | |
546fc854 | 13427 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
13428 | * event after aborting the sequence handling. |
13429 | **/ | |
13430 | static void | |
546fc854 | 13431 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
6669f9bb JS |
13432 | struct fc_frame_header *fc_hdr) |
13433 | { | |
13434 | struct lpfc_iocbq *ctiocb = NULL; | |
13435 | struct lpfc_nodelist *ndlp; | |
5ffc266e JS |
13436 | uint16_t oxid, rxid; |
13437 | uint32_t sid, fctl; | |
6669f9bb | 13438 | IOCB_t *icmd; |
546fc854 | 13439 | int rc; |
6669f9bb JS |
13440 | |
13441 | if (!lpfc_is_link_up(phba)) | |
13442 | return; | |
13443 | ||
13444 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
13445 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 13446 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
13447 | |
13448 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
13449 | if (!ndlp) { | |
13450 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
13451 | "1268 Find ndlp returned NULL for oxid:x%x " | |
13452 | "SID:x%x\n", oxid, sid); | |
13453 | return; | |
13454 | } | |
6d368e53 | 13455 | if (lpfc_sli4_xri_inrange(phba, rxid)) |
19ca7609 | 13456 | lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); |
6669f9bb | 13457 | |
546fc854 | 13458 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
13459 | ctiocb = lpfc_sli_get_iocbq(phba); |
13460 | if (!ctiocb) | |
13461 | return; | |
13462 | ||
5ffc266e JS |
13463 | /* Extract the F_CTL field from FC_HDR */ |
13464 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
13465 | ||
6669f9bb | 13466 | icmd = &ctiocb->iocb; |
6669f9bb | 13467 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 13468 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
13469 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
13470 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
13471 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
13472 | ||
13473 | /* Fill in the rest of iocb fields */ | |
13474 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
13475 | icmd->ulpBdeCount = 0; | |
13476 | icmd->ulpLe = 1; | |
13477 | icmd->ulpClass = CLASS3; | |
6d368e53 | 13478 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
be858b65 | 13479 | ctiocb->context1 = ndlp; |
6669f9bb | 13480 | |
6669f9bb JS |
13481 | ctiocb->iocb_cmpl = NULL; |
13482 | ctiocb->vport = phba->pport; | |
546fc854 | 13483 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 13484 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
13485 | ctiocb->sli4_xritag = NO_XRI; |
13486 | ||
13487 | /* If the oxid maps to the FCP XRI range or if it is out of range, | |
13488 | * send a BLS_RJT. The driver no longer has that exchange. | |
13489 | * Override the IOCB for a BA_RJT. | |
13490 | */ | |
13491 | if (oxid > (phba->sli4_hba.max_cfg_param.max_xri + | |
13492 | phba->sli4_hba.max_cfg_param.xri_base) || | |
13493 | oxid > (lpfc_sli4_get_els_iocb_cnt(phba) + | |
13494 | phba->sli4_hba.max_cfg_param.xri_base)) { | |
13495 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
13496 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
13497 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
13498 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
13499 | } | |
6669f9bb | 13500 | |
5ffc266e JS |
13501 | if (fctl & FC_FC_EX_CTX) { |
13502 | /* ABTS sent by responder to CT exchange, construction | |
13503 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
13504 | * field and RX_ID from ABTS for RX_ID field. | |
13505 | */ | |
546fc854 JS |
13506 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
13507 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); | |
5ffc266e JS |
13508 | } else { |
13509 | /* ABTS sent by initiator to CT exchange, construction | |
13510 | * of BA_ACC will need to allocate a new XRI as for the | |
13511 | * XRI_TAG and RX_ID fields. | |
13512 | */ | |
546fc854 JS |
13513 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
13514 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI); | |
5ffc266e | 13515 | } |
546fc854 | 13516 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 13517 | |
546fc854 | 13518 | /* Xmit CT abts response on exchange <xid> */ |
6669f9bb | 13519 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
13520 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
13521 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
13522 | ||
13523 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
13524 | if (rc == IOCB_ERROR) { | |
13525 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
13526 | "2925 Failed to issue CT ABTS RSP x%x on " | |
13527 | "xri x%x, Data x%x\n", | |
13528 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
13529 | phba->link_state); | |
13530 | lpfc_sli_release_iocbq(phba, ctiocb); | |
13531 | } | |
6669f9bb JS |
13532 | } |
13533 | ||
13534 | /** | |
13535 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
13536 | * @vport: Pointer to the vport on which this sequence was received | |
13537 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13538 | * | |
13539 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
13540 | * receive sequence is only partially assembed by the driver, it shall abort | |
13541 | * the partially assembled frames for the sequence. Otherwise, if the | |
13542 | * unsolicited receive sequence has been completely assembled and passed to | |
13543 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
13544 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
13545 | * accept to accept the abort. | |
13546 | **/ | |
13547 | void | |
13548 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
13549 | struct hbq_dmabuf *dmabuf) | |
13550 | { | |
13551 | struct lpfc_hba *phba = vport->phba; | |
13552 | struct fc_frame_header fc_hdr; | |
5ffc266e | 13553 | uint32_t fctl; |
6669f9bb JS |
13554 | bool abts_par; |
13555 | ||
6669f9bb JS |
13556 | /* Make a copy of fc_hdr before the dmabuf being released */ |
13557 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 13558 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 13559 | |
5ffc266e JS |
13560 | if (fctl & FC_FC_EX_CTX) { |
13561 | /* | |
13562 | * ABTS sent by responder to exchange, just free the buffer | |
13563 | */ | |
6669f9bb | 13564 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
13565 | } else { |
13566 | /* | |
13567 | * ABTS sent by initiator to exchange, need to do cleanup | |
13568 | */ | |
13569 | /* Try to abort partially assembled seq */ | |
13570 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
13571 | ||
13572 | /* Send abort to ULP if partially seq abort failed */ | |
13573 | if (abts_par == false) | |
13574 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
13575 | else | |
13576 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
13577 | } | |
6669f9bb | 13578 | /* Send basic accept (BA_ACC) to the abort requester */ |
546fc854 | 13579 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
6669f9bb JS |
13580 | } |
13581 | ||
4f774513 JS |
13582 | /** |
13583 | * lpfc_seq_complete - Indicates if a sequence is complete | |
13584 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13585 | * | |
13586 | * This function checks the sequence, starting with the frame described by | |
13587 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
13588 | * the frames associated with this sequence are linked to the @dmabuf using the | |
13589 | * dbuf list. This function looks for two major things. 1) That the first frame | |
13590 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
13591 | * set. 3) That there are no holes in the sequence count. The function will | |
13592 | * return 1 when the sequence is complete, otherwise it will return 0. | |
13593 | **/ | |
13594 | static int | |
13595 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
13596 | { | |
13597 | struct fc_frame_header *hdr; | |
13598 | struct lpfc_dmabuf *d_buf; | |
13599 | struct hbq_dmabuf *seq_dmabuf; | |
13600 | uint32_t fctl; | |
13601 | int seq_count = 0; | |
13602 | ||
13603 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
13604 | /* make sure first fame of sequence has a sequence count of zero */ | |
13605 | if (hdr->fh_seq_cnt != seq_count) | |
13606 | return 0; | |
13607 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
13608 | hdr->fh_f_ctl[1] << 8 | | |
13609 | hdr->fh_f_ctl[2]); | |
13610 | /* If last frame of sequence we can return success. */ | |
13611 | if (fctl & FC_FC_END_SEQ) | |
13612 | return 1; | |
13613 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
13614 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
13615 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
13616 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 13617 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
13618 | return 0; |
13619 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
13620 | hdr->fh_f_ctl[1] << 8 | | |
13621 | hdr->fh_f_ctl[2]); | |
13622 | /* If last frame of sequence we can return success. */ | |
13623 | if (fctl & FC_FC_END_SEQ) | |
13624 | return 1; | |
13625 | } | |
13626 | return 0; | |
13627 | } | |
13628 | ||
13629 | /** | |
13630 | * lpfc_prep_seq - Prep sequence for ULP processing | |
13631 | * @vport: Pointer to the vport on which this sequence was received | |
13632 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13633 | * | |
13634 | * This function takes a sequence, described by a list of frames, and creates | |
13635 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
13636 | * used to issue to the generic unsolicited sequence handler. This routine | |
13637 | * returns a pointer to the first iocbq in the list. If the function is unable | |
13638 | * to allocate an iocbq then it throw out the received frames that were not | |
13639 | * able to be described and return a pointer to the first iocbq. If unable to | |
13640 | * allocate any iocbqs (including the first) this function will return NULL. | |
13641 | **/ | |
13642 | static struct lpfc_iocbq * | |
13643 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
13644 | { | |
13645 | struct lpfc_dmabuf *d_buf, *n_buf; | |
13646 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
13647 | struct fc_frame_header *fc_hdr; | |
13648 | uint32_t sid; | |
eeead811 | 13649 | struct ulp_bde64 *pbde; |
4f774513 JS |
13650 | |
13651 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
13652 | /* remove from receive buffer list */ | |
13653 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 13654 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 13655 | /* get the Remote Port's SID */ |
6669f9bb | 13656 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
4f774513 JS |
13657 | /* Get an iocbq struct to fill in. */ |
13658 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
13659 | if (first_iocbq) { | |
13660 | /* Initialize the first IOCB. */ | |
8fa38513 | 13661 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 JS |
13662 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
13663 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
13664 | first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id); | |
6d368e53 JS |
13665 | /* iocbq is prepped for internal consumption. Logical vpi. */ |
13666 | first_iocbq->iocb.unsli3.rcvsli3.vpi = vport->vpi; | |
4f774513 JS |
13667 | /* put the first buffer into the first IOCBq */ |
13668 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
13669 | first_iocbq->context3 = NULL; | |
13670 | first_iocbq->iocb.ulpBdeCount = 1; | |
13671 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
13672 | LPFC_DATA_BUF_SIZE; | |
13673 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
8fa38513 | 13674 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
13675 | bf_get(lpfc_rcqe_length, |
13676 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
13677 | } |
13678 | iocbq = first_iocbq; | |
13679 | /* | |
13680 | * Each IOCBq can have two Buffers assigned, so go through the list | |
13681 | * of buffers for this sequence and save two buffers in each IOCBq | |
13682 | */ | |
13683 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
13684 | if (!iocbq) { | |
13685 | lpfc_in_buf_free(vport->phba, d_buf); | |
13686 | continue; | |
13687 | } | |
13688 | if (!iocbq->context3) { | |
13689 | iocbq->context3 = d_buf; | |
13690 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
13691 | pbde = (struct ulp_bde64 *) |
13692 | &iocbq->iocb.unsli3.sli3Words[4]; | |
13693 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
8fa38513 | 13694 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
13695 | bf_get(lpfc_rcqe_length, |
13696 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
13697 | } else { |
13698 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
13699 | if (!iocbq) { | |
13700 | if (first_iocbq) { | |
13701 | first_iocbq->iocb.ulpStatus = | |
13702 | IOSTAT_FCP_RSP_ERROR; | |
13703 | first_iocbq->iocb.un.ulpWord[4] = | |
13704 | IOERR_NO_RESOURCES; | |
13705 | } | |
13706 | lpfc_in_buf_free(vport->phba, d_buf); | |
13707 | continue; | |
13708 | } | |
13709 | iocbq->context2 = d_buf; | |
13710 | iocbq->context3 = NULL; | |
13711 | iocbq->iocb.ulpBdeCount = 1; | |
13712 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
13713 | LPFC_DATA_BUF_SIZE; | |
8fa38513 | 13714 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
13715 | bf_get(lpfc_rcqe_length, |
13716 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
13717 | iocbq->iocb.un.rcvels.remoteID = sid; |
13718 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
13719 | } | |
13720 | } | |
13721 | return first_iocbq; | |
13722 | } | |
13723 | ||
6669f9bb JS |
13724 | static void |
13725 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
13726 | struct hbq_dmabuf *seq_dmabuf) | |
13727 | { | |
13728 | struct fc_frame_header *fc_hdr; | |
13729 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
13730 | struct lpfc_hba *phba = vport->phba; | |
13731 | ||
13732 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
13733 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
13734 | if (!iocbq) { | |
13735 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13736 | "2707 Ring %d handler: Failed to allocate " | |
13737 | "iocb Rctl x%x Type x%x received\n", | |
13738 | LPFC_ELS_RING, | |
13739 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
13740 | return; | |
13741 | } | |
13742 | if (!lpfc_complete_unsol_iocb(phba, | |
13743 | &phba->sli.ring[LPFC_ELS_RING], | |
13744 | iocbq, fc_hdr->fh_r_ctl, | |
13745 | fc_hdr->fh_type)) | |
6d368e53 | 13746 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
13747 | "2540 Ring %d handler: unexpected Rctl " |
13748 | "x%x Type x%x received\n", | |
13749 | LPFC_ELS_RING, | |
13750 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
13751 | ||
13752 | /* Free iocb created in lpfc_prep_seq */ | |
13753 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
13754 | &iocbq->list, list) { | |
13755 | list_del_init(&curr_iocb->list); | |
13756 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
13757 | } | |
13758 | lpfc_sli_release_iocbq(phba, iocbq); | |
13759 | } | |
13760 | ||
4f774513 JS |
13761 | /** |
13762 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
13763 | * @phba: Pointer to HBA context object. | |
13764 | * | |
13765 | * This function is called with no lock held. This function processes all | |
13766 | * the received buffers and gives it to upper layers when a received buffer | |
13767 | * indicates that it is the final frame in the sequence. The interrupt | |
13768 | * service routine processes received buffers at interrupt contexts and adds | |
13769 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
13770 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
13771 | * appropriate receive function when the final frame in a sequence is received. | |
13772 | **/ | |
4d9ab994 JS |
13773 | void |
13774 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
13775 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 13776 | { |
4d9ab994 | 13777 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
13778 | struct fc_frame_header *fc_hdr; |
13779 | struct lpfc_vport *vport; | |
13780 | uint32_t fcfi; | |
4f774513 | 13781 | |
4f774513 | 13782 | /* Process each received buffer */ |
4d9ab994 JS |
13783 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
13784 | /* check to see if this a valid type of frame */ | |
13785 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
13786 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
13787 | return; | |
13788 | } | |
13789 | fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl); | |
13790 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); | |
c868595d | 13791 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
4d9ab994 JS |
13792 | /* throw out the frame */ |
13793 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
13794 | return; | |
13795 | } | |
6669f9bb JS |
13796 | /* Handle the basic abort sequence (BA_ABTS) event */ |
13797 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
13798 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
13799 | return; | |
13800 | } | |
13801 | ||
4d9ab994 JS |
13802 | /* Link this frame */ |
13803 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
13804 | if (!seq_dmabuf) { | |
13805 | /* unable to add frame to vport - throw it out */ | |
13806 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
13807 | return; | |
13808 | } | |
13809 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 13810 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 13811 | return; |
def9c7a9 | 13812 | |
6669f9bb JS |
13813 | /* Send the complete sequence to the upper layer protocol */ |
13814 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 13815 | } |
6fb120a7 JS |
13816 | |
13817 | /** | |
13818 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
13819 | * @phba: pointer to lpfc hba data structure. | |
13820 | * | |
13821 | * This routine is invoked to post rpi header templates to the | |
13822 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
13823 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
13824 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
13825 | * |
13826 | * This routine does not require any locks. It's usage is expected | |
13827 | * to be driver load or reset recovery when the driver is | |
13828 | * sequential. | |
13829 | * | |
13830 | * Return codes | |
af901ca1 | 13831 | * 0 - successful |
d439d286 | 13832 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
13833 | * When this error occurs, the driver is not guaranteed |
13834 | * to have any rpi regions posted to the device and | |
13835 | * must either attempt to repost the regions or take a | |
13836 | * fatal error. | |
13837 | **/ | |
13838 | int | |
13839 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
13840 | { | |
13841 | struct lpfc_rpi_hdr *rpi_page; | |
13842 | uint32_t rc = 0; | |
6d368e53 JS |
13843 | uint16_t lrpi = 0; |
13844 | ||
13845 | /* SLI4 ports that support extents do not require RPI headers. */ | |
13846 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
13847 | goto exit; | |
13848 | if (phba->sli4_hba.extents_in_use) | |
13849 | return -EIO; | |
6fb120a7 | 13850 | |
6fb120a7 | 13851 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
13852 | /* |
13853 | * Assign the rpi headers a physical rpi only if the driver | |
13854 | * has not initialized those resources. A port reset only | |
13855 | * needs the headers posted. | |
13856 | */ | |
13857 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
13858 | LPFC_RPI_RSRC_RDY) | |
13859 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
13860 | ||
6fb120a7 JS |
13861 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
13862 | if (rc != MBX_SUCCESS) { | |
13863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13864 | "2008 Error %d posting all rpi " | |
13865 | "headers\n", rc); | |
13866 | rc = -EIO; | |
13867 | break; | |
13868 | } | |
13869 | } | |
13870 | ||
6d368e53 JS |
13871 | exit: |
13872 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
13873 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
13874 | return rc; |
13875 | } | |
13876 | ||
13877 | /** | |
13878 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
13879 | * @phba: pointer to lpfc hba data structure. | |
13880 | * @rpi_page: pointer to the rpi memory region. | |
13881 | * | |
13882 | * This routine is invoked to post a single rpi header to the | |
13883 | * HBA consistent with the SLI-4 interface spec. This memory region | |
13884 | * maps up to 64 rpi context regions. | |
13885 | * | |
13886 | * Return codes | |
af901ca1 | 13887 | * 0 - successful |
d439d286 JS |
13888 | * -ENOMEM - No available memory |
13889 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
13890 | **/ |
13891 | int | |
13892 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
13893 | { | |
13894 | LPFC_MBOXQ_t *mboxq; | |
13895 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
13896 | uint32_t rc = 0; | |
6fb120a7 JS |
13897 | uint32_t shdr_status, shdr_add_status; |
13898 | union lpfc_sli4_cfg_shdr *shdr; | |
13899 | ||
6d368e53 JS |
13900 | /* SLI4 ports that support extents do not require RPI headers. */ |
13901 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
13902 | return rc; | |
13903 | if (phba->sli4_hba.extents_in_use) | |
13904 | return -EIO; | |
13905 | ||
6fb120a7 JS |
13906 | /* The port is notified of the header region via a mailbox command. */ |
13907 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13908 | if (!mboxq) { | |
13909 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13910 | "2001 Unable to allocate memory for issuing " | |
13911 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
13912 | return -ENOMEM; | |
13913 | } | |
13914 | ||
13915 | /* Post all rpi memory regions to the port. */ | |
13916 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
13917 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
13918 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
13919 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
13920 | sizeof(struct lpfc_sli4_cfg_mhdr), |
13921 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
13922 | |
13923 | ||
13924 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
13925 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
13926 | rpi_page->start_rpi); | |
6d368e53 JS |
13927 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
13928 | hdr_tmpl, rpi_page->page_count); | |
13929 | ||
6fb120a7 JS |
13930 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
13931 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 13932 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
13933 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
13934 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13935 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13936 | if (rc != MBX_TIMEOUT) | |
13937 | mempool_free(mboxq, phba->mbox_mem_pool); | |
13938 | if (shdr_status || shdr_add_status || rc) { | |
13939 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13940 | "2514 POST_RPI_HDR mailbox failed with " | |
13941 | "status x%x add_status x%x, mbx status x%x\n", | |
13942 | shdr_status, shdr_add_status, rc); | |
13943 | rc = -ENXIO; | |
13944 | } | |
13945 | return rc; | |
13946 | } | |
13947 | ||
13948 | /** | |
13949 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
13950 | * @phba: pointer to lpfc hba data structure. | |
13951 | * | |
13952 | * This routine is invoked to post rpi header templates to the | |
13953 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
13954 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
13955 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
13956 | * |
13957 | * Returns | |
af901ca1 | 13958 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
13959 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
13960 | **/ | |
13961 | int | |
13962 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
13963 | { | |
6d368e53 JS |
13964 | unsigned long rpi; |
13965 | uint16_t max_rpi, rpi_limit; | |
13966 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 JS |
13967 | struct lpfc_rpi_hdr *rpi_hdr; |
13968 | ||
13969 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6fb120a7 JS |
13970 | rpi_limit = phba->sli4_hba.next_rpi; |
13971 | ||
13972 | /* | |
6d368e53 JS |
13973 | * Fetch the next logical rpi. Because this index is logical, |
13974 | * the driver starts at 0 each time. | |
6fb120a7 JS |
13975 | */ |
13976 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
13977 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
13978 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
13979 | rpi = LPFC_RPI_ALLOC_ERROR; |
13980 | else { | |
13981 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
13982 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
13983 | phba->sli4_hba.rpi_count++; | |
13984 | } | |
13985 | ||
13986 | /* | |
13987 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 13988 | * has been exhausted. |
6fb120a7 JS |
13989 | */ |
13990 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
13991 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
13992 | spin_unlock_irq(&phba->hbalock); | |
13993 | return rpi; | |
13994 | } | |
13995 | ||
6d368e53 JS |
13996 | /* |
13997 | * RPI header postings are not required for SLI4 ports capable of | |
13998 | * extents. | |
13999 | */ | |
14000 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
14001 | spin_unlock_irq(&phba->hbalock); | |
14002 | return rpi; | |
14003 | } | |
14004 | ||
6fb120a7 JS |
14005 | /* |
14006 | * If the driver is running low on rpi resources, allocate another | |
14007 | * page now. Note that the next_rpi value is used because | |
14008 | * it represents how many are actually in use whereas max_rpi notes | |
14009 | * how many are supported max by the device. | |
14010 | */ | |
6d368e53 | 14011 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
6fb120a7 JS |
14012 | spin_unlock_irq(&phba->hbalock); |
14013 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
14014 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
14015 | if (!rpi_hdr) { | |
14016 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14017 | "2002 Error Could not grow rpi " | |
14018 | "count\n"); | |
14019 | } else { | |
6d368e53 JS |
14020 | lrpi = rpi_hdr->start_rpi; |
14021 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
14022 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
14023 | } | |
14024 | } | |
14025 | ||
14026 | return rpi; | |
14027 | } | |
14028 | ||
d7c47992 JS |
14029 | /** |
14030 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14031 | * @phba: pointer to lpfc hba data structure. | |
14032 | * | |
14033 | * This routine is invoked to release an rpi to the pool of | |
14034 | * available rpis maintained by the driver. | |
14035 | **/ | |
14036 | void | |
14037 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14038 | { | |
14039 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
14040 | phba->sli4_hba.rpi_count--; | |
14041 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
14042 | } | |
14043 | } | |
14044 | ||
6fb120a7 JS |
14045 | /** |
14046 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14047 | * @phba: pointer to lpfc hba data structure. | |
14048 | * | |
14049 | * This routine is invoked to release an rpi to the pool of | |
14050 | * available rpis maintained by the driver. | |
14051 | **/ | |
14052 | void | |
14053 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14054 | { | |
14055 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 14056 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
14057 | spin_unlock_irq(&phba->hbalock); |
14058 | } | |
14059 | ||
14060 | /** | |
14061 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
14062 | * @phba: pointer to lpfc hba data structure. | |
14063 | * | |
14064 | * This routine is invoked to remove the memory region that | |
14065 | * provided rpi via a bitmask. | |
14066 | **/ | |
14067 | void | |
14068 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
14069 | { | |
14070 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
14071 | kfree(phba->sli4_hba.rpi_ids); |
14072 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
14073 | } |
14074 | ||
14075 | /** | |
14076 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
14077 | * @phba: pointer to lpfc hba data structure. | |
14078 | * | |
14079 | * This routine is invoked to remove the memory region that | |
14080 | * provided rpi via a bitmask. | |
14081 | **/ | |
14082 | int | |
14083 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | |
14084 | { | |
14085 | LPFC_MBOXQ_t *mboxq; | |
14086 | struct lpfc_hba *phba = ndlp->phba; | |
14087 | int rc; | |
14088 | ||
14089 | /* The port is notified of the header region via a mailbox command. */ | |
14090 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14091 | if (!mboxq) | |
14092 | return -ENOMEM; | |
14093 | ||
14094 | /* Post all rpi memory regions to the port. */ | |
14095 | lpfc_resume_rpi(mboxq, ndlp); | |
14096 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14097 | if (rc == MBX_NOT_FINISHED) { | |
14098 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14099 | "2010 Resume RPI Mailbox failed " | |
14100 | "status %d, mbxStatus x%x\n", rc, | |
14101 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
14102 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14103 | return -EIO; | |
14104 | } | |
14105 | return 0; | |
14106 | } | |
14107 | ||
14108 | /** | |
14109 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 14110 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 14111 | * |
76a95d75 | 14112 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
14113 | * |
14114 | * Returns: | |
14115 | * 0 success | |
14116 | * -Evalue otherwise | |
14117 | **/ | |
14118 | int | |
76a95d75 | 14119 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
14120 | { |
14121 | LPFC_MBOXQ_t *mboxq; | |
14122 | int rc = 0; | |
6a9c52cf | 14123 | int retval = MBX_SUCCESS; |
6fb120a7 | 14124 | uint32_t mbox_tmo; |
76a95d75 | 14125 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
14126 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14127 | if (!mboxq) | |
14128 | return -ENOMEM; | |
76a95d75 | 14129 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
6fb120a7 JS |
14130 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI); |
14131 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6fb120a7 | 14132 | if (rc != MBX_SUCCESS) { |
76a95d75 | 14133 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
14134 | "2022 INIT VPI Mailbox failed " |
14135 | "status %d, mbxStatus x%x\n", rc, | |
14136 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 14137 | retval = -EIO; |
6fb120a7 | 14138 | } |
6a9c52cf | 14139 | if (rc != MBX_TIMEOUT) |
76a95d75 | 14140 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
14141 | |
14142 | return retval; | |
6fb120a7 JS |
14143 | } |
14144 | ||
14145 | /** | |
14146 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
14147 | * @phba: pointer to lpfc hba data structure. | |
14148 | * @mboxq: Pointer to mailbox object. | |
14149 | * | |
14150 | * This routine is invoked to manually add a single FCF record. The caller | |
14151 | * must pass a completely initialized FCF_Record. This routine takes | |
14152 | * care of the nonembedded mailbox operations. | |
14153 | **/ | |
14154 | static void | |
14155 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
14156 | { | |
14157 | void *virt_addr; | |
14158 | union lpfc_sli4_cfg_shdr *shdr; | |
14159 | uint32_t shdr_status, shdr_add_status; | |
14160 | ||
14161 | virt_addr = mboxq->sge_array->addr[0]; | |
14162 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14163 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
14164 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14165 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14166 | ||
14167 | if ((shdr_status || shdr_add_status) && | |
14168 | (shdr_status != STATUS_FCF_IN_USE)) | |
14169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14170 | "2558 ADD_FCF_RECORD mailbox failed with " | |
14171 | "status x%x add_status x%x\n", | |
14172 | shdr_status, shdr_add_status); | |
14173 | ||
14174 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14175 | } | |
14176 | ||
14177 | /** | |
14178 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
14179 | * @phba: pointer to lpfc hba data structure. | |
14180 | * @fcf_record: pointer to the initialized fcf record to add. | |
14181 | * | |
14182 | * This routine is invoked to manually add a single FCF record. The caller | |
14183 | * must pass a completely initialized FCF_Record. This routine takes | |
14184 | * care of the nonembedded mailbox operations. | |
14185 | **/ | |
14186 | int | |
14187 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
14188 | { | |
14189 | int rc = 0; | |
14190 | LPFC_MBOXQ_t *mboxq; | |
14191 | uint8_t *bytep; | |
14192 | void *virt_addr; | |
14193 | dma_addr_t phys_addr; | |
14194 | struct lpfc_mbx_sge sge; | |
14195 | uint32_t alloc_len, req_len; | |
14196 | uint32_t fcfindex; | |
14197 | ||
14198 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14199 | if (!mboxq) { | |
14200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14201 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
14202 | return -ENOMEM; | |
14203 | } | |
14204 | ||
14205 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
14206 | sizeof(uint32_t); | |
14207 | ||
14208 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14209 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14210 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
14211 | req_len, LPFC_SLI4_MBX_NEMBED); | |
14212 | if (alloc_len < req_len) { | |
14213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14214 | "2523 Allocated DMA memory size (x%x) is " | |
14215 | "less than the requested DMA memory " | |
14216 | "size (x%x)\n", alloc_len, req_len); | |
14217 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14218 | return -ENOMEM; | |
14219 | } | |
14220 | ||
14221 | /* | |
14222 | * Get the first SGE entry from the non-embedded DMA memory. This | |
14223 | * routine only uses a single SGE. | |
14224 | */ | |
14225 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
14226 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
14227 | virt_addr = mboxq->sge_array->addr[0]; |
14228 | /* | |
14229 | * Configure the FCF record for FCFI 0. This is the driver's | |
14230 | * hardcoded default and gets used in nonFIP mode. | |
14231 | */ | |
14232 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
14233 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
14234 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
14235 | ||
14236 | /* | |
14237 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
14238 | * the FCoE header plus word10. The data copy needs to be endian | |
14239 | * correct. | |
14240 | */ | |
14241 | bytep += sizeof(uint32_t); | |
14242 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
14243 | mboxq->vport = phba->pport; | |
14244 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
14245 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14246 | if (rc == MBX_NOT_FINISHED) { | |
14247 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14248 | "2515 ADD_FCF_RECORD mailbox failed with " | |
14249 | "status 0x%x\n", rc); | |
14250 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14251 | rc = -EIO; | |
14252 | } else | |
14253 | rc = 0; | |
14254 | ||
14255 | return rc; | |
14256 | } | |
14257 | ||
14258 | /** | |
14259 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
14260 | * @phba: pointer to lpfc hba data structure. | |
14261 | * @fcf_record: pointer to the fcf record to write the default data. | |
14262 | * @fcf_index: FCF table entry index. | |
14263 | * | |
14264 | * This routine is invoked to build the driver's default FCF record. The | |
14265 | * values used are hardcoded. This routine handles memory initialization. | |
14266 | * | |
14267 | **/ | |
14268 | void | |
14269 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
14270 | struct fcf_record *fcf_record, | |
14271 | uint16_t fcf_index) | |
14272 | { | |
14273 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
14274 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
14275 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
14276 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
14277 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
14278 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
14279 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
14280 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
14281 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
14282 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
14283 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
14284 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
14285 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
14286 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 14287 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
14288 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
14289 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
14290 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
14291 | /* Set the VLAN bit map */ | |
14292 | if (phba->valid_vlan) { | |
14293 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
14294 | = 1 << (phba->vlan_id % 8); | |
14295 | } | |
14296 | } | |
14297 | ||
14298 | /** | |
0c9ab6f5 | 14299 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
14300 | * @phba: pointer to lpfc hba data structure. |
14301 | * @fcf_index: FCF table entry offset. | |
14302 | * | |
0c9ab6f5 JS |
14303 | * This routine is invoked to scan the entire FCF table by reading FCF |
14304 | * record and processing it one at a time starting from the @fcf_index | |
14305 | * for initial FCF discovery or fast FCF failover rediscovery. | |
14306 | * | |
25985edc | 14307 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 14308 | * otherwise. |
6fb120a7 JS |
14309 | **/ |
14310 | int | |
0c9ab6f5 | 14311 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
14312 | { |
14313 | int rc = 0, error; | |
14314 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 14315 | |
32b9793f | 14316 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
6fb120a7 JS |
14317 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14318 | if (!mboxq) { | |
14319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14320 | "2000 Failed to allocate mbox for " | |
14321 | "READ_FCF cmd\n"); | |
4d9ab994 | 14322 | error = -ENOMEM; |
0c9ab6f5 | 14323 | goto fail_fcf_scan; |
6fb120a7 | 14324 | } |
ecfd03c6 | 14325 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 14326 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
14327 | if (rc) { |
14328 | error = -EINVAL; | |
0c9ab6f5 | 14329 | goto fail_fcf_scan; |
6fb120a7 | 14330 | } |
ecfd03c6 | 14331 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 14332 | mboxq->vport = phba->pport; |
0c9ab6f5 | 14333 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
14334 | |
14335 | spin_lock_irq(&phba->hbalock); | |
14336 | phba->hba_flag |= FCF_TS_INPROG; | |
14337 | spin_unlock_irq(&phba->hbalock); | |
14338 | ||
6fb120a7 | 14339 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 14340 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 14341 | error = -EIO; |
ecfd03c6 | 14342 | else { |
38b92ef8 JS |
14343 | /* Reset eligible FCF count for new scan */ |
14344 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 14345 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 14346 | error = 0; |
32b9793f | 14347 | } |
0c9ab6f5 | 14348 | fail_fcf_scan: |
4d9ab994 JS |
14349 | if (error) { |
14350 | if (mboxq) | |
14351 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 14352 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 14353 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 14354 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
14355 | spin_unlock_irq(&phba->hbalock); |
14356 | } | |
6fb120a7 JS |
14357 | return error; |
14358 | } | |
a0c87cbd | 14359 | |
0c9ab6f5 | 14360 | /** |
a93ff37a | 14361 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
14362 | * @phba: pointer to lpfc hba data structure. |
14363 | * @fcf_index: FCF table entry offset. | |
14364 | * | |
14365 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 14366 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 14367 | * |
25985edc | 14368 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
14369 | * otherwise. |
14370 | **/ | |
14371 | int | |
14372 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
14373 | { | |
14374 | int rc = 0, error; | |
14375 | LPFC_MBOXQ_t *mboxq; | |
14376 | ||
14377 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14378 | if (!mboxq) { | |
14379 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
14380 | "2763 Failed to allocate mbox for " | |
14381 | "READ_FCF cmd\n"); | |
14382 | error = -ENOMEM; | |
14383 | goto fail_fcf_read; | |
14384 | } | |
14385 | /* Construct the read FCF record mailbox command */ | |
14386 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
14387 | if (rc) { | |
14388 | error = -EINVAL; | |
14389 | goto fail_fcf_read; | |
14390 | } | |
14391 | /* Issue the mailbox command asynchronously */ | |
14392 | mboxq->vport = phba->pport; | |
14393 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
14394 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14395 | if (rc == MBX_NOT_FINISHED) | |
14396 | error = -EIO; | |
14397 | else | |
14398 | error = 0; | |
14399 | ||
14400 | fail_fcf_read: | |
14401 | if (error && mboxq) | |
14402 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14403 | return error; | |
14404 | } | |
14405 | ||
14406 | /** | |
14407 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
14408 | * @phba: pointer to lpfc hba data structure. | |
14409 | * @fcf_index: FCF table entry offset. | |
14410 | * | |
14411 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 14412 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 14413 | * |
25985edc | 14414 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
14415 | * otherwise. |
14416 | **/ | |
14417 | int | |
14418 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
14419 | { | |
14420 | int rc = 0, error; | |
14421 | LPFC_MBOXQ_t *mboxq; | |
14422 | ||
14423 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14424 | if (!mboxq) { | |
14425 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
14426 | "2758 Failed to allocate mbox for " | |
14427 | "READ_FCF cmd\n"); | |
14428 | error = -ENOMEM; | |
14429 | goto fail_fcf_read; | |
14430 | } | |
14431 | /* Construct the read FCF record mailbox command */ | |
14432 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
14433 | if (rc) { | |
14434 | error = -EINVAL; | |
14435 | goto fail_fcf_read; | |
14436 | } | |
14437 | /* Issue the mailbox command asynchronously */ | |
14438 | mboxq->vport = phba->pport; | |
14439 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
14440 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14441 | if (rc == MBX_NOT_FINISHED) | |
14442 | error = -EIO; | |
14443 | else | |
14444 | error = 0; | |
14445 | ||
14446 | fail_fcf_read: | |
14447 | if (error && mboxq) | |
14448 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14449 | return error; | |
14450 | } | |
14451 | ||
14452 | /** | |
14453 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
14454 | * @phba: pointer to lpfc hba data structure. | |
14455 | * | |
14456 | * This routine is to get the next eligible FCF record index in a round | |
14457 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 14458 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
14459 | * shall be returned, otherwise, the next eligible FCF record's index |
14460 | * shall be returned. | |
14461 | **/ | |
14462 | uint16_t | |
14463 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
14464 | { | |
14465 | uint16_t next_fcf_index; | |
14466 | ||
3804dc84 JS |
14467 | /* Search start from next bit of currently registered FCF index */ |
14468 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % | |
14469 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
14470 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
14471 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
14472 | next_fcf_index); |
14473 | ||
0c9ab6f5 JS |
14474 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
14475 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) | |
14476 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, | |
14477 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
3804dc84 JS |
14478 | |
14479 | /* Check roundrobin failover list empty condition */ | |
14480 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
14481 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
14482 | "2844 No roundrobin failover FCF available\n"); | |
0c9ab6f5 | 14483 | return LPFC_FCOE_FCF_NEXT_NONE; |
3804dc84 JS |
14484 | } |
14485 | ||
3804dc84 | 14486 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
14487 | "2845 Get next roundrobin failover FCF (x%x)\n", |
14488 | next_fcf_index); | |
14489 | ||
0c9ab6f5 JS |
14490 | return next_fcf_index; |
14491 | } | |
14492 | ||
14493 | /** | |
14494 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
14495 | * @phba: pointer to lpfc hba data structure. | |
14496 | * | |
14497 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 14498 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
14499 | * does not go beyond the range of the driver allocated bmask dimension |
14500 | * before setting the bit. | |
14501 | * | |
14502 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
14503 | * -EINVAL. | |
14504 | **/ | |
14505 | int | |
14506 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
14507 | { | |
14508 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
14509 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
14510 | "2610 FCF (x%x) reached driver's book " |
14511 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
14512 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
14513 | return -EINVAL; | |
14514 | } | |
14515 | /* Set the eligible FCF record index bmask */ | |
14516 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
14517 | ||
3804dc84 | 14518 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 14519 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
14520 | "bmask\n", fcf_index); |
14521 | ||
0c9ab6f5 JS |
14522 | return 0; |
14523 | } | |
14524 | ||
14525 | /** | |
3804dc84 | 14526 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
14527 | * @phba: pointer to lpfc hba data structure. |
14528 | * | |
14529 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 14530 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
14531 | * does not go beyond the range of the driver allocated bmask dimension |
14532 | * before clearing the bit. | |
14533 | **/ | |
14534 | void | |
14535 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
14536 | { | |
14537 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
14538 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
14539 | "2762 FCF (x%x) reached driver's book " |
14540 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
14541 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
14542 | return; | |
14543 | } | |
14544 | /* Clear the eligible FCF record index bmask */ | |
14545 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
3804dc84 JS |
14546 | |
14547 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 14548 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 14549 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
14550 | } |
14551 | ||
ecfd03c6 JS |
14552 | /** |
14553 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
14554 | * @phba: pointer to lpfc hba data structure. | |
14555 | * | |
14556 | * This routine is the completion routine for the rediscover FCF table mailbox | |
14557 | * command. If the mailbox command returned failure, it will try to stop the | |
14558 | * FCF rediscover wait timer. | |
14559 | **/ | |
14560 | void | |
14561 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
14562 | { | |
14563 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
14564 | uint32_t shdr_status, shdr_add_status; | |
14565 | ||
14566 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
14567 | ||
14568 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
14569 | &redisc_fcf->header.cfg_shdr.response); | |
14570 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
14571 | &redisc_fcf->header.cfg_shdr.response); | |
14572 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 14573 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
14574 | "2746 Requesting for FCF rediscovery failed " |
14575 | "status x%x add_status x%x\n", | |
14576 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 14577 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 14578 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 14579 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
14580 | spin_unlock_irq(&phba->hbalock); |
14581 | /* | |
14582 | * CVL event triggered FCF rediscover request failed, | |
14583 | * last resort to re-try current registered FCF entry. | |
14584 | */ | |
14585 | lpfc_retry_pport_discovery(phba); | |
14586 | } else { | |
14587 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 14588 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
14589 | spin_unlock_irq(&phba->hbalock); |
14590 | /* | |
14591 | * DEAD FCF event triggered FCF rediscover request | |
14592 | * failed, last resort to fail over as a link down | |
14593 | * to FCF registration. | |
14594 | */ | |
14595 | lpfc_sli4_fcf_dead_failthrough(phba); | |
14596 | } | |
0c9ab6f5 JS |
14597 | } else { |
14598 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 14599 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
14600 | /* |
14601 | * Start FCF rediscovery wait timer for pending FCF | |
14602 | * before rescan FCF record table. | |
14603 | */ | |
14604 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 14605 | } |
ecfd03c6 JS |
14606 | |
14607 | mempool_free(mbox, phba->mbox_mem_pool); | |
14608 | } | |
14609 | ||
14610 | /** | |
3804dc84 | 14611 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
14612 | * @phba: pointer to lpfc hba data structure. |
14613 | * | |
14614 | * This routine is invoked to request for rediscovery of the entire FCF table | |
14615 | * by the port. | |
14616 | **/ | |
14617 | int | |
14618 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
14619 | { | |
14620 | LPFC_MBOXQ_t *mbox; | |
14621 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
14622 | int rc, length; | |
14623 | ||
0c9ab6f5 JS |
14624 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
14625 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
14626 | ||
ecfd03c6 JS |
14627 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14628 | if (!mbox) { | |
14629 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14630 | "2745 Failed to allocate mbox for " | |
14631 | "requesting FCF rediscover.\n"); | |
14632 | return -ENOMEM; | |
14633 | } | |
14634 | ||
14635 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
14636 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
14637 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14638 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
14639 | length, LPFC_SLI4_MBX_EMBED); | |
14640 | ||
14641 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
14642 | /* Set count to 0 for invalidating the entire FCF database */ | |
14643 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
14644 | ||
14645 | /* Issue the mailbox command asynchronously */ | |
14646 | mbox->vport = phba->pport; | |
14647 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
14648 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
14649 | ||
14650 | if (rc == MBX_NOT_FINISHED) { | |
14651 | mempool_free(mbox, phba->mbox_mem_pool); | |
14652 | return -EIO; | |
14653 | } | |
14654 | return 0; | |
14655 | } | |
14656 | ||
fc2b989b JS |
14657 | /** |
14658 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
14659 | * @phba: pointer to lpfc hba data structure. | |
14660 | * | |
14661 | * This function is the failover routine as a last resort to the FCF DEAD | |
14662 | * event when driver failed to perform fast FCF failover. | |
14663 | **/ | |
14664 | void | |
14665 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
14666 | { | |
14667 | uint32_t link_state; | |
14668 | ||
14669 | /* | |
14670 | * Last resort as FCF DEAD event failover will treat this as | |
14671 | * a link down, but save the link state because we don't want | |
14672 | * it to be changed to Link Down unless it is already down. | |
14673 | */ | |
14674 | link_state = phba->link_state; | |
14675 | lpfc_linkdown(phba); | |
14676 | phba->link_state = link_state; | |
14677 | ||
14678 | /* Unregister FCF if no devices connected to it */ | |
14679 | lpfc_unregister_unused_fcf(phba); | |
14680 | } | |
14681 | ||
a0c87cbd JS |
14682 | /** |
14683 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
14684 | * @phba: pointer to lpfc hba data structure. | |
14685 | * | |
14686 | * This function read region 23 and parse TLV for port status to | |
14687 | * decide if the user disaled the port. If the TLV indicates the | |
14688 | * port is disabled, the hba_flag is set accordingly. | |
14689 | **/ | |
14690 | void | |
14691 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
14692 | { | |
14693 | LPFC_MBOXQ_t *pmb = NULL; | |
14694 | MAILBOX_t *mb; | |
14695 | uint8_t *rgn23_data = NULL; | |
14696 | uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset; | |
14697 | int rc; | |
14698 | ||
14699 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14700 | if (!pmb) { | |
14701 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14702 | "2600 lpfc_sli_read_serdes_param failed to" | |
14703 | " allocate mailbox memory\n"); | |
14704 | goto out; | |
14705 | } | |
14706 | mb = &pmb->u.mb; | |
14707 | ||
14708 | /* Get adapter Region 23 data */ | |
14709 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
14710 | if (!rgn23_data) | |
14711 | goto out; | |
14712 | ||
14713 | do { | |
14714 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
14715 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
14716 | ||
14717 | if (rc != MBX_SUCCESS) { | |
14718 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
14719 | "2601 lpfc_sli_read_link_ste failed to" | |
14720 | " read config region 23 rc 0x%x Status 0x%x\n", | |
14721 | rc, mb->mbxStatus); | |
14722 | mb->un.varDmp.word_cnt = 0; | |
14723 | } | |
14724 | /* | |
14725 | * dump mem may return a zero when finished or we got a | |
14726 | * mailbox error, either way we are done. | |
14727 | */ | |
14728 | if (mb->un.varDmp.word_cnt == 0) | |
14729 | break; | |
14730 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
14731 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
14732 | ||
14733 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
14734 | rgn23_data + offset, | |
14735 | mb->un.varDmp.word_cnt); | |
14736 | offset += mb->un.varDmp.word_cnt; | |
14737 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
14738 | ||
14739 | data_size = offset; | |
14740 | offset = 0; | |
14741 | ||
14742 | if (!data_size) | |
14743 | goto out; | |
14744 | ||
14745 | /* Check the region signature first */ | |
14746 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
14747 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14748 | "2619 Config region 23 has bad signature\n"); | |
14749 | goto out; | |
14750 | } | |
14751 | offset += 4; | |
14752 | ||
14753 | /* Check the data structure version */ | |
14754 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
14755 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14756 | "2620 Config region 23 has bad version\n"); | |
14757 | goto out; | |
14758 | } | |
14759 | offset += 4; | |
14760 | ||
14761 | /* Parse TLV entries in the region */ | |
14762 | while (offset < data_size) { | |
14763 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
14764 | break; | |
14765 | /* | |
14766 | * If the TLV is not driver specific TLV or driver id is | |
14767 | * not linux driver id, skip the record. | |
14768 | */ | |
14769 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
14770 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
14771 | (rgn23_data[offset + 3] != 0)) { | |
14772 | offset += rgn23_data[offset + 1] * 4 + 4; | |
14773 | continue; | |
14774 | } | |
14775 | ||
14776 | /* Driver found a driver specific TLV in the config region */ | |
14777 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
14778 | offset += 4; | |
14779 | tlv_offset = 0; | |
14780 | ||
14781 | /* | |
14782 | * Search for configured port state sub-TLV. | |
14783 | */ | |
14784 | while ((offset < data_size) && | |
14785 | (tlv_offset < sub_tlv_len)) { | |
14786 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
14787 | offset += 4; | |
14788 | tlv_offset += 4; | |
14789 | break; | |
14790 | } | |
14791 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
14792 | offset += rgn23_data[offset + 1] * 4 + 4; | |
14793 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
14794 | continue; | |
14795 | } | |
14796 | ||
14797 | /* This HBA contains PORT_STE configured */ | |
14798 | if (!rgn23_data[offset + 2]) | |
14799 | phba->hba_flag |= LINK_DISABLED; | |
14800 | ||
14801 | goto out; | |
14802 | } | |
14803 | } | |
14804 | out: | |
14805 | if (pmb) | |
14806 | mempool_free(pmb, phba->mbox_mem_pool); | |
14807 | kfree(rgn23_data); | |
14808 | return; | |
14809 | } | |
695a814e | 14810 | |
52d52440 JS |
14811 | /** |
14812 | * lpfc_wr_object - write an object to the firmware | |
14813 | * @phba: HBA structure that indicates port to create a queue on. | |
14814 | * @dmabuf_list: list of dmabufs to write to the port. | |
14815 | * @size: the total byte value of the objects to write to the port. | |
14816 | * @offset: the current offset to be used to start the transfer. | |
14817 | * | |
14818 | * This routine will create a wr_object mailbox command to send to the port. | |
14819 | * the mailbox command will be constructed using the dma buffers described in | |
14820 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
14821 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
14822 | * used to indicate the starting offset of the transfer and will also return | |
14823 | * the offset after the write object mailbox has completed. @size is used to | |
14824 | * determine the end of the object and whether the eof bit should be set. | |
14825 | * | |
14826 | * Return 0 is successful and offset will contain the the new offset to use | |
14827 | * for the next write. | |
14828 | * Return negative value for error cases. | |
14829 | **/ | |
14830 | int | |
14831 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
14832 | uint32_t size, uint32_t *offset) | |
14833 | { | |
14834 | struct lpfc_mbx_wr_object *wr_object; | |
14835 | LPFC_MBOXQ_t *mbox; | |
14836 | int rc = 0, i = 0; | |
14837 | uint32_t shdr_status, shdr_add_status; | |
14838 | uint32_t mbox_tmo; | |
14839 | union lpfc_sli4_cfg_shdr *shdr; | |
14840 | struct lpfc_dmabuf *dmabuf; | |
14841 | uint32_t written = 0; | |
14842 | ||
14843 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14844 | if (!mbox) | |
14845 | return -ENOMEM; | |
14846 | ||
14847 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
14848 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
14849 | sizeof(struct lpfc_mbx_wr_object) - | |
14850 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
14851 | ||
14852 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
14853 | wr_object->u.request.write_offset = *offset; | |
14854 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
14855 | wr_object->u.request.object_name[0] = | |
14856 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
14857 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
14858 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
14859 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
14860 | break; | |
14861 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
14862 | wr_object->u.request.bde[i].addrHigh = | |
14863 | putPaddrHigh(dmabuf->phys); | |
14864 | if (written + SLI4_PAGE_SIZE >= size) { | |
14865 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
14866 | (size - written); | |
14867 | written += (size - written); | |
14868 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
14869 | } else { | |
14870 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
14871 | SLI4_PAGE_SIZE; | |
14872 | written += SLI4_PAGE_SIZE; | |
14873 | } | |
14874 | i++; | |
14875 | } | |
14876 | wr_object->u.request.bde_count = i; | |
14877 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
14878 | if (!phba->sli4_hba.intr_enable) | |
14879 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
14880 | else { | |
14881 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
14882 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
14883 | } | |
14884 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14885 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
14886 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14887 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14888 | if (rc != MBX_TIMEOUT) | |
14889 | mempool_free(mbox, phba->mbox_mem_pool); | |
14890 | if (shdr_status || shdr_add_status || rc) { | |
14891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14892 | "3025 Write Object mailbox failed with " | |
14893 | "status x%x add_status x%x, mbx status x%x\n", | |
14894 | shdr_status, shdr_add_status, rc); | |
14895 | rc = -ENXIO; | |
14896 | } else | |
14897 | *offset += wr_object->u.response.actual_write_length; | |
14898 | return rc; | |
14899 | } | |
14900 | ||
695a814e JS |
14901 | /** |
14902 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
14903 | * @vport: pointer to vport data structure. | |
14904 | * | |
14905 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
14906 | * and REG_VPI mailbox commands associated with the vport. This function | |
14907 | * is called when driver want to restart discovery of the vport due to | |
14908 | * a Clear Virtual Link event. | |
14909 | **/ | |
14910 | void | |
14911 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
14912 | { | |
14913 | struct lpfc_hba *phba = vport->phba; | |
14914 | LPFC_MBOXQ_t *mb, *nextmb; | |
14915 | struct lpfc_dmabuf *mp; | |
78730cfe | 14916 | struct lpfc_nodelist *ndlp; |
d439d286 | 14917 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 14918 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 14919 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 14920 | uint8_t restart_loop; |
695a814e | 14921 | |
d439d286 | 14922 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
14923 | spin_lock_irq(&phba->hbalock); |
14924 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
14925 | if (mb->vport != vport) | |
14926 | continue; | |
14927 | ||
14928 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
14929 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
14930 | continue; | |
14931 | ||
d439d286 JS |
14932 | list_del(&mb->list); |
14933 | list_add_tail(&mb->list, &mbox_cmd_list); | |
14934 | } | |
14935 | /* Clean up active mailbox command with the vport */ | |
14936 | mb = phba->sli.mbox_active; | |
14937 | if (mb && (mb->vport == vport)) { | |
14938 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
14939 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
14940 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14941 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
14942 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
14943 | /* Put reference count for delayed processing */ | |
14944 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
14945 | /* Unregister the RPI when mailbox complete */ | |
14946 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
14947 | } | |
14948 | } | |
63e801ce JS |
14949 | /* Cleanup any mailbox completions which are not yet processed */ |
14950 | do { | |
14951 | restart_loop = 0; | |
14952 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
14953 | /* | |
14954 | * If this mailox is already processed or it is | |
14955 | * for another vport ignore it. | |
14956 | */ | |
14957 | if ((mb->vport != vport) || | |
14958 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
14959 | continue; | |
14960 | ||
14961 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
14962 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
14963 | continue; | |
14964 | ||
14965 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
14966 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
14967 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
14968 | /* Unregister the RPI when mailbox complete */ | |
14969 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
14970 | restart_loop = 1; | |
14971 | spin_unlock_irq(&phba->hbalock); | |
14972 | spin_lock(shost->host_lock); | |
14973 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
14974 | spin_unlock(shost->host_lock); | |
14975 | spin_lock_irq(&phba->hbalock); | |
14976 | break; | |
14977 | } | |
14978 | } | |
14979 | } while (restart_loop); | |
14980 | ||
d439d286 JS |
14981 | spin_unlock_irq(&phba->hbalock); |
14982 | ||
14983 | /* Release the cleaned-up mailbox commands */ | |
14984 | while (!list_empty(&mbox_cmd_list)) { | |
14985 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
14986 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
14987 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
14988 | if (mp) { | |
14989 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
14990 | kfree(mp); | |
14991 | } | |
78730cfe | 14992 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 14993 | mb->context2 = NULL; |
78730cfe | 14994 | if (ndlp) { |
ec21b3b0 | 14995 | spin_lock(shost->host_lock); |
589a52d6 | 14996 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 14997 | spin_unlock(shost->host_lock); |
78730cfe | 14998 | lpfc_nlp_put(ndlp); |
78730cfe | 14999 | } |
695a814e | 15000 | } |
695a814e JS |
15001 | mempool_free(mb, phba->mbox_mem_pool); |
15002 | } | |
d439d286 JS |
15003 | |
15004 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
15005 | if (act_mbx_ndlp) { | |
15006 | spin_lock(shost->host_lock); | |
15007 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15008 | spin_unlock(shost->host_lock); | |
15009 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 15010 | } |
695a814e JS |
15011 | } |
15012 | ||
2a9bf3d0 JS |
15013 | /** |
15014 | * lpfc_drain_txq - Drain the txq | |
15015 | * @phba: Pointer to HBA context object. | |
15016 | * | |
15017 | * This function attempt to submit IOCBs on the txq | |
15018 | * to the adapter. For SLI4 adapters, the txq contains | |
15019 | * ELS IOCBs that have been deferred because the there | |
15020 | * are no SGLs. This congestion can occur with large | |
15021 | * vport counts during node discovery. | |
15022 | **/ | |
15023 | ||
15024 | uint32_t | |
15025 | lpfc_drain_txq(struct lpfc_hba *phba) | |
15026 | { | |
15027 | LIST_HEAD(completions); | |
15028 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
15029 | struct lpfc_iocbq *piocbq = 0; | |
15030 | unsigned long iflags = 0; | |
15031 | char *fail_msg = NULL; | |
15032 | struct lpfc_sglq *sglq; | |
15033 | union lpfc_wqe wqe; | |
15034 | ||
15035 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15036 | if (pring->txq_cnt > pring->txq_max) | |
15037 | pring->txq_max = pring->txq_cnt; | |
15038 | ||
15039 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15040 | ||
15041 | while (pring->txq_cnt) { | |
15042 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15043 | ||
19ca7609 JS |
15044 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
15045 | sglq = __lpfc_sli_get_sglq(phba, piocbq); | |
2a9bf3d0 | 15046 | if (!sglq) { |
19ca7609 | 15047 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
15048 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
15049 | break; | |
15050 | } else { | |
2a9bf3d0 JS |
15051 | if (!piocbq) { |
15052 | /* The txq_cnt out of sync. This should | |
15053 | * never happen | |
15054 | */ | |
15055 | sglq = __lpfc_clear_active_sglq(phba, | |
6d368e53 | 15056 | sglq->sli4_lxritag); |
2a9bf3d0 JS |
15057 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
15058 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15059 | "2823 txq empty and txq_cnt is %d\n ", | |
15060 | pring->txq_cnt); | |
15061 | break; | |
15062 | } | |
15063 | } | |
15064 | ||
15065 | /* The xri and iocb resources secured, | |
15066 | * attempt to issue request | |
15067 | */ | |
6d368e53 | 15068 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
15069 | piocbq->sli4_xritag = sglq->sli4_xritag; |
15070 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
15071 | fail_msg = "to convert bpl to sgl"; | |
15072 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
15073 | fail_msg = "to convert iocb to wqe"; | |
15074 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
15075 | fail_msg = " - Wq is full"; | |
15076 | else | |
15077 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
15078 | ||
15079 | if (fail_msg) { | |
15080 | /* Failed means we can't issue and need to cancel */ | |
15081 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15082 | "2822 IOCB failed %s iotag 0x%x " | |
15083 | "xri 0x%x\n", | |
15084 | fail_msg, | |
15085 | piocbq->iotag, piocbq->sli4_xritag); | |
15086 | list_add_tail(&piocbq->list, &completions); | |
15087 | } | |
15088 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15089 | } | |
15090 | ||
2a9bf3d0 JS |
15091 | /* Cancel all the IOCBs that cannot be issued */ |
15092 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
15093 | IOERR_SLI_ABORTED); | |
15094 | ||
15095 | return pring->txq_cnt; | |
15096 | } |