Commit | Line | Data |
---|---|---|
dea3101e | 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 | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | |
91886523 | 28 | #include <scsi/scsi.h> |
dea3101e | 29 | #include <scsi/scsi_cmnd.h> |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_host.h> | |
f888ba3c | 32 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 33 | #include <scsi/fc/fc_fs.h> |
0d878419 | 34 | #include <linux/aer.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e | 37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e | 41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_crtn.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_compat.h" | |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
04c68496 | 48 | #include "lpfc_vport.h" |
dea3101e | 49 | |
50 | /* There are only four IOCB completion types. */ | |
51 | typedef enum _lpfc_iocb_type { | |
52 | LPFC_UNKNOWN_IOCB, | |
53 | LPFC_UNSOL_IOCB, | |
54 | LPFC_SOL_IOCB, | |
55 | LPFC_ABORT_IOCB | |
56 | } lpfc_iocb_type; | |
57 | ||
4f774513 JS |
58 | |
59 | /* Provide function prototypes local to this module. */ | |
60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
61 | uint32_t); | |
62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
63 | uint8_t *, uint32_t *); |
64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
65 | struct lpfc_iocbq *); | |
6669f9bb JS |
66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
67 | struct hbq_dmabuf *); | |
0558056c JS |
68 | static int lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *, struct lpfc_queue *, |
69 | struct lpfc_cqe *); | |
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 */ | |
ff78d8f9 | 100 | if (!((q->host_index + 1) % q->entry_repost)) |
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 */ | |
73d91e50 | 382 | if (!(hq->host_index % hq->entry_repost)) { |
4f774513 JS |
383 | doorbell.word0 = 0; |
384 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | |
73d91e50 | 385 | hq->entry_repost); |
4f774513 JS |
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; | |
7851fe2c | 563 | rrq->xritag = 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 1211 | } |
1212 | } | |
ed957684 JS |
1213 | mempool_free(pmb, phba->mbox_mem_pool); |
1214 | return ret; | |
dea3101e | 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 | 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 | 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 | 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 | 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 | 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 | 1306 | pring->local_getidx, max_cmd_idx); |
1307 | ||
2e0fef85 | 1308 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 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 | 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 | 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 | 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 | 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 | 1435 | /* |
1436 | * Issue iocb command to adapter | |
1437 | */ | |
92d7f7b0 | 1438 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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, | |
73d91e50 | 1867 | lpfc_hbq_defs[qno]->entry_count); |
def9c7a9 JS |
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 | 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 | 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 | 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 | 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 | 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 | 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 | 2050 | { |
2051 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2052 | unsigned long drvr_flag; |
dea3101e | 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 | 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 | 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 | 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 | 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 | 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 | 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 " |
a183a15f | 2203 | "x%x (x%x/x%x) Cmpl\n", |
92d7f7b0 | 2204 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 | 2205 | pmbox->mbxCommand, |
a183a15f JS |
2206 | lpfc_sli_config_mbox_subsys_get(phba, |
2207 | pmb), | |
2208 | lpfc_sli_config_mbox_opcode_get(phba, | |
2209 | pmb)); | |
2e0fef85 | 2210 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 2211 | phba->work_hs = HS_FFER3; |
2212 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2213 | continue; |
dea3101e | 2214 | } |
2215 | ||
dea3101e | 2216 | if (pmbox->mbxStatus) { |
2217 | phba->sli.slistat.mbox_stat_err++; | |
2218 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2219 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 | 2220 | lpfc_printf_log(phba, KERN_INFO, |
a183a15f JS |
2221 | LOG_MBOX | LOG_SLI, |
2222 | "(%d):0305 Mbox cmd cmpl " | |
2223 | "error - RETRYing Data: x%x " | |
2224 | "(x%x/x%x) x%x x%x x%x\n", | |
2225 | pmb->vport ? pmb->vport->vpi : 0, | |
2226 | pmbox->mbxCommand, | |
2227 | lpfc_sli_config_mbox_subsys_get(phba, | |
2228 | pmb), | |
2229 | lpfc_sli_config_mbox_opcode_get(phba, | |
2230 | pmb), | |
2231 | pmbox->mbxStatus, | |
2232 | pmbox->un.varWords[0], | |
2233 | pmb->vport->port_state); | |
dea3101e | 2234 | pmbox->mbxStatus = 0; |
2235 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2236 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2237 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2238 | continue; |
dea3101e | 2239 | } |
2240 | } | |
2241 | ||
2242 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2243 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
a183a15f | 2244 | "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl x%p " |
dea3101e | 2245 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2246 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2247 | pmbox->mbxCommand, |
a183a15f JS |
2248 | lpfc_sli_config_mbox_subsys_get(phba, pmb), |
2249 | lpfc_sli_config_mbox_opcode_get(phba, pmb), | |
dea3101e | 2250 | pmb->mbox_cmpl, |
2251 | *((uint32_t *) pmbox), | |
2252 | pmbox->un.varWords[0], | |
2253 | pmbox->un.varWords[1], | |
2254 | pmbox->un.varWords[2], | |
2255 | pmbox->un.varWords[3], | |
2256 | pmbox->un.varWords[4], | |
2257 | pmbox->un.varWords[5], | |
2258 | pmbox->un.varWords[6], | |
2259 | pmbox->un.varWords[7]); | |
2260 | ||
92d7f7b0 | 2261 | if (pmb->mbox_cmpl) |
dea3101e | 2262 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2263 | } while (1); |
2264 | return 0; | |
2265 | } | |
dea3101e | 2266 | |
e59058c4 | 2267 | /** |
3621a710 | 2268 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2269 | * @phba: Pointer to HBA context object. |
2270 | * @pring: Pointer to driver SLI ring object. | |
2271 | * @tag: buffer tag. | |
2272 | * | |
2273 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2274 | * is set in the tag the buffer is posted for a particular exchange, | |
2275 | * the function will return the buffer without replacing the buffer. | |
2276 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2277 | * returns the buffer and also posts another buffer to the firmware. | |
2278 | **/ | |
76bb24ef JS |
2279 | static struct lpfc_dmabuf * |
2280 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2281 | struct lpfc_sli_ring *pring, |
2282 | uint32_t tag) | |
76bb24ef | 2283 | { |
9f1e1b50 JS |
2284 | struct hbq_dmabuf *hbq_entry; |
2285 | ||
76bb24ef JS |
2286 | if (tag & QUE_BUFTAG_BIT) |
2287 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2288 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2289 | if (!hbq_entry) | |
2290 | return NULL; | |
2291 | return &hbq_entry->dbuf; | |
76bb24ef | 2292 | } |
57127f15 | 2293 | |
3772a991 JS |
2294 | /** |
2295 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2296 | * @phba: Pointer to HBA context object. | |
2297 | * @pring: Pointer to driver SLI ring object. | |
2298 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2299 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2300 | * @fch_type: the type for the first frame of the sequence. | |
2301 | * | |
2302 | * This function is called with no lock held. This function uses the r_ctl and | |
2303 | * type of the received sequence to find the correct callback function to call | |
2304 | * to process the sequence. | |
2305 | **/ | |
2306 | static int | |
2307 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2308 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2309 | uint32_t fch_type) | |
2310 | { | |
2311 | int i; | |
2312 | ||
2313 | /* unSolicited Responses */ | |
2314 | if (pring->prt[0].profile) { | |
2315 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2316 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2317 | saveq); | |
2318 | return 1; | |
2319 | } | |
2320 | /* We must search, based on rctl / type | |
2321 | for the right routine */ | |
2322 | for (i = 0; i < pring->num_mask; i++) { | |
2323 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2324 | (pring->prt[i].type == fch_type)) { | |
2325 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2326 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2327 | (phba, pring, saveq); | |
2328 | return 1; | |
2329 | } | |
2330 | } | |
2331 | return 0; | |
2332 | } | |
e59058c4 JS |
2333 | |
2334 | /** | |
3621a710 | 2335 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2336 | * @phba: Pointer to HBA context object. |
2337 | * @pring: Pointer to driver SLI ring object. | |
2338 | * @saveq: Pointer to the unsolicited iocb. | |
2339 | * | |
2340 | * This function is called with no lock held by the ring event handler | |
2341 | * when there is an unsolicited iocb posted to the response ring by the | |
2342 | * firmware. This function gets the buffer associated with the iocbs | |
2343 | * and calls the event handler for the ring. This function handles both | |
2344 | * qring buffers and hbq buffers. | |
2345 | * When the function returns 1 the caller can free the iocb object otherwise | |
2346 | * upper layer functions will free the iocb objects. | |
2347 | **/ | |
dea3101e | 2348 | static int |
2349 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2350 | struct lpfc_iocbq *saveq) | |
2351 | { | |
2352 | IOCB_t * irsp; | |
2353 | WORD5 * w5p; | |
2354 | uint32_t Rctl, Type; | |
3772a991 | 2355 | uint32_t match; |
76bb24ef | 2356 | struct lpfc_iocbq *iocbq; |
3163f725 | 2357 | struct lpfc_dmabuf *dmzbuf; |
dea3101e | 2358 | |
2359 | match = 0; | |
2360 | irsp = &(saveq->iocb); | |
57127f15 JS |
2361 | |
2362 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2363 | if (pring->lpfc_sli_rcv_async_status) | |
2364 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2365 | else | |
2366 | lpfc_printf_log(phba, | |
2367 | KERN_WARNING, | |
2368 | LOG_SLI, | |
2369 | "0316 Ring %d handler: unexpected " | |
2370 | "ASYNC_STATUS iocb received evt_code " | |
2371 | "0x%x\n", | |
2372 | pring->ringno, | |
2373 | irsp->un.asyncstat.evt_code); | |
2374 | return 1; | |
2375 | } | |
2376 | ||
3163f725 JS |
2377 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2378 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2379 | if (irsp->ulpBdeCount > 0) { | |
2380 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2381 | irsp->un.ulpWord[3]); | |
2382 | lpfc_in_buf_free(phba, dmzbuf); | |
2383 | } | |
2384 | ||
2385 | if (irsp->ulpBdeCount > 1) { | |
2386 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2387 | irsp->unsli3.sli3Words[3]); | |
2388 | lpfc_in_buf_free(phba, dmzbuf); | |
2389 | } | |
2390 | ||
2391 | if (irsp->ulpBdeCount > 2) { | |
2392 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2393 | irsp->unsli3.sli3Words[7]); | |
2394 | lpfc_in_buf_free(phba, dmzbuf); | |
2395 | } | |
2396 | ||
2397 | return 1; | |
2398 | } | |
2399 | ||
92d7f7b0 | 2400 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2401 | if (irsp->ulpBdeCount != 0) { |
2402 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2403 | irsp->un.ulpWord[3]); | |
2404 | if (!saveq->context2) | |
2405 | lpfc_printf_log(phba, | |
2406 | KERN_ERR, | |
2407 | LOG_SLI, | |
2408 | "0341 Ring %d Cannot find buffer for " | |
2409 | "an unsolicited iocb. tag 0x%x\n", | |
2410 | pring->ringno, | |
2411 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2412 | } |
2413 | if (irsp->ulpBdeCount == 2) { | |
2414 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2415 | irsp->unsli3.sli3Words[7]); | |
2416 | if (!saveq->context3) | |
2417 | lpfc_printf_log(phba, | |
2418 | KERN_ERR, | |
2419 | LOG_SLI, | |
2420 | "0342 Ring %d Cannot find buffer for an" | |
2421 | " unsolicited iocb. tag 0x%x\n", | |
2422 | pring->ringno, | |
2423 | irsp->unsli3.sli3Words[7]); | |
2424 | } | |
2425 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2426 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2427 | if (irsp->ulpBdeCount != 0) { |
2428 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2429 | irsp->un.ulpWord[3]); | |
9c2face6 | 2430 | if (!iocbq->context2) |
76bb24ef JS |
2431 | lpfc_printf_log(phba, |
2432 | KERN_ERR, | |
2433 | LOG_SLI, | |
2434 | "0343 Ring %d Cannot find " | |
2435 | "buffer for an unsolicited iocb" | |
2436 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2437 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2438 | } |
2439 | if (irsp->ulpBdeCount == 2) { | |
2440 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2441 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2442 | if (!iocbq->context3) |
76bb24ef JS |
2443 | lpfc_printf_log(phba, |
2444 | KERN_ERR, | |
2445 | LOG_SLI, | |
2446 | "0344 Ring %d Cannot find " | |
2447 | "buffer for an unsolicited " | |
2448 | "iocb. tag 0x%x\n", | |
2449 | pring->ringno, | |
2450 | irsp->unsli3.sli3Words[7]); | |
2451 | } | |
2452 | } | |
92d7f7b0 | 2453 | } |
9c2face6 JS |
2454 | if (irsp->ulpBdeCount != 0 && |
2455 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2456 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2457 | int found = 0; | |
2458 | ||
2459 | /* search continue save q for same XRI */ | |
2460 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
7851fe2c JS |
2461 | if (iocbq->iocb.unsli3.rcvsli3.ox_id == |
2462 | saveq->iocb.unsli3.rcvsli3.ox_id) { | |
9c2face6 JS |
2463 | list_add_tail(&saveq->list, &iocbq->list); |
2464 | found = 1; | |
2465 | break; | |
2466 | } | |
2467 | } | |
2468 | if (!found) | |
2469 | list_add_tail(&saveq->clist, | |
2470 | &pring->iocb_continue_saveq); | |
2471 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2472 | list_del_init(&iocbq->clist); | |
2473 | saveq = iocbq; | |
2474 | irsp = &(saveq->iocb); | |
2475 | } else | |
2476 | return 0; | |
2477 | } | |
2478 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2479 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2480 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2481 | Rctl = FC_RCTL_ELS_REQ; |
2482 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2483 | } else { |
2484 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2485 | Rctl = w5p->hcsw.Rctl; | |
2486 | Type = w5p->hcsw.Type; | |
2487 | ||
2488 | /* Firmware Workaround */ | |
2489 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2490 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2491 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2492 | Rctl = FC_RCTL_ELS_REQ; |
2493 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2494 | w5p->hcsw.Rctl = Rctl; |
2495 | w5p->hcsw.Type = Type; | |
2496 | } | |
2497 | } | |
92d7f7b0 | 2498 | |
3772a991 | 2499 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2500 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2501 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2502 | "Type x%x received\n", |
e8b62011 | 2503 | pring->ringno, Rctl, Type); |
3772a991 | 2504 | |
92d7f7b0 | 2505 | return 1; |
dea3101e | 2506 | } |
2507 | ||
e59058c4 | 2508 | /** |
3621a710 | 2509 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2510 | * @phba: Pointer to HBA context object. |
2511 | * @pring: Pointer to driver SLI ring object. | |
2512 | * @prspiocb: Pointer to response iocb object. | |
2513 | * | |
2514 | * This function looks up the iocb_lookup table to get the command iocb | |
2515 | * corresponding to the given response iocb using the iotag of the | |
2516 | * response iocb. This function is called with the hbalock held. | |
2517 | * This function returns the command iocb object if it finds the command | |
2518 | * iocb else returns NULL. | |
2519 | **/ | |
dea3101e | 2520 | static struct lpfc_iocbq * |
2e0fef85 JS |
2521 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2522 | struct lpfc_sli_ring *pring, | |
2523 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2524 | { |
dea3101e | 2525 | struct lpfc_iocbq *cmd_iocb = NULL; |
2526 | uint16_t iotag; | |
2527 | ||
604a3e30 JB |
2528 | iotag = prspiocb->iocb.ulpIoTag; |
2529 | ||
2530 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2531 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2532 | list_del_init(&cmd_iocb->list); |
2a9bf3d0 JS |
2533 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2534 | pring->txcmplq_cnt--; | |
2535 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2536 | } | |
604a3e30 | 2537 | return cmd_iocb; |
dea3101e | 2538 | } |
2539 | ||
dea3101e | 2540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2541 | "0317 iotag x%x is out off " |
604a3e30 | 2542 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2543 | iotag, phba->sli.last_iotag, |
604a3e30 | 2544 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e | 2545 | return NULL; |
2546 | } | |
2547 | ||
3772a991 JS |
2548 | /** |
2549 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2550 | * @phba: Pointer to HBA context object. | |
2551 | * @pring: Pointer to driver SLI ring object. | |
2552 | * @iotag: IOCB tag. | |
2553 | * | |
2554 | * This function looks up the iocb_lookup table to get the command iocb | |
2555 | * corresponding to the given iotag. This function is called with the | |
2556 | * hbalock held. | |
2557 | * This function returns the command iocb object if it finds the command | |
2558 | * iocb else returns NULL. | |
2559 | **/ | |
2560 | static struct lpfc_iocbq * | |
2561 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2562 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2563 | { | |
2564 | struct lpfc_iocbq *cmd_iocb; | |
2565 | ||
2566 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2567 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
2568 | list_del_init(&cmd_iocb->list); | |
2a9bf3d0 JS |
2569 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2570 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2571 | pring->txcmplq_cnt--; | |
2572 | } | |
3772a991 JS |
2573 | return cmd_iocb; |
2574 | } | |
2575 | ||
2576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2577 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2578 | iotag, phba->sli.last_iotag); | |
2579 | return NULL; | |
2580 | } | |
2581 | ||
e59058c4 | 2582 | /** |
3621a710 | 2583 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2584 | * @phba: Pointer to HBA context object. |
2585 | * @pring: Pointer to driver SLI ring object. | |
2586 | * @saveq: Pointer to the response iocb to be processed. | |
2587 | * | |
2588 | * This function is called by the ring event handler for non-fcp | |
2589 | * rings when there is a new response iocb in the response ring. | |
2590 | * The caller is not required to hold any locks. This function | |
2591 | * gets the command iocb associated with the response iocb and | |
2592 | * calls the completion handler for the command iocb. If there | |
2593 | * is no completion handler, the function will free the resources | |
2594 | * associated with command iocb. If the response iocb is for | |
2595 | * an already aborted command iocb, the status of the completion | |
2596 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2597 | * This function always returns 1. | |
2598 | **/ | |
dea3101e | 2599 | static int |
2e0fef85 | 2600 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e | 2601 | struct lpfc_iocbq *saveq) |
2602 | { | |
2e0fef85 | 2603 | struct lpfc_iocbq *cmdiocbp; |
dea3101e | 2604 | int rc = 1; |
2605 | unsigned long iflag; | |
2606 | ||
2607 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2608 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2609 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2610 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2611 | ||
dea3101e | 2612 | if (cmdiocbp) { |
2613 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2614 | /* |
2615 | * If an ELS command failed send an event to mgmt | |
2616 | * application. | |
2617 | */ | |
2618 | if (saveq->iocb.ulpStatus && | |
2619 | (pring->ringno == LPFC_ELS_RING) && | |
2620 | (cmdiocbp->iocb.ulpCommand == | |
2621 | CMD_ELS_REQUEST64_CR)) | |
2622 | lpfc_send_els_failure_event(phba, | |
2623 | cmdiocbp, saveq); | |
2624 | ||
dea3101e | 2625 | /* |
2626 | * Post all ELS completions to the worker thread. | |
2627 | * All other are passed to the completion callback. | |
2628 | */ | |
2629 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2630 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2631 | (cmdiocbp->iocb_flag & | |
2632 | LPFC_DRIVER_ABORTED)) { | |
2633 | spin_lock_irqsave(&phba->hbalock, | |
2634 | iflag); | |
07951076 JS |
2635 | cmdiocbp->iocb_flag &= |
2636 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2637 | spin_unlock_irqrestore(&phba->hbalock, |
2638 | iflag); | |
07951076 JS |
2639 | saveq->iocb.ulpStatus = |
2640 | IOSTAT_LOCAL_REJECT; | |
2641 | saveq->iocb.un.ulpWord[4] = | |
2642 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2643 | |
2644 | /* Firmware could still be in progress | |
2645 | * of DMAing payload, so don't free data | |
2646 | * buffer till after a hbeat. | |
2647 | */ | |
341af102 JS |
2648 | spin_lock_irqsave(&phba->hbalock, |
2649 | iflag); | |
0ff10d46 | 2650 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2651 | spin_unlock_irqrestore(&phba->hbalock, |
2652 | iflag); | |
2653 | } | |
0f65ff68 JS |
2654 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2655 | if (saveq->iocb_flag & | |
2656 | LPFC_EXCHANGE_BUSY) { | |
2657 | /* Set cmdiocb flag for the | |
2658 | * exchange busy so sgl (xri) | |
2659 | * will not be released until | |
2660 | * the abort xri is received | |
2661 | * from hba. | |
2662 | */ | |
2663 | spin_lock_irqsave( | |
2664 | &phba->hbalock, iflag); | |
2665 | cmdiocbp->iocb_flag |= | |
2666 | LPFC_EXCHANGE_BUSY; | |
2667 | spin_unlock_irqrestore( | |
2668 | &phba->hbalock, iflag); | |
2669 | } | |
2670 | if (cmdiocbp->iocb_flag & | |
2671 | LPFC_DRIVER_ABORTED) { | |
2672 | /* | |
2673 | * Clear LPFC_DRIVER_ABORTED | |
2674 | * bit in case it was driver | |
2675 | * initiated abort. | |
2676 | */ | |
2677 | spin_lock_irqsave( | |
2678 | &phba->hbalock, iflag); | |
2679 | cmdiocbp->iocb_flag &= | |
2680 | ~LPFC_DRIVER_ABORTED; | |
2681 | spin_unlock_irqrestore( | |
2682 | &phba->hbalock, iflag); | |
2683 | cmdiocbp->iocb.ulpStatus = | |
2684 | IOSTAT_LOCAL_REJECT; | |
2685 | cmdiocbp->iocb.un.ulpWord[4] = | |
2686 | IOERR_ABORT_REQUESTED; | |
2687 | /* | |
2688 | * For SLI4, irsiocb contains | |
2689 | * NO_XRI in sli_xritag, it | |
2690 | * shall not affect releasing | |
2691 | * sgl (xri) process. | |
2692 | */ | |
2693 | saveq->iocb.ulpStatus = | |
2694 | IOSTAT_LOCAL_REJECT; | |
2695 | saveq->iocb.un.ulpWord[4] = | |
2696 | IOERR_SLI_ABORTED; | |
2697 | spin_lock_irqsave( | |
2698 | &phba->hbalock, iflag); | |
2699 | saveq->iocb_flag |= | |
2700 | LPFC_DELAY_MEM_FREE; | |
2701 | spin_unlock_irqrestore( | |
2702 | &phba->hbalock, iflag); | |
2703 | } | |
07951076 | 2704 | } |
dea3101e | 2705 | } |
2e0fef85 | 2706 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2707 | } else |
2708 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e | 2709 | } else { |
2710 | /* | |
2711 | * Unknown initiating command based on the response iotag. | |
2712 | * This could be the case on the ELS ring because of | |
2713 | * lpfc_els_abort(). | |
2714 | */ | |
2715 | if (pring->ringno != LPFC_ELS_RING) { | |
2716 | /* | |
2717 | * Ring <ringno> handler: unexpected completion IoTag | |
2718 | * <IoTag> | |
2719 | */ | |
a257bf90 | 2720 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2721 | "0322 Ring %d handler: " |
2722 | "unexpected completion IoTag x%x " | |
2723 | "Data: x%x x%x x%x x%x\n", | |
2724 | pring->ringno, | |
2725 | saveq->iocb.ulpIoTag, | |
2726 | saveq->iocb.ulpStatus, | |
2727 | saveq->iocb.un.ulpWord[4], | |
2728 | saveq->iocb.ulpCommand, | |
2729 | saveq->iocb.ulpContext); | |
dea3101e | 2730 | } |
2731 | } | |
68876920 | 2732 | |
dea3101e | 2733 | return rc; |
2734 | } | |
2735 | ||
e59058c4 | 2736 | /** |
3621a710 | 2737 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2738 | * @phba: Pointer to HBA context object. |
2739 | * @pring: Pointer to driver SLI ring object. | |
2740 | * | |
2741 | * This function is called from the iocb ring event handlers when | |
2742 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2743 | * an error attention condition to the worker thread and the worker | |
2744 | * thread will transition the HBA to offline state. | |
2745 | **/ | |
2e0fef85 JS |
2746 | static void |
2747 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2748 | { |
34b02dcd | 2749 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2750 | /* |
025dfdaf | 2751 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2752 | * rsp ring <portRspMax> |
2753 | */ | |
2754 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2755 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2756 | "is bigger than rsp ring %d\n", |
e8b62011 | 2757 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
2758 | pring->numRiocb); |
2759 | ||
2e0fef85 | 2760 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2761 | |
2762 | /* | |
2763 | * All error attention handlers are posted to | |
2764 | * worker thread | |
2765 | */ | |
2766 | phba->work_ha |= HA_ERATT; | |
2767 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2768 | |
5e9d9b82 | 2769 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2770 | |
2771 | return; | |
2772 | } | |
2773 | ||
9399627f | 2774 | /** |
3621a710 | 2775 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2776 | * @ptr: Pointer to address of HBA context object. |
2777 | * | |
2778 | * This function is invoked by the Error Attention polling timer when the | |
2779 | * timer times out. It will check the SLI Error Attention register for | |
2780 | * possible attention events. If so, it will post an Error Attention event | |
2781 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2782 | * Error Attention polling timer for the next poll. | |
2783 | **/ | |
2784 | void lpfc_poll_eratt(unsigned long ptr) | |
2785 | { | |
2786 | struct lpfc_hba *phba; | |
2787 | uint32_t eratt = 0; | |
2788 | ||
2789 | phba = (struct lpfc_hba *)ptr; | |
2790 | ||
2791 | /* Check chip HA register for error event */ | |
2792 | eratt = lpfc_sli_check_eratt(phba); | |
2793 | ||
2794 | if (eratt) | |
2795 | /* Tell the worker thread there is work to do */ | |
2796 | lpfc_worker_wake_up(phba); | |
2797 | else | |
2798 | /* Restart the timer for next eratt poll */ | |
2799 | mod_timer(&phba->eratt_poll, jiffies + | |
2800 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2801 | return; | |
2802 | } | |
2803 | ||
875fbdfe | 2804 | |
e59058c4 | 2805 | /** |
3621a710 | 2806 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2807 | * @phba: Pointer to HBA context object. |
2808 | * @pring: Pointer to driver SLI ring object. | |
2809 | * @mask: Host attention register mask for this ring. | |
2810 | * | |
2811 | * This function is called from the interrupt context when there is a ring | |
2812 | * event for the fcp ring. The caller does not hold any lock. | |
2813 | * The function processes each response iocb in the response ring until it | |
25985edc | 2814 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2815 | * LE bit set. The function will call the completion handler of the command iocb |
2816 | * if the response iocb indicates a completion for a command iocb or it is | |
2817 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2818 | * function if this is an unsolicited iocb. | |
dea3101e | 2819 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2820 | * to check it explicitly. |
2821 | */ | |
2822 | int | |
2e0fef85 JS |
2823 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2824 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2825 | { |
34b02dcd | 2826 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2827 | IOCB_t *irsp = NULL; |
87f6eaff | 2828 | IOCB_t *entry = NULL; |
dea3101e | 2829 | struct lpfc_iocbq *cmdiocbq = NULL; |
2830 | struct lpfc_iocbq rspiocbq; | |
dea3101e | 2831 | uint32_t status; |
2832 | uint32_t portRspPut, portRspMax; | |
2833 | int rc = 1; | |
2834 | lpfc_iocb_type type; | |
2835 | unsigned long iflag; | |
2836 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2837 | |
2e0fef85 | 2838 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 2839 | pring->stats.iocb_event++; |
2840 | ||
dea3101e | 2841 | /* |
2842 | * The next available response entry should never exceed the maximum | |
2843 | * entries. If it does, treat it as an adapter hardware error. | |
2844 | */ | |
2845 | portRspMax = pring->numRiocb; | |
2846 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2847 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2848 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2849 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2850 | return 1; |
2851 | } | |
45ed1190 JS |
2852 | if (phba->fcp_ring_in_use) { |
2853 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2854 | return 1; | |
2855 | } else | |
2856 | phba->fcp_ring_in_use = 1; | |
dea3101e | 2857 | |
2858 | rmb(); | |
2859 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
2860 | /* |
2861 | * Fetch an entry off the ring and copy it into a local data | |
2862 | * structure. The copy involves a byte-swap since the | |
2863 | * network byte order and pci byte orders are different. | |
2864 | */ | |
ed957684 | 2865 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2866 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
2867 | |
2868 | if (++pring->rspidx >= portRspMax) | |
2869 | pring->rspidx = 0; | |
2870 | ||
87f6eaff JSEC |
2871 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2872 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2873 | phba->iocb_rsp_size); |
a4bc3379 | 2874 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2875 | irsp = &rspiocbq.iocb; |
2876 | ||
dea3101e | 2877 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2878 | pring->stats.iocb_rsp++; | |
2879 | rsp_cmpl++; | |
2880 | ||
2881 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2882 | /* |
2883 | * If resource errors reported from HBA, reduce | |
2884 | * queuedepths of the SCSI device. | |
2885 | */ | |
2886 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2887 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2888 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2889 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2890 | spin_lock_irqsave(&phba->hbalock, iflag); |
2891 | } | |
2892 | ||
dea3101e | 2893 | /* Rsp ring <ringno> error: IOCB */ |
2894 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2895 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2896 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2897 | pring->ringno, |
92d7f7b0 JS |
2898 | irsp->un.ulpWord[0], |
2899 | irsp->un.ulpWord[1], | |
2900 | irsp->un.ulpWord[2], | |
2901 | irsp->un.ulpWord[3], | |
2902 | irsp->un.ulpWord[4], | |
2903 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2904 | *(uint32_t *)&irsp->un1, |
2905 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e | 2906 | } |
2907 | ||
2908 | switch (type) { | |
2909 | case LPFC_ABORT_IOCB: | |
2910 | case LPFC_SOL_IOCB: | |
2911 | /* | |
2912 | * Idle exchange closed via ABTS from port. No iocb | |
2913 | * resources need to be recovered. | |
2914 | */ | |
2915 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2916 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2917 | "0333 IOCB cmd 0x%x" |
dca9479b | 2918 | " processed. Skipping" |
92d7f7b0 | 2919 | " completion\n", |
dca9479b | 2920 | irsp->ulpCommand); |
dea3101e | 2921 | break; |
2922 | } | |
2923 | ||
604a3e30 JB |
2924 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2925 | &rspiocbq); | |
0f65ff68 JS |
2926 | if (unlikely(!cmdiocbq)) |
2927 | break; | |
2928 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2929 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2930 | if (cmdiocbq->iocb_cmpl) { | |
2931 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2932 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2933 | &rspiocbq); | |
2934 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2935 | } | |
dea3101e | 2936 | break; |
a4bc3379 | 2937 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2938 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2939 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2940 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2941 | break; |
dea3101e | 2942 | default: |
2943 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2944 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2945 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2946 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2947 | MAX_MSG_DATA); | |
898eb71c JP |
2948 | dev_warn(&((phba->pcidev)->dev), |
2949 | "lpfc%d: %s\n", | |
dea3101e | 2950 | phba->brd_no, adaptermsg); |
2951 | } else { | |
2952 | /* Unknown IOCB command */ | |
2953 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2954 | "0334 Unknown IOCB command " |
92d7f7b0 | 2955 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2956 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2957 | irsp->ulpStatus, |
2958 | irsp->ulpIoTag, | |
2959 | irsp->ulpContext); | |
dea3101e | 2960 | } |
2961 | break; | |
2962 | } | |
2963 | ||
2964 | /* | |
2965 | * The response IOCB has been processed. Update the ring | |
2966 | * pointer in SLIM. If the port response put pointer has not | |
2967 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2968 | * response put pointer. | |
2969 | */ | |
ed957684 | 2970 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 2971 | |
2972 | if (pring->rspidx == portRspPut) | |
2973 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2974 | } | |
2975 | ||
2976 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
2977 | pring->stats.iocb_rsp_full++; | |
2978 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2979 | writel(status, phba->CAregaddr); | |
2980 | readl(phba->CAregaddr); | |
2981 | } | |
2982 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2983 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2984 | pring->stats.iocb_cmd_empty++; | |
2985 | ||
2986 | /* Force update of the local copy of cmdGetInx */ | |
2987 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2988 | lpfc_sli_resume_iocb(phba, pring); | |
2989 | ||
2990 | if ((pring->lpfc_sli_cmd_available)) | |
2991 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2992 | ||
2993 | } | |
2994 | ||
45ed1190 | 2995 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 2996 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2997 | return rc; |
2998 | } | |
2999 | ||
e59058c4 | 3000 | /** |
3772a991 JS |
3001 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3002 | * @phba: Pointer to HBA context object. | |
3003 | * @pring: Pointer to driver SLI ring object. | |
3004 | * @rspiocbp: Pointer to driver response IOCB object. | |
3005 | * | |
3006 | * This function is called from the worker thread when there is a slow-path | |
3007 | * response IOCB to process. This function chains all the response iocbs until | |
3008 | * seeing the iocb with the LE bit set. The function will call | |
3009 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3010 | * completion of a command iocb. The function will call the | |
3011 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3012 | * The function frees the resources or calls the completion handler if this | |
3013 | * iocb is an abort completion. The function returns NULL when the response | |
3014 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3015 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3016 | * response iocb passed in. | |
3017 | **/ | |
3018 | static struct lpfc_iocbq * | |
3019 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3020 | struct lpfc_iocbq *rspiocbp) | |
3021 | { | |
3022 | struct lpfc_iocbq *saveq; | |
3023 | struct lpfc_iocbq *cmdiocbp; | |
3024 | struct lpfc_iocbq *next_iocb; | |
3025 | IOCB_t *irsp = NULL; | |
3026 | uint32_t free_saveq; | |
3027 | uint8_t iocb_cmd_type; | |
3028 | lpfc_iocb_type type; | |
3029 | unsigned long iflag; | |
3030 | int rc; | |
3031 | ||
3032 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3033 | /* First add the response iocb to the countinueq list */ | |
3034 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3035 | pring->iocb_continueq_cnt++; | |
3036 | ||
70f23fd6 | 3037 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3038 | irsp = &rspiocbp->iocb; |
3039 | if (irsp->ulpLe) { | |
3040 | /* | |
3041 | * By default, the driver expects to free all resources | |
3042 | * associated with this iocb completion. | |
3043 | */ | |
3044 | free_saveq = 1; | |
3045 | saveq = list_get_first(&pring->iocb_continueq, | |
3046 | struct lpfc_iocbq, list); | |
3047 | irsp = &(saveq->iocb); | |
3048 | list_del_init(&pring->iocb_continueq); | |
3049 | pring->iocb_continueq_cnt = 0; | |
3050 | ||
3051 | pring->stats.iocb_rsp++; | |
3052 | ||
3053 | /* | |
3054 | * If resource errors reported from HBA, reduce | |
3055 | * queuedepths of the SCSI device. | |
3056 | */ | |
3057 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3058 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3059 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3060 | phba->lpfc_rampdown_queue_depth(phba); | |
3061 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3062 | } | |
3063 | ||
3064 | if (irsp->ulpStatus) { | |
3065 | /* Rsp ring <ringno> error: IOCB */ | |
3066 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3067 | "0328 Rsp Ring %d error: " | |
3068 | "IOCB Data: " | |
3069 | "x%x x%x x%x x%x " | |
3070 | "x%x x%x x%x x%x " | |
3071 | "x%x x%x x%x x%x " | |
3072 | "x%x x%x x%x x%x\n", | |
3073 | pring->ringno, | |
3074 | irsp->un.ulpWord[0], | |
3075 | irsp->un.ulpWord[1], | |
3076 | irsp->un.ulpWord[2], | |
3077 | irsp->un.ulpWord[3], | |
3078 | irsp->un.ulpWord[4], | |
3079 | irsp->un.ulpWord[5], | |
3080 | *(((uint32_t *) irsp) + 6), | |
3081 | *(((uint32_t *) irsp) + 7), | |
3082 | *(((uint32_t *) irsp) + 8), | |
3083 | *(((uint32_t *) irsp) + 9), | |
3084 | *(((uint32_t *) irsp) + 10), | |
3085 | *(((uint32_t *) irsp) + 11), | |
3086 | *(((uint32_t *) irsp) + 12), | |
3087 | *(((uint32_t *) irsp) + 13), | |
3088 | *(((uint32_t *) irsp) + 14), | |
3089 | *(((uint32_t *) irsp) + 15)); | |
3090 | } | |
3091 | ||
3092 | /* | |
3093 | * Fetch the IOCB command type and call the correct completion | |
3094 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3095 | * get freed back to the lpfc_iocb_list by the discovery | |
3096 | * kernel thread. | |
3097 | */ | |
3098 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3099 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3100 | switch (type) { | |
3101 | case LPFC_SOL_IOCB: | |
3102 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3103 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3104 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3105 | break; | |
3106 | ||
3107 | case LPFC_UNSOL_IOCB: | |
3108 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3109 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3110 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3111 | if (!rc) | |
3112 | free_saveq = 0; | |
3113 | break; | |
3114 | ||
3115 | case LPFC_ABORT_IOCB: | |
3116 | cmdiocbp = NULL; | |
3117 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3118 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3119 | saveq); | |
3120 | if (cmdiocbp) { | |
3121 | /* Call the specified completion routine */ | |
3122 | if (cmdiocbp->iocb_cmpl) { | |
3123 | spin_unlock_irqrestore(&phba->hbalock, | |
3124 | iflag); | |
3125 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3126 | saveq); | |
3127 | spin_lock_irqsave(&phba->hbalock, | |
3128 | iflag); | |
3129 | } else | |
3130 | __lpfc_sli_release_iocbq(phba, | |
3131 | cmdiocbp); | |
3132 | } | |
3133 | break; | |
3134 | ||
3135 | case LPFC_UNKNOWN_IOCB: | |
3136 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3137 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3138 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3139 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3140 | MAX_MSG_DATA); | |
3141 | dev_warn(&((phba->pcidev)->dev), | |
3142 | "lpfc%d: %s\n", | |
3143 | phba->brd_no, adaptermsg); | |
3144 | } else { | |
3145 | /* Unknown IOCB command */ | |
3146 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3147 | "0335 Unknown IOCB " | |
3148 | "command Data: x%x " | |
3149 | "x%x x%x x%x\n", | |
3150 | irsp->ulpCommand, | |
3151 | irsp->ulpStatus, | |
3152 | irsp->ulpIoTag, | |
3153 | irsp->ulpContext); | |
3154 | } | |
3155 | break; | |
3156 | } | |
3157 | ||
3158 | if (free_saveq) { | |
3159 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3160 | &saveq->list, list) { | |
3161 | list_del(&rspiocbp->list); | |
3162 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3163 | } | |
3164 | __lpfc_sli_release_iocbq(phba, saveq); | |
3165 | } | |
3166 | rspiocbp = NULL; | |
3167 | } | |
3168 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3169 | return rspiocbp; | |
3170 | } | |
3171 | ||
3172 | /** | |
3173 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3174 | * @phba: Pointer to HBA context object. |
3175 | * @pring: Pointer to driver SLI ring object. | |
3176 | * @mask: Host attention register mask for this ring. | |
3177 | * | |
3772a991 JS |
3178 | * This routine wraps the actual slow_ring event process routine from the |
3179 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3180 | **/ |
3772a991 | 3181 | void |
2e0fef85 JS |
3182 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3183 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3184 | { |
3185 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3186 | } | |
3187 | ||
3188 | /** | |
3189 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3190 | * @phba: Pointer to HBA context object. | |
3191 | * @pring: Pointer to driver SLI ring object. | |
3192 | * @mask: Host attention register mask for this ring. | |
3193 | * | |
3194 | * This function is called from the worker thread when there is a ring event | |
3195 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3196 | * remove each response iocb in the response ring and calls the handle | |
3197 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3198 | **/ | |
3199 | static void | |
3200 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3201 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3202 | { |
34b02dcd | 3203 | struct lpfc_pgp *pgp; |
dea3101e | 3204 | IOCB_t *entry; |
3205 | IOCB_t *irsp = NULL; | |
3206 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3207 | uint32_t portRspPut, portRspMax; |
dea3101e | 3208 | unsigned long iflag; |
3772a991 | 3209 | uint32_t status; |
dea3101e | 3210 | |
34b02dcd | 3211 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3212 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 3213 | pring->stats.iocb_event++; |
3214 | ||
dea3101e | 3215 | /* |
3216 | * The next available response entry should never exceed the maximum | |
3217 | * entries. If it does, treat it as an adapter hardware error. | |
3218 | */ | |
3219 | portRspMax = pring->numRiocb; | |
3220 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3221 | if (portRspPut >= portRspMax) { | |
3222 | /* | |
025dfdaf | 3223 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e | 3224 | * rsp ring <portRspMax> |
3225 | */ | |
ed957684 | 3226 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3227 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3228 | "is bigger than rsp ring %d\n", |
e8b62011 | 3229 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3230 | |
2e0fef85 JS |
3231 | phba->link_state = LPFC_HBA_ERROR; |
3232 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e | 3233 | |
3234 | phba->work_hs = HS_FFER3; | |
3235 | lpfc_handle_eratt(phba); | |
3236 | ||
3772a991 | 3237 | return; |
dea3101e | 3238 | } |
3239 | ||
3240 | rmb(); | |
dea3101e | 3241 | while (pring->rspidx != portRspPut) { |
3242 | /* | |
3243 | * Build a completion list and call the appropriate handler. | |
3244 | * The process is to get the next available response iocb, get | |
3245 | * a free iocb from the list, copy the response data into the | |
3246 | * free iocb, insert to the continuation list, and update the | |
3247 | * next response index to slim. This process makes response | |
3248 | * iocb's in the ring available to DMA as fast as possible but | |
3249 | * pays a penalty for a copy operation. Since the iocb is | |
3250 | * only 32 bytes, this penalty is considered small relative to | |
3251 | * the PCI reads for register values and a slim write. When | |
3252 | * the ulpLe field is set, the entire Command has been | |
3253 | * received. | |
3254 | */ | |
ed957684 JS |
3255 | entry = lpfc_resp_iocb(phba, pring); |
3256 | ||
858c9f6c | 3257 | phba->last_completion_time = jiffies; |
2e0fef85 | 3258 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 3259 | if (rspiocbp == NULL) { |
3260 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3261 | "completion.\n", __func__); |
dea3101e | 3262 | break; |
3263 | } | |
3264 | ||
ed957684 JS |
3265 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3266 | phba->iocb_rsp_size); | |
dea3101e | 3267 | irsp = &rspiocbp->iocb; |
3268 | ||
3269 | if (++pring->rspidx >= portRspMax) | |
3270 | pring->rspidx = 0; | |
3271 | ||
a58cbd52 JS |
3272 | if (pring->ringno == LPFC_ELS_RING) { |
3273 | lpfc_debugfs_slow_ring_trc(phba, | |
3274 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3275 | *(((uint32_t *) irsp) + 4), | |
3276 | *(((uint32_t *) irsp) + 6), | |
3277 | *(((uint32_t *) irsp) + 7)); | |
3278 | } | |
3279 | ||
ed957684 | 3280 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 3281 | |
3772a991 JS |
3282 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3283 | /* Handle the response IOCB */ | |
3284 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3285 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e | 3286 | |
3287 | /* | |
3288 | * If the port response put pointer has not been updated, sync | |
3289 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3290 | * response put pointer. | |
3291 | */ | |
3292 | if (pring->rspidx == portRspPut) { | |
3293 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3294 | } | |
3295 | } /* while (pring->rspidx != portRspPut) */ | |
3296 | ||
92d7f7b0 | 3297 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e | 3298 | /* At least one response entry has been freed */ |
3299 | pring->stats.iocb_rsp_full++; | |
3300 | /* SET RxRE_RSP in Chip Att register */ | |
3301 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3302 | writel(status, phba->CAregaddr); | |
3303 | readl(phba->CAregaddr); /* flush */ | |
3304 | } | |
3305 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3306 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3307 | pring->stats.iocb_cmd_empty++; | |
3308 | ||
3309 | /* Force update of the local copy of cmdGetInx */ | |
3310 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3311 | lpfc_sli_resume_iocb(phba, pring); | |
3312 | ||
3313 | if ((pring->lpfc_sli_cmd_available)) | |
3314 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3315 | ||
3316 | } | |
3317 | ||
2e0fef85 | 3318 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3319 | return; |
dea3101e | 3320 | } |
3321 | ||
4f774513 JS |
3322 | /** |
3323 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3324 | * @phba: Pointer to HBA context object. | |
3325 | * @pring: Pointer to driver SLI ring object. | |
3326 | * @mask: Host attention register mask for this ring. | |
3327 | * | |
3328 | * This function is called from the worker thread when there is a pending | |
3329 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3330 | * queue. The caller does not hold any lock. The function will remove each | |
3331 | * response iocb from the response worker queue and calls the handle | |
3332 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3333 | **/ | |
3334 | static void | |
3335 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3336 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3337 | { | |
3338 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3339 | struct hbq_dmabuf *dmabuf; |
3340 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3341 | unsigned long iflag; |
3342 | ||
45ed1190 JS |
3343 | spin_lock_irqsave(&phba->hbalock, iflag); |
3344 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3345 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3346 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3347 | /* Get the response iocb from the head of work queue */ |
3348 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3349 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3350 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3351 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3352 | |
3353 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3354 | case CQE_CODE_COMPL_WQE: | |
3355 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3356 | cq_event); | |
45ed1190 JS |
3357 | /* Translate ELS WCQE to response IOCBQ */ |
3358 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3359 | irspiocbq); | |
3360 | if (irspiocbq) | |
3361 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3362 | irspiocbq); | |
4d9ab994 JS |
3363 | break; |
3364 | case CQE_CODE_RECEIVE: | |
7851fe2c | 3365 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 JS |
3366 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
3367 | cq_event); | |
3368 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3369 | break; | |
3370 | default: | |
3371 | break; | |
3372 | } | |
4f774513 JS |
3373 | } |
3374 | } | |
3375 | ||
e59058c4 | 3376 | /** |
3621a710 | 3377 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3378 | * @phba: Pointer to HBA context object. |
3379 | * @pring: Pointer to driver SLI ring object. | |
3380 | * | |
3381 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3382 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3383 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3384 | * the return of this function. The caller is not required to hold any locks. | |
3385 | **/ | |
2e0fef85 | 3386 | void |
dea3101e | 3387 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3388 | { | |
2534ba75 | 3389 | LIST_HEAD(completions); |
dea3101e | 3390 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3391 | |
92d7f7b0 JS |
3392 | if (pring->ringno == LPFC_ELS_RING) { |
3393 | lpfc_fabric_abort_hba(phba); | |
3394 | } | |
3395 | ||
dea3101e | 3396 | /* Error everything on txq and txcmplq |
3397 | * First do the txq. | |
3398 | */ | |
2e0fef85 | 3399 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3400 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3401 | pring->txq_cnt = 0; |
dea3101e | 3402 | |
3403 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3404 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3405 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3406 | |
2e0fef85 | 3407 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3408 | |
a257bf90 JS |
3409 | /* Cancel all the IOCBs from the completions list */ |
3410 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3411 | IOERR_SLI_ABORTED); | |
dea3101e | 3412 | } |
3413 | ||
a8e497d5 | 3414 | /** |
3621a710 | 3415 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3416 | * @phba: Pointer to HBA context object. |
3417 | * | |
3418 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3419 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3420 | * for all the iocb commands in txcmplq, they will just be returned with | |
3421 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3422 | * slot has been permanently disabled. | |
3423 | **/ | |
3424 | void | |
3425 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3426 | { | |
3427 | LIST_HEAD(txq); | |
3428 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3429 | struct lpfc_sli *psli = &phba->sli; |
3430 | struct lpfc_sli_ring *pring; | |
3431 | ||
3432 | /* Currently, only one fcp ring */ | |
3433 | pring = &psli->ring[psli->fcp_ring]; | |
3434 | ||
3435 | spin_lock_irq(&phba->hbalock); | |
3436 | /* Retrieve everything on txq */ | |
3437 | list_splice_init(&pring->txq, &txq); | |
3438 | pring->txq_cnt = 0; | |
3439 | ||
3440 | /* Retrieve everything on the txcmplq */ | |
3441 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3442 | pring->txcmplq_cnt = 0; | |
3443 | spin_unlock_irq(&phba->hbalock); | |
3444 | ||
3445 | /* Flush the txq */ | |
a257bf90 JS |
3446 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3447 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3448 | |
3449 | /* Flush the txcmpq */ | |
a257bf90 JS |
3450 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3451 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3452 | } |
3453 | ||
e59058c4 | 3454 | /** |
3772a991 | 3455 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3456 | * @phba: Pointer to HBA context object. |
3457 | * @mask: Bit mask to be checked. | |
3458 | * | |
3459 | * This function reads the host status register and compares | |
3460 | * with the provided bit mask to check if HBA completed | |
3461 | * the restart. This function will wait in a loop for the | |
3462 | * HBA to complete restart. If the HBA does not restart within | |
3463 | * 15 iterations, the function will reset the HBA again. The | |
3464 | * function returns 1 when HBA fail to restart otherwise returns | |
3465 | * zero. | |
3466 | **/ | |
3772a991 JS |
3467 | static int |
3468 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3469 | { |
41415862 JW |
3470 | uint32_t status; |
3471 | int i = 0; | |
3472 | int retval = 0; | |
dea3101e | 3473 | |
41415862 | 3474 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3475 | if (lpfc_readl(phba->HSregaddr, &status)) |
3476 | return 1; | |
dea3101e | 3477 | |
41415862 JW |
3478 | /* |
3479 | * Check status register every 100ms for 5 retries, then every | |
3480 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3481 | * every 2.5 sec for 4. | |
3482 | * Break our of the loop if errors occurred during init. | |
3483 | */ | |
3484 | while (((status & mask) != mask) && | |
3485 | !(status & HS_FFERM) && | |
3486 | i++ < 20) { | |
dea3101e | 3487 | |
41415862 JW |
3488 | if (i <= 5) |
3489 | msleep(10); | |
3490 | else if (i <= 10) | |
3491 | msleep(500); | |
3492 | else | |
3493 | msleep(2500); | |
dea3101e | 3494 | |
41415862 | 3495 | if (i == 15) { |
2e0fef85 | 3496 | /* Do post */ |
92d7f7b0 | 3497 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3498 | lpfc_sli_brdrestart(phba); |
3499 | } | |
3500 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3501 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3502 | retval = 1; | |
3503 | break; | |
3504 | } | |
41415862 | 3505 | } |
dea3101e | 3506 | |
41415862 JW |
3507 | /* Check to see if any errors occurred during init */ |
3508 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3509 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3510 | "2751 Adapter failed to restart, " | |
3511 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3512 | status, | |
3513 | readl(phba->MBslimaddr + 0xa8), | |
3514 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3515 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3516 | retval = 1; |
dea3101e | 3517 | } |
dea3101e | 3518 | |
41415862 JW |
3519 | return retval; |
3520 | } | |
dea3101e | 3521 | |
da0436e9 JS |
3522 | /** |
3523 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3524 | * @phba: Pointer to HBA context object. | |
3525 | * @mask: Bit mask to be checked. | |
3526 | * | |
3527 | * This function checks the host status register to check if HBA is | |
3528 | * ready. This function will wait in a loop for the HBA to be ready | |
3529 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3530 | * function again. The function returns 1 when HBA fail to be ready | |
3531 | * otherwise returns zero. | |
3532 | **/ | |
3533 | static int | |
3534 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3535 | { | |
3536 | uint32_t status; | |
3537 | int retval = 0; | |
3538 | ||
3539 | /* Read the HBA Host Status Register */ | |
3540 | status = lpfc_sli4_post_status_check(phba); | |
3541 | ||
3542 | if (status) { | |
3543 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3544 | lpfc_sli_brdrestart(phba); | |
3545 | status = lpfc_sli4_post_status_check(phba); | |
3546 | } | |
3547 | ||
3548 | /* Check to see if any errors occurred during init */ | |
3549 | if (status) { | |
3550 | phba->link_state = LPFC_HBA_ERROR; | |
3551 | retval = 1; | |
3552 | } else | |
3553 | phba->sli4_hba.intr_enable = 0; | |
3554 | ||
3555 | return retval; | |
3556 | } | |
3557 | ||
3558 | /** | |
3559 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3560 | * @phba: Pointer to HBA context object. | |
3561 | * @mask: Bit mask to be checked. | |
3562 | * | |
3563 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3564 | * from the API jump table function pointer from the lpfc_hba struct. | |
3565 | **/ | |
3566 | int | |
3567 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3568 | { | |
3569 | return phba->lpfc_sli_brdready(phba, mask); | |
3570 | } | |
3571 | ||
9290831f JS |
3572 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3573 | ||
e59058c4 | 3574 | /** |
3621a710 | 3575 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3576 | * @phba: Pointer to HBA context object. |
3577 | * | |
3578 | * This function is called before resetting an HBA. This | |
3579 | * function requests HBA to quiesce DMAs before a reset. | |
3580 | **/ | |
2e0fef85 | 3581 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3582 | { |
65a29c16 JS |
3583 | uint32_t __iomem *resp_buf; |
3584 | uint32_t __iomem *mbox_buf; | |
9290831f | 3585 | volatile uint32_t mbox; |
9940b97b | 3586 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3587 | int i; |
3588 | uint8_t hdrtype; | |
3589 | ||
3590 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3591 | if (hdrtype != 0x80 || | |
3592 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3593 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3594 | return; | |
3595 | ||
3596 | /* | |
3597 | * Tell the other part of the chip to suspend temporarily all | |
3598 | * its DMA activity. | |
3599 | */ | |
65a29c16 | 3600 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3601 | |
3602 | /* Disable the error attention */ | |
9940b97b JS |
3603 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3604 | return; | |
9290831f JS |
3605 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3606 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3607 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3608 | |
9940b97b JS |
3609 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3610 | return; | |
3611 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3612 | /* Clear Chip error bit */ |
3613 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3614 | phba->pport->stopped = 1; |
9290831f JS |
3615 | } |
3616 | ||
3617 | mbox = 0; | |
3618 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3619 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3620 | ||
3621 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3622 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3623 | writel(mbox, mbox_buf); |
3624 | ||
9940b97b JS |
3625 | for (i = 0; i < 50; i++) { |
3626 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3627 | return; | |
3628 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3629 | mdelay(1); | |
3630 | else | |
3631 | break; | |
3632 | } | |
3633 | resp_data = 0; | |
3634 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3635 | return; | |
3636 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3637 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3638 | phba->pport->stopped) |
9290831f JS |
3639 | goto restore_hc; |
3640 | else | |
3641 | goto clear_errat; | |
3642 | } | |
3643 | ||
3644 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3645 | resp_data = 0; |
3646 | for (i = 0; i < 500; i++) { | |
3647 | if (lpfc_readl(resp_buf, &resp_data)) | |
3648 | return; | |
3649 | if (resp_data != mbox) | |
3650 | mdelay(1); | |
3651 | else | |
3652 | break; | |
3653 | } | |
9290831f JS |
3654 | |
3655 | clear_errat: | |
3656 | ||
9940b97b JS |
3657 | while (++i < 500) { |
3658 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3659 | return; | |
3660 | if (!(ha_copy & HA_ERATT)) | |
3661 | mdelay(1); | |
3662 | else | |
3663 | break; | |
3664 | } | |
9290831f JS |
3665 | |
3666 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3667 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3668 | phba->pport->stopped = 1; |
9290831f JS |
3669 | } |
3670 | ||
3671 | restore_hc: | |
2e0fef85 | 3672 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3673 | writel(hc_copy, phba->HCregaddr); |
3674 | readl(phba->HCregaddr); /* flush */ | |
3675 | } | |
3676 | ||
e59058c4 | 3677 | /** |
3621a710 | 3678 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3679 | * @phba: Pointer to HBA context object. |
3680 | * | |
3681 | * This function issues a kill_board mailbox command and waits for | |
3682 | * the error attention interrupt. This function is called for stopping | |
3683 | * the firmware processing. The caller is not required to hold any | |
3684 | * locks. This function calls lpfc_hba_down_post function to free | |
3685 | * any pending commands after the kill. The function will return 1 when it | |
3686 | * fails to kill the board else will return 0. | |
3687 | **/ | |
41415862 | 3688 | int |
2e0fef85 | 3689 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3690 | { |
3691 | struct lpfc_sli *psli; | |
3692 | LPFC_MBOXQ_t *pmb; | |
3693 | uint32_t status; | |
3694 | uint32_t ha_copy; | |
3695 | int retval; | |
3696 | int i = 0; | |
dea3101e | 3697 | |
41415862 | 3698 | psli = &phba->sli; |
dea3101e | 3699 | |
41415862 | 3700 | /* Kill HBA */ |
ed957684 | 3701 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3702 | "0329 Kill HBA Data: x%x x%x\n", |
3703 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3704 | |
98c9ea5c JS |
3705 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3706 | if (!pmb) | |
41415862 | 3707 | return 1; |
41415862 JW |
3708 | |
3709 | /* Disable the error attention */ | |
2e0fef85 | 3710 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3711 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3712 | spin_unlock_irq(&phba->hbalock); | |
3713 | mempool_free(pmb, phba->mbox_mem_pool); | |
3714 | return 1; | |
3715 | } | |
41415862 JW |
3716 | status &= ~HC_ERINT_ENA; |
3717 | writel(status, phba->HCregaddr); | |
3718 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3719 | phba->link_flag |= LS_IGNORE_ERATT; |
3720 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3721 | |
3722 | lpfc_kill_board(phba, pmb); | |
3723 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3724 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3725 | ||
3726 | if (retval != MBX_SUCCESS) { | |
3727 | if (retval != MBX_BUSY) | |
3728 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3729 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3730 | "2752 KILL_BOARD command failed retval %d\n", | |
3731 | retval); | |
2e0fef85 JS |
3732 | spin_lock_irq(&phba->hbalock); |
3733 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3734 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3735 | return 1; |
3736 | } | |
3737 | ||
f4b4c68f JS |
3738 | spin_lock_irq(&phba->hbalock); |
3739 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3740 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3741 | |
41415862 JW |
3742 | mempool_free(pmb, phba->mbox_mem_pool); |
3743 | ||
3744 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3745 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3746 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3747 | * board is now undefined. | |
3748 | */ | |
9940b97b JS |
3749 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3750 | return 1; | |
41415862 JW |
3751 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3752 | mdelay(100); | |
9940b97b JS |
3753 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3754 | return 1; | |
41415862 JW |
3755 | } |
3756 | ||
3757 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3758 | if (ha_copy & HA_ERATT) { |
3759 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3760 | phba->pport->stopped = 1; |
9290831f | 3761 | } |
2e0fef85 | 3762 | spin_lock_irq(&phba->hbalock); |
41415862 | 3763 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3764 | psli->mbox_active = NULL; |
2e0fef85 JS |
3765 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3766 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3767 | |
41415862 | 3768 | lpfc_hba_down_post(phba); |
2e0fef85 | 3769 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3770 | |
2e0fef85 | 3771 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e | 3772 | } |
3773 | ||
e59058c4 | 3774 | /** |
3772a991 | 3775 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3776 | * @phba: Pointer to HBA context object. |
3777 | * | |
3778 | * This function resets the HBA by writing HC_INITFF to the control | |
3779 | * register. After the HBA resets, this function resets all the iocb ring | |
3780 | * indices. This function disables PCI layer parity checking during | |
3781 | * the reset. | |
3782 | * This function returns 0 always. | |
3783 | * The caller is not required to hold any locks. | |
3784 | **/ | |
41415862 | 3785 | int |
2e0fef85 | 3786 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3787 | { |
41415862 | 3788 | struct lpfc_sli *psli; |
dea3101e | 3789 | struct lpfc_sli_ring *pring; |
41415862 | 3790 | uint16_t cfg_value; |
dea3101e | 3791 | int i; |
dea3101e | 3792 | |
41415862 | 3793 | psli = &phba->sli; |
dea3101e | 3794 | |
41415862 JW |
3795 | /* Reset HBA */ |
3796 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3797 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3798 | phba->pport->port_state, psli->sli_flag); |
dea3101e | 3799 | |
3800 | /* perform board reset */ | |
3801 | phba->fc_eventTag = 0; | |
4d9ab994 | 3802 | phba->link_events = 0; |
2e0fef85 JS |
3803 | phba->pport->fc_myDID = 0; |
3804 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3805 | |
41415862 JW |
3806 | /* Turn off parity checking and serr during the physical reset */ |
3807 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3808 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3809 | (cfg_value & | |
3810 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3811 | ||
3772a991 JS |
3812 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3813 | ||
41415862 JW |
3814 | /* Now toggle INITFF bit in the Host Control Register */ |
3815 | writel(HC_INITFF, phba->HCregaddr); | |
3816 | mdelay(1); | |
3817 | readl(phba->HCregaddr); /* flush */ | |
3818 | writel(0, phba->HCregaddr); | |
3819 | readl(phba->HCregaddr); /* flush */ | |
3820 | ||
3821 | /* Restore PCI cmd register */ | |
3822 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e | 3823 | |
3824 | /* Initialize relevant SLI info */ | |
41415862 JW |
3825 | for (i = 0; i < psli->num_rings; i++) { |
3826 | pring = &psli->ring[i]; | |
dea3101e | 3827 | pring->flag = 0; |
3828 | pring->rspidx = 0; | |
3829 | pring->next_cmdidx = 0; | |
3830 | pring->local_getidx = 0; | |
3831 | pring->cmdidx = 0; | |
3832 | pring->missbufcnt = 0; | |
3833 | } | |
dea3101e | 3834 | |
2e0fef85 | 3835 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3836 | return 0; |
3837 | } | |
3838 | ||
e59058c4 | 3839 | /** |
da0436e9 JS |
3840 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3841 | * @phba: Pointer to HBA context object. | |
3842 | * | |
3843 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3844 | * checking during resets the device. The caller is not required to hold | |
3845 | * any locks. | |
3846 | * | |
3847 | * This function returns 0 always. | |
3848 | **/ | |
3849 | int | |
3850 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3851 | { | |
3852 | struct lpfc_sli *psli = &phba->sli; | |
3853 | uint16_t cfg_value; | |
3854 | uint8_t qindx; | |
3855 | ||
3856 | /* Reset HBA */ | |
3857 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3858 | "0295 Reset HBA Data: x%x x%x\n", | |
3859 | phba->pport->port_state, psli->sli_flag); | |
3860 | ||
3861 | /* perform board reset */ | |
3862 | phba->fc_eventTag = 0; | |
4d9ab994 | 3863 | phba->link_events = 0; |
da0436e9 JS |
3864 | phba->pport->fc_myDID = 0; |
3865 | phba->pport->fc_prevDID = 0; | |
3866 | ||
da0436e9 JS |
3867 | spin_lock_irq(&phba->hbalock); |
3868 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3869 | phba->fcf.fcf_flag = 0; | |
3870 | /* Clean up the child queue list for the CQs */ | |
3871 | list_del_init(&phba->sli4_hba.mbx_wq->list); | |
3872 | list_del_init(&phba->sli4_hba.els_wq->list); | |
3873 | list_del_init(&phba->sli4_hba.hdr_rq->list); | |
3874 | list_del_init(&phba->sli4_hba.dat_rq->list); | |
3875 | list_del_init(&phba->sli4_hba.mbx_cq->list); | |
3876 | list_del_init(&phba->sli4_hba.els_cq->list); | |
da0436e9 JS |
3877 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
3878 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | |
0558056c JS |
3879 | qindx = 0; |
3880 | do | |
da0436e9 | 3881 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); |
0558056c | 3882 | while (++qindx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
3883 | spin_unlock_irq(&phba->hbalock); |
3884 | ||
3885 | /* Now physically reset the device */ | |
3886 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3887 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
3888 | |
3889 | /* Turn off parity checking and serr during the physical reset */ | |
3890 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3891 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
3892 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3893 | ||
da0436e9 JS |
3894 | /* Perform FCoE PCI function reset */ |
3895 | lpfc_pci_function_reset(phba); | |
3896 | ||
be858b65 JS |
3897 | /* Restore PCI cmd register */ |
3898 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
3899 | ||
da0436e9 JS |
3900 | return 0; |
3901 | } | |
3902 | ||
3903 | /** | |
3904 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3905 | * @phba: Pointer to HBA context object. |
3906 | * | |
3907 | * This function is called in the SLI initialization code path to | |
3908 | * restart the HBA. The caller is not required to hold any lock. | |
3909 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3910 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3911 | * function to free any pending commands. The function enables | |
3912 | * POST only during the first initialization. The function returns zero. | |
3913 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3914 | * command before the return of this function. | |
3915 | **/ | |
da0436e9 JS |
3916 | static int |
3917 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3918 | { |
3919 | MAILBOX_t *mb; | |
3920 | struct lpfc_sli *psli; | |
41415862 JW |
3921 | volatile uint32_t word0; |
3922 | void __iomem *to_slim; | |
0d878419 | 3923 | uint32_t hba_aer_enabled; |
41415862 | 3924 | |
2e0fef85 | 3925 | spin_lock_irq(&phba->hbalock); |
41415862 | 3926 | |
0d878419 JS |
3927 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3928 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3929 | ||
41415862 JW |
3930 | psli = &phba->sli; |
3931 | ||
3932 | /* Restart HBA */ | |
3933 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3934 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3935 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3936 | |
3937 | word0 = 0; | |
3938 | mb = (MAILBOX_t *) &word0; | |
3939 | mb->mbxCommand = MBX_RESTART; | |
3940 | mb->mbxHc = 1; | |
3941 | ||
9290831f JS |
3942 | lpfc_reset_barrier(phba); |
3943 | ||
41415862 JW |
3944 | to_slim = phba->MBslimaddr; |
3945 | writel(*(uint32_t *) mb, to_slim); | |
3946 | readl(to_slim); /* flush */ | |
3947 | ||
3948 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3949 | if (phba->pport->port_state) |
41415862 | 3950 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 3951 | else |
41415862 | 3952 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 3953 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
3954 | writel(*(uint32_t *) mb, to_slim); |
3955 | readl(to_slim); /* flush */ | |
dea3101e | 3956 | |
41415862 | 3957 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
3958 | phba->pport->stopped = 0; |
3959 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 3960 | phba->hba_flag = 0; |
2e0fef85 | 3961 | spin_unlock_irq(&phba->hbalock); |
41415862 | 3962 | |
64ba8818 JS |
3963 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
3964 | psli->stats_start = get_seconds(); | |
3965 | ||
eaf15d5b JS |
3966 | /* Give the INITFF and Post time to settle. */ |
3967 | mdelay(100); | |
41415862 | 3968 | |
0d878419 JS |
3969 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3970 | if (hba_aer_enabled) | |
3971 | pci_disable_pcie_error_reporting(phba->pcidev); | |
3972 | ||
41415862 | 3973 | lpfc_hba_down_post(phba); |
dea3101e | 3974 | |
3975 | return 0; | |
3976 | } | |
3977 | ||
da0436e9 JS |
3978 | /** |
3979 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
3980 | * @phba: Pointer to HBA context object. | |
3981 | * | |
3982 | * This function is called in the SLI initialization code path to restart | |
3983 | * a SLI4 HBA. The caller is not required to hold any lock. | |
3984 | * At the end of the function, it calls lpfc_hba_down_post function to | |
3985 | * free any pending commands. | |
3986 | **/ | |
3987 | static int | |
3988 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
3989 | { | |
3990 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 3991 | uint32_t hba_aer_enabled; |
da0436e9 JS |
3992 | |
3993 | /* Restart HBA */ | |
3994 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3995 | "0296 Restart HBA Data: x%x x%x\n", | |
3996 | phba->pport->port_state, psli->sli_flag); | |
3997 | ||
75baf696 JS |
3998 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3999 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4000 | ||
da0436e9 JS |
4001 | lpfc_sli4_brdreset(phba); |
4002 | ||
4003 | spin_lock_irq(&phba->hbalock); | |
4004 | phba->pport->stopped = 0; | |
4005 | phba->link_state = LPFC_INIT_START; | |
4006 | phba->hba_flag = 0; | |
4007 | spin_unlock_irq(&phba->hbalock); | |
4008 | ||
4009 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4010 | psli->stats_start = get_seconds(); | |
4011 | ||
75baf696 JS |
4012 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4013 | if (hba_aer_enabled) | |
4014 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4015 | ||
da0436e9 JS |
4016 | lpfc_hba_down_post(phba); |
4017 | ||
4018 | return 0; | |
4019 | } | |
4020 | ||
4021 | /** | |
4022 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4023 | * @phba: Pointer to HBA context object. | |
4024 | * | |
4025 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4026 | * API jump table function pointer from the lpfc_hba struct. | |
4027 | **/ | |
4028 | int | |
4029 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4030 | { | |
4031 | return phba->lpfc_sli_brdrestart(phba); | |
4032 | } | |
4033 | ||
e59058c4 | 4034 | /** |
3621a710 | 4035 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4036 | * @phba: Pointer to HBA context object. |
4037 | * | |
4038 | * This function is called after a HBA restart to wait for successful | |
4039 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4040 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4041 | * iteration, the function will restart the HBA again. The function returns | |
4042 | * zero if HBA successfully restarted else returns negative error code. | |
4043 | **/ | |
dea3101e | 4044 | static int |
4045 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4046 | { | |
4047 | uint32_t status, i = 0; | |
4048 | ||
4049 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4050 | if (lpfc_readl(phba->HSregaddr, &status)) |
4051 | return -EIO; | |
dea3101e | 4052 | |
4053 | /* Check status register to see what current state is */ | |
4054 | i = 0; | |
4055 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4056 | ||
dcf2a4e0 JS |
4057 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4058 | * retries, then every 1 sec for 50 retires for a total of | |
4059 | * ~60 seconds before reset the board again and check every | |
4060 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4061 | * board ready is required by the Falcon FIPS zeroization | |
4062 | * complete, and any reset the board in between shall cause | |
4063 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4064 | */ |
dcf2a4e0 | 4065 | if (i++ >= 200) { |
dea3101e | 4066 | /* Adapter failed to init, timeout, status reg |
4067 | <status> */ | |
ed957684 | 4068 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4069 | "0436 Adapter failed to init, " |
09372820 JS |
4070 | "timeout, status reg x%x, " |
4071 | "FW Data: A8 x%x AC x%x\n", status, | |
4072 | readl(phba->MBslimaddr + 0xa8), | |
4073 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4074 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4075 | return -ETIMEDOUT; |
4076 | } | |
4077 | ||
4078 | /* Check to see if any errors occurred during init */ | |
4079 | if (status & HS_FFERM) { | |
4080 | /* ERROR: During chipset initialization */ | |
4081 | /* Adapter failed to init, chipset, status reg | |
4082 | <status> */ | |
ed957684 | 4083 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4084 | "0437 Adapter failed to init, " |
09372820 JS |
4085 | "chipset, status reg x%x, " |
4086 | "FW Data: A8 x%x AC x%x\n", status, | |
4087 | readl(phba->MBslimaddr + 0xa8), | |
4088 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4089 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4090 | return -EIO; |
4091 | } | |
4092 | ||
dcf2a4e0 | 4093 | if (i <= 10) |
dea3101e | 4094 | msleep(10); |
dcf2a4e0 JS |
4095 | else if (i <= 100) |
4096 | msleep(100); | |
4097 | else | |
4098 | msleep(1000); | |
dea3101e | 4099 | |
dcf2a4e0 JS |
4100 | if (i == 150) { |
4101 | /* Do post */ | |
92d7f7b0 | 4102 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4103 | lpfc_sli_brdrestart(phba); |
dea3101e | 4104 | } |
4105 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4106 | if (lpfc_readl(phba->HSregaddr, &status)) |
4107 | return -EIO; | |
dea3101e | 4108 | } |
4109 | ||
4110 | /* Check to see if any errors occurred during init */ | |
4111 | if (status & HS_FFERM) { | |
4112 | /* ERROR: During chipset initialization */ | |
4113 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4114 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4115 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4116 | "status reg x%x, " |
4117 | "FW Data: A8 x%x AC x%x\n", status, | |
4118 | readl(phba->MBslimaddr + 0xa8), | |
4119 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4120 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4121 | return -EIO; |
4122 | } | |
4123 | ||
4124 | /* Clear all interrupt enable conditions */ | |
4125 | writel(0, phba->HCregaddr); | |
4126 | readl(phba->HCregaddr); /* flush */ | |
4127 | ||
4128 | /* setup host attn register */ | |
4129 | writel(0xffffffff, phba->HAregaddr); | |
4130 | readl(phba->HAregaddr); /* flush */ | |
4131 | return 0; | |
4132 | } | |
4133 | ||
e59058c4 | 4134 | /** |
3621a710 | 4135 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4136 | * |
4137 | * This function calculates and returns the number of HBQs required to be | |
4138 | * configured. | |
4139 | **/ | |
78b2d852 | 4140 | int |
ed957684 JS |
4141 | lpfc_sli_hbq_count(void) |
4142 | { | |
92d7f7b0 | 4143 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4144 | } |
4145 | ||
e59058c4 | 4146 | /** |
3621a710 | 4147 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4148 | * |
4149 | * This function adds the number of hbq entries in every HBQ to get | |
4150 | * the total number of hbq entries required for the HBA and returns | |
4151 | * the total count. | |
4152 | **/ | |
ed957684 JS |
4153 | static int |
4154 | lpfc_sli_hbq_entry_count(void) | |
4155 | { | |
4156 | int hbq_count = lpfc_sli_hbq_count(); | |
4157 | int count = 0; | |
4158 | int i; | |
4159 | ||
4160 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4161 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4162 | return count; |
4163 | } | |
4164 | ||
e59058c4 | 4165 | /** |
3621a710 | 4166 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4167 | * |
4168 | * This function calculates amount of memory required for all hbq entries | |
4169 | * to be configured and returns the total memory required. | |
4170 | **/ | |
dea3101e | 4171 | int |
ed957684 JS |
4172 | lpfc_sli_hbq_size(void) |
4173 | { | |
4174 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4175 | } | |
4176 | ||
e59058c4 | 4177 | /** |
3621a710 | 4178 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4179 | * @phba: Pointer to HBA context object. |
4180 | * | |
4181 | * This function is called during the SLI initialization to configure | |
4182 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4183 | * required to hold any locks. This function will return zero if successful | |
4184 | * else it will return negative error code. | |
4185 | **/ | |
ed957684 JS |
4186 | static int |
4187 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4188 | { | |
4189 | int hbq_count = lpfc_sli_hbq_count(); | |
4190 | LPFC_MBOXQ_t *pmb; | |
4191 | MAILBOX_t *pmbox; | |
4192 | uint32_t hbqno; | |
4193 | uint32_t hbq_entry_index; | |
ed957684 | 4194 | |
92d7f7b0 JS |
4195 | /* Get a Mailbox buffer to setup mailbox |
4196 | * commands for HBA initialization | |
4197 | */ | |
ed957684 JS |
4198 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4199 | ||
4200 | if (!pmb) | |
4201 | return -ENOMEM; | |
4202 | ||
04c68496 | 4203 | pmbox = &pmb->u.mb; |
ed957684 JS |
4204 | |
4205 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4206 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4207 | phba->hbq_in_use = 1; |
ed957684 JS |
4208 | |
4209 | hbq_entry_index = 0; | |
4210 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4211 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4212 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4213 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4214 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4215 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4216 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4217 | hbq_entry_index, pmb); | |
ed957684 JS |
4218 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4219 | ||
4220 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4221 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4222 | mbxStatus <status>, ring <num> */ | |
4223 | ||
4224 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4225 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4226 | "1805 Adapter failed to init. " |
ed957684 | 4227 | "Data: x%x x%x x%x\n", |
e8b62011 | 4228 | pmbox->mbxCommand, |
ed957684 JS |
4229 | pmbox->mbxStatus, hbqno); |
4230 | ||
4231 | phba->link_state = LPFC_HBA_ERROR; | |
4232 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4233 | return -ENXIO; |
ed957684 JS |
4234 | } |
4235 | } | |
4236 | phba->hbq_count = hbq_count; | |
4237 | ||
ed957684 JS |
4238 | mempool_free(pmb, phba->mbox_mem_pool); |
4239 | ||
92d7f7b0 | 4240 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4241 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4242 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4243 | return 0; |
4244 | } | |
4245 | ||
4f774513 JS |
4246 | /** |
4247 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4248 | * @phba: Pointer to HBA context object. | |
4249 | * | |
4250 | * This function is called during the SLI initialization to configure | |
4251 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4252 | * required to hold any locks. This function will return zero if successful | |
4253 | * else it will return negative error code. | |
4254 | **/ | |
4255 | static int | |
4256 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4257 | { | |
4258 | phba->hbq_in_use = 1; | |
4259 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4260 | phba->hbq_count = 1; | |
4261 | /* Initially populate or replenish the HBQs */ | |
4262 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4263 | return 0; | |
4264 | } | |
4265 | ||
e59058c4 | 4266 | /** |
3621a710 | 4267 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4268 | * @phba: Pointer to HBA context object. |
4269 | * @sli_mode: sli mode - 2/3 | |
4270 | * | |
4271 | * This function is called by the sli intialization code path | |
4272 | * to issue config_port mailbox command. This function restarts the | |
4273 | * HBA firmware and issues a config_port mailbox command to configure | |
4274 | * the SLI interface in the sli mode specified by sli_mode | |
4275 | * variable. The caller is not required to hold any locks. | |
4276 | * The function returns 0 if successful, else returns negative error | |
4277 | * code. | |
4278 | **/ | |
9399627f JS |
4279 | int |
4280 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e | 4281 | { |
4282 | LPFC_MBOXQ_t *pmb; | |
4283 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4284 | ||
4285 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4286 | if (!pmb) { | |
2e0fef85 | 4287 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4288 | return -ENOMEM; |
4289 | } | |
4290 | ||
ed957684 | 4291 | phba->sli_rev = sli_mode; |
dea3101e | 4292 | while (resetcount < 2 && !done) { |
2e0fef85 | 4293 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4294 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4295 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4296 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4297 | lpfc_sli_brdrestart(phba); |
dea3101e | 4298 | rc = lpfc_sli_chipset_init(phba); |
4299 | if (rc) | |
4300 | break; | |
4301 | ||
2e0fef85 | 4302 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4303 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4304 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4305 | resetcount++; |
4306 | ||
ed957684 JS |
4307 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4308 | * value of 0 means the call was successful. Any other | |
4309 | * nonzero value is a failure, but if ERESTART is returned, | |
4310 | * the driver may reset the HBA and try again. | |
4311 | */ | |
dea3101e | 4312 | rc = lpfc_config_port_prep(phba); |
4313 | if (rc == -ERESTART) { | |
ed957684 | 4314 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4315 | continue; |
34b02dcd | 4316 | } else if (rc) |
dea3101e | 4317 | break; |
6d368e53 | 4318 | |
2e0fef85 | 4319 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 4320 | lpfc_config_port(phba, pmb); |
4321 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4322 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4323 | LPFC_SLI3_HBQ_ENABLED | | |
4324 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4325 | LPFC_SLI3_BG_ENABLED | |
4326 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4327 | if (rc != MBX_SUCCESS) { |
dea3101e | 4328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4329 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4330 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4331 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4332 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4333 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4334 | spin_unlock_irq(&phba->hbalock); |
4335 | rc = -ENXIO; | |
04c68496 JS |
4336 | } else { |
4337 | /* Allow asynchronous mailbox command to go through */ | |
4338 | spin_lock_irq(&phba->hbalock); | |
4339 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4340 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4341 | done = 1; |
cb69f7de JS |
4342 | |
4343 | if ((pmb->u.mb.un.varCfgPort.casabt == 1) && | |
4344 | (pmb->u.mb.un.varCfgPort.gasabt == 0)) | |
4345 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4346 | "3110 Port did not grant ASABT\n"); | |
04c68496 | 4347 | } |
dea3101e | 4348 | } |
ed957684 JS |
4349 | if (!done) { |
4350 | rc = -EINVAL; | |
4351 | goto do_prep_failed; | |
4352 | } | |
04c68496 JS |
4353 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4354 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4355 | rc = -ENXIO; |
4356 | goto do_prep_failed; | |
4357 | } | |
04c68496 | 4358 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4359 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4360 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4361 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4362 | phba->max_vpi : phba->max_vports; | |
4363 | ||
34b02dcd JS |
4364 | } else |
4365 | phba->max_vpi = 0; | |
bc73905a JS |
4366 | phba->fips_level = 0; |
4367 | phba->fips_spec_rev = 0; | |
4368 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4369 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4370 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4371 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4372 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4373 | "2850 Security Crypto Active. FIPS x%d " | |
4374 | "(Spec Rev: x%d)", | |
4375 | phba->fips_level, phba->fips_spec_rev); | |
4376 | } | |
4377 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4378 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4379 | "2856 Config Port Security Crypto " | |
4380 | "Error: x%x ", | |
4381 | pmb->u.mb.un.varCfgPort.sec_err); | |
4382 | } | |
04c68496 | 4383 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4384 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4385 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4386 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4387 | |
4388 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4389 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4390 | |
4391 | if (phba->cfg_enable_bg) { | |
04c68496 | 4392 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4393 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4394 | else | |
4395 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4396 | "0443 Adapter did not grant " | |
4397 | "BlockGuard\n"); | |
4398 | } | |
34b02dcd | 4399 | } else { |
8f34f4ce | 4400 | phba->hbq_get = NULL; |
34b02dcd | 4401 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4402 | phba->max_vpi = 0; |
ed957684 | 4403 | } |
92d7f7b0 | 4404 | do_prep_failed: |
ed957684 JS |
4405 | mempool_free(pmb, phba->mbox_mem_pool); |
4406 | return rc; | |
4407 | } | |
4408 | ||
e59058c4 JS |
4409 | |
4410 | /** | |
3621a710 | 4411 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4412 | * @phba: Pointer to HBA context object. |
4413 | * | |
4414 | * This function is the main SLI intialization function. This function | |
4415 | * is called by the HBA intialization code, HBA reset code and HBA | |
4416 | * error attention handler code. Caller is not required to hold any | |
4417 | * locks. This function issues config_port mailbox command to configure | |
4418 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4419 | * calls the config_port_post function to issue init_link mailbox | |
4420 | * command and to start the discovery. The function will return zero | |
4421 | * if successful, else it will return negative error code. | |
4422 | **/ | |
ed957684 JS |
4423 | int |
4424 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4425 | { | |
4426 | uint32_t rc; | |
6d368e53 JS |
4427 | int mode = 3, i; |
4428 | int longs; | |
ed957684 JS |
4429 | |
4430 | switch (lpfc_sli_mode) { | |
4431 | case 2: | |
78b2d852 | 4432 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4433 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4434 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4435 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4436 | lpfc_sli_mode); |
92d7f7b0 JS |
4437 | break; |
4438 | } | |
ed957684 JS |
4439 | mode = 2; |
4440 | break; | |
4441 | case 0: | |
4442 | case 3: | |
4443 | break; | |
4444 | default: | |
92d7f7b0 | 4445 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4446 | "1819 Unrecognized lpfc_sli_mode " |
4447 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4448 | |
4449 | break; | |
4450 | } | |
4451 | ||
9399627f JS |
4452 | rc = lpfc_sli_config_port(phba, mode); |
4453 | ||
ed957684 | 4454 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4456 | "1820 Unable to select SLI-3. " |
4457 | "Not supported by adapter.\n"); | |
ed957684 | 4458 | if (rc && mode != 2) |
9399627f | 4459 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4460 | if (rc) |
dea3101e | 4461 | goto lpfc_sli_hba_setup_error; |
4462 | ||
0d878419 JS |
4463 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4464 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4465 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4466 | if (!rc) { | |
4467 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4468 | "2709 This device supports " | |
4469 | "Advanced Error Reporting (AER)\n"); | |
4470 | spin_lock_irq(&phba->hbalock); | |
4471 | phba->hba_flag |= HBA_AER_ENABLED; | |
4472 | spin_unlock_irq(&phba->hbalock); | |
4473 | } else { | |
4474 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4475 | "2708 This device does not support " | |
4476 | "Advanced Error Reporting (AER)\n"); | |
4477 | phba->cfg_aer_support = 0; | |
4478 | } | |
4479 | } | |
4480 | ||
ed957684 JS |
4481 | if (phba->sli_rev == 3) { |
4482 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4483 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4484 | } else { |
4485 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4486 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4487 | phba->sli3_options = 0; |
ed957684 JS |
4488 | } |
4489 | ||
4490 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4491 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4492 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4493 | rc = lpfc_sli_ring_map(phba); |
dea3101e | 4494 | |
4495 | if (rc) | |
4496 | goto lpfc_sli_hba_setup_error; | |
4497 | ||
6d368e53 JS |
4498 | /* Initialize VPIs. */ |
4499 | if (phba->sli_rev == LPFC_SLI_REV3) { | |
4500 | /* | |
4501 | * The VPI bitmask and physical ID array are allocated | |
4502 | * and initialized once only - at driver load. A port | |
4503 | * reset doesn't need to reinitialize this memory. | |
4504 | */ | |
4505 | if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) { | |
4506 | longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG; | |
4507 | phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4508 | GFP_KERNEL); | |
4509 | if (!phba->vpi_bmask) { | |
4510 | rc = -ENOMEM; | |
4511 | goto lpfc_sli_hba_setup_error; | |
4512 | } | |
4513 | ||
4514 | phba->vpi_ids = kzalloc( | |
4515 | (phba->max_vpi+1) * sizeof(uint16_t), | |
4516 | GFP_KERNEL); | |
4517 | if (!phba->vpi_ids) { | |
4518 | kfree(phba->vpi_bmask); | |
4519 | rc = -ENOMEM; | |
4520 | goto lpfc_sli_hba_setup_error; | |
4521 | } | |
4522 | for (i = 0; i < phba->max_vpi; i++) | |
4523 | phba->vpi_ids[i] = i; | |
4524 | } | |
4525 | } | |
4526 | ||
9399627f | 4527 | /* Init HBQs */ |
ed957684 JS |
4528 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4529 | rc = lpfc_sli_hbq_setup(phba); | |
4530 | if (rc) | |
4531 | goto lpfc_sli_hba_setup_error; | |
4532 | } | |
04c68496 | 4533 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4534 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4535 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4536 | |
4537 | rc = lpfc_config_port_post(phba); | |
4538 | if (rc) | |
4539 | goto lpfc_sli_hba_setup_error; | |
4540 | ||
ed957684 JS |
4541 | return rc; |
4542 | ||
92d7f7b0 | 4543 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4544 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4545 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4546 | "0445 Firmware initialization failed\n"); |
dea3101e | 4547 | return rc; |
4548 | } | |
4549 | ||
e59058c4 | 4550 | /** |
da0436e9 JS |
4551 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4552 | * @phba: Pointer to HBA context object. | |
4553 | * @mboxq: mailbox pointer. | |
4554 | * This function issue a dump mailbox command to read config region | |
4555 | * 23 and parse the records in the region and populate driver | |
4556 | * data structure. | |
e59058c4 | 4557 | **/ |
da0436e9 | 4558 | static int |
ff78d8f9 | 4559 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba) |
dea3101e | 4560 | { |
ff78d8f9 | 4561 | LPFC_MBOXQ_t *mboxq; |
da0436e9 JS |
4562 | struct lpfc_dmabuf *mp; |
4563 | struct lpfc_mqe *mqe; | |
4564 | uint32_t data_length; | |
4565 | int rc; | |
dea3101e | 4566 | |
da0436e9 JS |
4567 | /* Program the default value of vlan_id and fc_map */ |
4568 | phba->valid_vlan = 0; | |
4569 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4570 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4571 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4572 | |
ff78d8f9 JS |
4573 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4574 | if (!mboxq) | |
da0436e9 JS |
4575 | return -ENOMEM; |
4576 | ||
ff78d8f9 JS |
4577 | mqe = &mboxq->u.mqe; |
4578 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) { | |
4579 | rc = -ENOMEM; | |
4580 | goto out_free_mboxq; | |
4581 | } | |
4582 | ||
da0436e9 JS |
4583 | mp = (struct lpfc_dmabuf *) mboxq->context1; |
4584 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4585 | ||
4586 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4587 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4588 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4589 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4590 | "CQ: x%x x%x x%x x%x\n", | |
4591 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4592 | bf_get(lpfc_mqe_command, mqe), | |
4593 | bf_get(lpfc_mqe_status, mqe), | |
4594 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4595 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4596 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4597 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4598 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4599 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4600 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4601 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4602 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4603 | mboxq->mcqe.word0, | |
4604 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4605 | mboxq->mcqe.trailer); | |
4606 | ||
4607 | if (rc) { | |
4608 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4609 | kfree(mp); | |
ff78d8f9 JS |
4610 | rc = -EIO; |
4611 | goto out_free_mboxq; | |
da0436e9 JS |
4612 | } |
4613 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4614 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4615 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4616 | kfree(mp); | |
ff78d8f9 JS |
4617 | rc = -EIO; |
4618 | goto out_free_mboxq; | |
d11e31dd | 4619 | } |
dea3101e | 4620 | |
da0436e9 JS |
4621 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4622 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4623 | kfree(mp); | |
ff78d8f9 JS |
4624 | rc = 0; |
4625 | ||
4626 | out_free_mboxq: | |
4627 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4628 | return rc; | |
da0436e9 | 4629 | } |
e59058c4 JS |
4630 | |
4631 | /** | |
da0436e9 JS |
4632 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4633 | * @phba: pointer to lpfc hba data structure. | |
4634 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4635 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4636 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4637 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4638 | * |
da0436e9 JS |
4639 | * This routine executes a READ_REV SLI4 mailbox command. In |
4640 | * addition, this routine gets the port vpd data. | |
4641 | * | |
4642 | * Return codes | |
af901ca1 | 4643 | * 0 - successful |
d439d286 | 4644 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4645 | **/ |
da0436e9 JS |
4646 | static int |
4647 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4648 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4649 | { |
da0436e9 JS |
4650 | int rc = 0; |
4651 | uint32_t dma_size; | |
4652 | struct lpfc_dmabuf *dmabuf; | |
4653 | struct lpfc_mqe *mqe; | |
dea3101e | 4654 | |
da0436e9 JS |
4655 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4656 | if (!dmabuf) | |
4657 | return -ENOMEM; | |
4658 | ||
4659 | /* | |
4660 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4661 | * mailbox command. | |
a257bf90 | 4662 | */ |
da0436e9 JS |
4663 | dma_size = *vpd_size; |
4664 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4665 | dma_size, | |
4666 | &dmabuf->phys, | |
4667 | GFP_KERNEL); | |
4668 | if (!dmabuf->virt) { | |
4669 | kfree(dmabuf); | |
4670 | return -ENOMEM; | |
a257bf90 | 4671 | } |
da0436e9 | 4672 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4673 | |
da0436e9 JS |
4674 | /* |
4675 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4676 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4677 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4678 | */ |
da0436e9 JS |
4679 | lpfc_read_rev(phba, mboxq); |
4680 | mqe = &mboxq->u.mqe; | |
4681 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4682 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4683 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4684 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4685 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4686 | ||
4687 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4688 | if (rc) { | |
4689 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4690 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4691 | kfree(dmabuf); |
da0436e9 JS |
4692 | return -EIO; |
4693 | } | |
1dcb58e5 | 4694 | |
da0436e9 JS |
4695 | /* |
4696 | * The available vpd length cannot be bigger than the | |
4697 | * DMA buffer passed to the port. Catch the less than | |
4698 | * case and update the caller's size. | |
4699 | */ | |
4700 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4701 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4702 | |
d7c47992 JS |
4703 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4704 | ||
da0436e9 JS |
4705 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4706 | dmabuf->virt, dmabuf->phys); | |
4707 | kfree(dmabuf); | |
4708 | return 0; | |
dea3101e | 4709 | } |
4710 | ||
cd1c8301 JS |
4711 | /** |
4712 | * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name | |
4713 | * @phba: pointer to lpfc hba data structure. | |
4714 | * | |
4715 | * This routine retrieves SLI4 device physical port name this PCI function | |
4716 | * is attached to. | |
4717 | * | |
4718 | * Return codes | |
4719 | * 0 - sucessful | |
4720 | * otherwise - failed to retrieve physical port name | |
4721 | **/ | |
4722 | static int | |
4723 | lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba) | |
4724 | { | |
4725 | LPFC_MBOXQ_t *mboxq; | |
cd1c8301 JS |
4726 | struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr; |
4727 | struct lpfc_controller_attribute *cntl_attr; | |
4728 | struct lpfc_mbx_get_port_name *get_port_name; | |
4729 | void *virtaddr = NULL; | |
4730 | uint32_t alloclen, reqlen; | |
4731 | uint32_t shdr_status, shdr_add_status; | |
4732 | union lpfc_sli4_cfg_shdr *shdr; | |
4733 | char cport_name = 0; | |
4734 | int rc; | |
4735 | ||
4736 | /* We assume nothing at this point */ | |
4737 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; | |
4738 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON; | |
4739 | ||
4740 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4741 | if (!mboxq) | |
4742 | return -ENOMEM; | |
cd1c8301 | 4743 | /* obtain link type and link number via READ_CONFIG */ |
ff78d8f9 JS |
4744 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL; |
4745 | lpfc_sli4_read_config(phba); | |
4746 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) | |
4747 | goto retrieve_ppname; | |
cd1c8301 JS |
4748 | |
4749 | /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */ | |
4750 | reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes); | |
4751 | alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4752 | LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen, | |
4753 | LPFC_SLI4_MBX_NEMBED); | |
4754 | if (alloclen < reqlen) { | |
4755 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4756 | "3084 Allocated DMA memory size (%d) is " | |
4757 | "less than the requested DMA memory size " | |
4758 | "(%d)\n", alloclen, reqlen); | |
4759 | rc = -ENOMEM; | |
4760 | goto out_free_mboxq; | |
4761 | } | |
4762 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4763 | virtaddr = mboxq->sge_array->addr[0]; | |
4764 | mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr; | |
4765 | shdr = &mbx_cntl_attr->cfg_shdr; | |
4766 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4767 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4768 | if (shdr_status || shdr_add_status || rc) { | |
4769 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4770 | "3085 Mailbox x%x (x%x/x%x) failed, " | |
4771 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4772 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4773 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4774 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4775 | rc, shdr_status, shdr_add_status); | |
4776 | rc = -ENXIO; | |
4777 | goto out_free_mboxq; | |
4778 | } | |
4779 | cntl_attr = &mbx_cntl_attr->cntl_attr; | |
4780 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
4781 | phba->sli4_hba.lnk_info.lnk_tp = | |
4782 | bf_get(lpfc_cntl_attr_lnk_type, cntl_attr); | |
4783 | phba->sli4_hba.lnk_info.lnk_no = | |
4784 | bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr); | |
4785 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4786 | "3086 lnk_type:%d, lnk_numb:%d\n", | |
4787 | phba->sli4_hba.lnk_info.lnk_tp, | |
4788 | phba->sli4_hba.lnk_info.lnk_no); | |
4789 | ||
4790 | retrieve_ppname: | |
4791 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4792 | LPFC_MBOX_OPCODE_GET_PORT_NAME, | |
4793 | sizeof(struct lpfc_mbx_get_port_name) - | |
4794 | sizeof(struct lpfc_sli4_cfg_mhdr), | |
4795 | LPFC_SLI4_MBX_EMBED); | |
4796 | get_port_name = &mboxq->u.mqe.un.get_port_name; | |
4797 | shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr; | |
4798 | bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1); | |
4799 | bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request, | |
4800 | phba->sli4_hba.lnk_info.lnk_tp); | |
4801 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4802 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
4803 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
4804 | if (shdr_status || shdr_add_status || rc) { | |
4805 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4806 | "3087 Mailbox x%x (x%x/x%x) failed: " | |
4807 | "rc:x%x, status:x%x, add_status:x%x\n", | |
4808 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
4809 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
4810 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
4811 | rc, shdr_status, shdr_add_status); | |
4812 | rc = -ENXIO; | |
4813 | goto out_free_mboxq; | |
4814 | } | |
4815 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
4816 | case LPFC_LINK_NUMBER_0: | |
4817 | cport_name = bf_get(lpfc_mbx_get_port_name_name0, | |
4818 | &get_port_name->u.response); | |
4819 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4820 | break; | |
4821 | case LPFC_LINK_NUMBER_1: | |
4822 | cport_name = bf_get(lpfc_mbx_get_port_name_name1, | |
4823 | &get_port_name->u.response); | |
4824 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4825 | break; | |
4826 | case LPFC_LINK_NUMBER_2: | |
4827 | cport_name = bf_get(lpfc_mbx_get_port_name_name2, | |
4828 | &get_port_name->u.response); | |
4829 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4830 | break; | |
4831 | case LPFC_LINK_NUMBER_3: | |
4832 | cport_name = bf_get(lpfc_mbx_get_port_name_name3, | |
4833 | &get_port_name->u.response); | |
4834 | phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET; | |
4835 | break; | |
4836 | default: | |
4837 | break; | |
4838 | } | |
4839 | ||
4840 | if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) { | |
4841 | phba->Port[0] = cport_name; | |
4842 | phba->Port[1] = '\0'; | |
4843 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4844 | "3091 SLI get port name: %s\n", phba->Port); | |
4845 | } | |
4846 | ||
4847 | out_free_mboxq: | |
4848 | if (rc != MBX_TIMEOUT) { | |
4849 | if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG) | |
4850 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
4851 | else | |
4852 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4853 | } | |
4854 | return rc; | |
4855 | } | |
4856 | ||
e59058c4 | 4857 | /** |
da0436e9 JS |
4858 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4859 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4860 | * |
da0436e9 JS |
4861 | * This routine is called to explicitly arm the SLI4 device's completion and |
4862 | * event queues | |
4863 | **/ | |
4864 | static void | |
4865 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4866 | { | |
4867 | uint8_t fcp_eqidx; | |
4868 | ||
4869 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4870 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
0558056c JS |
4871 | fcp_eqidx = 0; |
4872 | do | |
da0436e9 JS |
4873 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], |
4874 | LPFC_QUEUE_REARM); | |
0558056c | 4875 | while (++fcp_eqidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
4876 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); |
4877 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | |
4878 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | |
4879 | LPFC_QUEUE_REARM); | |
4880 | } | |
4881 | ||
6d368e53 JS |
4882 | /** |
4883 | * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count. | |
4884 | * @phba: Pointer to HBA context object. | |
4885 | * @type: The resource extent type. | |
b76f2dc9 JS |
4886 | * @extnt_count: buffer to hold port available extent count. |
4887 | * @extnt_size: buffer to hold element count per extent. | |
6d368e53 | 4888 | * |
b76f2dc9 JS |
4889 | * This function calls the port and retrievs the number of available |
4890 | * extents and their size for a particular extent type. | |
4891 | * | |
4892 | * Returns: 0 if successful. Nonzero otherwise. | |
6d368e53 | 4893 | **/ |
b76f2dc9 | 4894 | int |
6d368e53 JS |
4895 | lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type, |
4896 | uint16_t *extnt_count, uint16_t *extnt_size) | |
4897 | { | |
4898 | int rc = 0; | |
4899 | uint32_t length; | |
4900 | uint32_t mbox_tmo; | |
4901 | struct lpfc_mbx_get_rsrc_extent_info *rsrc_info; | |
4902 | LPFC_MBOXQ_t *mbox; | |
4903 | ||
4904 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4905 | if (!mbox) | |
4906 | return -ENOMEM; | |
4907 | ||
4908 | /* Find out how many extents are available for this resource type */ | |
4909 | length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) - | |
4910 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
4911 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
4912 | LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO, | |
4913 | length, LPFC_SLI4_MBX_EMBED); | |
4914 | ||
4915 | /* Send an extents count of 0 - the GET doesn't use it. */ | |
4916 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
4917 | LPFC_SLI4_MBX_EMBED); | |
4918 | if (unlikely(rc)) { | |
4919 | rc = -EIO; | |
4920 | goto err_exit; | |
4921 | } | |
4922 | ||
4923 | if (!phba->sli4_hba.intr_enable) | |
4924 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
4925 | else { | |
a183a15f | 4926 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
4927 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
4928 | } | |
4929 | if (unlikely(rc)) { | |
4930 | rc = -EIO; | |
4931 | goto err_exit; | |
4932 | } | |
4933 | ||
4934 | rsrc_info = &mbox->u.mqe.un.rsrc_extent_info; | |
4935 | if (bf_get(lpfc_mbox_hdr_status, | |
4936 | &rsrc_info->header.cfg_shdr.response)) { | |
4937 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
4938 | "2930 Failed to get resource extents " | |
4939 | "Status 0x%x Add'l Status 0x%x\n", | |
4940 | bf_get(lpfc_mbox_hdr_status, | |
4941 | &rsrc_info->header.cfg_shdr.response), | |
4942 | bf_get(lpfc_mbox_hdr_add_status, | |
4943 | &rsrc_info->header.cfg_shdr.response)); | |
4944 | rc = -EIO; | |
4945 | goto err_exit; | |
4946 | } | |
4947 | ||
4948 | *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt, | |
4949 | &rsrc_info->u.rsp); | |
4950 | *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size, | |
4951 | &rsrc_info->u.rsp); | |
4952 | err_exit: | |
4953 | mempool_free(mbox, phba->mbox_mem_pool); | |
4954 | return rc; | |
4955 | } | |
4956 | ||
4957 | /** | |
4958 | * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents. | |
4959 | * @phba: Pointer to HBA context object. | |
4960 | * @type: The extent type to check. | |
4961 | * | |
4962 | * This function reads the current available extents from the port and checks | |
4963 | * if the extent count or extent size has changed since the last access. | |
4964 | * Callers use this routine post port reset to understand if there is a | |
4965 | * extent reprovisioning requirement. | |
4966 | * | |
4967 | * Returns: | |
4968 | * -Error: error indicates problem. | |
4969 | * 1: Extent count or size has changed. | |
4970 | * 0: No changes. | |
4971 | **/ | |
4972 | static int | |
4973 | lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type) | |
4974 | { | |
4975 | uint16_t curr_ext_cnt, rsrc_ext_cnt; | |
4976 | uint16_t size_diff, rsrc_ext_size; | |
4977 | int rc = 0; | |
4978 | struct lpfc_rsrc_blks *rsrc_entry; | |
4979 | struct list_head *rsrc_blk_list = NULL; | |
4980 | ||
4981 | size_diff = 0; | |
4982 | curr_ext_cnt = 0; | |
4983 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
4984 | &rsrc_ext_cnt, | |
4985 | &rsrc_ext_size); | |
4986 | if (unlikely(rc)) | |
4987 | return -EIO; | |
4988 | ||
4989 | switch (type) { | |
4990 | case LPFC_RSC_TYPE_FCOE_RPI: | |
4991 | rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
4992 | break; | |
4993 | case LPFC_RSC_TYPE_FCOE_VPI: | |
4994 | rsrc_blk_list = &phba->lpfc_vpi_blk_list; | |
4995 | break; | |
4996 | case LPFC_RSC_TYPE_FCOE_XRI: | |
4997 | rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
4998 | break; | |
4999 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5000 | rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5001 | break; | |
5002 | default: | |
5003 | break; | |
5004 | } | |
5005 | ||
5006 | list_for_each_entry(rsrc_entry, rsrc_blk_list, list) { | |
5007 | curr_ext_cnt++; | |
5008 | if (rsrc_entry->rsrc_size != rsrc_ext_size) | |
5009 | size_diff++; | |
5010 | } | |
5011 | ||
5012 | if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0) | |
5013 | rc = 1; | |
5014 | ||
5015 | return rc; | |
5016 | } | |
5017 | ||
5018 | /** | |
5019 | * lpfc_sli4_cfg_post_extnts - | |
5020 | * @phba: Pointer to HBA context object. | |
5021 | * @extnt_cnt - number of available extents. | |
5022 | * @type - the extent type (rpi, xri, vfi, vpi). | |
5023 | * @emb - buffer to hold either MBX_EMBED or MBX_NEMBED operation. | |
5024 | * @mbox - pointer to the caller's allocated mailbox structure. | |
5025 | * | |
5026 | * This function executes the extents allocation request. It also | |
5027 | * takes care of the amount of memory needed to allocate or get the | |
5028 | * allocated extents. It is the caller's responsibility to evaluate | |
5029 | * the response. | |
5030 | * | |
5031 | * Returns: | |
5032 | * -Error: Error value describes the condition found. | |
5033 | * 0: if successful | |
5034 | **/ | |
5035 | static int | |
5036 | lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t *extnt_cnt, | |
5037 | uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox) | |
5038 | { | |
5039 | int rc = 0; | |
5040 | uint32_t req_len; | |
5041 | uint32_t emb_len; | |
5042 | uint32_t alloc_len, mbox_tmo; | |
5043 | ||
5044 | /* Calculate the total requested length of the dma memory */ | |
5045 | req_len = *extnt_cnt * sizeof(uint16_t); | |
5046 | ||
5047 | /* | |
5048 | * Calculate the size of an embedded mailbox. The uint32_t | |
5049 | * accounts for extents-specific word. | |
5050 | */ | |
5051 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5052 | sizeof(uint32_t); | |
5053 | ||
5054 | /* | |
5055 | * Presume the allocation and response will fit into an embedded | |
5056 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5057 | */ | |
5058 | *emb = LPFC_SLI4_MBX_EMBED; | |
5059 | if (req_len > emb_len) { | |
5060 | req_len = *extnt_cnt * sizeof(uint16_t) + | |
5061 | sizeof(union lpfc_sli4_cfg_shdr) + | |
5062 | sizeof(uint32_t); | |
5063 | *emb = LPFC_SLI4_MBX_NEMBED; | |
5064 | } | |
5065 | ||
5066 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5067 | LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT, | |
5068 | req_len, *emb); | |
5069 | if (alloc_len < req_len) { | |
5070 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
b76f2dc9 | 5071 | "2982 Allocated DMA memory size (x%x) is " |
6d368e53 JS |
5072 | "less than the requested DMA memory " |
5073 | "size (x%x)\n", alloc_len, req_len); | |
5074 | return -ENOMEM; | |
5075 | } | |
5076 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, *extnt_cnt, type, *emb); | |
5077 | if (unlikely(rc)) | |
5078 | return -EIO; | |
5079 | ||
5080 | if (!phba->sli4_hba.intr_enable) | |
5081 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5082 | else { | |
a183a15f | 5083 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5084 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5085 | } | |
5086 | ||
5087 | if (unlikely(rc)) | |
5088 | rc = -EIO; | |
5089 | return rc; | |
5090 | } | |
5091 | ||
5092 | /** | |
5093 | * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent. | |
5094 | * @phba: Pointer to HBA context object. | |
5095 | * @type: The resource extent type to allocate. | |
5096 | * | |
5097 | * This function allocates the number of elements for the specified | |
5098 | * resource type. | |
5099 | **/ | |
5100 | static int | |
5101 | lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5102 | { | |
5103 | bool emb = false; | |
5104 | uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size; | |
5105 | uint16_t rsrc_id, rsrc_start, j, k; | |
5106 | uint16_t *ids; | |
5107 | int i, rc; | |
5108 | unsigned long longs; | |
5109 | unsigned long *bmask; | |
5110 | struct lpfc_rsrc_blks *rsrc_blks; | |
5111 | LPFC_MBOXQ_t *mbox; | |
5112 | uint32_t length; | |
5113 | struct lpfc_id_range *id_array = NULL; | |
5114 | void *virtaddr = NULL; | |
5115 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5116 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5117 | struct list_head *ext_blk_list; | |
5118 | ||
5119 | rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type, | |
5120 | &rsrc_cnt, | |
5121 | &rsrc_size); | |
5122 | if (unlikely(rc)) | |
5123 | return -EIO; | |
5124 | ||
5125 | if ((rsrc_cnt == 0) || (rsrc_size == 0)) { | |
5126 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5127 | "3009 No available Resource Extents " | |
5128 | "for resource type 0x%x: Count: 0x%x, " | |
5129 | "Size 0x%x\n", type, rsrc_cnt, | |
5130 | rsrc_size); | |
5131 | return -ENOMEM; | |
5132 | } | |
5133 | ||
5134 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT, | |
5135 | "2903 Available Resource Extents " | |
5136 | "for resource type 0x%x: Count: 0x%x, " | |
5137 | "Size 0x%x\n", type, rsrc_cnt, | |
5138 | rsrc_size); | |
5139 | ||
5140 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5141 | if (!mbox) | |
5142 | return -ENOMEM; | |
5143 | ||
5144 | rc = lpfc_sli4_cfg_post_extnts(phba, &rsrc_cnt, type, &emb, mbox); | |
5145 | if (unlikely(rc)) { | |
5146 | rc = -EIO; | |
5147 | goto err_exit; | |
5148 | } | |
5149 | ||
5150 | /* | |
5151 | * Figure out where the response is located. Then get local pointers | |
5152 | * to the response data. The port does not guarantee to respond to | |
5153 | * all extents counts request so update the local variable with the | |
5154 | * allocated count from the port. | |
5155 | */ | |
5156 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5157 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5158 | id_array = &rsrc_ext->u.rsp.id[0]; | |
5159 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5160 | } else { | |
5161 | virtaddr = mbox->sge_array->addr[0]; | |
5162 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5163 | rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5164 | id_array = &n_rsrc->id; | |
5165 | } | |
5166 | ||
5167 | longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5168 | rsrc_id_cnt = rsrc_cnt * rsrc_size; | |
5169 | ||
5170 | /* | |
5171 | * Based on the resource size and count, correct the base and max | |
5172 | * resource values. | |
5173 | */ | |
5174 | length = sizeof(struct lpfc_rsrc_blks); | |
5175 | switch (type) { | |
5176 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5177 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5178 | sizeof(unsigned long), | |
5179 | GFP_KERNEL); | |
5180 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5181 | rc = -ENOMEM; | |
5182 | goto err_exit; | |
5183 | } | |
5184 | phba->sli4_hba.rpi_ids = kzalloc(rsrc_id_cnt * | |
5185 | sizeof(uint16_t), | |
5186 | GFP_KERNEL); | |
5187 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5188 | kfree(phba->sli4_hba.rpi_bmask); | |
5189 | rc = -ENOMEM; | |
5190 | goto err_exit; | |
5191 | } | |
5192 | ||
5193 | /* | |
5194 | * The next_rpi was initialized with the maximum available | |
5195 | * count but the port may allocate a smaller number. Catch | |
5196 | * that case and update the next_rpi. | |
5197 | */ | |
5198 | phba->sli4_hba.next_rpi = rsrc_id_cnt; | |
5199 | ||
5200 | /* Initialize local ptrs for common extent processing later. */ | |
5201 | bmask = phba->sli4_hba.rpi_bmask; | |
5202 | ids = phba->sli4_hba.rpi_ids; | |
5203 | ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5204 | break; | |
5205 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5206 | phba->vpi_bmask = kzalloc(longs * | |
5207 | sizeof(unsigned long), | |
5208 | GFP_KERNEL); | |
5209 | if (unlikely(!phba->vpi_bmask)) { | |
5210 | rc = -ENOMEM; | |
5211 | goto err_exit; | |
5212 | } | |
5213 | phba->vpi_ids = kzalloc(rsrc_id_cnt * | |
5214 | sizeof(uint16_t), | |
5215 | GFP_KERNEL); | |
5216 | if (unlikely(!phba->vpi_ids)) { | |
5217 | kfree(phba->vpi_bmask); | |
5218 | rc = -ENOMEM; | |
5219 | goto err_exit; | |
5220 | } | |
5221 | ||
5222 | /* Initialize local ptrs for common extent processing later. */ | |
5223 | bmask = phba->vpi_bmask; | |
5224 | ids = phba->vpi_ids; | |
5225 | ext_blk_list = &phba->lpfc_vpi_blk_list; | |
5226 | break; | |
5227 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5228 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5229 | sizeof(unsigned long), | |
5230 | GFP_KERNEL); | |
5231 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5232 | rc = -ENOMEM; | |
5233 | goto err_exit; | |
5234 | } | |
5235 | phba->sli4_hba.xri_ids = kzalloc(rsrc_id_cnt * | |
5236 | sizeof(uint16_t), | |
5237 | GFP_KERNEL); | |
5238 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5239 | kfree(phba->sli4_hba.xri_bmask); | |
5240 | rc = -ENOMEM; | |
5241 | goto err_exit; | |
5242 | } | |
5243 | ||
5244 | /* Initialize local ptrs for common extent processing later. */ | |
5245 | bmask = phba->sli4_hba.xri_bmask; | |
5246 | ids = phba->sli4_hba.xri_ids; | |
5247 | ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list; | |
5248 | break; | |
5249 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5250 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5251 | sizeof(unsigned long), | |
5252 | GFP_KERNEL); | |
5253 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5254 | rc = -ENOMEM; | |
5255 | goto err_exit; | |
5256 | } | |
5257 | phba->sli4_hba.vfi_ids = kzalloc(rsrc_id_cnt * | |
5258 | sizeof(uint16_t), | |
5259 | GFP_KERNEL); | |
5260 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5261 | kfree(phba->sli4_hba.vfi_bmask); | |
5262 | rc = -ENOMEM; | |
5263 | goto err_exit; | |
5264 | } | |
5265 | ||
5266 | /* Initialize local ptrs for common extent processing later. */ | |
5267 | bmask = phba->sli4_hba.vfi_bmask; | |
5268 | ids = phba->sli4_hba.vfi_ids; | |
5269 | ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5270 | break; | |
5271 | default: | |
5272 | /* Unsupported Opcode. Fail call. */ | |
5273 | id_array = NULL; | |
5274 | bmask = NULL; | |
5275 | ids = NULL; | |
5276 | ext_blk_list = NULL; | |
5277 | goto err_exit; | |
5278 | } | |
5279 | ||
5280 | /* | |
5281 | * Complete initializing the extent configuration with the | |
5282 | * allocated ids assigned to this function. The bitmask serves | |
5283 | * as an index into the array and manages the available ids. The | |
5284 | * array just stores the ids communicated to the port via the wqes. | |
5285 | */ | |
5286 | for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) { | |
5287 | if ((i % 2) == 0) | |
5288 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0, | |
5289 | &id_array[k]); | |
5290 | else | |
5291 | rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1, | |
5292 | &id_array[k]); | |
5293 | ||
5294 | rsrc_blks = kzalloc(length, GFP_KERNEL); | |
5295 | if (unlikely(!rsrc_blks)) { | |
5296 | rc = -ENOMEM; | |
5297 | kfree(bmask); | |
5298 | kfree(ids); | |
5299 | goto err_exit; | |
5300 | } | |
5301 | rsrc_blks->rsrc_start = rsrc_id; | |
5302 | rsrc_blks->rsrc_size = rsrc_size; | |
5303 | list_add_tail(&rsrc_blks->list, ext_blk_list); | |
5304 | rsrc_start = rsrc_id; | |
5305 | if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) | |
5306 | phba->sli4_hba.scsi_xri_start = rsrc_start + | |
5307 | lpfc_sli4_get_els_iocb_cnt(phba); | |
5308 | ||
5309 | while (rsrc_id < (rsrc_start + rsrc_size)) { | |
5310 | ids[j] = rsrc_id; | |
5311 | rsrc_id++; | |
5312 | j++; | |
5313 | } | |
5314 | /* Entire word processed. Get next word.*/ | |
5315 | if ((i % 2) == 1) | |
5316 | k++; | |
5317 | } | |
5318 | err_exit: | |
5319 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5320 | return rc; | |
5321 | } | |
5322 | ||
5323 | /** | |
5324 | * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent. | |
5325 | * @phba: Pointer to HBA context object. | |
5326 | * @type: the extent's type. | |
5327 | * | |
5328 | * This function deallocates all extents of a particular resource type. | |
5329 | * SLI4 does not allow for deallocating a particular extent range. It | |
5330 | * is the caller's responsibility to release all kernel memory resources. | |
5331 | **/ | |
5332 | static int | |
5333 | lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type) | |
5334 | { | |
5335 | int rc; | |
5336 | uint32_t length, mbox_tmo = 0; | |
5337 | LPFC_MBOXQ_t *mbox; | |
5338 | struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc; | |
5339 | struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next; | |
5340 | ||
5341 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5342 | if (!mbox) | |
5343 | return -ENOMEM; | |
5344 | ||
5345 | /* | |
5346 | * This function sends an embedded mailbox because it only sends the | |
5347 | * the resource type. All extents of this type are released by the | |
5348 | * port. | |
5349 | */ | |
5350 | length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) - | |
5351 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
5352 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5353 | LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT, | |
5354 | length, LPFC_SLI4_MBX_EMBED); | |
5355 | ||
5356 | /* Send an extents count of 0 - the dealloc doesn't use it. */ | |
5357 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type, | |
5358 | LPFC_SLI4_MBX_EMBED); | |
5359 | if (unlikely(rc)) { | |
5360 | rc = -EIO; | |
5361 | goto out_free_mbox; | |
5362 | } | |
5363 | if (!phba->sli4_hba.intr_enable) | |
5364 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5365 | else { | |
a183a15f | 5366 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
5367 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5368 | } | |
5369 | if (unlikely(rc)) { | |
5370 | rc = -EIO; | |
5371 | goto out_free_mbox; | |
5372 | } | |
5373 | ||
5374 | dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents; | |
5375 | if (bf_get(lpfc_mbox_hdr_status, | |
5376 | &dealloc_rsrc->header.cfg_shdr.response)) { | |
5377 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5378 | "2919 Failed to release resource extents " | |
5379 | "for type %d - Status 0x%x Add'l Status 0x%x. " | |
5380 | "Resource memory not released.\n", | |
5381 | type, | |
5382 | bf_get(lpfc_mbox_hdr_status, | |
5383 | &dealloc_rsrc->header.cfg_shdr.response), | |
5384 | bf_get(lpfc_mbox_hdr_add_status, | |
5385 | &dealloc_rsrc->header.cfg_shdr.response)); | |
5386 | rc = -EIO; | |
5387 | goto out_free_mbox; | |
5388 | } | |
5389 | ||
5390 | /* Release kernel memory resources for the specific type. */ | |
5391 | switch (type) { | |
5392 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5393 | kfree(phba->vpi_bmask); | |
5394 | kfree(phba->vpi_ids); | |
5395 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5396 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5397 | &phba->lpfc_vpi_blk_list, list) { | |
5398 | list_del_init(&rsrc_blk->list); | |
5399 | kfree(rsrc_blk); | |
5400 | } | |
5401 | break; | |
5402 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5403 | kfree(phba->sli4_hba.xri_bmask); | |
5404 | kfree(phba->sli4_hba.xri_ids); | |
5405 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5406 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5407 | &phba->sli4_hba.lpfc_xri_blk_list, list) { | |
5408 | list_del_init(&rsrc_blk->list); | |
5409 | kfree(rsrc_blk); | |
5410 | } | |
5411 | break; | |
5412 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5413 | kfree(phba->sli4_hba.vfi_bmask); | |
5414 | kfree(phba->sli4_hba.vfi_ids); | |
5415 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5416 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5417 | &phba->sli4_hba.lpfc_vfi_blk_list, list) { | |
5418 | list_del_init(&rsrc_blk->list); | |
5419 | kfree(rsrc_blk); | |
5420 | } | |
5421 | break; | |
5422 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5423 | /* RPI bitmask and physical id array are cleaned up earlier. */ | |
5424 | list_for_each_entry_safe(rsrc_blk, rsrc_blk_next, | |
5425 | &phba->sli4_hba.lpfc_rpi_blk_list, list) { | |
5426 | list_del_init(&rsrc_blk->list); | |
5427 | kfree(rsrc_blk); | |
5428 | } | |
5429 | break; | |
5430 | default: | |
5431 | break; | |
5432 | } | |
5433 | ||
5434 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5435 | ||
5436 | out_free_mbox: | |
5437 | mempool_free(mbox, phba->mbox_mem_pool); | |
5438 | return rc; | |
5439 | } | |
5440 | ||
5441 | /** | |
5442 | * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents. | |
5443 | * @phba: Pointer to HBA context object. | |
5444 | * | |
5445 | * This function allocates all SLI4 resource identifiers. | |
5446 | **/ | |
5447 | int | |
5448 | lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba) | |
5449 | { | |
5450 | int i, rc, error = 0; | |
5451 | uint16_t count, base; | |
5452 | unsigned long longs; | |
5453 | ||
ff78d8f9 JS |
5454 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5455 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6d368e53 JS |
5456 | if (phba->sli4_hba.extents_in_use) { |
5457 | /* | |
5458 | * The port supports resource extents. The XRI, VPI, VFI, RPI | |
5459 | * resource extent count must be read and allocated before | |
5460 | * provisioning the resource id arrays. | |
5461 | */ | |
5462 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
5463 | LPFC_IDX_RSRC_RDY) { | |
5464 | /* | |
5465 | * Extent-based resources are set - the driver could | |
5466 | * be in a port reset. Figure out if any corrective | |
5467 | * actions need to be taken. | |
5468 | */ | |
5469 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5470 | LPFC_RSC_TYPE_FCOE_VFI); | |
5471 | if (rc != 0) | |
5472 | error++; | |
5473 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5474 | LPFC_RSC_TYPE_FCOE_VPI); | |
5475 | if (rc != 0) | |
5476 | error++; | |
5477 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5478 | LPFC_RSC_TYPE_FCOE_XRI); | |
5479 | if (rc != 0) | |
5480 | error++; | |
5481 | rc = lpfc_sli4_chk_avail_extnt_rsrc(phba, | |
5482 | LPFC_RSC_TYPE_FCOE_RPI); | |
5483 | if (rc != 0) | |
5484 | error++; | |
5485 | ||
5486 | /* | |
5487 | * It's possible that the number of resources | |
5488 | * provided to this port instance changed between | |
5489 | * resets. Detect this condition and reallocate | |
5490 | * resources. Otherwise, there is no action. | |
5491 | */ | |
5492 | if (error) { | |
5493 | lpfc_printf_log(phba, KERN_INFO, | |
5494 | LOG_MBOX | LOG_INIT, | |
5495 | "2931 Detected extent resource " | |
5496 | "change. Reallocating all " | |
5497 | "extents.\n"); | |
5498 | rc = lpfc_sli4_dealloc_extent(phba, | |
5499 | LPFC_RSC_TYPE_FCOE_VFI); | |
5500 | rc = lpfc_sli4_dealloc_extent(phba, | |
5501 | LPFC_RSC_TYPE_FCOE_VPI); | |
5502 | rc = lpfc_sli4_dealloc_extent(phba, | |
5503 | LPFC_RSC_TYPE_FCOE_XRI); | |
5504 | rc = lpfc_sli4_dealloc_extent(phba, | |
5505 | LPFC_RSC_TYPE_FCOE_RPI); | |
5506 | } else | |
5507 | return 0; | |
5508 | } | |
5509 | ||
5510 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5511 | if (unlikely(rc)) | |
5512 | goto err_exit; | |
5513 | ||
5514 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5515 | if (unlikely(rc)) | |
5516 | goto err_exit; | |
5517 | ||
5518 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5519 | if (unlikely(rc)) | |
5520 | goto err_exit; | |
5521 | ||
5522 | rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5523 | if (unlikely(rc)) | |
5524 | goto err_exit; | |
5525 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5526 | LPFC_IDX_RSRC_RDY); | |
5527 | return rc; | |
5528 | } else { | |
5529 | /* | |
5530 | * The port does not support resource extents. The XRI, VPI, | |
5531 | * VFI, RPI resource ids were determined from READ_CONFIG. | |
5532 | * Just allocate the bitmasks and provision the resource id | |
5533 | * arrays. If a port reset is active, the resources don't | |
5534 | * need any action - just exit. | |
5535 | */ | |
5536 | if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) == | |
ff78d8f9 JS |
5537 | LPFC_IDX_RSRC_RDY) { |
5538 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5539 | lpfc_sli4_remove_rpis(phba); | |
5540 | } | |
6d368e53 JS |
5541 | /* RPIs. */ |
5542 | count = phba->sli4_hba.max_cfg_param.max_rpi; | |
5543 | base = phba->sli4_hba.max_cfg_param.rpi_base; | |
5544 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5545 | phba->sli4_hba.rpi_bmask = kzalloc(longs * | |
5546 | sizeof(unsigned long), | |
5547 | GFP_KERNEL); | |
5548 | if (unlikely(!phba->sli4_hba.rpi_bmask)) { | |
5549 | rc = -ENOMEM; | |
5550 | goto err_exit; | |
5551 | } | |
5552 | phba->sli4_hba.rpi_ids = kzalloc(count * | |
5553 | sizeof(uint16_t), | |
5554 | GFP_KERNEL); | |
5555 | if (unlikely(!phba->sli4_hba.rpi_ids)) { | |
5556 | rc = -ENOMEM; | |
5557 | goto free_rpi_bmask; | |
5558 | } | |
5559 | ||
5560 | for (i = 0; i < count; i++) | |
5561 | phba->sli4_hba.rpi_ids[i] = base + i; | |
5562 | ||
5563 | /* VPIs. */ | |
5564 | count = phba->sli4_hba.max_cfg_param.max_vpi; | |
5565 | base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5566 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5567 | phba->vpi_bmask = kzalloc(longs * | |
5568 | sizeof(unsigned long), | |
5569 | GFP_KERNEL); | |
5570 | if (unlikely(!phba->vpi_bmask)) { | |
5571 | rc = -ENOMEM; | |
5572 | goto free_rpi_ids; | |
5573 | } | |
5574 | phba->vpi_ids = kzalloc(count * | |
5575 | sizeof(uint16_t), | |
5576 | GFP_KERNEL); | |
5577 | if (unlikely(!phba->vpi_ids)) { | |
5578 | rc = -ENOMEM; | |
5579 | goto free_vpi_bmask; | |
5580 | } | |
5581 | ||
5582 | for (i = 0; i < count; i++) | |
5583 | phba->vpi_ids[i] = base + i; | |
5584 | ||
5585 | /* XRIs. */ | |
5586 | count = phba->sli4_hba.max_cfg_param.max_xri; | |
5587 | base = phba->sli4_hba.max_cfg_param.xri_base; | |
5588 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5589 | phba->sli4_hba.xri_bmask = kzalloc(longs * | |
5590 | sizeof(unsigned long), | |
5591 | GFP_KERNEL); | |
5592 | if (unlikely(!phba->sli4_hba.xri_bmask)) { | |
5593 | rc = -ENOMEM; | |
5594 | goto free_vpi_ids; | |
5595 | } | |
5596 | phba->sli4_hba.xri_ids = kzalloc(count * | |
5597 | sizeof(uint16_t), | |
5598 | GFP_KERNEL); | |
5599 | if (unlikely(!phba->sli4_hba.xri_ids)) { | |
5600 | rc = -ENOMEM; | |
5601 | goto free_xri_bmask; | |
5602 | } | |
5603 | ||
5604 | for (i = 0; i < count; i++) | |
5605 | phba->sli4_hba.xri_ids[i] = base + i; | |
5606 | ||
5607 | /* VFIs. */ | |
5608 | count = phba->sli4_hba.max_cfg_param.max_vfi; | |
5609 | base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5610 | longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
5611 | phba->sli4_hba.vfi_bmask = kzalloc(longs * | |
5612 | sizeof(unsigned long), | |
5613 | GFP_KERNEL); | |
5614 | if (unlikely(!phba->sli4_hba.vfi_bmask)) { | |
5615 | rc = -ENOMEM; | |
5616 | goto free_xri_ids; | |
5617 | } | |
5618 | phba->sli4_hba.vfi_ids = kzalloc(count * | |
5619 | sizeof(uint16_t), | |
5620 | GFP_KERNEL); | |
5621 | if (unlikely(!phba->sli4_hba.vfi_ids)) { | |
5622 | rc = -ENOMEM; | |
5623 | goto free_vfi_bmask; | |
5624 | } | |
5625 | ||
5626 | for (i = 0; i < count; i++) | |
5627 | phba->sli4_hba.vfi_ids[i] = base + i; | |
5628 | ||
5629 | /* | |
5630 | * Mark all resources ready. An HBA reset doesn't need | |
5631 | * to reset the initialization. | |
5632 | */ | |
5633 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
5634 | LPFC_IDX_RSRC_RDY); | |
5635 | return 0; | |
5636 | } | |
5637 | ||
5638 | free_vfi_bmask: | |
5639 | kfree(phba->sli4_hba.vfi_bmask); | |
5640 | free_xri_ids: | |
5641 | kfree(phba->sli4_hba.xri_ids); | |
5642 | free_xri_bmask: | |
5643 | kfree(phba->sli4_hba.xri_bmask); | |
5644 | free_vpi_ids: | |
5645 | kfree(phba->vpi_ids); | |
5646 | free_vpi_bmask: | |
5647 | kfree(phba->vpi_bmask); | |
5648 | free_rpi_ids: | |
5649 | kfree(phba->sli4_hba.rpi_ids); | |
5650 | free_rpi_bmask: | |
5651 | kfree(phba->sli4_hba.rpi_bmask); | |
5652 | err_exit: | |
5653 | return rc; | |
5654 | } | |
5655 | ||
5656 | /** | |
5657 | * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents. | |
5658 | * @phba: Pointer to HBA context object. | |
5659 | * | |
5660 | * This function allocates the number of elements for the specified | |
5661 | * resource type. | |
5662 | **/ | |
5663 | int | |
5664 | lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba) | |
5665 | { | |
5666 | if (phba->sli4_hba.extents_in_use) { | |
5667 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI); | |
5668 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI); | |
5669 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI); | |
5670 | lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI); | |
5671 | } else { | |
5672 | kfree(phba->vpi_bmask); | |
5673 | kfree(phba->vpi_ids); | |
5674 | bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5675 | kfree(phba->sli4_hba.xri_bmask); | |
5676 | kfree(phba->sli4_hba.xri_ids); | |
5677 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5678 | kfree(phba->sli4_hba.vfi_bmask); | |
5679 | kfree(phba->sli4_hba.vfi_ids); | |
5680 | bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5681 | bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
5682 | } | |
5683 | ||
5684 | return 0; | |
5685 | } | |
5686 | ||
b76f2dc9 JS |
5687 | /** |
5688 | * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents. | |
5689 | * @phba: Pointer to HBA context object. | |
5690 | * @type: The resource extent type. | |
5691 | * @extnt_count: buffer to hold port extent count response | |
5692 | * @extnt_size: buffer to hold port extent size response. | |
5693 | * | |
5694 | * This function calls the port to read the host allocated extents | |
5695 | * for a particular type. | |
5696 | **/ | |
5697 | int | |
5698 | lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type, | |
5699 | uint16_t *extnt_cnt, uint16_t *extnt_size) | |
5700 | { | |
5701 | bool emb; | |
5702 | int rc = 0; | |
5703 | uint16_t curr_blks = 0; | |
5704 | uint32_t req_len, emb_len; | |
5705 | uint32_t alloc_len, mbox_tmo; | |
5706 | struct list_head *blk_list_head; | |
5707 | struct lpfc_rsrc_blks *rsrc_blk; | |
5708 | LPFC_MBOXQ_t *mbox; | |
5709 | void *virtaddr = NULL; | |
5710 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc; | |
5711 | struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext; | |
5712 | union lpfc_sli4_cfg_shdr *shdr; | |
5713 | ||
5714 | switch (type) { | |
5715 | case LPFC_RSC_TYPE_FCOE_VPI: | |
5716 | blk_list_head = &phba->lpfc_vpi_blk_list; | |
5717 | break; | |
5718 | case LPFC_RSC_TYPE_FCOE_XRI: | |
5719 | blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list; | |
5720 | break; | |
5721 | case LPFC_RSC_TYPE_FCOE_VFI: | |
5722 | blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list; | |
5723 | break; | |
5724 | case LPFC_RSC_TYPE_FCOE_RPI: | |
5725 | blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list; | |
5726 | break; | |
5727 | default: | |
5728 | return -EIO; | |
5729 | } | |
5730 | ||
5731 | /* Count the number of extents currently allocatd for this type. */ | |
5732 | list_for_each_entry(rsrc_blk, blk_list_head, list) { | |
5733 | if (curr_blks == 0) { | |
5734 | /* | |
5735 | * The GET_ALLOCATED mailbox does not return the size, | |
5736 | * just the count. The size should be just the size | |
5737 | * stored in the current allocated block and all sizes | |
5738 | * for an extent type are the same so set the return | |
5739 | * value now. | |
5740 | */ | |
5741 | *extnt_size = rsrc_blk->rsrc_size; | |
5742 | } | |
5743 | curr_blks++; | |
5744 | } | |
5745 | ||
5746 | /* Calculate the total requested length of the dma memory. */ | |
5747 | req_len = curr_blks * sizeof(uint16_t); | |
5748 | ||
5749 | /* | |
5750 | * Calculate the size of an embedded mailbox. The uint32_t | |
5751 | * accounts for extents-specific word. | |
5752 | */ | |
5753 | emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) - | |
5754 | sizeof(uint32_t); | |
5755 | ||
5756 | /* | |
5757 | * Presume the allocation and response will fit into an embedded | |
5758 | * mailbox. If not true, reconfigure to a non-embedded mailbox. | |
5759 | */ | |
5760 | emb = LPFC_SLI4_MBX_EMBED; | |
5761 | req_len = emb_len; | |
5762 | if (req_len > emb_len) { | |
5763 | req_len = curr_blks * sizeof(uint16_t) + | |
5764 | sizeof(union lpfc_sli4_cfg_shdr) + | |
5765 | sizeof(uint32_t); | |
5766 | emb = LPFC_SLI4_MBX_NEMBED; | |
5767 | } | |
5768 | ||
5769 | mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5770 | if (!mbox) | |
5771 | return -ENOMEM; | |
5772 | memset(mbox, 0, sizeof(LPFC_MBOXQ_t)); | |
5773 | ||
5774 | alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
5775 | LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT, | |
5776 | req_len, emb); | |
5777 | if (alloc_len < req_len) { | |
5778 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5779 | "2983 Allocated DMA memory size (x%x) is " | |
5780 | "less than the requested DMA memory " | |
5781 | "size (x%x)\n", alloc_len, req_len); | |
5782 | rc = -ENOMEM; | |
5783 | goto err_exit; | |
5784 | } | |
5785 | rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb); | |
5786 | if (unlikely(rc)) { | |
5787 | rc = -EIO; | |
5788 | goto err_exit; | |
5789 | } | |
5790 | ||
5791 | if (!phba->sli4_hba.intr_enable) | |
5792 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
5793 | else { | |
a183a15f | 5794 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
b76f2dc9 JS |
5795 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
5796 | } | |
5797 | ||
5798 | if (unlikely(rc)) { | |
5799 | rc = -EIO; | |
5800 | goto err_exit; | |
5801 | } | |
5802 | ||
5803 | /* | |
5804 | * Figure out where the response is located. Then get local pointers | |
5805 | * to the response data. The port does not guarantee to respond to | |
5806 | * all extents counts request so update the local variable with the | |
5807 | * allocated count from the port. | |
5808 | */ | |
5809 | if (emb == LPFC_SLI4_MBX_EMBED) { | |
5810 | rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents; | |
5811 | shdr = &rsrc_ext->header.cfg_shdr; | |
5812 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp); | |
5813 | } else { | |
5814 | virtaddr = mbox->sge_array->addr[0]; | |
5815 | n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; | |
5816 | shdr = &n_rsrc->cfg_shdr; | |
5817 | *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc); | |
5818 | } | |
5819 | ||
5820 | if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) { | |
5821 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
5822 | "2984 Failed to read allocated resources " | |
5823 | "for type %d - Status 0x%x Add'l Status 0x%x.\n", | |
5824 | type, | |
5825 | bf_get(lpfc_mbox_hdr_status, &shdr->response), | |
5826 | bf_get(lpfc_mbox_hdr_add_status, &shdr->response)); | |
5827 | rc = -EIO; | |
5828 | goto err_exit; | |
5829 | } | |
5830 | err_exit: | |
5831 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
5832 | return rc; | |
5833 | } | |
5834 | ||
da0436e9 JS |
5835 | /** |
5836 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
5837 | * @phba: Pointer to HBA context object. | |
5838 | * | |
5839 | * This function is the main SLI4 device intialization PCI function. This | |
5840 | * function is called by the HBA intialization code, HBA reset code and | |
5841 | * HBA error attention handler code. Caller is not required to hold any | |
5842 | * locks. | |
5843 | **/ | |
5844 | int | |
5845 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
5846 | { | |
5847 | int rc; | |
5848 | LPFC_MBOXQ_t *mboxq; | |
5849 | struct lpfc_mqe *mqe; | |
5850 | uint8_t *vpd; | |
5851 | uint32_t vpd_size; | |
5852 | uint32_t ftr_rsp = 0; | |
5853 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
5854 | struct lpfc_vport *vport = phba->pport; | |
5855 | struct lpfc_dmabuf *mp; | |
5856 | ||
5857 | /* Perform a PCI function reset to start from clean */ | |
5858 | rc = lpfc_pci_function_reset(phba); | |
5859 | if (unlikely(rc)) | |
5860 | return -ENODEV; | |
5861 | ||
5862 | /* Check the HBA Host Status Register for readyness */ | |
5863 | rc = lpfc_sli4_post_status_check(phba); | |
5864 | if (unlikely(rc)) | |
5865 | return -ENODEV; | |
5866 | else { | |
5867 | spin_lock_irq(&phba->hbalock); | |
5868 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
5869 | spin_unlock_irq(&phba->hbalock); | |
5870 | } | |
5871 | ||
5872 | /* | |
5873 | * Allocate a single mailbox container for initializing the | |
5874 | * port. | |
5875 | */ | |
5876 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
5877 | if (!mboxq) | |
5878 | return -ENOMEM; | |
5879 | ||
da0436e9 | 5880 | /* Issue READ_REV to collect vpd and FW information. */ |
49198b37 | 5881 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
5882 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
5883 | if (!vpd) { | |
5884 | rc = -ENOMEM; | |
5885 | goto out_free_mbox; | |
5886 | } | |
5887 | ||
5888 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
5889 | if (unlikely(rc)) { |
5890 | kfree(vpd); | |
5891 | goto out_free_mbox; | |
5892 | } | |
da0436e9 | 5893 | mqe = &mboxq->u.mqe; |
f1126688 JS |
5894 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
5895 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
5896 | phba->hba_flag |= HBA_FCOE_MODE; |
5897 | else | |
5898 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
5899 | |
5900 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
5901 | LPFC_DCBX_CEE_MODE) | |
5902 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
5903 | else | |
5904 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
5905 | ||
c31098ce | 5906 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
5907 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5908 | "0376 READ_REV Error. SLI Level %d " | |
5909 | "FCoE enabled %d\n", | |
76a95d75 | 5910 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 5911 | rc = -EIO; |
76a95d75 JS |
5912 | kfree(vpd); |
5913 | goto out_free_mbox; | |
da0436e9 | 5914 | } |
cd1c8301 | 5915 | |
ff78d8f9 JS |
5916 | /* |
5917 | * Continue initialization with default values even if driver failed | |
5918 | * to read FCoE param config regions, only read parameters if the | |
5919 | * board is FCoE | |
5920 | */ | |
5921 | if (phba->hba_flag & HBA_FCOE_MODE && | |
5922 | lpfc_sli4_read_fcoe_params(phba)) | |
5923 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT, | |
5924 | "2570 Failed to read FCoE parameters\n"); | |
5925 | ||
cd1c8301 JS |
5926 | /* |
5927 | * Retrieve sli4 device physical port name, failure of doing it | |
5928 | * is considered as non-fatal. | |
5929 | */ | |
5930 | rc = lpfc_sli4_retrieve_pport_name(phba); | |
5931 | if (!rc) | |
5932 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5933 | "3080 Successful retrieving SLI4 device " | |
5934 | "physical port name: %s.\n", phba->Port); | |
5935 | ||
da0436e9 JS |
5936 | /* |
5937 | * Evaluate the read rev and vpd data. Populate the driver | |
5938 | * state with the results. If this routine fails, the failure | |
5939 | * is not fatal as the driver will use generic values. | |
5940 | */ | |
5941 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
5942 | if (unlikely(!rc)) { | |
5943 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5944 | "0377 Error %d parsing vpd. " | |
5945 | "Using defaults.\n", rc); | |
5946 | rc = 0; | |
5947 | } | |
76a95d75 | 5948 | kfree(vpd); |
da0436e9 | 5949 | |
f1126688 JS |
5950 | /* Save information as VPD data */ |
5951 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
5952 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
5953 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
5954 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
5955 | &mqe->un.read_rev); | |
5956 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
5957 | &mqe->un.read_rev); | |
5958 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
5959 | &mqe->un.read_rev); | |
5960 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
5961 | &mqe->un.read_rev); | |
5962 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
5963 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
5964 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
5965 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
5966 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
5967 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
5968 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5969 | "(%d):0380 READ_REV Status x%x " | |
5970 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
5971 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5972 | bf_get(lpfc_mqe_status, mqe), | |
5973 | phba->vpd.rev.opFwName, | |
5974 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
5975 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
5976 | |
5977 | /* | |
5978 | * Discover the port's supported feature set and match it against the | |
5979 | * hosts requests. | |
5980 | */ | |
5981 | lpfc_request_features(phba, mboxq); | |
5982 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5983 | if (unlikely(rc)) { | |
5984 | rc = -EIO; | |
76a95d75 | 5985 | goto out_free_mbox; |
da0436e9 JS |
5986 | } |
5987 | ||
5988 | /* | |
5989 | * The port must support FCP initiator mode as this is the | |
5990 | * only mode running in the host. | |
5991 | */ | |
5992 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
5993 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
5994 | "0378 No support for fcpi mode.\n"); | |
5995 | ftr_rsp++; | |
5996 | } | |
fedd3b7b JS |
5997 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
5998 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
5999 | else | |
6000 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
6001 | /* |
6002 | * If the port cannot support the host's requested features | |
6003 | * then turn off the global config parameters to disable the | |
6004 | * feature in the driver. This is not a fatal error. | |
6005 | */ | |
bf08611b JS |
6006 | phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED; |
6007 | if (phba->cfg_enable_bg) { | |
6008 | if (bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)) | |
6009 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; | |
6010 | else | |
6011 | ftr_rsp++; | |
6012 | } | |
da0436e9 JS |
6013 | |
6014 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
6015 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6016 | ftr_rsp++; | |
6017 | ||
6018 | if (ftr_rsp) { | |
6019 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6020 | "0379 Feature Mismatch Data: x%08x %08x " | |
6021 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
6022 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
6023 | phba->cfg_enable_npiv, phba->max_vpi); | |
6024 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
6025 | phba->cfg_enable_bg = 0; | |
6026 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
6027 | phba->cfg_enable_npiv = 0; | |
6028 | } | |
6029 | ||
6030 | /* These SLI3 features are assumed in SLI4 */ | |
6031 | spin_lock_irq(&phba->hbalock); | |
6032 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
6033 | spin_unlock_irq(&phba->hbalock); | |
6034 | ||
6d368e53 JS |
6035 | /* |
6036 | * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent | |
6037 | * calls depends on these resources to complete port setup. | |
6038 | */ | |
6039 | rc = lpfc_sli4_alloc_resource_identifiers(phba); | |
6040 | if (rc) { | |
6041 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6042 | "2920 Failed to alloc Resource IDs " | |
6043 | "rc = x%x\n", rc); | |
6044 | goto out_free_mbox; | |
6045 | } | |
ff78d8f9 JS |
6046 | /* update physical xri mappings in the scsi buffers */ |
6047 | lpfc_scsi_buf_update(phba); | |
6d368e53 | 6048 | |
da0436e9 | 6049 | /* Read the port's service parameters. */ |
9f1177a3 JS |
6050 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
6051 | if (rc) { | |
6052 | phba->link_state = LPFC_HBA_ERROR; | |
6053 | rc = -ENOMEM; | |
76a95d75 | 6054 | goto out_free_mbox; |
9f1177a3 JS |
6055 | } |
6056 | ||
da0436e9 JS |
6057 | mboxq->vport = vport; |
6058 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6059 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
6060 | if (rc == MBX_SUCCESS) { | |
6061 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
6062 | rc = 0; | |
6063 | } | |
6064 | ||
6065 | /* | |
6066 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
6067 | * it to the mbuf pool. | |
6068 | */ | |
6069 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
6070 | kfree(mp); | |
6071 | mboxq->context1 = NULL; | |
6072 | if (unlikely(rc)) { | |
6073 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6074 | "0382 READ_SPARAM command failed " | |
6075 | "status %d, mbxStatus x%x\n", | |
6076 | rc, bf_get(lpfc_mqe_status, mqe)); | |
6077 | phba->link_state = LPFC_HBA_ERROR; | |
6078 | rc = -EIO; | |
76a95d75 | 6079 | goto out_free_mbox; |
da0436e9 JS |
6080 | } |
6081 | ||
0558056c | 6082 | lpfc_update_vport_wwn(vport); |
da0436e9 JS |
6083 | |
6084 | /* Update the fc_host data structures with new wwn. */ | |
6085 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
6086 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
6087 | ||
6088 | /* Register SGL pool to the device using non-embedded mailbox command */ | |
6d368e53 JS |
6089 | if (!phba->sli4_hba.extents_in_use) { |
6090 | rc = lpfc_sli4_post_els_sgl_list(phba); | |
6091 | if (unlikely(rc)) { | |
6092 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6093 | "0582 Error %d during els sgl post " | |
6094 | "operation\n", rc); | |
6095 | rc = -ENODEV; | |
6096 | goto out_free_mbox; | |
6097 | } | |
6098 | } else { | |
6099 | rc = lpfc_sli4_post_els_sgl_list_ext(phba); | |
6100 | if (unlikely(rc)) { | |
6101 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6102 | "2560 Error %d during els sgl post " | |
6103 | "operation\n", rc); | |
6104 | rc = -ENODEV; | |
6105 | goto out_free_mbox; | |
6106 | } | |
da0436e9 JS |
6107 | } |
6108 | ||
6109 | /* Register SCSI SGL pool to the device */ | |
6110 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
6111 | if (unlikely(rc)) { | |
6d368e53 | 6112 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6a9c52cf JS |
6113 | "0383 Error %d during scsi sgl post " |
6114 | "operation\n", rc); | |
da0436e9 JS |
6115 | /* Some Scsi buffers were moved to the abort scsi list */ |
6116 | /* A pci function reset will repost them */ | |
6117 | rc = -ENODEV; | |
76a95d75 | 6118 | goto out_free_mbox; |
da0436e9 JS |
6119 | } |
6120 | ||
6121 | /* Post the rpi header region to the device. */ | |
6122 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
6123 | if (unlikely(rc)) { | |
6124 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6125 | "0393 Error %d during rpi post operation\n", | |
6126 | rc); | |
6127 | rc = -ENODEV; | |
76a95d75 | 6128 | goto out_free_mbox; |
da0436e9 | 6129 | } |
da0436e9 | 6130 | |
5350d872 JS |
6131 | /* Create all the SLI4 queues */ |
6132 | rc = lpfc_sli4_queue_create(phba); | |
6133 | if (rc) { | |
6134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6135 | "3089 Failed to allocate queues\n"); | |
6136 | rc = -ENODEV; | |
6137 | goto out_stop_timers; | |
6138 | } | |
da0436e9 JS |
6139 | /* Set up all the queues to the device */ |
6140 | rc = lpfc_sli4_queue_setup(phba); | |
6141 | if (unlikely(rc)) { | |
6142 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6143 | "0381 Error %d during queue setup.\n ", rc); | |
5350d872 | 6144 | goto out_destroy_queue; |
da0436e9 JS |
6145 | } |
6146 | ||
6147 | /* Arm the CQs and then EQs on device */ | |
6148 | lpfc_sli4_arm_cqeq_intr(phba); | |
6149 | ||
6150 | /* Indicate device interrupt mode */ | |
6151 | phba->sli4_hba.intr_enable = 1; | |
6152 | ||
6153 | /* Allow asynchronous mailbox command to go through */ | |
6154 | spin_lock_irq(&phba->hbalock); | |
6155 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6156 | spin_unlock_irq(&phba->hbalock); | |
6157 | ||
6158 | /* Post receive buffers to the device */ | |
6159 | lpfc_sli4_rb_setup(phba); | |
6160 | ||
fc2b989b JS |
6161 | /* Reset HBA FCF states after HBA reset */ |
6162 | phba->fcf.fcf_flag = 0; | |
6163 | phba->fcf.current_rec.flag = 0; | |
6164 | ||
da0436e9 | 6165 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
6166 | mod_timer(&vport->els_tmofunc, |
6167 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
6168 | |
6169 | /* Start heart beat timer */ | |
6170 | mod_timer(&phba->hb_tmofunc, | |
6171 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
6172 | phba->hb_outstanding = 0; | |
6173 | phba->last_completion_time = jiffies; | |
6174 | ||
6175 | /* Start error attention (ERATT) polling timer */ | |
6176 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
6177 | ||
75baf696 JS |
6178 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
6179 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
6180 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
6181 | if (!rc) { | |
6182 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6183 | "2829 This device supports " | |
6184 | "Advanced Error Reporting (AER)\n"); | |
6185 | spin_lock_irq(&phba->hbalock); | |
6186 | phba->hba_flag |= HBA_AER_ENABLED; | |
6187 | spin_unlock_irq(&phba->hbalock); | |
6188 | } else { | |
6189 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6190 | "2830 This device does not support " | |
6191 | "Advanced Error Reporting (AER)\n"); | |
6192 | phba->cfg_aer_support = 0; | |
6193 | } | |
0a96e975 | 6194 | rc = 0; |
75baf696 JS |
6195 | } |
6196 | ||
76a95d75 JS |
6197 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
6198 | /* | |
6199 | * The FC Port needs to register FCFI (index 0) | |
6200 | */ | |
6201 | lpfc_reg_fcfi(phba, mboxq); | |
6202 | mboxq->vport = phba->pport; | |
6203 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 6204 | if (rc != MBX_SUCCESS) |
76a95d75 | 6205 | goto out_unset_queue; |
9589b062 JS |
6206 | rc = 0; |
6207 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
6208 | &mboxq->u.mqe.un.reg_fcfi); | |
026abb87 JS |
6209 | |
6210 | /* Check if the port is configured to be disabled */ | |
6211 | lpfc_sli_read_link_ste(phba); | |
76a95d75 | 6212 | } |
026abb87 | 6213 | |
da0436e9 JS |
6214 | /* |
6215 | * The port is ready, set the host's link state to LINK_DOWN | |
6216 | * in preparation for link interrupts. | |
6217 | */ | |
da0436e9 JS |
6218 | spin_lock_irq(&phba->hbalock); |
6219 | phba->link_state = LPFC_LINK_DOWN; | |
6220 | spin_unlock_irq(&phba->hbalock); | |
026abb87 JS |
6221 | if (!(phba->hba_flag & HBA_FCOE_MODE) && |
6222 | (phba->hba_flag & LINK_DISABLED)) { | |
6223 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6224 | "3103 Adapter Link is disabled.\n"); | |
6225 | lpfc_down_link(phba, mboxq); | |
6226 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6227 | if (rc != MBX_SUCCESS) { | |
6228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_SLI, | |
6229 | "3104 Adapter failed to issue " | |
6230 | "DOWN_LINK mbox cmd, rc:x%x\n", rc); | |
6231 | goto out_unset_queue; | |
6232 | } | |
6233 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { | |
fedd3b7b | 6234 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
5350d872 JS |
6235 | if (rc) |
6236 | goto out_unset_queue; | |
6237 | } | |
6238 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6239 | return rc; | |
76a95d75 | 6240 | out_unset_queue: |
da0436e9 | 6241 | /* Unset all the queues set up in this routine when error out */ |
5350d872 JS |
6242 | lpfc_sli4_queue_unset(phba); |
6243 | out_destroy_queue: | |
6244 | lpfc_sli4_queue_destroy(phba); | |
da0436e9 | 6245 | out_stop_timers: |
5350d872 | 6246 | lpfc_stop_hba_timers(phba); |
da0436e9 JS |
6247 | out_free_mbox: |
6248 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6249 | return rc; | |
6250 | } | |
6251 | ||
6252 | /** | |
6253 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
6254 | * @ptr: context object - pointer to hba structure. | |
6255 | * | |
6256 | * This is the callback function for mailbox timer. The mailbox | |
6257 | * timer is armed when a new mailbox command is issued and the timer | |
6258 | * is deleted when the mailbox complete. The function is called by | |
6259 | * the kernel timer code when a mailbox does not complete within | |
6260 | * expected time. This function wakes up the worker thread to | |
6261 | * process the mailbox timeout and returns. All the processing is | |
6262 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
6263 | **/ | |
6264 | void | |
6265 | lpfc_mbox_timeout(unsigned long ptr) | |
6266 | { | |
6267 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
6268 | unsigned long iflag; | |
6269 | uint32_t tmo_posted; | |
6270 | ||
6271 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
6272 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
6273 | if (!tmo_posted) | |
6274 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
6275 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
6276 | ||
6277 | if (!tmo_posted) | |
6278 | lpfc_worker_wake_up(phba); | |
6279 | return; | |
6280 | } | |
6281 | ||
6282 | ||
6283 | /** | |
6284 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
6285 | * @phba: Pointer to HBA context object. | |
6286 | * | |
6287 | * This function is called from worker thread when a mailbox command times out. | |
6288 | * The caller is not required to hold any locks. This function will reset the | |
6289 | * HBA and recover all the pending commands. | |
6290 | **/ | |
6291 | void | |
6292 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
6293 | { | |
6294 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 6295 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
6296 | struct lpfc_sli *psli = &phba->sli; |
6297 | struct lpfc_sli_ring *pring; | |
6298 | ||
6299 | /* Check the pmbox pointer first. There is a race condition | |
6300 | * between the mbox timeout handler getting executed in the | |
6301 | * worklist and the mailbox actually completing. When this | |
6302 | * race condition occurs, the mbox_active will be NULL. | |
6303 | */ | |
6304 | spin_lock_irq(&phba->hbalock); | |
6305 | if (pmbox == NULL) { | |
6306 | lpfc_printf_log(phba, KERN_WARNING, | |
6307 | LOG_MBOX | LOG_SLI, | |
6308 | "0353 Active Mailbox cleared - mailbox timeout " | |
6309 | "exiting\n"); | |
6310 | spin_unlock_irq(&phba->hbalock); | |
6311 | return; | |
6312 | } | |
6313 | ||
6314 | /* Mbox cmd <mbxCommand> timeout */ | |
6315 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6316 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
6317 | mb->mbxCommand, | |
6318 | phba->pport->port_state, | |
6319 | phba->sli.sli_flag, | |
6320 | phba->sli.mbox_active); | |
6321 | spin_unlock_irq(&phba->hbalock); | |
6322 | ||
6323 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
6324 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 6325 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
6326 | */ |
6327 | spin_lock_irq(&phba->pport->work_port_lock); | |
6328 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
6329 | spin_unlock_irq(&phba->pport->work_port_lock); | |
6330 | spin_lock_irq(&phba->hbalock); | |
6331 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 6332 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
6333 | spin_unlock_irq(&phba->hbalock); |
6334 | ||
6335 | pring = &psli->ring[psli->fcp_ring]; | |
6336 | lpfc_sli_abort_iocb_ring(phba, pring); | |
6337 | ||
6338 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6339 | "0345 Resetting board due to mailbox timeout\n"); | |
6340 | ||
6341 | /* Reset the HBA device */ | |
6342 | lpfc_reset_hba(phba); | |
6343 | } | |
6344 | ||
6345 | /** | |
6346 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
6347 | * @phba: Pointer to HBA context object. | |
6348 | * @pmbox: Pointer to mailbox object. | |
6349 | * @flag: Flag indicating how the mailbox need to be processed. | |
6350 | * | |
6351 | * This function is called by discovery code and HBA management code | |
6352 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
6353 | * function gets the hbalock to protect the data structures. | |
6354 | * The mailbox command can be submitted in polling mode, in which case | |
6355 | * this function will wait in a polling loop for the completion of the | |
6356 | * mailbox. | |
6357 | * If the mailbox is submitted in no_wait mode (not polling) the | |
6358 | * function will submit the command and returns immediately without waiting | |
6359 | * for the mailbox completion. The no_wait is supported only when HBA | |
6360 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
6361 | * The SLI interface allows only one mailbox pending at a time. If the | |
6362 | * mailbox is issued in polling mode and there is already a mailbox | |
6363 | * pending, then the function will return an error. If the mailbox is issued | |
6364 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
6365 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
6366 | * The sli layer owns the mailbox object until the completion of mailbox | |
6367 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
6368 | * return codes the caller owns the mailbox command after the return of | |
6369 | * the function. | |
e59058c4 | 6370 | **/ |
3772a991 JS |
6371 | static int |
6372 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
6373 | uint32_t flag) | |
dea3101e | 6374 | { |
dea3101e | 6375 | MAILBOX_t *mb; |
2e0fef85 | 6376 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6377 | uint32_t status, evtctr; |
9940b97b | 6378 | uint32_t ha_copy, hc_copy; |
dea3101e | 6379 | int i; |
09372820 | 6380 | unsigned long timeout; |
dea3101e | 6381 | unsigned long drvr_flag = 0; |
34b02dcd | 6382 | uint32_t word0, ldata; |
dea3101e | 6383 | void __iomem *to_slim; |
58da1ffb JS |
6384 | int processing_queue = 0; |
6385 | ||
6386 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6387 | if (!pmbox) { | |
8568a4d2 | 6388 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 6389 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
6390 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
6391 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6392 | return MBX_SUCCESS; | |
6393 | } | |
58da1ffb | 6394 | processing_queue = 1; |
58da1ffb JS |
6395 | pmbox = lpfc_mbox_get(phba); |
6396 | if (!pmbox) { | |
6397 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6398 | return MBX_SUCCESS; | |
6399 | } | |
6400 | } | |
dea3101e | 6401 | |
ed957684 | 6402 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 6403 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 6404 | if(!pmbox->vport) { |
58da1ffb | 6405 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 6406 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 6407 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 6408 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 6409 | pmbox->u.mb.mbxCommand); |
ed957684 | 6410 | dump_stack(); |
58da1ffb | 6411 | goto out_not_finished; |
ed957684 JS |
6412 | } |
6413 | } | |
6414 | ||
8d63f375 | 6415 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
6416 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
6417 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6418 | goto out_not_finished; | |
6419 | } | |
8d63f375 | 6420 | |
a257bf90 JS |
6421 | /* If HBA has a deferred error attention, fail the iocb. */ |
6422 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
6423 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6424 | goto out_not_finished; | |
6425 | } | |
6426 | ||
dea3101e | 6427 | psli = &phba->sli; |
92d7f7b0 | 6428 | |
3772a991 | 6429 | mb = &pmbox->u.mb; |
dea3101e | 6430 | status = MBX_SUCCESS; |
6431 | ||
2e0fef85 JS |
6432 | if (phba->link_state == LPFC_HBA_ERROR) { |
6433 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
6434 | |
6435 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6436 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6437 | "(%d):0311 Mailbox command x%x cannot " | |
6438 | "issue Data: x%x x%x\n", | |
6439 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6440 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 6441 | goto out_not_finished; |
41415862 JW |
6442 | } |
6443 | ||
9940b97b JS |
6444 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
6445 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || | |
6446 | !(hc_copy & HC_MBINT_ENA)) { | |
6447 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
6448 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
6449 | "(%d):2528 Mailbox command x%x cannot " |
6450 | "issue Data: x%x x%x\n", | |
6451 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6452 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
6453 | goto out_not_finished; |
6454 | } | |
9290831f JS |
6455 | } |
6456 | ||
dea3101e | 6457 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
6458 | /* Polling for a mbox command when another one is already active | |
6459 | * is not allowed in SLI. Also, the driver must have established | |
6460 | * SLI2 mode to queue and process multiple mbox commands. | |
6461 | */ | |
6462 | ||
6463 | if (flag & MBX_POLL) { | |
2e0fef85 | 6464 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6465 | |
6466 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
6467 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6468 | "(%d):2529 Mailbox command x%x " | |
6469 | "cannot issue Data: x%x x%x\n", | |
6470 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6471 | pmbox->u.mb.mbxCommand, | |
6472 | psli->sli_flag, flag); | |
58da1ffb | 6473 | goto out_not_finished; |
dea3101e | 6474 | } |
6475 | ||
3772a991 | 6476 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 6477 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6478 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6479 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6480 | "(%d):2530 Mailbox command x%x " | |
6481 | "cannot issue Data: x%x x%x\n", | |
6482 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6483 | pmbox->u.mb.mbxCommand, | |
6484 | psli->sli_flag, flag); | |
58da1ffb | 6485 | goto out_not_finished; |
dea3101e | 6486 | } |
6487 | ||
dea3101e | 6488 | /* Another mailbox command is still being processed, queue this |
6489 | * command to be processed later. | |
6490 | */ | |
6491 | lpfc_mbox_put(phba, pmbox); | |
6492 | ||
6493 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 6494 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6495 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 6496 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
6497 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
6498 | mb->mbxCommand, phba->pport->port_state, | |
6499 | psli->sli_flag, flag); | |
dea3101e | 6500 | |
6501 | psli->slistat.mbox_busy++; | |
2e0fef85 | 6502 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6503 | |
858c9f6c JS |
6504 | if (pmbox->vport) { |
6505 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6506 | LPFC_DISC_TRC_MBOX_VPORT, | |
6507 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
6508 | (uint32_t)mb->mbxCommand, | |
6509 | mb->un.varWords[0], mb->un.varWords[1]); | |
6510 | } | |
6511 | else { | |
6512 | lpfc_debugfs_disc_trc(phba->pport, | |
6513 | LPFC_DISC_TRC_MBOX, | |
6514 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
6515 | (uint32_t)mb->mbxCommand, | |
6516 | mb->un.varWords[0], mb->un.varWords[1]); | |
6517 | } | |
6518 | ||
2e0fef85 | 6519 | return MBX_BUSY; |
dea3101e | 6520 | } |
6521 | ||
dea3101e | 6522 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
6523 | ||
6524 | /* If we are not polling, we MUST be in SLI2 mode */ | |
6525 | if (flag != MBX_POLL) { | |
3772a991 | 6526 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 6527 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 6528 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6529 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 6530 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
6531 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
6532 | "(%d):2531 Mailbox command x%x " | |
6533 | "cannot issue Data: x%x x%x\n", | |
6534 | pmbox->vport ? pmbox->vport->vpi : 0, | |
6535 | pmbox->u.mb.mbxCommand, | |
6536 | psli->sli_flag, flag); | |
58da1ffb | 6537 | goto out_not_finished; |
dea3101e | 6538 | } |
6539 | /* timeout active mbox command */ | |
a309a6b6 | 6540 | mod_timer(&psli->mbox_tmo, (jiffies + |
a183a15f | 6541 | (HZ * lpfc_mbox_tmo_val(phba, pmbox)))); |
dea3101e | 6542 | } |
6543 | ||
6544 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 6545 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 6546 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 6547 | "x%x\n", |
e8b62011 | 6548 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
6549 | mb->mbxCommand, phba->pport->port_state, |
6550 | psli->sli_flag, flag); | |
dea3101e | 6551 | |
858c9f6c JS |
6552 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
6553 | if (pmbox->vport) { | |
6554 | lpfc_debugfs_disc_trc(pmbox->vport, | |
6555 | LPFC_DISC_TRC_MBOX_VPORT, | |
6556 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
6557 | (uint32_t)mb->mbxCommand, | |
6558 | mb->un.varWords[0], mb->un.varWords[1]); | |
6559 | } | |
6560 | else { | |
6561 | lpfc_debugfs_disc_trc(phba->pport, | |
6562 | LPFC_DISC_TRC_MBOX, | |
6563 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
6564 | (uint32_t)mb->mbxCommand, | |
6565 | mb->un.varWords[0], mb->un.varWords[1]); | |
6566 | } | |
6567 | } | |
6568 | ||
dea3101e | 6569 | psli->slistat.mbox_cmd++; |
6570 | evtctr = psli->slistat.mbox_event; | |
6571 | ||
6572 | /* next set own bit for the adapter and copy over command word */ | |
6573 | mb->mbxOwner = OWN_CHIP; | |
6574 | ||
3772a991 | 6575 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
6576 | /* Populate mbox extension offset word. */ |
6577 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
6578 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6579 | = (uint8_t *)phba->mbox_ext | |
6580 | - (uint8_t *)phba->mbox; | |
6581 | } | |
6582 | ||
6583 | /* Copy the mailbox extension data */ | |
6584 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6585 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
6586 | (uint8_t *)phba->mbox_ext, | |
6587 | pmbox->in_ext_byte_len); | |
6588 | } | |
6589 | /* Copy command data to host SLIM area */ | |
34b02dcd | 6590 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 6591 | } else { |
7a470277 JS |
6592 | /* Populate mbox extension offset word. */ |
6593 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
6594 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
6595 | = MAILBOX_HBA_EXT_OFFSET; | |
6596 | ||
6597 | /* Copy the mailbox extension data */ | |
6598 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
6599 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
6600 | MAILBOX_HBA_EXT_OFFSET, | |
6601 | pmbox->context2, pmbox->in_ext_byte_len); | |
6602 | ||
6603 | } | |
9290831f | 6604 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 6605 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 6606 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 6607 | } |
6608 | ||
6609 | /* First copy mbox command data to HBA SLIM, skip past first | |
6610 | word */ | |
6611 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
6612 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
6613 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
6614 | ||
6615 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 6616 | ldata = *((uint32_t *)mb); |
dea3101e | 6617 | to_slim = phba->MBslimaddr; |
6618 | writel(ldata, to_slim); | |
6619 | readl(to_slim); /* flush */ | |
6620 | ||
6621 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6622 | /* switch over to host mailbox */ | |
3772a991 | 6623 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e | 6624 | } |
6625 | } | |
6626 | ||
6627 | wmb(); | |
dea3101e | 6628 | |
6629 | switch (flag) { | |
6630 | case MBX_NOWAIT: | |
09372820 | 6631 | /* Set up reference to mailbox command */ |
dea3101e | 6632 | psli->mbox_active = pmbox; |
09372820 JS |
6633 | /* Interrupt board to do it */ |
6634 | writel(CA_MBATT, phba->CAregaddr); | |
6635 | readl(phba->CAregaddr); /* flush */ | |
6636 | /* Don't wait for it to finish, just return */ | |
dea3101e | 6637 | break; |
6638 | ||
6639 | case MBX_POLL: | |
09372820 | 6640 | /* Set up null reference to mailbox command */ |
dea3101e | 6641 | psli->mbox_active = NULL; |
09372820 JS |
6642 | /* Interrupt board to do it */ |
6643 | writel(CA_MBATT, phba->CAregaddr); | |
6644 | readl(phba->CAregaddr); /* flush */ | |
6645 | ||
3772a991 | 6646 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6647 | /* First read mbox status word */ |
34b02dcd | 6648 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 6649 | word0 = le32_to_cpu(word0); |
6650 | } else { | |
6651 | /* First read mbox status word */ | |
9940b97b JS |
6652 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
6653 | spin_unlock_irqrestore(&phba->hbalock, | |
6654 | drvr_flag); | |
6655 | goto out_not_finished; | |
6656 | } | |
dea3101e | 6657 | } |
6658 | ||
6659 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6660 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6661 | spin_unlock_irqrestore(&phba->hbalock, | |
6662 | drvr_flag); | |
6663 | goto out_not_finished; | |
6664 | } | |
a183a15f JS |
6665 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) * |
6666 | 1000) + jiffies; | |
09372820 | 6667 | i = 0; |
dea3101e | 6668 | /* Wait for command to complete */ |
41415862 JW |
6669 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
6670 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 6671 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 6672 | if (time_after(jiffies, timeout)) { |
dea3101e | 6673 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 6674 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 6675 | drvr_flag); |
58da1ffb | 6676 | goto out_not_finished; |
dea3101e | 6677 | } |
6678 | ||
6679 | /* Check if we took a mbox interrupt while we were | |
6680 | polling */ | |
6681 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
6682 | && (evtctr != psli->slistat.mbox_event)) | |
6683 | break; | |
6684 | ||
09372820 JS |
6685 | if (i++ > 10) { |
6686 | spin_unlock_irqrestore(&phba->hbalock, | |
6687 | drvr_flag); | |
6688 | msleep(1); | |
6689 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
6690 | } | |
dea3101e | 6691 | |
3772a991 | 6692 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6693 | /* First copy command data */ |
34b02dcd | 6694 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 6695 | word0 = le32_to_cpu(word0); |
6696 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
6697 | MAILBOX_t *slimmb; | |
34b02dcd | 6698 | uint32_t slimword0; |
dea3101e | 6699 | /* Check real SLIM for any errors */ |
6700 | slimword0 = readl(phba->MBslimaddr); | |
6701 | slimmb = (MAILBOX_t *) & slimword0; | |
6702 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
6703 | && slimmb->mbxStatus) { | |
6704 | psli->sli_flag &= | |
3772a991 | 6705 | ~LPFC_SLI_ACTIVE; |
dea3101e | 6706 | word0 = slimword0; |
6707 | } | |
6708 | } | |
6709 | } else { | |
6710 | /* First copy command data */ | |
6711 | word0 = readl(phba->MBslimaddr); | |
6712 | } | |
6713 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
6714 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
6715 | spin_unlock_irqrestore(&phba->hbalock, | |
6716 | drvr_flag); | |
6717 | goto out_not_finished; | |
6718 | } | |
dea3101e | 6719 | } |
6720 | ||
3772a991 | 6721 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 6722 | /* copy results back to user */ |
34b02dcd | 6723 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
6724 | /* Copy the mailbox extension data */ |
6725 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6726 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
6727 | pmbox->context2, | |
6728 | pmbox->out_ext_byte_len); | |
6729 | } | |
dea3101e | 6730 | } else { |
6731 | /* First copy command data */ | |
6732 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
6733 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
6734 | /* Copy the mailbox extension data */ |
6735 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
6736 | lpfc_memcpy_from_slim(pmbox->context2, | |
6737 | phba->MBslimaddr + | |
6738 | MAILBOX_HBA_EXT_OFFSET, | |
6739 | pmbox->out_ext_byte_len); | |
dea3101e | 6740 | } |
6741 | } | |
6742 | ||
6743 | writel(HA_MBATT, phba->HAregaddr); | |
6744 | readl(phba->HAregaddr); /* flush */ | |
6745 | ||
6746 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6747 | status = mb->mbxStatus; | |
6748 | } | |
6749 | ||
2e0fef85 JS |
6750 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
6751 | return status; | |
58da1ffb JS |
6752 | |
6753 | out_not_finished: | |
6754 | if (processing_queue) { | |
da0436e9 | 6755 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
6756 | lpfc_mbox_cmpl_put(phba, pmbox); |
6757 | } | |
6758 | return MBX_NOT_FINISHED; | |
dea3101e | 6759 | } |
6760 | ||
f1126688 JS |
6761 | /** |
6762 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
6763 | * @phba: Pointer to HBA context object. | |
6764 | * | |
6765 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
6766 | * the driver internal pending mailbox queue. It will then try to wait out the | |
6767 | * possible outstanding mailbox command before return. | |
6768 | * | |
6769 | * Returns: | |
6770 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
6771 | * the outstanding mailbox command timed out. | |
6772 | **/ | |
6773 | static int | |
6774 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
6775 | { | |
6776 | struct lpfc_sli *psli = &phba->sli; | |
f1126688 | 6777 | int rc = 0; |
a183a15f | 6778 | unsigned long timeout = 0; |
f1126688 JS |
6779 | |
6780 | /* Mark the asynchronous mailbox command posting as blocked */ | |
6781 | spin_lock_irq(&phba->hbalock); | |
6782 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
f1126688 JS |
6783 | /* Determine how long we might wait for the active mailbox |
6784 | * command to be gracefully completed by firmware. | |
6785 | */ | |
a183a15f JS |
6786 | if (phba->sli.mbox_active) |
6787 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
6788 | phba->sli.mbox_active) * | |
6789 | 1000) + jiffies; | |
6790 | spin_unlock_irq(&phba->hbalock); | |
6791 | ||
f1126688 JS |
6792 | /* Wait for the outstnading mailbox command to complete */ |
6793 | while (phba->sli.mbox_active) { | |
6794 | /* Check active mailbox complete status every 2ms */ | |
6795 | msleep(2); | |
6796 | if (time_after(jiffies, timeout)) { | |
6797 | /* Timeout, marked the outstanding cmd not complete */ | |
6798 | rc = 1; | |
6799 | break; | |
6800 | } | |
6801 | } | |
6802 | ||
6803 | /* Can not cleanly block async mailbox command, fails it */ | |
6804 | if (rc) { | |
6805 | spin_lock_irq(&phba->hbalock); | |
6806 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6807 | spin_unlock_irq(&phba->hbalock); | |
6808 | } | |
6809 | return rc; | |
6810 | } | |
6811 | ||
6812 | /** | |
6813 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
6814 | * @phba: Pointer to HBA context object. | |
6815 | * | |
6816 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
6817 | * commands from the driver internal pending mailbox queue. It makes sure | |
6818 | * that there is no outstanding mailbox command before resuming posting | |
6819 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
6820 | * mailbox command, it will try to wait it out before resuming asynchronous | |
6821 | * mailbox command posting. | |
6822 | **/ | |
6823 | static void | |
6824 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
6825 | { | |
6826 | struct lpfc_sli *psli = &phba->sli; | |
6827 | ||
6828 | spin_lock_irq(&phba->hbalock); | |
6829 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
6830 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
6831 | spin_unlock_irq(&phba->hbalock); | |
6832 | return; | |
6833 | } | |
6834 | ||
6835 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
6836 | * successful or timeout, after timing-out the outstanding mailbox | |
6837 | * command shall always be removed, so just unblock posting async | |
6838 | * mailbox command and resume | |
6839 | */ | |
6840 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
6841 | spin_unlock_irq(&phba->hbalock); | |
6842 | ||
6843 | /* wake up worker thread to post asynchronlous mailbox command */ | |
6844 | lpfc_worker_wake_up(phba); | |
6845 | } | |
6846 | ||
da0436e9 JS |
6847 | /** |
6848 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
6849 | * @phba: Pointer to HBA context object. | |
6850 | * @mboxq: Pointer to mailbox object. | |
6851 | * | |
6852 | * The function posts a mailbox to the port. The mailbox is expected | |
6853 | * to be comletely filled in and ready for the port to operate on it. | |
6854 | * This routine executes a synchronous completion operation on the | |
6855 | * mailbox by polling for its completion. | |
6856 | * | |
6857 | * The caller must not be holding any locks when calling this routine. | |
6858 | * | |
6859 | * Returns: | |
6860 | * MBX_SUCCESS - mailbox posted successfully | |
6861 | * Any of the MBX error values. | |
6862 | **/ | |
6863 | static int | |
6864 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
6865 | { | |
6866 | int rc = MBX_SUCCESS; | |
6867 | unsigned long iflag; | |
6868 | uint32_t db_ready; | |
6869 | uint32_t mcqe_status; | |
6870 | uint32_t mbx_cmnd; | |
6871 | unsigned long timeout; | |
6872 | struct lpfc_sli *psli = &phba->sli; | |
6873 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
6874 | struct lpfc_bmbx_create *mbox_rgn; | |
6875 | struct dma_address *dma_address; | |
6876 | struct lpfc_register bmbx_reg; | |
6877 | ||
6878 | /* | |
6879 | * Only one mailbox can be active to the bootstrap mailbox region | |
6880 | * at a time and there is no queueing provided. | |
6881 | */ | |
6882 | spin_lock_irqsave(&phba->hbalock, iflag); | |
6883 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
6884 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6885 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 6886 | "(%d):2532 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
6887 | "cannot issue Data: x%x x%x\n", |
6888 | mboxq->vport ? mboxq->vport->vpi : 0, | |
6889 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
6890 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
6891 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
6892 | psli->sli_flag, MBX_POLL); |
6893 | return MBXERR_ERROR; | |
6894 | } | |
6895 | /* The server grabs the token and owns it until release */ | |
6896 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
6897 | phba->sli.mbox_active = mboxq; | |
6898 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6899 | ||
6900 | /* | |
6901 | * Initialize the bootstrap memory region to avoid stale data areas | |
6902 | * in the mailbox post. Then copy the caller's mailbox contents to | |
6903 | * the bmbx mailbox region. | |
6904 | */ | |
6905 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
6906 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
6907 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
6908 | sizeof(struct lpfc_mqe)); | |
6909 | ||
6910 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
6911 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
6912 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
6913 | ||
a183a15f | 6914 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
da0436e9 JS |
6915 | * 1000) + jiffies; |
6916 | do { | |
6917 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
6918 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
6919 | if (!db_ready) | |
6920 | msleep(2); | |
6921 | ||
6922 | if (time_after(jiffies, timeout)) { | |
6923 | rc = MBXERR_ERROR; | |
6924 | goto exit; | |
6925 | } | |
6926 | } while (!db_ready); | |
6927 | ||
6928 | /* Post the low mailbox dma address to the port. */ | |
6929 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
a183a15f | 6930 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq) |
da0436e9 JS |
6931 | * 1000) + jiffies; |
6932 | do { | |
6933 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
6934 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
6935 | if (!db_ready) | |
6936 | msleep(2); | |
6937 | ||
6938 | if (time_after(jiffies, timeout)) { | |
6939 | rc = MBXERR_ERROR; | |
6940 | goto exit; | |
6941 | } | |
6942 | } while (!db_ready); | |
6943 | ||
6944 | /* | |
6945 | * Read the CQ to ensure the mailbox has completed. | |
6946 | * If so, update the mailbox status so that the upper layers | |
6947 | * can complete the request normally. | |
6948 | */ | |
6949 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
6950 | sizeof(struct lpfc_mqe)); | |
6951 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
6952 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
6953 | sizeof(struct lpfc_mcqe)); | |
6954 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
0558056c JS |
6955 | /* |
6956 | * When the CQE status indicates a failure and the mailbox status | |
6957 | * indicates success then copy the CQE status into the mailbox status | |
6958 | * (and prefix it with x4000). | |
6959 | */ | |
da0436e9 | 6960 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { |
0558056c JS |
6961 | if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS) |
6962 | bf_set(lpfc_mqe_status, mb, | |
6963 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
da0436e9 | 6964 | rc = MBXERR_ERROR; |
d7c47992 JS |
6965 | } else |
6966 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
6967 | |
6968 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 6969 | "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x " |
da0436e9 JS |
6970 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" |
6971 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
a183a15f JS |
6972 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, |
6973 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), | |
6974 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
6975 | bf_get(lpfc_mqe_status, mb), |
6976 | mb->un.mb_words[0], mb->un.mb_words[1], | |
6977 | mb->un.mb_words[2], mb->un.mb_words[3], | |
6978 | mb->un.mb_words[4], mb->un.mb_words[5], | |
6979 | mb->un.mb_words[6], mb->un.mb_words[7], | |
6980 | mb->un.mb_words[8], mb->un.mb_words[9], | |
6981 | mb->un.mb_words[10], mb->un.mb_words[11], | |
6982 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
6983 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
6984 | mboxq->mcqe.trailer); | |
6985 | exit: | |
6986 | /* We are holding the token, no needed for lock when release */ | |
6987 | spin_lock_irqsave(&phba->hbalock, iflag); | |
6988 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6989 | phba->sli.mbox_active = NULL; | |
6990 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6991 | return rc; | |
6992 | } | |
6993 | ||
6994 | /** | |
6995 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
6996 | * @phba: Pointer to HBA context object. | |
6997 | * @pmbox: Pointer to mailbox object. | |
6998 | * @flag: Flag indicating how the mailbox need to be processed. | |
6999 | * | |
7000 | * This function is called by discovery code and HBA management code to submit | |
7001 | * a mailbox command to firmware with SLI-4 interface spec. | |
7002 | * | |
7003 | * Return codes the caller owns the mailbox command after the return of the | |
7004 | * function. | |
7005 | **/ | |
7006 | static int | |
7007 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
7008 | uint32_t flag) | |
7009 | { | |
7010 | struct lpfc_sli *psli = &phba->sli; | |
7011 | unsigned long iflags; | |
7012 | int rc; | |
7013 | ||
b76f2dc9 JS |
7014 | /* dump from issue mailbox command if setup */ |
7015 | lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb); | |
7016 | ||
8fa38513 JS |
7017 | rc = lpfc_mbox_dev_check(phba); |
7018 | if (unlikely(rc)) { | |
7019 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7020 | "(%d):2544 Mailbox command x%x (x%x/x%x) " |
8fa38513 JS |
7021 | "cannot issue Data: x%x x%x\n", |
7022 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7023 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7024 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7025 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
8fa38513 JS |
7026 | psli->sli_flag, flag); |
7027 | goto out_not_finished; | |
7028 | } | |
7029 | ||
da0436e9 JS |
7030 | /* Detect polling mode and jump to a handler */ |
7031 | if (!phba->sli4_hba.intr_enable) { | |
7032 | if (flag == MBX_POLL) | |
7033 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7034 | else | |
7035 | rc = -EIO; | |
7036 | if (rc != MBX_SUCCESS) | |
0558056c | 7037 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
da0436e9 | 7038 | "(%d):2541 Mailbox command x%x " |
a183a15f JS |
7039 | "(x%x/x%x) cannot issue Data: " |
7040 | "x%x x%x\n", | |
da0436e9 JS |
7041 | mboxq->vport ? mboxq->vport->vpi : 0, |
7042 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7043 | lpfc_sli_config_mbox_subsys_get(phba, |
7044 | mboxq), | |
7045 | lpfc_sli_config_mbox_opcode_get(phba, | |
7046 | mboxq), | |
da0436e9 JS |
7047 | psli->sli_flag, flag); |
7048 | return rc; | |
7049 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
7050 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
7051 | "(%d):2542 Try to issue mailbox command " | |
a183a15f | 7052 | "x%x (x%x/x%x) synchronously ahead of async" |
f1126688 | 7053 | "mailbox command queue: x%x x%x\n", |
da0436e9 JS |
7054 | mboxq->vport ? mboxq->vport->vpi : 0, |
7055 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7056 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7057 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 | 7058 | psli->sli_flag, flag); |
f1126688 JS |
7059 | /* Try to block the asynchronous mailbox posting */ |
7060 | rc = lpfc_sli4_async_mbox_block(phba); | |
7061 | if (!rc) { | |
7062 | /* Successfully blocked, now issue sync mbox cmd */ | |
7063 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
7064 | if (rc != MBX_SUCCESS) | |
7065 | lpfc_printf_log(phba, KERN_ERR, | |
a183a15f JS |
7066 | LOG_MBOX | LOG_SLI, |
7067 | "(%d):2597 Mailbox command " | |
7068 | "x%x (x%x/x%x) cannot issue " | |
7069 | "Data: x%x x%x\n", | |
7070 | mboxq->vport ? | |
7071 | mboxq->vport->vpi : 0, | |
7072 | mboxq->u.mb.mbxCommand, | |
7073 | lpfc_sli_config_mbox_subsys_get(phba, | |
7074 | mboxq), | |
7075 | lpfc_sli_config_mbox_opcode_get(phba, | |
7076 | mboxq), | |
7077 | psli->sli_flag, flag); | |
f1126688 JS |
7078 | /* Unblock the async mailbox posting afterward */ |
7079 | lpfc_sli4_async_mbox_unblock(phba); | |
7080 | } | |
7081 | return rc; | |
da0436e9 JS |
7082 | } |
7083 | ||
7084 | /* Now, interrupt mode asynchrous mailbox command */ | |
7085 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
7086 | if (rc) { | |
7087 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7088 | "(%d):2543 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7089 | "cannot issue Data: x%x x%x\n", |
7090 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7091 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7092 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7093 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7094 | psli->sli_flag, flag); |
7095 | goto out_not_finished; | |
7096 | } | |
da0436e9 JS |
7097 | |
7098 | /* Put the mailbox command to the driver internal FIFO */ | |
7099 | psli->slistat.mbox_busy++; | |
7100 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7101 | lpfc_mbox_put(phba, mboxq); | |
7102 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7103 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
7104 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
a183a15f | 7105 | "x%x (x%x/x%x) x%x x%x x%x\n", |
da0436e9 JS |
7106 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, |
7107 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
a183a15f JS |
7108 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7109 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7110 | phba->pport->port_state, |
7111 | psli->sli_flag, MBX_NOWAIT); | |
7112 | /* Wake up worker thread to transport mailbox command from head */ | |
7113 | lpfc_worker_wake_up(phba); | |
7114 | ||
7115 | return MBX_BUSY; | |
7116 | ||
7117 | out_not_finished: | |
7118 | return MBX_NOT_FINISHED; | |
7119 | } | |
7120 | ||
7121 | /** | |
7122 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
7123 | * @phba: Pointer to HBA context object. | |
7124 | * | |
7125 | * This function is called by worker thread to send a mailbox command to | |
7126 | * SLI4 HBA firmware. | |
7127 | * | |
7128 | **/ | |
7129 | int | |
7130 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
7131 | { | |
7132 | struct lpfc_sli *psli = &phba->sli; | |
7133 | LPFC_MBOXQ_t *mboxq; | |
7134 | int rc = MBX_SUCCESS; | |
7135 | unsigned long iflags; | |
7136 | struct lpfc_mqe *mqe; | |
7137 | uint32_t mbx_cmnd; | |
7138 | ||
7139 | /* Check interrupt mode before post async mailbox command */ | |
7140 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
7141 | return MBX_NOT_FINISHED; | |
7142 | ||
7143 | /* Check for mailbox command service token */ | |
7144 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7145 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
7146 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7147 | return MBX_NOT_FINISHED; | |
7148 | } | |
7149 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7150 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7151 | return MBX_NOT_FINISHED; | |
7152 | } | |
7153 | if (unlikely(phba->sli.mbox_active)) { | |
7154 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7155 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
7156 | "0384 There is pending active mailbox cmd\n"); | |
7157 | return MBX_NOT_FINISHED; | |
7158 | } | |
7159 | /* Take the mailbox command service token */ | |
7160 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
7161 | ||
7162 | /* Get the next mailbox command from head of queue */ | |
7163 | mboxq = lpfc_mbox_get(phba); | |
7164 | ||
7165 | /* If no more mailbox command waiting for post, we're done */ | |
7166 | if (!mboxq) { | |
7167 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7168 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7169 | return MBX_SUCCESS; | |
7170 | } | |
7171 | phba->sli.mbox_active = mboxq; | |
7172 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7173 | ||
7174 | /* Check device readiness for posting mailbox command */ | |
7175 | rc = lpfc_mbox_dev_check(phba); | |
7176 | if (unlikely(rc)) | |
7177 | /* Driver clean routine will clean up pending mailbox */ | |
7178 | goto out_not_finished; | |
7179 | ||
7180 | /* Prepare the mbox command to be posted */ | |
7181 | mqe = &mboxq->u.mqe; | |
7182 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
7183 | ||
7184 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
7185 | mod_timer(&psli->mbox_tmo, (jiffies + | |
a183a15f | 7186 | (HZ * lpfc_mbox_tmo_val(phba, mboxq)))); |
da0436e9 JS |
7187 | |
7188 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
a183a15f | 7189 | "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: " |
da0436e9 JS |
7190 | "x%x x%x\n", |
7191 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
a183a15f JS |
7192 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7193 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7194 | phba->pport->port_state, psli->sli_flag); |
7195 | ||
7196 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
7197 | if (mboxq->vport) { | |
7198 | lpfc_debugfs_disc_trc(mboxq->vport, | |
7199 | LPFC_DISC_TRC_MBOX_VPORT, | |
7200 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
7201 | mbx_cmnd, mqe->un.mb_words[0], | |
7202 | mqe->un.mb_words[1]); | |
7203 | } else { | |
7204 | lpfc_debugfs_disc_trc(phba->pport, | |
7205 | LPFC_DISC_TRC_MBOX, | |
7206 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
7207 | mbx_cmnd, mqe->un.mb_words[0], | |
7208 | mqe->un.mb_words[1]); | |
7209 | } | |
7210 | } | |
7211 | psli->slistat.mbox_cmd++; | |
7212 | ||
7213 | /* Post the mailbox command to the port */ | |
7214 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
7215 | if (rc != MBX_SUCCESS) { | |
7216 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
a183a15f | 7217 | "(%d):2533 Mailbox command x%x (x%x/x%x) " |
da0436e9 JS |
7218 | "cannot issue Data: x%x x%x\n", |
7219 | mboxq->vport ? mboxq->vport->vpi : 0, | |
7220 | mboxq->u.mb.mbxCommand, | |
a183a15f JS |
7221 | lpfc_sli_config_mbox_subsys_get(phba, mboxq), |
7222 | lpfc_sli_config_mbox_opcode_get(phba, mboxq), | |
da0436e9 JS |
7223 | psli->sli_flag, MBX_NOWAIT); |
7224 | goto out_not_finished; | |
7225 | } | |
7226 | ||
7227 | return rc; | |
7228 | ||
7229 | out_not_finished: | |
7230 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7231 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7232 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7233 | /* Release the token */ | |
7234 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7235 | phba->sli.mbox_active = NULL; | |
7236 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7237 | ||
7238 | return MBX_NOT_FINISHED; | |
7239 | } | |
7240 | ||
7241 | /** | |
7242 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
7243 | * @phba: Pointer to HBA context object. | |
7244 | * @pmbox: Pointer to mailbox object. | |
7245 | * @flag: Flag indicating how the mailbox need to be processed. | |
7246 | * | |
7247 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
7248 | * the API jump table function pointer from the lpfc_hba struct. | |
7249 | * | |
7250 | * Return codes the caller owns the mailbox command after the return of the | |
7251 | * function. | |
7252 | **/ | |
7253 | int | |
7254 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
7255 | { | |
7256 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
7257 | } | |
7258 | ||
7259 | /** | |
25985edc | 7260 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
7261 | * @phba: The hba struct for which this call is being executed. |
7262 | * @dev_grp: The HBA PCI-Device group number. | |
7263 | * | |
7264 | * This routine sets up the mbox interface API function jump table in @phba | |
7265 | * struct. | |
7266 | * Returns: 0 - success, -ENODEV - failure. | |
7267 | **/ | |
7268 | int | |
7269 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
7270 | { | |
7271 | ||
7272 | switch (dev_grp) { | |
7273 | case LPFC_PCI_DEV_LP: | |
7274 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
7275 | phba->lpfc_sli_handle_slow_ring_event = | |
7276 | lpfc_sli_handle_slow_ring_event_s3; | |
7277 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
7278 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
7279 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
7280 | break; | |
7281 | case LPFC_PCI_DEV_OC: | |
7282 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
7283 | phba->lpfc_sli_handle_slow_ring_event = | |
7284 | lpfc_sli_handle_slow_ring_event_s4; | |
7285 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
7286 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
7287 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
7288 | break; | |
7289 | default: | |
7290 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7291 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
7292 | dev_grp); | |
7293 | return -ENODEV; | |
7294 | break; | |
7295 | } | |
7296 | return 0; | |
7297 | } | |
7298 | ||
e59058c4 | 7299 | /** |
3621a710 | 7300 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
7301 | * @phba: Pointer to HBA context object. |
7302 | * @pring: Pointer to driver SLI ring object. | |
7303 | * @piocb: Pointer to address of newly added command iocb. | |
7304 | * | |
7305 | * This function is called with hbalock held to add a command | |
7306 | * iocb to the txq when SLI layer cannot submit the command iocb | |
7307 | * to the ring. | |
7308 | **/ | |
2a9bf3d0 | 7309 | void |
92d7f7b0 | 7310 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 7311 | struct lpfc_iocbq *piocb) |
dea3101e | 7312 | { |
7313 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
7314 | list_add_tail(&piocb->list, &pring->txq); | |
7315 | pring->txq_cnt++; | |
dea3101e | 7316 | } |
7317 | ||
e59058c4 | 7318 | /** |
3621a710 | 7319 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
7320 | * @phba: Pointer to HBA context object. |
7321 | * @pring: Pointer to driver SLI ring object. | |
7322 | * @piocb: Pointer to address of newly added command iocb. | |
7323 | * | |
7324 | * This function is called with hbalock held before a new | |
7325 | * iocb is submitted to the firmware. This function checks | |
7326 | * txq to flush the iocbs in txq to Firmware before | |
7327 | * submitting new iocbs to the Firmware. | |
7328 | * If there are iocbs in the txq which need to be submitted | |
7329 | * to firmware, lpfc_sli_next_iocb returns the first element | |
7330 | * of the txq after dequeuing it from txq. | |
7331 | * If there is no iocb in the txq then the function will return | |
7332 | * *piocb and *piocb is set to NULL. Caller needs to check | |
7333 | * *piocb to find if there are more commands in the txq. | |
7334 | **/ | |
dea3101e | 7335 | static struct lpfc_iocbq * |
7336 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7337 | struct lpfc_iocbq **piocb) |
dea3101e | 7338 | { |
7339 | struct lpfc_iocbq * nextiocb; | |
7340 | ||
7341 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
7342 | if (!nextiocb) { | |
7343 | nextiocb = *piocb; | |
7344 | *piocb = NULL; | |
7345 | } | |
7346 | ||
7347 | return nextiocb; | |
7348 | } | |
7349 | ||
e59058c4 | 7350 | /** |
3772a991 | 7351 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 7352 | * @phba: Pointer to HBA context object. |
3772a991 | 7353 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
7354 | * @piocb: Pointer to command iocb. |
7355 | * @flag: Flag indicating if this command can be put into txq. | |
7356 | * | |
3772a991 JS |
7357 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
7358 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
7359 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
7360 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
7361 | * this function allows only iocbs for posting buffers. This function finds | |
7362 | * next available slot in the command ring and posts the command to the | |
7363 | * available slot and writes the port attention register to request HBA start | |
7364 | * processing new iocb. If there is no slot available in the ring and | |
7365 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
7366 | * the function returns IOCB_BUSY. | |
e59058c4 | 7367 | * |
3772a991 JS |
7368 | * This function is called with hbalock held. The function will return success |
7369 | * after it successfully submit the iocb to firmware or after adding to the | |
7370 | * txq. | |
e59058c4 | 7371 | **/ |
98c9ea5c | 7372 | static int |
3772a991 | 7373 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e | 7374 | struct lpfc_iocbq *piocb, uint32_t flag) |
7375 | { | |
7376 | struct lpfc_iocbq *nextiocb; | |
7377 | IOCB_t *iocb; | |
3772a991 | 7378 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 7379 | |
92d7f7b0 JS |
7380 | if (piocb->iocb_cmpl && (!piocb->vport) && |
7381 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
7382 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
7383 | lpfc_printf_log(phba, KERN_ERR, | |
7384 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 7385 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
7386 | piocb->iocb.ulpCommand); |
7387 | dump_stack(); | |
7388 | return IOCB_ERROR; | |
7389 | } | |
7390 | ||
7391 | ||
8d63f375 LV |
7392 | /* If the PCI channel is in offline state, do not post iocbs. */ |
7393 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
7394 | return IOCB_ERROR; | |
7395 | ||
a257bf90 JS |
7396 | /* If HBA has a deferred error attention, fail the iocb. */ |
7397 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
7398 | return IOCB_ERROR; | |
7399 | ||
dea3101e | 7400 | /* |
7401 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
7402 | */ | |
2e0fef85 | 7403 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e | 7404 | return IOCB_ERROR; |
7405 | ||
7406 | /* | |
7407 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 7408 | * outstanding event. |
dea3101e | 7409 | */ |
0b727fea | 7410 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e | 7411 | goto iocb_busy; |
7412 | ||
2e0fef85 | 7413 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 7414 | /* |
2680eeaa | 7415 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e | 7416 | * can be issued if the link is not up. |
7417 | */ | |
7418 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
7419 | case CMD_GEN_REQUEST64_CR: |
7420 | case CMD_GEN_REQUEST64_CX: | |
7421 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
7422 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 7423 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
7424 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
7425 | MENLO_TRANSPORT_TYPE)) | |
7426 | ||
7427 | goto iocb_busy; | |
7428 | break; | |
dea3101e | 7429 | case CMD_QUE_RING_BUF_CN: |
7430 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e | 7431 | /* |
7432 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
7433 | * completion, iocb_cmpl MUST be 0. | |
7434 | */ | |
7435 | if (piocb->iocb_cmpl) | |
7436 | piocb->iocb_cmpl = NULL; | |
7437 | /*FALLTHROUGH*/ | |
7438 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
7439 | case CMD_CLOSE_XRI_CN: |
7440 | case CMD_CLOSE_XRI_CX: | |
dea3101e | 7441 | break; |
7442 | default: | |
7443 | goto iocb_busy; | |
7444 | } | |
7445 | ||
7446 | /* | |
7447 | * For FCP commands, we must be in a state where we can process link | |
7448 | * attention events. | |
7449 | */ | |
7450 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 7451 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 7452 | goto iocb_busy; |
92d7f7b0 | 7453 | } |
dea3101e | 7454 | |
dea3101e | 7455 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
7456 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
7457 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
7458 | ||
7459 | if (iocb) | |
7460 | lpfc_sli_update_ring(phba, pring); | |
7461 | else | |
7462 | lpfc_sli_update_full_ring(phba, pring); | |
7463 | ||
7464 | if (!piocb) | |
7465 | return IOCB_SUCCESS; | |
7466 | ||
7467 | goto out_busy; | |
7468 | ||
7469 | iocb_busy: | |
7470 | pring->stats.iocb_cmd_delay++; | |
7471 | ||
7472 | out_busy: | |
7473 | ||
7474 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 7475 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e | 7476 | return IOCB_SUCCESS; |
7477 | } | |
7478 | ||
7479 | return IOCB_BUSY; | |
7480 | } | |
7481 | ||
3772a991 | 7482 | /** |
4f774513 JS |
7483 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
7484 | * @phba: Pointer to HBA context object. | |
7485 | * @piocb: Pointer to command iocb. | |
7486 | * @sglq: Pointer to the scatter gather queue object. | |
7487 | * | |
7488 | * This routine converts the bpl or bde that is in the IOCB | |
7489 | * to a sgl list for the sli4 hardware. The physical address | |
7490 | * of the bpl/bde is converted back to a virtual address. | |
7491 | * If the IOCB contains a BPL then the list of BDE's is | |
7492 | * converted to sli4_sge's. If the IOCB contains a single | |
7493 | * BDE then it is converted to a single sli_sge. | |
7494 | * The IOCB is still in cpu endianess so the contents of | |
7495 | * the bpl can be used without byte swapping. | |
7496 | * | |
7497 | * Returns valid XRI = Success, NO_XRI = Failure. | |
7498 | **/ | |
7499 | static uint16_t | |
7500 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
7501 | struct lpfc_sglq *sglq) | |
3772a991 | 7502 | { |
4f774513 JS |
7503 | uint16_t xritag = NO_XRI; |
7504 | struct ulp_bde64 *bpl = NULL; | |
7505 | struct ulp_bde64 bde; | |
7506 | struct sli4_sge *sgl = NULL; | |
7507 | IOCB_t *icmd; | |
7508 | int numBdes = 0; | |
7509 | int i = 0; | |
63e801ce JS |
7510 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
7511 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 7512 | |
4f774513 JS |
7513 | if (!piocbq || !sglq) |
7514 | return xritag; | |
7515 | ||
7516 | sgl = (struct sli4_sge *)sglq->sgl; | |
7517 | icmd = &piocbq->iocb; | |
7518 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
7519 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
7520 | sizeof(struct ulp_bde64); | |
7521 | /* The addrHigh and addrLow fields within the IOCB | |
7522 | * have not been byteswapped yet so there is no | |
7523 | * need to swap them back. | |
7524 | */ | |
7525 | bpl = (struct ulp_bde64 *) | |
7526 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | |
7527 | ||
7528 | if (!bpl) | |
7529 | return xritag; | |
7530 | ||
7531 | for (i = 0; i < numBdes; i++) { | |
7532 | /* Should already be byte swapped. */ | |
28baac74 JS |
7533 | sgl->addr_hi = bpl->addrHigh; |
7534 | sgl->addr_lo = bpl->addrLow; | |
7535 | ||
0558056c | 7536 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7537 | if ((i+1) == numBdes) |
7538 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
7539 | else | |
7540 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
7541 | /* swap the size field back to the cpu so we |
7542 | * can assign it to the sgl. | |
7543 | */ | |
7544 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
7545 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
7546 | /* The offsets in the sgl need to be accumulated |
7547 | * separately for the request and reply lists. | |
7548 | * The request is always first, the reply follows. | |
7549 | */ | |
7550 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
7551 | /* add up the reply sg entries */ | |
7552 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
7553 | inbound++; | |
7554 | /* first inbound? reset the offset */ | |
7555 | if (inbound == 1) | |
7556 | offset = 0; | |
7557 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
f9bb2da1 JS |
7558 | bf_set(lpfc_sli4_sge_type, sgl, |
7559 | LPFC_SGE_TYPE_DATA); | |
63e801ce JS |
7560 | offset += bde.tus.f.bdeSize; |
7561 | } | |
546fc854 | 7562 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
7563 | bpl++; |
7564 | sgl++; | |
7565 | } | |
7566 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
7567 | /* The addrHigh and addrLow fields of the BDE have not | |
7568 | * been byteswapped yet so they need to be swapped | |
7569 | * before putting them in the sgl. | |
7570 | */ | |
7571 | sgl->addr_hi = | |
7572 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
7573 | sgl->addr_lo = | |
7574 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
0558056c | 7575 | sgl->word2 = le32_to_cpu(sgl->word2); |
4f774513 JS |
7576 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
7577 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
7578 | sgl->sge_len = |
7579 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
7580 | } |
7581 | return sglq->sli4_xritag; | |
3772a991 | 7582 | } |
92d7f7b0 | 7583 | |
e59058c4 | 7584 | /** |
4f774513 | 7585 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 7586 | * @phba: Pointer to HBA context object. |
e59058c4 | 7587 | * |
a93ff37a | 7588 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
7589 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
7590 | * held. | |
4f774513 JS |
7591 | * |
7592 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 7593 | **/ |
4f774513 | 7594 | static uint32_t |
8fa38513 | 7595 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 7596 | { |
8fa38513 JS |
7597 | ++phba->fcp_qidx; |
7598 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) | |
7599 | phba->fcp_qidx = 0; | |
92d7f7b0 | 7600 | |
8fa38513 | 7601 | return phba->fcp_qidx; |
92d7f7b0 JS |
7602 | } |
7603 | ||
e59058c4 | 7604 | /** |
4f774513 | 7605 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 7606 | * @phba: Pointer to HBA context object. |
4f774513 JS |
7607 | * @piocb: Pointer to command iocb. |
7608 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 7609 | * |
4f774513 JS |
7610 | * This routine converts the iocb command to its Work Queue Entry |
7611 | * equivalent. The wqe pointer should not have any fields set when | |
7612 | * this routine is called because it will memcpy over them. | |
7613 | * This routine does not set the CQ_ID or the WQEC bits in the | |
7614 | * wqe. | |
e59058c4 | 7615 | * |
4f774513 | 7616 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 7617 | **/ |
cf5bf97e | 7618 | static int |
4f774513 JS |
7619 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
7620 | union lpfc_wqe *wqe) | |
cf5bf97e | 7621 | { |
5ffc266e | 7622 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
7623 | uint8_t ct = 0; |
7624 | uint32_t fip; | |
7625 | uint32_t abort_tag; | |
7626 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
7627 | uint8_t cmnd; | |
7628 | uint16_t xritag; | |
dcf2a4e0 JS |
7629 | uint16_t abrt_iotag; |
7630 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 7631 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 7632 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
7633 | int numBdes, i; |
7634 | struct ulp_bde64 bde; | |
c31098ce | 7635 | struct lpfc_nodelist *ndlp; |
ff78d8f9 | 7636 | uint32_t *pcmd; |
4f774513 | 7637 | |
45ed1190 | 7638 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 7639 | /* The fcp commands will set command type */ |
0c287589 | 7640 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 7641 | command_type = FCP_COMMAND; |
c868595d | 7642 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
7643 | command_type = ELS_COMMAND_FIP; |
7644 | else | |
7645 | command_type = ELS_COMMAND_NON_FIP; | |
7646 | ||
4f774513 JS |
7647 | /* Some of the fields are in the right position already */ |
7648 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
7649 | abort_tag = (uint32_t) iocbq->iotag; | |
7650 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 7651 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
7652 | /* words0-2 bpl convert bde */ |
7653 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
7654 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
7655 | sizeof(struct ulp_bde64); | |
4f774513 JS |
7656 | bpl = (struct ulp_bde64 *) |
7657 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
7658 | if (!bpl) | |
7659 | return IOCB_ERROR; | |
cf5bf97e | 7660 | |
4f774513 JS |
7661 | /* Should already be byte swapped. */ |
7662 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
7663 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
7664 | /* swap the size field back to the cpu so we | |
7665 | * can assign it to the sgl. | |
7666 | */ | |
7667 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
7668 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
7669 | total_len = 0; | |
7670 | for (i = 0; i < numBdes; i++) { | |
7671 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
7672 | total_len += bde.tus.f.bdeSize; | |
7673 | } | |
4f774513 | 7674 | } else |
5ffc266e | 7675 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 7676 | |
4f774513 JS |
7677 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
7678 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 7679 | |
4f774513 JS |
7680 | switch (iocbq->iocb.ulpCommand) { |
7681 | case CMD_ELS_REQUEST64_CR: | |
c31098ce | 7682 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 JS |
7683 | if (!iocbq->iocb.ulpLe) { |
7684 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7685 | "2007 Only Limited Edition cmd Format" | |
7686 | " supported 0x%x\n", | |
7687 | iocbq->iocb.ulpCommand); | |
7688 | return IOCB_ERROR; | |
7689 | } | |
ff78d8f9 | 7690 | |
5ffc266e | 7691 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
7692 | /* Els_reguest64 has a TMO */ |
7693 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
7694 | iocbq->iocb.ulpTimeout); | |
7695 | /* Need a VF for word 4 set the vf bit*/ | |
7696 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
7697 | /* And a VFID for word 12 */ | |
7698 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 7699 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
7700 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
7701 | iocbq->iocb.ulpContext); | |
7702 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
7703 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 7704 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
ff78d8f9 | 7705 | if (command_type == ELS_COMMAND_FIP) |
c868595d JS |
7706 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) |
7707 | >> LPFC_FIP_ELS_ID_SHIFT); | |
ff78d8f9 JS |
7708 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
7709 | iocbq->context2)->virt); | |
7710 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
7711 | if (pcmd && (*pcmd == ELS_CMD_FLOGI || | |
cb69f7de | 7712 | *pcmd == ELS_CMD_SCR || |
ff78d8f9 JS |
7713 | *pcmd == ELS_CMD_PLOGI)) { |
7714 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
7715 | bf_set(els_req64_sid, &wqe->els_req, | |
7716 | iocbq->vport->fc_myDID); | |
7717 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); | |
7718 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
7719 | phba->vpi_ids[phba->pport->vpi]); | |
7720 | } else if (iocbq->context1) { | |
7721 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 0); | |
7722 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
7723 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
7724 | } | |
c868595d | 7725 | } |
6d368e53 JS |
7726 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, |
7727 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
f0d9bccc JS |
7728 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
7729 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
7730 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
7731 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
7732 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
7733 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
7851fe2c | 7734 | break; |
5ffc266e | 7735 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
7736 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
7737 | iocbq->iocb.un.ulpWord[3]); | |
7738 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
7851fe2c | 7739 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
5ffc266e JS |
7740 | /* The entire sequence is transmitted for this IOCB */ |
7741 | xmit_len = total_len; | |
7742 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
4f774513 | 7743 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
7744 | /* word3 iocb=io_tag32 wqe=reserved */ |
7745 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
7746 | /* word4 relative_offset memcpy */ |
7747 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
7748 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
7749 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
7750 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
7751 | LPFC_WQE_IOD_WRITE); | |
7752 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
7753 | LPFC_WQE_LENLOC_WORD12); | |
7754 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
7755 | wqe->xmit_sequence.xmit_len = xmit_len; |
7756 | command_type = OTHER_COMMAND; | |
7851fe2c | 7757 | break; |
4f774513 | 7758 | case CMD_XMIT_BCAST64_CN: |
f0d9bccc JS |
7759 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
7760 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
7761 | /* word4 iocb=rsvd wqe=rsvd */ |
7762 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
7763 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 7764 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 7765 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
7766 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
7767 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
7768 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
7769 | LPFC_WQE_LENLOC_WORD3); | |
7770 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
7851fe2c | 7771 | break; |
4f774513 JS |
7772 | case CMD_FCP_IWRITE64_CR: |
7773 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
7774 | /* word3 iocb=iotag wqe=payload_offset_len */ |
7775 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
7776 | wqe->fcp_iwrite.payload_offset_len = | |
7777 | xmit_len + sizeof(struct fcp_rsp); | |
7778 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
7779 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
7780 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
7781 | iocbq->iocb.ulpFCP2Rcvy); | |
7782 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
7783 | /* Always open the exchange */ | |
7784 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
7785 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
7786 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); | |
7787 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
7788 | LPFC_WQE_LENLOC_WORD4); | |
7789 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
7790 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
7851fe2c | 7791 | break; |
4f774513 | 7792 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
7793 | /* word3 iocb=iotag wqe=payload_offset_len */ |
7794 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
7795 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 7796 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
7797 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
7798 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
7799 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
7800 | iocbq->iocb.ulpFCP2Rcvy); | |
7801 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
7802 | /* Always open the exchange */ |
7803 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
7804 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
7805 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); | |
7806 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
7807 | LPFC_WQE_LENLOC_WORD4); | |
7808 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
7809 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
7851fe2c | 7810 | break; |
4f774513 | 7811 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
7812 | /* word3 iocb=IO_TAG wqe=reserved */ |
7813 | wqe->fcp_icmd.rsrvd3 = 0; | |
7814 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 7815 | /* Always open the exchange */ |
f0d9bccc JS |
7816 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
7817 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
7818 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
7819 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
7820 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
7821 | LPFC_WQE_LENLOC_NONE); | |
7822 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
7851fe2c | 7823 | break; |
4f774513 | 7824 | case CMD_GEN_REQUEST64_CR: |
63e801ce JS |
7825 | /* For this command calculate the xmit length of the |
7826 | * request bde. | |
7827 | */ | |
7828 | xmit_len = 0; | |
7829 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
7830 | sizeof(struct ulp_bde64); | |
7831 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 7832 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
7833 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
7834 | break; | |
63e801ce JS |
7835 | xmit_len += bde.tus.f.bdeSize; |
7836 | } | |
f0d9bccc JS |
7837 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
7838 | wqe->gen_req.request_payload_len = xmit_len; | |
7839 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
7840 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
7841 | /* word6 context tag copied in memcpy */ |
7842 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
7843 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
7844 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7845 | "2015 Invalid CT %x command 0x%x\n", | |
7846 | ct, iocbq->iocb.ulpCommand); | |
7847 | return IOCB_ERROR; | |
7848 | } | |
f0d9bccc JS |
7849 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
7850 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
7851 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
7852 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
7853 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
7854 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
7855 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
7856 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 | 7857 | command_type = OTHER_COMMAND; |
7851fe2c | 7858 | break; |
4f774513 | 7859 | case CMD_XMIT_ELS_RSP64_CX: |
c31098ce | 7860 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 7861 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
7862 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
7863 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
4f774513 | 7864 | /* word4 iocb=did wge=rsvd. */ |
f0d9bccc | 7865 | wqe->xmit_els_rsp.rsvd4 = 0; |
4f774513 JS |
7866 | /* word5 iocb=rsvd wge=did */ |
7867 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
7868 | iocbq->iocb.un.elsreq64.remoteID); | |
f0d9bccc JS |
7869 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
7870 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
7871 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
7872 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
7851fe2c | 7873 | iocbq->iocb.unsli3.rcvsli3.ox_id); |
4f774513 | 7874 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 7875 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
6d368e53 | 7876 | phba->vpi_ids[iocbq->vport->vpi]); |
f0d9bccc JS |
7877 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
7878 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
7879 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
7880 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
7881 | LPFC_WQE_LENLOC_WORD3); | |
7882 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
6d368e53 JS |
7883 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, |
7884 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); | |
ff78d8f9 JS |
7885 | pcmd = (uint32_t *) (((struct lpfc_dmabuf *) |
7886 | iocbq->context2)->virt); | |
7887 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
7888 | bf_set(els_req64_sp, &wqe->els_req, 1); | |
7889 | bf_set(els_req64_sid, &wqe->els_req, | |
7890 | iocbq->vport->fc_myDID); | |
7891 | bf_set(wqe_ct, &wqe->els_req.wqe_com, 1); | |
7892 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, | |
7893 | phba->vpi_ids[phba->pport->vpi]); | |
7894 | } | |
4f774513 | 7895 | command_type = OTHER_COMMAND; |
7851fe2c | 7896 | break; |
4f774513 JS |
7897 | case CMD_CLOSE_XRI_CN: |
7898 | case CMD_ABORT_XRI_CN: | |
7899 | case CMD_ABORT_XRI_CX: | |
7900 | /* words 0-2 memcpy should be 0 rserved */ | |
7901 | /* port will send abts */ | |
dcf2a4e0 JS |
7902 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
7903 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
7904 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
7905 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
7906 | } else | |
7907 | fip = 0; | |
7908 | ||
7909 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 7910 | /* |
dcf2a4e0 JS |
7911 | * The link is down, or the command was ELS_FIP |
7912 | * so the fw does not need to send abts | |
4f774513 JS |
7913 | * on the wire. |
7914 | */ | |
7915 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
7916 | else | |
7917 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
7918 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
7919 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
7920 | wqe->abort_cmd.rsrvd5 = 0; | |
7921 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
7922 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
7923 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
7924 | /* |
7925 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
7926 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
7927 | */ | |
f0d9bccc JS |
7928 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
7929 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
7930 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
7931 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
7932 | cmnd = CMD_ABORT_XRI_CX; |
7933 | command_type = OTHER_COMMAND; | |
7934 | xritag = 0; | |
7851fe2c | 7935 | break; |
6669f9bb | 7936 | case CMD_XMIT_BLS_RSP64_CX: |
546fc854 | 7937 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
7938 | * we re-construct this WQE here based on information in |
7939 | * iocbq from scratch. | |
7940 | */ | |
7941 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 7942 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 7943 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
7944 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
7945 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
7946 | LPFC_ABTS_UNSOL_INT) { |
7947 | /* ABTS sent by initiator to CT exchange, the | |
7948 | * RX_ID field will be filled with the newly | |
7949 | * allocated responder XRI. | |
7950 | */ | |
7951 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
7952 | iocbq->sli4_xritag); | |
7953 | } else { | |
7954 | /* ABTS sent by responder to CT exchange, the | |
7955 | * RX_ID field will be filled with the responder | |
7956 | * RX_ID from ABTS. | |
7957 | */ | |
7958 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 7959 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 7960 | } |
6669f9bb JS |
7961 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
7962 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
7963 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, | |
7964 | iocbq->iocb.ulpContext); | |
f0d9bccc JS |
7965 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
7966 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
7967 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
7968 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
7969 | command_type = OTHER_COMMAND; | |
546fc854 JS |
7970 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
7971 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
7972 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
7973 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
7974 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
7975 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
7976 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
7977 | } | |
7978 | ||
7851fe2c | 7979 | break; |
4f774513 JS |
7980 | case CMD_XRI_ABORTED_CX: |
7981 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
7982 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
7983 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
7984 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
7985 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
7986 | default: | |
7987 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7988 | "2014 Invalid command 0x%x\n", | |
7989 | iocbq->iocb.ulpCommand); | |
7990 | return IOCB_ERROR; | |
7851fe2c | 7991 | break; |
4f774513 | 7992 | } |
6d368e53 | 7993 | |
f0d9bccc JS |
7994 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
7995 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
7996 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
7997 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
7998 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
7999 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
8000 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
8001 | return 0; |
8002 | } | |
8003 | ||
8004 | /** | |
8005 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
8006 | * @phba: Pointer to HBA context object. | |
8007 | * @ring_number: SLI ring number to issue iocb on. | |
8008 | * @piocb: Pointer to command iocb. | |
8009 | * @flag: Flag indicating if this command can be put into txq. | |
8010 | * | |
8011 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
8012 | * an iocb command to an HBA with SLI-4 interface spec. | |
8013 | * | |
8014 | * This function is called with hbalock held. The function will return success | |
8015 | * after it successfully submit the iocb to firmware or after adding to the | |
8016 | * txq. | |
8017 | **/ | |
8018 | static int | |
8019 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
8020 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8021 | { | |
8022 | struct lpfc_sglq *sglq; | |
4f774513 JS |
8023 | union lpfc_wqe wqe; |
8024 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
8025 | |
8026 | if (piocb->sli4_xritag == NO_XRI) { | |
8027 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
546fc854 JS |
8028 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
8029 | piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX) | |
4f774513 JS |
8030 | sglq = NULL; |
8031 | else { | |
2a9bf3d0 JS |
8032 | if (pring->txq_cnt) { |
8033 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8034 | __lpfc_sli_ringtx_put(phba, | |
8035 | pring, piocb); | |
8036 | return IOCB_SUCCESS; | |
8037 | } else { | |
8038 | return IOCB_BUSY; | |
8039 | } | |
8040 | } else { | |
6d368e53 | 8041 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
8042 | if (!sglq) { |
8043 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
8044 | __lpfc_sli_ringtx_put(phba, | |
8045 | pring, | |
8046 | piocb); | |
8047 | return IOCB_SUCCESS; | |
8048 | } else | |
8049 | return IOCB_BUSY; | |
8050 | } | |
8051 | } | |
4f774513 JS |
8052 | } |
8053 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6d368e53 JS |
8054 | /* These IO's already have an XRI and a mapped sgl. */ |
8055 | sglq = NULL; | |
4f774513 | 8056 | } else { |
6d368e53 JS |
8057 | /* |
8058 | * This is a continuation of a commandi,(CX) so this | |
4f774513 JS |
8059 | * sglq is on the active list |
8060 | */ | |
8061 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
8062 | if (!sglq) | |
8063 | return IOCB_ERROR; | |
8064 | } | |
8065 | ||
8066 | if (sglq) { | |
6d368e53 | 8067 | piocb->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 | 8068 | piocb->sli4_xritag = sglq->sli4_xritag; |
2a9bf3d0 | 8069 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) |
4f774513 JS |
8070 | return IOCB_ERROR; |
8071 | } | |
8072 | ||
8073 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
8074 | return IOCB_ERROR; | |
8075 | ||
341af102 JS |
8076 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
8077 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
8078 | /* |
8079 | * For FCP command IOCB, get a new WQ index to distribute | |
8080 | * WQE across the WQsr. On the other hand, for abort IOCB, | |
8081 | * it carries the same WQ index to the original command | |
8082 | * IOCB. | |
8083 | */ | |
341af102 | 8084 | if (piocb->iocb_flag & LPFC_IO_FCP) |
5ffc266e JS |
8085 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
8086 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], | |
8087 | &wqe)) | |
4f774513 JS |
8088 | return IOCB_ERROR; |
8089 | } else { | |
8090 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
8091 | return IOCB_ERROR; | |
8092 | } | |
8093 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
8094 | ||
8095 | return 0; | |
8096 | } | |
8097 | ||
8098 | /** | |
8099 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
8100 | * | |
8101 | * This routine wraps the actual lockless version for issusing IOCB function | |
8102 | * pointer from the lpfc_hba struct. | |
8103 | * | |
8104 | * Return codes: | |
8105 | * IOCB_ERROR - Error | |
8106 | * IOCB_SUCCESS - Success | |
8107 | * IOCB_BUSY - Busy | |
8108 | **/ | |
2a9bf3d0 | 8109 | int |
4f774513 JS |
8110 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
8111 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8112 | { | |
8113 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8114 | } | |
8115 | ||
8116 | /** | |
25985edc | 8117 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
8118 | * @phba: The hba struct for which this call is being executed. |
8119 | * @dev_grp: The HBA PCI-Device group number. | |
8120 | * | |
8121 | * This routine sets up the SLI interface API function jump table in @phba | |
8122 | * struct. | |
8123 | * Returns: 0 - success, -ENODEV - failure. | |
8124 | **/ | |
8125 | int | |
8126 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
8127 | { | |
8128 | ||
8129 | switch (dev_grp) { | |
8130 | case LPFC_PCI_DEV_LP: | |
8131 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
8132 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
8133 | break; | |
8134 | case LPFC_PCI_DEV_OC: | |
8135 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
8136 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
8137 | break; | |
8138 | default: | |
8139 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8140 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
8141 | dev_grp); | |
8142 | return -ENODEV; | |
8143 | break; | |
8144 | } | |
8145 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
8146 | return 0; | |
8147 | } | |
8148 | ||
8149 | /** | |
8150 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
8151 | * @phba: Pointer to HBA context object. | |
8152 | * @pring: Pointer to driver SLI ring object. | |
8153 | * @piocb: Pointer to command iocb. | |
8154 | * @flag: Flag indicating if this command can be put into txq. | |
8155 | * | |
8156 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
8157 | * function. This function gets the hbalock and calls | |
8158 | * __lpfc_sli_issue_iocb function and will return the error returned | |
8159 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
8160 | * functions which do not hold hbalock. | |
8161 | **/ | |
8162 | int | |
8163 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
8164 | struct lpfc_iocbq *piocb, uint32_t flag) | |
8165 | { | |
8166 | unsigned long iflags; | |
8167 | int rc; | |
8168 | ||
8169 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8170 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
8171 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8172 | ||
8173 | return rc; | |
8174 | } | |
8175 | ||
8176 | /** | |
8177 | * lpfc_extra_ring_setup - Extra ring setup function | |
8178 | * @phba: Pointer to HBA context object. | |
8179 | * | |
8180 | * This function is called while driver attaches with the | |
8181 | * HBA to setup the extra ring. The extra ring is used | |
8182 | * only when driver needs to support target mode functionality | |
8183 | * or IP over FC functionalities. | |
8184 | * | |
8185 | * This function is called with no lock held. | |
8186 | **/ | |
8187 | static int | |
8188 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
8189 | { | |
8190 | struct lpfc_sli *psli; | |
8191 | struct lpfc_sli_ring *pring; | |
8192 | ||
8193 | psli = &phba->sli; | |
8194 | ||
8195 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
8196 | ||
8197 | /* Take some away from the FCP ring */ | |
8198 | pring = &psli->ring[psli->fcp_ring]; | |
8199 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
8200 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
cf5bf97e JW |
8201 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
8202 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
8203 | ||
a4bc3379 JS |
8204 | /* and give them to the extra ring */ |
8205 | pring = &psli->ring[psli->extra_ring]; | |
8206 | ||
cf5bf97e JW |
8207 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
8208 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8209 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8210 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
8211 | ||
8212 | /* Setup default profile for this ring */ | |
8213 | pring->iotag_max = 4096; | |
8214 | pring->num_mask = 1; | |
8215 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
8216 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
8217 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
8218 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
8219 | return 0; | |
8220 | } | |
8221 | ||
cb69f7de JS |
8222 | /* lpfc_sli_abts_recover_port - Recover a port that failed an ABTS. |
8223 | * @vport: pointer to virtual port object. | |
8224 | * @ndlp: nodelist pointer for the impacted rport. | |
8225 | * | |
8226 | * The driver calls this routine in response to a XRI ABORT CQE | |
8227 | * event from the port. In this event, the driver is required to | |
8228 | * recover its login to the rport even though its login may be valid | |
8229 | * from the driver's perspective. The failed ABTS notice from the | |
8230 | * port indicates the rport is not responding. | |
8231 | */ | |
8232 | static void | |
8233 | lpfc_sli_abts_recover_port(struct lpfc_vport *vport, | |
8234 | struct lpfc_nodelist *ndlp) | |
8235 | { | |
8236 | struct Scsi_Host *shost; | |
8237 | struct lpfc_hba *phba; | |
8238 | unsigned long flags = 0; | |
8239 | ||
8240 | shost = lpfc_shost_from_vport(vport); | |
8241 | phba = vport->phba; | |
8242 | if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) { | |
8243 | lpfc_printf_log(phba, KERN_INFO, | |
8244 | LOG_SLI, "3093 No rport recovery needed. " | |
8245 | "rport in state 0x%x\n", | |
8246 | ndlp->nlp_state); | |
8247 | return; | |
8248 | } | |
8249 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8250 | "3094 Start rport recovery on shost id 0x%x " | |
8251 | "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x " | |
8252 | "flags 0x%x\n", | |
8253 | shost->host_no, ndlp->nlp_DID, | |
8254 | vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state, | |
8255 | ndlp->nlp_flag); | |
8256 | /* | |
8257 | * The rport is not responding. Don't attempt ADISC recovery. | |
8258 | * Remove the FCP-2 flag to force a PLOGI. | |
8259 | */ | |
8260 | spin_lock_irqsave(shost->host_lock, flags); | |
8261 | ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE; | |
8262 | spin_unlock_irqrestore(shost->host_lock, flags); | |
8263 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
8264 | NLP_EVT_DEVICE_RECOVERY); | |
8265 | lpfc_cancel_retry_delay_tmo(vport, ndlp); | |
8266 | spin_lock_irqsave(shost->host_lock, flags); | |
8267 | ndlp->nlp_flag |= NLP_NPR_2B_DISC; | |
8268 | spin_unlock_irqrestore(shost->host_lock, flags); | |
8269 | lpfc_disc_start(vport); | |
8270 | } | |
8271 | ||
8272 | /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port. | |
8273 | * @phba: Pointer to HBA context object. | |
8274 | * @iocbq: Pointer to iocb object. | |
8275 | * | |
8276 | * The async_event handler calls this routine when it receives | |
8277 | * an ASYNC_STATUS_CN event from the port. The port generates | |
8278 | * this event when an Abort Sequence request to an rport fails | |
8279 | * twice in succession. The abort could be originated by the | |
8280 | * driver or by the port. The ABTS could have been for an ELS | |
8281 | * or FCP IO. The port only generates this event when an ABTS | |
8282 | * fails to complete after one retry. | |
8283 | */ | |
8284 | static void | |
8285 | lpfc_sli_abts_err_handler(struct lpfc_hba *phba, | |
8286 | struct lpfc_iocbq *iocbq) | |
8287 | { | |
8288 | struct lpfc_nodelist *ndlp = NULL; | |
8289 | uint16_t rpi = 0, vpi = 0; | |
8290 | struct lpfc_vport *vport = NULL; | |
8291 | ||
8292 | /* The rpi in the ulpContext is vport-sensitive. */ | |
8293 | vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag; | |
8294 | rpi = iocbq->iocb.ulpContext; | |
8295 | ||
8296 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8297 | "3092 Port generated ABTS async event " | |
8298 | "on vpi %d rpi %d status 0x%x\n", | |
8299 | vpi, rpi, iocbq->iocb.ulpStatus); | |
8300 | ||
8301 | vport = lpfc_find_vport_by_vpid(phba, vpi); | |
8302 | if (!vport) | |
8303 | goto err_exit; | |
8304 | ndlp = lpfc_findnode_rpi(vport, rpi); | |
8305 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
8306 | goto err_exit; | |
8307 | ||
8308 | if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | |
8309 | lpfc_sli_abts_recover_port(vport, ndlp); | |
8310 | return; | |
8311 | ||
8312 | err_exit: | |
8313 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8314 | "3095 Event Context not found, no " | |
8315 | "action on vpi %d rpi %d status 0x%x, reason 0x%x\n", | |
8316 | iocbq->iocb.ulpContext, iocbq->iocb.ulpStatus, | |
8317 | vpi, rpi); | |
8318 | } | |
8319 | ||
8320 | /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port. | |
8321 | * @phba: pointer to HBA context object. | |
8322 | * @ndlp: nodelist pointer for the impacted rport. | |
8323 | * @axri: pointer to the wcqe containing the failed exchange. | |
8324 | * | |
8325 | * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the | |
8326 | * port. The port generates this event when an abort exchange request to an | |
8327 | * rport fails twice in succession with no reply. The abort could be originated | |
8328 | * by the driver or by the port. The ABTS could have been for an ELS or FCP IO. | |
8329 | */ | |
8330 | void | |
8331 | lpfc_sli4_abts_err_handler(struct lpfc_hba *phba, | |
8332 | struct lpfc_nodelist *ndlp, | |
8333 | struct sli4_wcqe_xri_aborted *axri) | |
8334 | { | |
8335 | struct lpfc_vport *vport; | |
8336 | ||
8337 | if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) | |
8338 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8339 | "3115 Node Context not found, driver " | |
8340 | "ignoring abts err event\n"); | |
8341 | vport = ndlp->vport; | |
8342 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8343 | "3116 Port generated FCP XRI ABORT event on " | |
8344 | "vpi %d rpi %d xri x%x status 0x%x\n", | |
8345 | ndlp->vport->vpi, ndlp->nlp_rpi, | |
8346 | bf_get(lpfc_wcqe_xa_xri, axri), | |
8347 | bf_get(lpfc_wcqe_xa_status, axri)); | |
8348 | ||
8349 | if (bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) | |
8350 | lpfc_sli_abts_recover_port(vport, ndlp); | |
8351 | } | |
8352 | ||
e59058c4 | 8353 | /** |
3621a710 | 8354 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
8355 | * @phba: Pointer to HBA context object. |
8356 | * @pring: Pointer to driver SLI ring object. | |
8357 | * @iocbq: Pointer to iocb object. | |
8358 | * | |
8359 | * This function is called by the slow ring event handler | |
8360 | * function when there is an ASYNC event iocb in the ring. | |
8361 | * This function is called with no lock held. | |
8362 | * Currently this function handles only temperature related | |
8363 | * ASYNC events. The function decodes the temperature sensor | |
8364 | * event message and posts events for the management applications. | |
8365 | **/ | |
98c9ea5c | 8366 | static void |
57127f15 JS |
8367 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
8368 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
8369 | { | |
8370 | IOCB_t *icmd; | |
8371 | uint16_t evt_code; | |
57127f15 JS |
8372 | struct temp_event temp_event_data; |
8373 | struct Scsi_Host *shost; | |
a257bf90 | 8374 | uint32_t *iocb_w; |
57127f15 JS |
8375 | |
8376 | icmd = &iocbq->iocb; | |
8377 | evt_code = icmd->un.asyncstat.evt_code; | |
57127f15 | 8378 | |
cb69f7de JS |
8379 | switch (evt_code) { |
8380 | case ASYNC_TEMP_WARN: | |
8381 | case ASYNC_TEMP_SAFE: | |
8382 | temp_event_data.data = (uint32_t) icmd->ulpContext; | |
8383 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
8384 | if (evt_code == ASYNC_TEMP_WARN) { | |
8385 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
8386 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
8387 | "0347 Adapter is very hot, please take " | |
8388 | "corrective action. temperature : %d Celsius\n", | |
8389 | (uint32_t) icmd->ulpContext); | |
8390 | } else { | |
8391 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
8392 | lpfc_printf_log(phba, KERN_ERR, LOG_TEMP, | |
8393 | "0340 Adapter temperature is OK now. " | |
8394 | "temperature : %d Celsius\n", | |
8395 | (uint32_t) icmd->ulpContext); | |
8396 | } | |
8397 | ||
8398 | /* Send temperature change event to applications */ | |
8399 | shost = lpfc_shost_from_vport(phba->pport); | |
8400 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
8401 | sizeof(temp_event_data), (char *) &temp_event_data, | |
8402 | LPFC_NL_VENDOR_ID); | |
8403 | break; | |
8404 | case ASYNC_STATUS_CN: | |
8405 | lpfc_sli_abts_err_handler(phba, iocbq); | |
8406 | break; | |
8407 | default: | |
a257bf90 | 8408 | iocb_w = (uint32_t *) icmd; |
cb69f7de | 8409 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
76bb24ef | 8410 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 8411 | " evt_code 0x%x\n" |
a257bf90 JS |
8412 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
8413 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
8414 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
8415 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
cb69f7de | 8416 | pring->ringno, icmd->un.asyncstat.evt_code, |
a257bf90 JS |
8417 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], |
8418 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
8419 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
8420 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
8421 | ||
cb69f7de | 8422 | break; |
57127f15 | 8423 | } |
57127f15 JS |
8424 | } |
8425 | ||
8426 | ||
e59058c4 | 8427 | /** |
3621a710 | 8428 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
8429 | * @phba: Pointer to HBA context object. |
8430 | * | |
8431 | * lpfc_sli_setup sets up rings of the SLI interface with | |
8432 | * number of iocbs per ring and iotags. This function is | |
8433 | * called while driver attach to the HBA and before the | |
8434 | * interrupts are enabled. So there is no need for locking. | |
8435 | * | |
8436 | * This function always returns 0. | |
8437 | **/ | |
dea3101e | 8438 | int |
8439 | lpfc_sli_setup(struct lpfc_hba *phba) | |
8440 | { | |
ed957684 | 8441 | int i, totiocbsize = 0; |
dea3101e | 8442 | struct lpfc_sli *psli = &phba->sli; |
8443 | struct lpfc_sli_ring *pring; | |
8444 | ||
8445 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
8446 | psli->sli_flag = 0; | |
8447 | psli->fcp_ring = LPFC_FCP_RING; | |
8448 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 8449 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 8450 | |
604a3e30 JB |
8451 | psli->iocbq_lookup = NULL; |
8452 | psli->iocbq_lookup_len = 0; | |
8453 | psli->last_iotag = 0; | |
8454 | ||
dea3101e | 8455 | for (i = 0; i < psli->num_rings; i++) { |
8456 | pring = &psli->ring[i]; | |
8457 | switch (i) { | |
8458 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
8459 | /* numCiocb and numRiocb are used in config_port */ | |
8460 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
8461 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
8462 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
8463 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
8464 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
8465 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 8466 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8467 | SLI3_IOCB_CMD_SIZE : |
8468 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 8469 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8470 | SLI3_IOCB_RSP_SIZE : |
8471 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 8472 | pring->iotag_ctr = 0; |
8473 | pring->iotag_max = | |
92d7f7b0 | 8474 | (phba->cfg_hba_queue_depth * 2); |
dea3101e | 8475 | pring->fast_iotag = pring->iotag_max; |
8476 | pring->num_mask = 0; | |
8477 | break; | |
a4bc3379 | 8478 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 8479 | /* numCiocb and numRiocb are used in config_port */ |
8480 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
8481 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 8482 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8483 | SLI3_IOCB_CMD_SIZE : |
8484 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 8485 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8486 | SLI3_IOCB_RSP_SIZE : |
8487 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 8488 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e | 8489 | pring->num_mask = 0; |
8490 | break; | |
8491 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
8492 | /* numCiocb and numRiocb are used in config_port */ | |
8493 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
8494 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 8495 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8496 | SLI3_IOCB_CMD_SIZE : |
8497 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 8498 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
8499 | SLI3_IOCB_RSP_SIZE : |
8500 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 8501 | pring->fast_iotag = 0; |
8502 | pring->iotag_ctr = 0; | |
8503 | pring->iotag_max = 4096; | |
57127f15 JS |
8504 | pring->lpfc_sli_rcv_async_status = |
8505 | lpfc_sli_async_event_handler; | |
6669f9bb | 8506 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 8507 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
8508 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
8509 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 8510 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8511 | lpfc_els_unsol_event; |
dea3101e | 8512 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
8513 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
8514 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 8515 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8516 | lpfc_els_unsol_event; |
dea3101e | 8517 | pring->prt[2].profile = 0; /* Mask 2 */ |
8518 | /* NameServer Inquiry */ | |
6a9c52cf | 8519 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 8520 | /* NameServer */ |
6a9c52cf | 8521 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 8522 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8523 | lpfc_ct_unsol_event; |
dea3101e | 8524 | pring->prt[3].profile = 0; /* Mask 3 */ |
8525 | /* NameServer response */ | |
6a9c52cf | 8526 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 8527 | /* NameServer */ |
6a9c52cf | 8528 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 8529 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 8530 | lpfc_ct_unsol_event; |
6669f9bb JS |
8531 | /* abort unsolicited sequence */ |
8532 | pring->prt[4].profile = 0; /* Mask 4 */ | |
8533 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
8534 | pring->prt[4].type = FC_TYPE_BLS; | |
8535 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
8536 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e | 8537 | break; |
8538 | } | |
ed957684 | 8539 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 8540 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 8541 | } |
ed957684 | 8542 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 8543 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
8544 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
8545 | "SLI2 SLIM Data: x%x x%lx\n", | |
8546 | phba->brd_no, totiocbsize, | |
8547 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 8548 | } |
cf5bf97e JW |
8549 | if (phba->cfg_multi_ring_support == 2) |
8550 | lpfc_extra_ring_setup(phba); | |
dea3101e | 8551 | |
8552 | return 0; | |
8553 | } | |
8554 | ||
e59058c4 | 8555 | /** |
3621a710 | 8556 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
8557 | * @phba: Pointer to HBA context object. |
8558 | * | |
8559 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
8560 | * ring. This function also initializes ring indices of each ring. | |
8561 | * This function is called during the initialization of the SLI | |
8562 | * interface of an HBA. | |
8563 | * This function is called with no lock held and always returns | |
8564 | * 1. | |
8565 | **/ | |
dea3101e | 8566 | int |
2e0fef85 | 8567 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e | 8568 | { |
8569 | struct lpfc_sli *psli; | |
8570 | struct lpfc_sli_ring *pring; | |
604a3e30 | 8571 | int i; |
dea3101e | 8572 | |
8573 | psli = &phba->sli; | |
2e0fef85 | 8574 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8575 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 8576 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e | 8577 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
8578 | for (i = 0; i < psli->num_rings; i++) { | |
8579 | pring = &psli->ring[i]; | |
8580 | pring->ringno = i; | |
8581 | pring->next_cmdidx = 0; | |
8582 | pring->local_getidx = 0; | |
8583 | pring->cmdidx = 0; | |
8584 | INIT_LIST_HEAD(&pring->txq); | |
8585 | INIT_LIST_HEAD(&pring->txcmplq); | |
8586 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 8587 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 8588 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 8589 | } |
2e0fef85 JS |
8590 | spin_unlock_irq(&phba->hbalock); |
8591 | return 1; | |
dea3101e | 8592 | } |
8593 | ||
04c68496 JS |
8594 | /** |
8595 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
8596 | * @phba: Pointer to HBA context object. | |
8597 | * | |
8598 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
8599 | * flush all the mailbox commands in the three possible stages in the mailbox | |
8600 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
8601 | * command; and completed mailbox command queue. It is caller's responsibility | |
8602 | * to make sure that the driver is in the proper state to flush the mailbox | |
8603 | * command sub-system. Namely, the posting of mailbox commands into the | |
8604 | * pending mailbox command queue from the various clients must be stopped; | |
8605 | * either the HBA is in a state that it will never works on the outstanding | |
8606 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
8607 | * mailbox command has been completed. | |
8608 | **/ | |
8609 | static void | |
8610 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
8611 | { | |
8612 | LIST_HEAD(completions); | |
8613 | struct lpfc_sli *psli = &phba->sli; | |
8614 | LPFC_MBOXQ_t *pmb; | |
8615 | unsigned long iflag; | |
8616 | ||
8617 | /* Flush all the mailbox commands in the mbox system */ | |
8618 | spin_lock_irqsave(&phba->hbalock, iflag); | |
8619 | /* The pending mailbox command queue */ | |
8620 | list_splice_init(&phba->sli.mboxq, &completions); | |
8621 | /* The outstanding active mailbox command */ | |
8622 | if (psli->mbox_active) { | |
8623 | list_add_tail(&psli->mbox_active->list, &completions); | |
8624 | psli->mbox_active = NULL; | |
8625 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8626 | } | |
8627 | /* The completed mailbox command queue */ | |
8628 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
8629 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8630 | ||
8631 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
8632 | while (!list_empty(&completions)) { | |
8633 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
8634 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8635 | if (pmb->mbox_cmpl) | |
8636 | pmb->mbox_cmpl(phba, pmb); | |
8637 | } | |
8638 | } | |
8639 | ||
e59058c4 | 8640 | /** |
3621a710 | 8641 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
8642 | * @vport: Pointer to virtual port object. |
8643 | * | |
8644 | * lpfc_sli_host_down is called to clean up the resources | |
8645 | * associated with a vport before destroying virtual | |
8646 | * port data structures. | |
8647 | * This function does following operations: | |
8648 | * - Free discovery resources associated with this virtual | |
8649 | * port. | |
8650 | * - Free iocbs associated with this virtual port in | |
8651 | * the txq. | |
8652 | * - Send abort for all iocb commands associated with this | |
8653 | * vport in txcmplq. | |
8654 | * | |
8655 | * This function is called with no lock held and always returns 1. | |
8656 | **/ | |
92d7f7b0 JS |
8657 | int |
8658 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
8659 | { | |
858c9f6c | 8660 | LIST_HEAD(completions); |
92d7f7b0 JS |
8661 | struct lpfc_hba *phba = vport->phba; |
8662 | struct lpfc_sli *psli = &phba->sli; | |
8663 | struct lpfc_sli_ring *pring; | |
8664 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
8665 | int i; |
8666 | unsigned long flags = 0; | |
8667 | uint16_t prev_pring_flag; | |
8668 | ||
8669 | lpfc_cleanup_discovery_resources(vport); | |
8670 | ||
8671 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
8672 | for (i = 0; i < psli->num_rings; i++) { |
8673 | pring = &psli->ring[i]; | |
8674 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
8675 | /* Only slow rings */ |
8676 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 8677 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
8678 | /* Set the lpfc data pending flag */ |
8679 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
8680 | } | |
92d7f7b0 JS |
8681 | /* |
8682 | * Error everything on the txq since these iocbs have not been | |
8683 | * given to the FW yet. | |
8684 | */ | |
92d7f7b0 JS |
8685 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
8686 | if (iocb->vport != vport) | |
8687 | continue; | |
858c9f6c | 8688 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 8689 | pring->txq_cnt--; |
92d7f7b0 JS |
8690 | } |
8691 | ||
8692 | /* Next issue ABTS for everything on the txcmplq */ | |
8693 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
8694 | list) { | |
8695 | if (iocb->vport != vport) | |
8696 | continue; | |
8697 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
8698 | } | |
8699 | ||
8700 | pring->flag = prev_pring_flag; | |
8701 | } | |
8702 | ||
8703 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
8704 | ||
a257bf90 JS |
8705 | /* Cancel all the IOCBs from the completions list */ |
8706 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8707 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
8708 | return 1; |
8709 | } | |
8710 | ||
e59058c4 | 8711 | /** |
3621a710 | 8712 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
8713 | * @phba: Pointer to HBA context object. |
8714 | * | |
8715 | * This function cleans up all iocb, buffers, mailbox commands | |
8716 | * while shutting down the HBA. This function is called with no | |
8717 | * lock held and always returns 1. | |
8718 | * This function does the following to cleanup driver resources: | |
8719 | * - Free discovery resources for each virtual port | |
8720 | * - Cleanup any pending fabric iocbs | |
8721 | * - Iterate through the iocb txq and free each entry | |
8722 | * in the list. | |
8723 | * - Free up any buffer posted to the HBA | |
8724 | * - Free mailbox commands in the mailbox queue. | |
8725 | **/ | |
dea3101e | 8726 | int |
2e0fef85 | 8727 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 8728 | { |
2534ba75 | 8729 | LIST_HEAD(completions); |
2e0fef85 | 8730 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 8731 | struct lpfc_sli_ring *pring; |
0ff10d46 | 8732 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 8733 | unsigned long flags = 0; |
04c68496 JS |
8734 | int i; |
8735 | ||
8736 | /* Shutdown the mailbox command sub-system */ | |
8737 | lpfc_sli_mbox_sys_shutdown(phba); | |
dea3101e | 8738 | |
dea3101e | 8739 | lpfc_hba_down_prep(phba); |
8740 | ||
92d7f7b0 JS |
8741 | lpfc_fabric_abort_hba(phba); |
8742 | ||
2e0fef85 | 8743 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 8744 | for (i = 0; i < psli->num_rings; i++) { |
8745 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
8746 | /* Only slow rings */ |
8747 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 8748 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
8749 | /* Set the lpfc data pending flag */ |
8750 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
8751 | } | |
dea3101e | 8752 | |
8753 | /* | |
8754 | * Error everything on the txq since these iocbs have not been | |
8755 | * given to the FW yet. | |
8756 | */ | |
2534ba75 | 8757 | list_splice_init(&pring->txq, &completions); |
dea3101e | 8758 | pring->txq_cnt = 0; |
8759 | ||
2534ba75 | 8760 | } |
2e0fef85 | 8761 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 8762 | |
a257bf90 JS |
8763 | /* Cancel all the IOCBs from the completions list */ |
8764 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
8765 | IOERR_SLI_DOWN); | |
dea3101e | 8766 | |
0ff10d46 JS |
8767 | spin_lock_irqsave(&phba->hbalock, flags); |
8768 | list_splice_init(&phba->elsbuf, &completions); | |
8769 | phba->elsbuf_cnt = 0; | |
8770 | phba->elsbuf_prev_cnt = 0; | |
8771 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
8772 | ||
8773 | while (!list_empty(&completions)) { | |
8774 | list_remove_head(&completions, buf_ptr, | |
8775 | struct lpfc_dmabuf, list); | |
8776 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
8777 | kfree(buf_ptr); | |
8778 | } | |
8779 | ||
dea3101e | 8780 | /* Return any active mbox cmds */ |
8781 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 8782 | |
da0436e9 | 8783 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 8784 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 8785 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 8786 | |
da0436e9 JS |
8787 | return 1; |
8788 | } | |
8789 | ||
e59058c4 | 8790 | /** |
3621a710 | 8791 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
8792 | * @srcp: Source memory pointer. |
8793 | * @destp: Destination memory pointer. | |
8794 | * @cnt: Number of words required to be copied. | |
8795 | * | |
8796 | * This function is used for copying data between driver memory | |
8797 | * and the SLI memory. This function also changes the endianness | |
8798 | * of each word if native endianness is different from SLI | |
8799 | * endianness. This function can be called with or without | |
8800 | * lock. | |
8801 | **/ | |
dea3101e | 8802 | void |
8803 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
8804 | { | |
8805 | uint32_t *src = srcp; | |
8806 | uint32_t *dest = destp; | |
8807 | uint32_t ldata; | |
8808 | int i; | |
8809 | ||
8810 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
8811 | ldata = *src; | |
8812 | ldata = le32_to_cpu(ldata); | |
8813 | *dest = ldata; | |
8814 | src++; | |
8815 | dest++; | |
8816 | } | |
8817 | } | |
8818 | ||
e59058c4 | 8819 | |
a0c87cbd JS |
8820 | /** |
8821 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
8822 | * @srcp: Source memory pointer. | |
8823 | * @destp: Destination memory pointer. | |
8824 | * @cnt: Number of words required to be copied. | |
8825 | * | |
8826 | * This function is used for copying data between a data structure | |
8827 | * with big endian representation to local endianness. | |
8828 | * This function can be called with or without lock. | |
8829 | **/ | |
8830 | void | |
8831 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
8832 | { | |
8833 | uint32_t *src = srcp; | |
8834 | uint32_t *dest = destp; | |
8835 | uint32_t ldata; | |
8836 | int i; | |
8837 | ||
8838 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
8839 | ldata = *src; | |
8840 | ldata = be32_to_cpu(ldata); | |
8841 | *dest = ldata; | |
8842 | src++; | |
8843 | dest++; | |
8844 | } | |
8845 | } | |
8846 | ||
e59058c4 | 8847 | /** |
3621a710 | 8848 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
8849 | * @phba: Pointer to HBA context object. |
8850 | * @pring: Pointer to driver SLI ring object. | |
8851 | * @mp: Pointer to driver buffer object. | |
8852 | * | |
8853 | * This function is called with no lock held. | |
8854 | * It always return zero after adding the buffer to the postbufq | |
8855 | * buffer list. | |
8856 | **/ | |
dea3101e | 8857 | int |
2e0fef85 JS |
8858 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
8859 | struct lpfc_dmabuf *mp) | |
dea3101e | 8860 | { |
8861 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
8862 | later */ | |
2e0fef85 | 8863 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8864 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 8865 | pring->postbufq_cnt++; |
2e0fef85 | 8866 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 8867 | return 0; |
8868 | } | |
8869 | ||
e59058c4 | 8870 | /** |
3621a710 | 8871 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
8872 | * @phba: Pointer to HBA context object. |
8873 | * | |
8874 | * When HBQ is enabled, buffers are searched based on tags. This function | |
8875 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
8876 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
8877 | * does not conflict with tags of buffer posted for unsolicited events. | |
8878 | * The function returns the allocated tag. The function is called with | |
8879 | * no locks held. | |
8880 | **/ | |
76bb24ef JS |
8881 | uint32_t |
8882 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
8883 | { | |
8884 | spin_lock_irq(&phba->hbalock); | |
8885 | phba->buffer_tag_count++; | |
8886 | /* | |
8887 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
8888 | * a tag assigned by HBQ. | |
8889 | */ | |
8890 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
8891 | spin_unlock_irq(&phba->hbalock); | |
8892 | return phba->buffer_tag_count; | |
8893 | } | |
8894 | ||
e59058c4 | 8895 | /** |
3621a710 | 8896 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
8897 | * @phba: Pointer to HBA context object. |
8898 | * @pring: Pointer to driver SLI ring object. | |
8899 | * @tag: Buffer tag. | |
8900 | * | |
8901 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
8902 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
8903 | * iocb is posted to the response ring with the tag of the buffer. | |
8904 | * This function searches the pring->postbufq list using the tag | |
8905 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
8906 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
8907 | * buffer is returned to the caller else NULL is returned. | |
8908 | * This function is called with no lock held. | |
8909 | **/ | |
76bb24ef JS |
8910 | struct lpfc_dmabuf * |
8911 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
8912 | uint32_t tag) | |
8913 | { | |
8914 | struct lpfc_dmabuf *mp, *next_mp; | |
8915 | struct list_head *slp = &pring->postbufq; | |
8916 | ||
25985edc | 8917 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
8918 | spin_lock_irq(&phba->hbalock); |
8919 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
8920 | if (mp->buffer_tag == tag) { | |
8921 | list_del_init(&mp->list); | |
8922 | pring->postbufq_cnt--; | |
8923 | spin_unlock_irq(&phba->hbalock); | |
8924 | return mp; | |
8925 | } | |
8926 | } | |
8927 | ||
8928 | spin_unlock_irq(&phba->hbalock); | |
8929 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 8930 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
8931 | "ring %d Data x%lx x%p x%p x%x\n", |
8932 | pring->ringno, (unsigned long) tag, | |
8933 | slp->next, slp->prev, pring->postbufq_cnt); | |
8934 | ||
8935 | return NULL; | |
8936 | } | |
dea3101e | 8937 | |
e59058c4 | 8938 | /** |
3621a710 | 8939 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
8940 | * @phba: Pointer to HBA context object. |
8941 | * @pring: Pointer to driver SLI ring object. | |
8942 | * @phys: DMA address of the buffer. | |
8943 | * | |
8944 | * This function searches the buffer list using the dma_address | |
8945 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
8946 | * corresponding to the dma_address. The function returns the | |
8947 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
8948 | * This function is called by the ct and els unsolicited event | |
8949 | * handlers to get the buffer associated with the unsolicited | |
8950 | * event. | |
8951 | * | |
8952 | * This function is called with no lock held. | |
8953 | **/ | |
dea3101e | 8954 | struct lpfc_dmabuf * |
8955 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
8956 | dma_addr_t phys) | |
8957 | { | |
8958 | struct lpfc_dmabuf *mp, *next_mp; | |
8959 | struct list_head *slp = &pring->postbufq; | |
8960 | ||
25985edc | 8961 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 8962 | spin_lock_irq(&phba->hbalock); |
dea3101e | 8963 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
8964 | if (mp->phys == phys) { | |
8965 | list_del_init(&mp->list); | |
8966 | pring->postbufq_cnt--; | |
2e0fef85 | 8967 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 8968 | return mp; |
8969 | } | |
8970 | } | |
8971 | ||
2e0fef85 | 8972 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 8973 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 8974 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 8975 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 8976 | pring->ringno, (unsigned long long)phys, |
dea3101e | 8977 | slp->next, slp->prev, pring->postbufq_cnt); |
8978 | return NULL; | |
8979 | } | |
8980 | ||
e59058c4 | 8981 | /** |
3621a710 | 8982 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
8983 | * @phba: Pointer to HBA context object. |
8984 | * @cmdiocb: Pointer to driver command iocb object. | |
8985 | * @rspiocb: Pointer to driver response iocb object. | |
8986 | * | |
8987 | * This function is the completion handler for the abort iocbs for | |
8988 | * ELS commands. This function is called from the ELS ring event | |
8989 | * handler with no lock held. This function frees memory resources | |
8990 | * associated with the abort iocb. | |
8991 | **/ | |
dea3101e | 8992 | static void |
2e0fef85 JS |
8993 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
8994 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 8995 | { |
2e0fef85 | 8996 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 8997 | uint16_t abort_iotag, abort_context; |
ff78d8f9 | 8998 | struct lpfc_iocbq *abort_iocb = NULL; |
2680eeaa JS |
8999 | |
9000 | if (irsp->ulpStatus) { | |
ff78d8f9 JS |
9001 | |
9002 | /* | |
9003 | * Assume that the port already completed and returned, or | |
9004 | * will return the iocb. Just Log the message. | |
9005 | */ | |
2680eeaa JS |
9006 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; |
9007 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
9008 | ||
2e0fef85 | 9009 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
9010 | if (phba->sli_rev < LPFC_SLI_REV4) { |
9011 | if (abort_iotag != 0 && | |
9012 | abort_iotag <= phba->sli.last_iotag) | |
9013 | abort_iocb = | |
9014 | phba->sli.iocbq_lookup[abort_iotag]; | |
9015 | } else | |
9016 | /* For sli4 the abort_tag is the XRI, | |
9017 | * so the abort routine puts the iotag of the iocb | |
9018 | * being aborted in the context field of the abort | |
9019 | * IOCB. | |
9020 | */ | |
9021 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 9022 | |
2a9bf3d0 JS |
9023 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, |
9024 | "0327 Cannot abort els iocb %p " | |
9025 | "with tag %x context %x, abort status %x, " | |
9026 | "abort code %x\n", | |
9027 | abort_iocb, abort_iotag, abort_context, | |
9028 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
341af102 | 9029 | |
ff78d8f9 | 9030 | spin_unlock_irq(&phba->hbalock); |
2680eeaa | 9031 | } |
604a3e30 | 9032 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e | 9033 | return; |
9034 | } | |
9035 | ||
e59058c4 | 9036 | /** |
3621a710 | 9037 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
9038 | * @phba: Pointer to HBA context object. |
9039 | * @cmdiocb: Pointer to driver command iocb object. | |
9040 | * @rspiocb: Pointer to driver response iocb object. | |
9041 | * | |
9042 | * The function is called from SLI ring event handler with no | |
9043 | * lock held. This function is the completion handler for ELS commands | |
9044 | * which are aborted. The function frees memory resources used for | |
9045 | * the aborted ELS commands. | |
9046 | **/ | |
92d7f7b0 JS |
9047 | static void |
9048 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
9049 | struct lpfc_iocbq *rspiocb) | |
9050 | { | |
9051 | IOCB_t *irsp = &rspiocb->iocb; | |
9052 | ||
9053 | /* ELS cmd tag <ulpIoTag> completes */ | |
9054 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 9055 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 9056 | "x%x x%x x%x\n", |
e8b62011 | 9057 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 9058 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
9059 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
9060 | lpfc_ct_free_iocb(phba, cmdiocb); | |
9061 | else | |
9062 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
9063 | return; |
9064 | } | |
9065 | ||
e59058c4 | 9066 | /** |
5af5eee7 | 9067 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
9068 | * @phba: Pointer to HBA context object. |
9069 | * @pring: Pointer to driver SLI ring object. | |
9070 | * @cmdiocb: Pointer to driver command iocb object. | |
9071 | * | |
5af5eee7 JS |
9072 | * This function issues an abort iocb for the provided command iocb down to |
9073 | * the port. Other than the case the outstanding command iocb is an abort | |
9074 | * request, this function issues abort out unconditionally. This function is | |
9075 | * called with hbalock held. The function returns 0 when it fails due to | |
9076 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 9077 | **/ |
5af5eee7 JS |
9078 | static int |
9079 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 9080 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 9081 | { |
2e0fef85 | 9082 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 9083 | struct lpfc_iocbq *abtsiocbp; |
dea3101e | 9084 | IOCB_t *icmd = NULL; |
9085 | IOCB_t *iabt = NULL; | |
5af5eee7 | 9086 | int retval; |
07951076 | 9087 | |
92d7f7b0 JS |
9088 | /* |
9089 | * There are certain command types we don't want to abort. And we | |
9090 | * don't want to abort commands that are already in the process of | |
9091 | * being aborted. | |
07951076 JS |
9092 | */ |
9093 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 9094 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
9095 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
9096 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
9097 | return 0; |
9098 | ||
dea3101e | 9099 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 9100 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 9101 | if (abtsiocbp == NULL) |
9102 | return 0; | |
dea3101e | 9103 | |
07951076 | 9104 | /* This signals the response to set the correct status |
341af102 | 9105 | * before calling the completion handler |
07951076 JS |
9106 | */ |
9107 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
9108 | ||
dea3101e | 9109 | iabt = &abtsiocbp->iocb; |
07951076 JS |
9110 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
9111 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 9112 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 9113 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
9114 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
9115 | } | |
da0436e9 JS |
9116 | else |
9117 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
9118 | iabt->ulpLe = 1; |
9119 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 9120 | |
5ffc266e JS |
9121 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9122 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
9123 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
9124 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9125 | |
2e0fef85 | 9126 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
9127 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
9128 | else | |
9129 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 9130 | |
07951076 | 9131 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 9132 | |
e8b62011 JS |
9133 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
9134 | "0339 Abort xri x%x, original iotag x%x, " | |
9135 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 9136 | iabt->un.acxri.abortIoTag, |
e8b62011 | 9137 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 9138 | abtsiocbp->iotag); |
da0436e9 | 9139 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
dea3101e | 9140 | |
d7c255b2 JS |
9141 | if (retval) |
9142 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
9143 | |
9144 | /* | |
9145 | * Caller to this routine should check for IOCB_ERROR | |
9146 | * and handle it properly. This routine no longer removes | |
9147 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
9148 | */ | |
9149 | return retval; | |
9150 | } | |
9151 | ||
9152 | /** | |
9153 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
9154 | * @phba: Pointer to HBA context object. | |
9155 | * @pring: Pointer to driver SLI ring object. | |
9156 | * @cmdiocb: Pointer to driver command iocb object. | |
9157 | * | |
9158 | * This function issues an abort iocb for the provided command iocb. In case | |
9159 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
9160 | * ring. Instead, the callback function shall be changed to those commands | |
9161 | * so that nothing happens when them finishes. This function is called with | |
9162 | * hbalock held. The function returns 0 when the command iocb is an abort | |
9163 | * request. | |
9164 | **/ | |
9165 | int | |
9166 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
9167 | struct lpfc_iocbq *cmdiocb) | |
9168 | { | |
9169 | struct lpfc_vport *vport = cmdiocb->vport; | |
9170 | int retval = IOCB_ERROR; | |
9171 | IOCB_t *icmd = NULL; | |
9172 | ||
9173 | /* | |
9174 | * There are certain command types we don't want to abort. And we | |
9175 | * don't want to abort commands that are already in the process of | |
9176 | * being aborted. | |
9177 | */ | |
9178 | icmd = &cmdiocb->iocb; | |
9179 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
9180 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
9181 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
9182 | return 0; | |
9183 | ||
9184 | /* | |
9185 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
9186 | * the callback so that nothing happens when it finishes. | |
9187 | */ | |
9188 | if ((vport->load_flag & FC_UNLOADING) && | |
9189 | (pring->ringno == LPFC_ELS_RING)) { | |
9190 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
9191 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
9192 | else | |
9193 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
9194 | goto abort_iotag_exit; | |
9195 | } | |
9196 | ||
9197 | /* Now, we try to issue the abort to the cmdiocb out */ | |
9198 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
9199 | ||
07951076 | 9200 | abort_iotag_exit: |
2e0fef85 JS |
9201 | /* |
9202 | * Caller to this routine should check for IOCB_ERROR | |
9203 | * and handle it properly. This routine no longer removes | |
9204 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 9205 | */ |
2e0fef85 | 9206 | return retval; |
dea3101e | 9207 | } |
9208 | ||
5af5eee7 JS |
9209 | /** |
9210 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
9211 | * @phba: Pointer to HBA context object. | |
9212 | * @pring: Pointer to driver SLI ring object. | |
9213 | * | |
9214 | * This function aborts all iocbs in the given ring and frees all the iocb | |
9215 | * objects in txq. This function issues abort iocbs unconditionally for all | |
9216 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
9217 | * to complete before the return of this function. The caller is not required | |
9218 | * to hold any locks. | |
9219 | **/ | |
9220 | static void | |
9221 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
9222 | { | |
9223 | LIST_HEAD(completions); | |
9224 | struct lpfc_iocbq *iocb, *next_iocb; | |
9225 | ||
9226 | if (pring->ringno == LPFC_ELS_RING) | |
9227 | lpfc_fabric_abort_hba(phba); | |
9228 | ||
9229 | spin_lock_irq(&phba->hbalock); | |
9230 | ||
9231 | /* Take off all the iocbs on txq for cancelling */ | |
9232 | list_splice_init(&pring->txq, &completions); | |
9233 | pring->txq_cnt = 0; | |
9234 | ||
9235 | /* Next issue ABTS for everything on the txcmplq */ | |
9236 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
9237 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
9238 | ||
9239 | spin_unlock_irq(&phba->hbalock); | |
9240 | ||
9241 | /* Cancel all the IOCBs from the completions list */ | |
9242 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
9243 | IOERR_SLI_ABORTED); | |
9244 | } | |
9245 | ||
9246 | /** | |
9247 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
9248 | * @phba: pointer to lpfc HBA data structure. | |
9249 | * | |
9250 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
9251 | **/ | |
9252 | void | |
9253 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
9254 | { | |
9255 | struct lpfc_sli *psli = &phba->sli; | |
9256 | struct lpfc_sli_ring *pring; | |
9257 | int i; | |
9258 | ||
9259 | for (i = 0; i < psli->num_rings; i++) { | |
9260 | pring = &psli->ring[i]; | |
9261 | lpfc_sli_iocb_ring_abort(phba, pring); | |
9262 | } | |
9263 | } | |
9264 | ||
e59058c4 | 9265 | /** |
3621a710 | 9266 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
9267 | * @iocbq: Pointer to driver iocb object. |
9268 | * @vport: Pointer to driver virtual port object. | |
9269 | * @tgt_id: SCSI ID of the target. | |
9270 | * @lun_id: LUN ID of the scsi device. | |
9271 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
9272 | * | |
3621a710 | 9273 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
9274 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
9275 | * 0 if the filtering criteria is met for the given iocb and will return | |
9276 | * 1 if the filtering criteria is not met. | |
9277 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
9278 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
9279 | * lun_id parameter. | |
9280 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
9281 | * given iocb is for the SCSI target specified by vport and tgt_id | |
9282 | * parameters. | |
9283 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
9284 | * given iocb is for the SCSI host associated with the given vport. | |
9285 | * This function is called with no locks held. | |
9286 | **/ | |
dea3101e | 9287 | static int |
51ef4c26 JS |
9288 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
9289 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 9290 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 9291 | { |
0bd4ca25 | 9292 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 9293 | int rc = 1; |
9294 | ||
0bd4ca25 JSEC |
9295 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
9296 | return rc; | |
9297 | ||
51ef4c26 JS |
9298 | if (iocbq->vport != vport) |
9299 | return rc; | |
9300 | ||
0bd4ca25 | 9301 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 9302 | |
495a714c | 9303 | if (lpfc_cmd->pCmd == NULL) |
dea3101e | 9304 | return rc; |
9305 | ||
9306 | switch (ctx_cmd) { | |
9307 | case LPFC_CTX_LUN: | |
495a714c JS |
9308 | if ((lpfc_cmd->rdata->pnode) && |
9309 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
9310 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e | 9311 | rc = 0; |
9312 | break; | |
9313 | case LPFC_CTX_TGT: | |
495a714c JS |
9314 | if ((lpfc_cmd->rdata->pnode) && |
9315 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e | 9316 | rc = 0; |
9317 | break; | |
dea3101e | 9318 | case LPFC_CTX_HOST: |
9319 | rc = 0; | |
9320 | break; | |
9321 | default: | |
9322 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 9323 | __func__, ctx_cmd); |
dea3101e | 9324 | break; |
9325 | } | |
9326 | ||
9327 | return rc; | |
9328 | } | |
9329 | ||
e59058c4 | 9330 | /** |
3621a710 | 9331 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
9332 | * @vport: Pointer to virtual port. |
9333 | * @tgt_id: SCSI ID of the target. | |
9334 | * @lun_id: LUN ID of the scsi device. | |
9335 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9336 | * | |
9337 | * This function returns number of FCP commands pending for the vport. | |
9338 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
9339 | * commands pending on the vport associated with SCSI device specified | |
9340 | * by tgt_id and lun_id parameters. | |
9341 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
9342 | * commands pending on the vport associated with SCSI target specified | |
9343 | * by tgt_id parameter. | |
9344 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
9345 | * commands pending on the vport. | |
9346 | * This function returns the number of iocbs which satisfy the filter. | |
9347 | * This function is called without any lock held. | |
9348 | **/ | |
dea3101e | 9349 | int |
51ef4c26 JS |
9350 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
9351 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 9352 | { |
51ef4c26 | 9353 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9354 | struct lpfc_iocbq *iocbq; |
9355 | int sum, i; | |
dea3101e | 9356 | |
0bd4ca25 JSEC |
9357 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
9358 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9359 | |
51ef4c26 JS |
9360 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
9361 | ctx_cmd) == 0) | |
0bd4ca25 | 9362 | sum++; |
dea3101e | 9363 | } |
0bd4ca25 | 9364 | |
dea3101e | 9365 | return sum; |
9366 | } | |
9367 | ||
e59058c4 | 9368 | /** |
3621a710 | 9369 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
9370 | * @phba: Pointer to HBA context object |
9371 | * @cmdiocb: Pointer to command iocb object. | |
9372 | * @rspiocb: Pointer to response iocb object. | |
9373 | * | |
9374 | * This function is called when an aborted FCP iocb completes. This | |
9375 | * function is called by the ring event handler with no lock held. | |
9376 | * This function frees the iocb. | |
9377 | **/ | |
5eb95af0 | 9378 | void |
2e0fef85 JS |
9379 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
9380 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 9381 | { |
cb69f7de JS |
9382 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
9383 | "3096 ABORT_XRI_CN completing on xri x%x " | |
9384 | "original iotag x%x, abort cmd iotag x%x " | |
9385 | "status 0x%x, reason 0x%x\n", | |
9386 | cmdiocb->iocb.un.acxri.abortContextTag, | |
9387 | cmdiocb->iocb.un.acxri.abortIoTag, | |
9388 | cmdiocb->iotag, rspiocb->iocb.ulpStatus, | |
9389 | rspiocb->iocb.un.ulpWord[4]); | |
604a3e30 | 9390 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
9391 | return; |
9392 | } | |
9393 | ||
e59058c4 | 9394 | /** |
3621a710 | 9395 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
9396 | * @vport: Pointer to virtual port. |
9397 | * @pring: Pointer to driver SLI ring object. | |
9398 | * @tgt_id: SCSI ID of the target. | |
9399 | * @lun_id: LUN ID of the scsi device. | |
9400 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
9401 | * | |
9402 | * This function sends an abort command for every SCSI command | |
9403 | * associated with the given virtual port pending on the ring | |
9404 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
9405 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
9406 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
9407 | * parameters | |
9408 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
9409 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
9410 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
9411 | * FCP iocbs associated with virtual port. | |
9412 | * This function returns number of iocbs it failed to abort. | |
9413 | * This function is called with no locks held. | |
9414 | **/ | |
dea3101e | 9415 | int |
51ef4c26 JS |
9416 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
9417 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 9418 | { |
51ef4c26 | 9419 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
9420 | struct lpfc_iocbq *iocbq; |
9421 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 9422 | IOCB_t *cmd = NULL; |
dea3101e | 9423 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 9424 | int i; |
dea3101e | 9425 | |
0bd4ca25 JSEC |
9426 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
9427 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 9428 | |
51ef4c26 | 9429 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 9430 | abort_cmd) != 0) |
dea3101e | 9431 | continue; |
9432 | ||
9433 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 9434 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e | 9435 | if (abtsiocb == NULL) { |
9436 | errcnt++; | |
9437 | continue; | |
9438 | } | |
dea3101e | 9439 | |
0bd4ca25 | 9440 | cmd = &iocbq->iocb; |
dea3101e | 9441 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
9442 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
9443 | if (phba->sli_rev == LPFC_SLI_REV4) |
9444 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
9445 | else | |
9446 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 9447 | abtsiocb->iocb.ulpLe = 1; |
9448 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 9449 | abtsiocb->vport = phba->pport; |
dea3101e | 9450 | |
5ffc266e JS |
9451 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
9452 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
9453 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
9454 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 9455 | |
2e0fef85 | 9456 | if (lpfc_is_link_up(phba)) |
dea3101e | 9457 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
9458 | else | |
9459 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
9460 | ||
5eb95af0 JSEC |
9461 | /* Setup callback routine and issue the command. */ |
9462 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
9463 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
9464 | abtsiocb, 0); | |
dea3101e | 9465 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 9466 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e | 9467 | errcnt++; |
9468 | continue; | |
9469 | } | |
9470 | } | |
9471 | ||
9472 | return errcnt; | |
9473 | } | |
9474 | ||
e59058c4 | 9475 | /** |
3621a710 | 9476 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
9477 | * @phba: Pointer to HBA context object. |
9478 | * @cmdiocbq: Pointer to command iocb. | |
9479 | * @rspiocbq: Pointer to response iocb. | |
9480 | * | |
9481 | * This function is the completion handler for iocbs issued using | |
9482 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
9483 | * ring event handler function without any lock held. This function | |
9484 | * can be called from both worker thread context and interrupt | |
9485 | * context. This function also can be called from other thread which | |
9486 | * cleans up the SLI layer objects. | |
9487 | * This function copy the contents of the response iocb to the | |
9488 | * response iocb memory object provided by the caller of | |
9489 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
9490 | * sleeps for the iocb completion. | |
9491 | **/ | |
68876920 JSEC |
9492 | static void |
9493 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
9494 | struct lpfc_iocbq *cmdiocbq, | |
9495 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 9496 | { |
68876920 JSEC |
9497 | wait_queue_head_t *pdone_q; |
9498 | unsigned long iflags; | |
0f65ff68 | 9499 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 9500 | |
2e0fef85 | 9501 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
9502 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
9503 | if (cmdiocbq->context2 && rspiocbq) | |
9504 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
9505 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
9506 | ||
0f65ff68 JS |
9507 | /* Set the exchange busy flag for task management commands */ |
9508 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
9509 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
9510 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
9511 | cur_iocbq); | |
9512 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
9513 | } | |
9514 | ||
68876920 | 9515 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
9516 | if (pdone_q) |
9517 | wake_up(pdone_q); | |
858c9f6c | 9518 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e | 9519 | return; |
9520 | } | |
9521 | ||
d11e31dd JS |
9522 | /** |
9523 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
9524 | * @phba: Pointer to HBA context object.. | |
9525 | * @piocbq: Pointer to command iocb. | |
9526 | * @flag: Flag to test. | |
9527 | * | |
9528 | * This routine grabs the hbalock and then test the iocb_flag to | |
9529 | * see if the passed in flag is set. | |
9530 | * Returns: | |
9531 | * 1 if flag is set. | |
9532 | * 0 if flag is not set. | |
9533 | **/ | |
9534 | static int | |
9535 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
9536 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
9537 | { | |
9538 | unsigned long iflags; | |
9539 | int ret; | |
9540 | ||
9541 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9542 | ret = piocbq->iocb_flag & flag; | |
9543 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9544 | return ret; | |
9545 | ||
9546 | } | |
9547 | ||
e59058c4 | 9548 | /** |
3621a710 | 9549 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
9550 | * @phba: Pointer to HBA context object.. |
9551 | * @pring: Pointer to sli ring. | |
9552 | * @piocb: Pointer to command iocb. | |
9553 | * @prspiocbq: Pointer to response iocb. | |
9554 | * @timeout: Timeout in number of seconds. | |
9555 | * | |
9556 | * This function issues the iocb to firmware and waits for the | |
9557 | * iocb to complete. If the iocb command is not | |
9558 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
9559 | * Caller should not free the iocb resources if this function | |
9560 | * returns IOCB_TIMEDOUT. | |
9561 | * The function waits for the iocb completion using an | |
9562 | * non-interruptible wait. | |
9563 | * This function will sleep while waiting for iocb completion. | |
9564 | * So, this function should not be called from any context which | |
9565 | * does not allow sleeping. Due to the same reason, this function | |
9566 | * cannot be called with interrupt disabled. | |
9567 | * This function assumes that the iocb completions occur while | |
9568 | * this function sleep. So, this function cannot be called from | |
9569 | * the thread which process iocb completion for this ring. | |
9570 | * This function clears the iocb_flag of the iocb object before | |
9571 | * issuing the iocb and the iocb completion handler sets this | |
9572 | * flag and wakes this thread when the iocb completes. | |
9573 | * The contents of the response iocb will be copied to prspiocbq | |
9574 | * by the completion handler when the command completes. | |
9575 | * This function returns IOCB_SUCCESS when success. | |
9576 | * This function is called with no lock held. | |
9577 | **/ | |
dea3101e | 9578 | int |
2e0fef85 | 9579 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 9580 | uint32_t ring_number, |
2e0fef85 JS |
9581 | struct lpfc_iocbq *piocb, |
9582 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 9583 | uint32_t timeout) |
dea3101e | 9584 | { |
7259f0d0 | 9585 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
9586 | long timeleft, timeout_req = 0; |
9587 | int retval = IOCB_SUCCESS; | |
875fbdfe | 9588 | uint32_t creg_val; |
2a9bf3d0 | 9589 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 9590 | /* |
68876920 JSEC |
9591 | * If the caller has provided a response iocbq buffer, then context2 |
9592 | * is NULL or its an error. | |
dea3101e | 9593 | */ |
68876920 JSEC |
9594 | if (prspiocbq) { |
9595 | if (piocb->context2) | |
9596 | return IOCB_ERROR; | |
9597 | piocb->context2 = prspiocbq; | |
dea3101e | 9598 | } |
9599 | ||
68876920 JSEC |
9600 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
9601 | piocb->context_un.wait_queue = &done_q; | |
9602 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 9603 | |
875fbdfe | 9604 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9605 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9606 | return IOCB_ERROR; | |
875fbdfe JSEC |
9607 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
9608 | writel(creg_val, phba->HCregaddr); | |
9609 | readl(phba->HCregaddr); /* flush */ | |
9610 | } | |
9611 | ||
2a9bf3d0 JS |
9612 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
9613 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
9614 | if (retval == IOCB_SUCCESS) { |
9615 | timeout_req = timeout * HZ; | |
68876920 | 9616 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 9617 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 9618 | timeout_req); |
dea3101e | 9619 | |
7054a606 JS |
9620 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
9621 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 9622 | "0331 IOCB wake signaled\n"); |
7054a606 | 9623 | } else if (timeleft == 0) { |
68876920 | 9624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9625 | "0338 IOCB wait timeout error - no " |
9626 | "wake response Data x%x\n", timeout); | |
68876920 | 9627 | retval = IOCB_TIMEDOUT; |
7054a606 | 9628 | } else { |
68876920 | 9629 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
9630 | "0330 IOCB wake NOT set, " |
9631 | "Data x%x x%lx\n", | |
68876920 JSEC |
9632 | timeout, (timeleft / jiffies)); |
9633 | retval = IOCB_TIMEDOUT; | |
dea3101e | 9634 | } |
2a9bf3d0 JS |
9635 | } else if (retval == IOCB_BUSY) { |
9636 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9637 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
9638 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
9639 | return retval; | |
68876920 JSEC |
9640 | } else { |
9641 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 9642 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 9643 | retval); |
68876920 | 9644 | retval = IOCB_ERROR; |
dea3101e | 9645 | } |
9646 | ||
875fbdfe | 9647 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
9648 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
9649 | return IOCB_ERROR; | |
875fbdfe JSEC |
9650 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
9651 | writel(creg_val, phba->HCregaddr); | |
9652 | readl(phba->HCregaddr); /* flush */ | |
9653 | } | |
9654 | ||
68876920 JSEC |
9655 | if (prspiocbq) |
9656 | piocb->context2 = NULL; | |
9657 | ||
9658 | piocb->context_un.wait_queue = NULL; | |
9659 | piocb->iocb_cmpl = NULL; | |
dea3101e | 9660 | return retval; |
9661 | } | |
68876920 | 9662 | |
e59058c4 | 9663 | /** |
3621a710 | 9664 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
9665 | * @phba: Pointer to HBA context object. |
9666 | * @pmboxq: Pointer to driver mailbox object. | |
9667 | * @timeout: Timeout in number of seconds. | |
9668 | * | |
9669 | * This function issues the mailbox to firmware and waits for the | |
9670 | * mailbox command to complete. If the mailbox command is not | |
9671 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
9672 | * The function waits for the mailbox completion using an | |
9673 | * interruptible wait. If the thread is woken up due to a | |
9674 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
9675 | * should not free the mailbox resources, if this function returns | |
9676 | * MBX_TIMEOUT. | |
9677 | * This function will sleep while waiting for mailbox completion. | |
9678 | * So, this function should not be called from any context which | |
9679 | * does not allow sleeping. Due to the same reason, this function | |
9680 | * cannot be called with interrupt disabled. | |
9681 | * This function assumes that the mailbox completion occurs while | |
9682 | * this function sleep. So, this function cannot be called from | |
9683 | * the worker thread which processes mailbox completion. | |
9684 | * This function is called in the context of HBA management | |
9685 | * applications. | |
9686 | * This function returns MBX_SUCCESS when successful. | |
9687 | * This function is called with no lock held. | |
9688 | **/ | |
dea3101e | 9689 | int |
2e0fef85 | 9690 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e | 9691 | uint32_t timeout) |
9692 | { | |
7259f0d0 | 9693 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 9694 | int retval; |
858c9f6c | 9695 | unsigned long flag; |
dea3101e | 9696 | |
9697 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 9698 | if (pmboxq->context1) |
2e0fef85 | 9699 | return MBX_NOT_FINISHED; |
dea3101e | 9700 | |
495a714c | 9701 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e | 9702 | /* setup wake call as IOCB callback */ |
9703 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
9704 | /* setup context field to pass wait_queue pointer to wake function */ | |
9705 | pmboxq->context1 = &done_q; | |
9706 | ||
dea3101e | 9707 | /* now issue the command */ |
9708 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
dea3101e | 9709 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { |
7054a606 JS |
9710 | wait_event_interruptible_timeout(done_q, |
9711 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
9712 | timeout * HZ); | |
9713 | ||
858c9f6c | 9714 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 9715 | pmboxq->context1 = NULL; |
7054a606 JS |
9716 | /* |
9717 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
9718 | * else do not free the resources. | |
9719 | */ | |
d7c47992 | 9720 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 9721 | retval = MBX_SUCCESS; |
d7c47992 JS |
9722 | lpfc_sli4_swap_str(phba, pmboxq); |
9723 | } else { | |
7054a606 | 9724 | retval = MBX_TIMEOUT; |
858c9f6c JS |
9725 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
9726 | } | |
9727 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e | 9728 | } |
9729 | ||
dea3101e | 9730 | return retval; |
9731 | } | |
9732 | ||
e59058c4 | 9733 | /** |
3772a991 | 9734 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
9735 | * @phba: Pointer to HBA context. |
9736 | * | |
3772a991 JS |
9737 | * This function is called to shutdown the driver's mailbox sub-system. |
9738 | * It first marks the mailbox sub-system is in a block state to prevent | |
9739 | * the asynchronous mailbox command from issued off the pending mailbox | |
9740 | * command queue. If the mailbox command sub-system shutdown is due to | |
9741 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
9742 | * the mailbox sub-system flush routine to forcefully bring down the | |
9743 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
9744 | * as with offline or HBA function reset), this routine will wait for the | |
9745 | * outstanding mailbox command to complete before invoking the mailbox | |
9746 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 9747 | **/ |
3772a991 JS |
9748 | void |
9749 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) | |
b4c02652 | 9750 | { |
3772a991 | 9751 | struct lpfc_sli *psli = &phba->sli; |
3772a991 | 9752 | unsigned long timeout; |
b4c02652 | 9753 | |
a183a15f | 9754 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
3772a991 JS |
9755 | spin_lock_irq(&phba->hbalock); |
9756 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
9757 | spin_unlock_irq(&phba->hbalock); | |
b4c02652 | 9758 | |
3772a991 | 9759 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
ed957684 | 9760 | spin_lock_irq(&phba->hbalock); |
3772a991 JS |
9761 | /* Determine how long we might wait for the active mailbox |
9762 | * command to be gracefully completed by firmware. | |
9763 | */ | |
a183a15f JS |
9764 | if (phba->sli.mbox_active) |
9765 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
9766 | phba->sli.mbox_active) * | |
9767 | 1000) + jiffies; | |
9768 | spin_unlock_irq(&phba->hbalock); | |
9769 | ||
3772a991 JS |
9770 | while (phba->sli.mbox_active) { |
9771 | /* Check active mailbox complete status every 2ms */ | |
9772 | msleep(2); | |
9773 | if (time_after(jiffies, timeout)) | |
9774 | /* Timeout, let the mailbox flush routine to | |
9775 | * forcefully release active mailbox command | |
9776 | */ | |
9777 | break; | |
9778 | } | |
9779 | } | |
9780 | lpfc_sli_mbox_sys_flush(phba); | |
9781 | } | |
ed957684 | 9782 | |
3772a991 JS |
9783 | /** |
9784 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
9785 | * @phba: Pointer to HBA context. | |
9786 | * | |
9787 | * This function is called to read the SLI3 device error attention registers | |
9788 | * for possible error attention events. The caller must hold the hostlock | |
9789 | * with spin_lock_irq(). | |
9790 | * | |
25985edc | 9791 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
9792 | * Register and returns 0 otherwise. |
9793 | **/ | |
9794 | static int | |
9795 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
9796 | { | |
9797 | uint32_t ha_copy; | |
b4c02652 | 9798 | |
3772a991 | 9799 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
9800 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
9801 | goto unplug_err; | |
9802 | ||
3772a991 JS |
9803 | if (ha_copy & HA_ERATT) { |
9804 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
9805 | if (lpfc_sli_read_hs(phba)) |
9806 | goto unplug_err; | |
b4c02652 | 9807 | |
3772a991 JS |
9808 | /* Check if there is a deferred error condition is active */ |
9809 | if ((HS_FFER1 & phba->work_hs) && | |
9810 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 9811 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 9812 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
9813 | /* Clear all interrupt enable conditions */ |
9814 | writel(0, phba->HCregaddr); | |
9815 | readl(phba->HCregaddr); | |
9816 | } | |
9817 | ||
9818 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
9819 | phba->work_ha |= HA_ERATT; |
9820 | /* Indicate polling handles this ERATT */ | |
9821 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
9822 | return 1; |
9823 | } | |
9824 | return 0; | |
9940b97b JS |
9825 | |
9826 | unplug_err: | |
9827 | /* Set the driver HS work bitmap */ | |
9828 | phba->work_hs |= UNPLUG_ERR; | |
9829 | /* Set the driver HA work bitmap */ | |
9830 | phba->work_ha |= HA_ERATT; | |
9831 | /* Indicate polling handles this ERATT */ | |
9832 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9833 | return 1; | |
b4c02652 JS |
9834 | } |
9835 | ||
da0436e9 JS |
9836 | /** |
9837 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
9838 | * @phba: Pointer to HBA context. | |
9839 | * | |
9840 | * This function is called to read the SLI4 device error attention registers | |
9841 | * for possible error attention events. The caller must hold the hostlock | |
9842 | * with spin_lock_irq(). | |
9843 | * | |
25985edc | 9844 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
9845 | * Register and returns 0 otherwise. |
9846 | **/ | |
9847 | static int | |
9848 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
9849 | { | |
9850 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
9851 | uint32_t if_type, portsmphr; |
9852 | struct lpfc_register portstat_reg; | |
da0436e9 | 9853 | |
2fcee4bf JS |
9854 | /* |
9855 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
9856 | * registers for error attention. This can be changed later. |
9857 | */ | |
2fcee4bf JS |
9858 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
9859 | switch (if_type) { | |
9860 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
9861 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
9862 | &uerr_sta_lo) || | |
9863 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
9864 | &uerr_sta_hi)) { | |
9865 | phba->work_hs |= UNPLUG_ERR; | |
9866 | phba->work_ha |= HA_ERATT; | |
9867 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9868 | return 1; | |
9869 | } | |
2fcee4bf JS |
9870 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
9871 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
9872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9873 | "1423 HBA Unrecoverable error: " | |
9874 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
9875 | "ue_mask_lo_reg=0x%x, " | |
9876 | "ue_mask_hi_reg=0x%x\n", | |
9877 | uerr_sta_lo, uerr_sta_hi, | |
9878 | phba->sli4_hba.ue_mask_lo, | |
9879 | phba->sli4_hba.ue_mask_hi); | |
9880 | phba->work_status[0] = uerr_sta_lo; | |
9881 | phba->work_status[1] = uerr_sta_hi; | |
9882 | phba->work_ha |= HA_ERATT; | |
9883 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9884 | return 1; | |
9885 | } | |
9886 | break; | |
9887 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
9888 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
9889 | &portstat_reg.word0) || | |
9890 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
9891 | &portsmphr)){ | |
9892 | phba->work_hs |= UNPLUG_ERR; | |
9893 | phba->work_ha |= HA_ERATT; | |
9894 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9895 | return 1; | |
9896 | } | |
2fcee4bf JS |
9897 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
9898 | phba->work_status[0] = | |
9899 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
9900 | phba->work_status[1] = | |
9901 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
9902 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9903 | "2885 Port Error Detected: " | |
9904 | "port status reg 0x%x, " | |
9905 | "port smphr reg 0x%x, " | |
9906 | "error 1=0x%x, error 2=0x%x\n", | |
9907 | portstat_reg.word0, | |
9908 | portsmphr, | |
9909 | phba->work_status[0], | |
9910 | phba->work_status[1]); | |
9911 | phba->work_ha |= HA_ERATT; | |
9912 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9913 | return 1; | |
9914 | } | |
9915 | break; | |
9916 | case LPFC_SLI_INTF_IF_TYPE_1: | |
9917 | default: | |
a747c9ce | 9918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
9919 | "2886 HBA Error Attention on unsupported " |
9920 | "if type %d.", if_type); | |
a747c9ce | 9921 | return 1; |
da0436e9 | 9922 | } |
2fcee4bf | 9923 | |
da0436e9 JS |
9924 | return 0; |
9925 | } | |
9926 | ||
e59058c4 | 9927 | /** |
3621a710 | 9928 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
9929 | * @phba: Pointer to HBA context. |
9930 | * | |
3772a991 | 9931 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
9932 | * error attention register bit for error attention events. |
9933 | * | |
25985edc | 9934 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
9935 | * Register and returns 0 otherwise. |
9936 | **/ | |
9937 | int | |
9938 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
9939 | { | |
9940 | uint32_t ha_copy; | |
9941 | ||
9942 | /* If somebody is waiting to handle an eratt, don't process it | |
9943 | * here. The brdkill function will do this. | |
9944 | */ | |
9945 | if (phba->link_flag & LS_IGNORE_ERATT) | |
9946 | return 0; | |
9947 | ||
9948 | /* Check if interrupt handler handles this ERATT */ | |
9949 | spin_lock_irq(&phba->hbalock); | |
9950 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
9951 | /* Interrupt handler has handled ERATT */ | |
9952 | spin_unlock_irq(&phba->hbalock); | |
9953 | return 0; | |
9954 | } | |
9955 | ||
a257bf90 JS |
9956 | /* |
9957 | * If there is deferred error attention, do not check for error | |
9958 | * attention | |
9959 | */ | |
9960 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
9961 | spin_unlock_irq(&phba->hbalock); | |
9962 | return 0; | |
9963 | } | |
9964 | ||
3772a991 JS |
9965 | /* If PCI channel is offline, don't process it */ |
9966 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 9967 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
9968 | return 0; |
9969 | } | |
9970 | ||
9971 | switch (phba->sli_rev) { | |
9972 | case LPFC_SLI_REV2: | |
9973 | case LPFC_SLI_REV3: | |
9974 | /* Read chip Host Attention (HA) register */ | |
9975 | ha_copy = lpfc_sli_eratt_read(phba); | |
9976 | break; | |
da0436e9 | 9977 | case LPFC_SLI_REV4: |
2fcee4bf | 9978 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
9979 | ha_copy = lpfc_sli4_eratt_read(phba); |
9980 | break; | |
3772a991 JS |
9981 | default: |
9982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9983 | "0299 Invalid SLI revision (%d)\n", | |
9984 | phba->sli_rev); | |
9985 | ha_copy = 0; | |
9986 | break; | |
9399627f JS |
9987 | } |
9988 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
9989 | |
9990 | return ha_copy; | |
9991 | } | |
9992 | ||
9993 | /** | |
9994 | * lpfc_intr_state_check - Check device state for interrupt handling | |
9995 | * @phba: Pointer to HBA context. | |
9996 | * | |
9997 | * This inline routine checks whether a device or its PCI slot is in a state | |
9998 | * that the interrupt should be handled. | |
9999 | * | |
10000 | * This function returns 0 if the device or the PCI slot is in a state that | |
10001 | * interrupt should be handled, otherwise -EIO. | |
10002 | */ | |
10003 | static inline int | |
10004 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
10005 | { | |
10006 | /* If the pci channel is offline, ignore all the interrupts */ | |
10007 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
10008 | return -EIO; | |
10009 | ||
10010 | /* Update device level interrupt statistics */ | |
10011 | phba->sli.slistat.sli_intr++; | |
10012 | ||
10013 | /* Ignore all interrupts during initialization. */ | |
10014 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
10015 | return -EIO; | |
10016 | ||
9399627f JS |
10017 | return 0; |
10018 | } | |
10019 | ||
10020 | /** | |
3772a991 | 10021 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
10022 | * @irq: Interrupt number. |
10023 | * @dev_id: The device context pointer. | |
10024 | * | |
9399627f | 10025 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
10026 | * service routine when device with SLI-3 interface spec is enabled with |
10027 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
10028 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
10029 | * interrupt mode, this function is called as part of the device-level | |
10030 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
10031 | * is undergoing initialization, the interrupt handler will not process | |
10032 | * the interrupt. The link attention and ELS ring attention events are | |
10033 | * handled by the worker thread. The interrupt handler signals the worker | |
10034 | * thread and returns for these events. This function is called without | |
10035 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
10036 | * structures. |
10037 | * | |
10038 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10039 | * returns IRQ_NONE. | |
e59058c4 | 10040 | **/ |
dea3101e | 10041 | irqreturn_t |
3772a991 | 10042 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 10043 | { |
2e0fef85 | 10044 | struct lpfc_hba *phba; |
a747c9ce | 10045 | uint32_t ha_copy, hc_copy; |
dea3101e | 10046 | uint32_t work_ha_copy; |
10047 | unsigned long status; | |
5b75da2f | 10048 | unsigned long iflag; |
dea3101e | 10049 | uint32_t control; |
10050 | ||
92d7f7b0 | 10051 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
10052 | struct lpfc_vport *vport; |
10053 | struct lpfc_nodelist *ndlp; | |
10054 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
10055 | LPFC_MBOXQ_t *pmb; |
10056 | int rc; | |
10057 | ||
dea3101e | 10058 | /* |
10059 | * Get the driver's phba structure from the dev_id and | |
10060 | * assume the HBA is not interrupting. | |
10061 | */ | |
9399627f | 10062 | phba = (struct lpfc_hba *)dev_id; |
dea3101e | 10063 | |
10064 | if (unlikely(!phba)) | |
10065 | return IRQ_NONE; | |
10066 | ||
dea3101e | 10067 | /* |
9399627f JS |
10068 | * Stuff needs to be attented to when this function is invoked as an |
10069 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 10070 | */ |
9399627f | 10071 | if (phba->intr_type == MSIX) { |
3772a991 JS |
10072 | /* Check device state for handling interrupt */ |
10073 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10074 | return IRQ_NONE; |
10075 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 10076 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10077 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10078 | goto unplug_error; | |
9399627f JS |
10079 | /* If somebody is waiting to handle an eratt don't process it |
10080 | * here. The brdkill function will do this. | |
10081 | */ | |
10082 | if (phba->link_flag & LS_IGNORE_ERATT) | |
10083 | ha_copy &= ~HA_ERATT; | |
10084 | /* Check the need for handling ERATT in interrupt handler */ | |
10085 | if (ha_copy & HA_ERATT) { | |
10086 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10087 | /* ERATT polling has handled ERATT */ | |
10088 | ha_copy &= ~HA_ERATT; | |
10089 | else | |
10090 | /* Indicate interrupt handler handles ERATT */ | |
10091 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10092 | } | |
a257bf90 JS |
10093 | |
10094 | /* | |
10095 | * If there is deferred error attention, do not check for any | |
10096 | * interrupt. | |
10097 | */ | |
10098 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10099 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10100 | return IRQ_NONE; |
10101 | } | |
10102 | ||
9399627f | 10103 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
10104 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
10105 | goto unplug_error; | |
10106 | ||
a747c9ce JS |
10107 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
10108 | HC_LAINT_ENA | HC_ERINT_ENA), | |
10109 | phba->HCregaddr); | |
9399627f JS |
10110 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
10111 | phba->HAregaddr); | |
a747c9ce | 10112 | writel(hc_copy, phba->HCregaddr); |
9399627f | 10113 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 10114 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10115 | } else |
10116 | ha_copy = phba->ha_copy; | |
dea3101e | 10117 | |
dea3101e | 10118 | work_ha_copy = ha_copy & phba->work_ha_mask; |
10119 | ||
9399627f | 10120 | if (work_ha_copy) { |
dea3101e | 10121 | if (work_ha_copy & HA_LATT) { |
10122 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
10123 | /* | |
10124 | * Turn off Link Attention interrupts | |
10125 | * until CLEAR_LA done | |
10126 | */ | |
5b75da2f | 10127 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10128 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
10129 | if (lpfc_readl(phba->HCregaddr, &control)) |
10130 | goto unplug_error; | |
dea3101e | 10131 | control &= ~HC_LAINT_ENA; |
10132 | writel(control, phba->HCregaddr); | |
10133 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 10134 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 10135 | } |
10136 | else | |
10137 | work_ha_copy &= ~HA_LATT; | |
10138 | } | |
10139 | ||
9399627f | 10140 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
10141 | /* |
10142 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
10143 | * the only slow ring. | |
10144 | */ | |
10145 | status = (work_ha_copy & | |
10146 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10147 | status >>= (4*LPFC_ELS_RING); | |
10148 | if (status & HA_RXMASK) { | |
5b75da2f | 10149 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
10150 | if (lpfc_readl(phba->HCregaddr, &control)) |
10151 | goto unplug_error; | |
a58cbd52 JS |
10152 | |
10153 | lpfc_debugfs_slow_ring_trc(phba, | |
10154 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
10155 | control, status, | |
10156 | (uint32_t)phba->sli.slistat.sli_intr); | |
10157 | ||
858c9f6c | 10158 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
10159 | lpfc_debugfs_slow_ring_trc(phba, |
10160 | "ISR Disable ring:" | |
10161 | "pwork:x%x hawork:x%x wait:x%x", | |
10162 | phba->work_ha, work_ha_copy, | |
10163 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10164 | &phba->work_waitq)); |
a58cbd52 | 10165 | |
858c9f6c JS |
10166 | control &= |
10167 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e | 10168 | writel(control, phba->HCregaddr); |
10169 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 10170 | } |
a58cbd52 JS |
10171 | else { |
10172 | lpfc_debugfs_slow_ring_trc(phba, | |
10173 | "ISR slow ring: pwork:" | |
10174 | "x%x hawork:x%x wait:x%x", | |
10175 | phba->work_ha, work_ha_copy, | |
10176 | (uint32_t)((unsigned long) | |
5e9d9b82 | 10177 | &phba->work_waitq)); |
a58cbd52 | 10178 | } |
5b75da2f | 10179 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 10180 | } |
10181 | } | |
5b75da2f | 10182 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 10183 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
10184 | if (lpfc_sli_read_hs(phba)) |
10185 | goto unplug_error; | |
a257bf90 JS |
10186 | /* |
10187 | * Check if there is a deferred error condition | |
10188 | * is active | |
10189 | */ | |
10190 | if ((HS_FFER1 & phba->work_hs) && | |
10191 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
10192 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
10193 | phba->work_hs)) { | |
a257bf90 JS |
10194 | phba->hba_flag |= DEFER_ERATT; |
10195 | /* Clear all interrupt enable conditions */ | |
10196 | writel(0, phba->HCregaddr); | |
10197 | readl(phba->HCregaddr); | |
10198 | } | |
10199 | } | |
10200 | ||
9399627f | 10201 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 10202 | pmb = phba->sli.mbox_active; |
04c68496 | 10203 | pmbox = &pmb->u.mb; |
34b02dcd | 10204 | mbox = phba->mbox; |
858c9f6c | 10205 | vport = pmb->vport; |
92d7f7b0 JS |
10206 | |
10207 | /* First check out the status word */ | |
10208 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
10209 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 10210 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
10211 | /* |
10212 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
10213 | * mbxStatus <status> | |
10214 | */ | |
09372820 | 10215 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 10216 | LOG_SLI, |
e8b62011 | 10217 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
10218 | "Interrupt mbxCommand x%x " |
10219 | "mbxStatus x%x\n", | |
e8b62011 | 10220 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
10221 | pmbox->mbxCommand, |
10222 | pmbox->mbxStatus); | |
09372820 JS |
10223 | /* clear mailbox attention bit */ |
10224 | work_ha_copy &= ~HA_MBATT; | |
10225 | } else { | |
97eab634 | 10226 | phba->sli.mbox_active = NULL; |
5b75da2f | 10227 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
10228 | phba->last_completion_time = jiffies; |
10229 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
10230 | if (pmb->mbox_cmpl) { |
10231 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
10232 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
10233 | if (pmb->out_ext_byte_len && |
10234 | pmb->context2) | |
10235 | lpfc_sli_pcimem_bcopy( | |
10236 | phba->mbox_ext, | |
10237 | pmb->context2, | |
10238 | pmb->out_ext_byte_len); | |
09372820 JS |
10239 | } |
10240 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
10241 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
10242 | ||
10243 | lpfc_debugfs_disc_trc(vport, | |
10244 | LPFC_DISC_TRC_MBOX_VPORT, | |
10245 | "MBOX dflt rpi: : " | |
10246 | "status:x%x rpi:x%x", | |
10247 | (uint32_t)pmbox->mbxStatus, | |
10248 | pmbox->un.varWords[0], 0); | |
10249 | ||
10250 | if (!pmbox->mbxStatus) { | |
10251 | mp = (struct lpfc_dmabuf *) | |
10252 | (pmb->context1); | |
10253 | ndlp = (struct lpfc_nodelist *) | |
10254 | pmb->context2; | |
10255 | ||
10256 | /* Reg_LOGIN of dflt RPI was | |
10257 | * successful. new lets get | |
10258 | * rid of the RPI using the | |
10259 | * same mbox buffer. | |
10260 | */ | |
10261 | lpfc_unreg_login(phba, | |
10262 | vport->vpi, | |
10263 | pmbox->un.varWords[0], | |
10264 | pmb); | |
10265 | pmb->mbox_cmpl = | |
10266 | lpfc_mbx_cmpl_dflt_rpi; | |
10267 | pmb->context1 = mp; | |
10268 | pmb->context2 = ndlp; | |
10269 | pmb->vport = vport; | |
58da1ffb JS |
10270 | rc = lpfc_sli_issue_mbox(phba, |
10271 | pmb, | |
10272 | MBX_NOWAIT); | |
10273 | if (rc != MBX_BUSY) | |
10274 | lpfc_printf_log(phba, | |
10275 | KERN_ERR, | |
10276 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 10277 | "0350 rc should have" |
6a9c52cf | 10278 | "been MBX_BUSY\n"); |
3772a991 JS |
10279 | if (rc != MBX_NOT_FINISHED) |
10280 | goto send_current_mbox; | |
09372820 | 10281 | } |
858c9f6c | 10282 | } |
5b75da2f JS |
10283 | spin_lock_irqsave( |
10284 | &phba->pport->work_port_lock, | |
10285 | iflag); | |
09372820 JS |
10286 | phba->pport->work_port_events &= |
10287 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
10288 | spin_unlock_irqrestore( |
10289 | &phba->pport->work_port_lock, | |
10290 | iflag); | |
09372820 | 10291 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 10292 | } |
97eab634 | 10293 | } else |
5b75da2f | 10294 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 10295 | |
92d7f7b0 JS |
10296 | if ((work_ha_copy & HA_MBATT) && |
10297 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 10298 | send_current_mbox: |
92d7f7b0 | 10299 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
10300 | do { |
10301 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
10302 | MBX_NOWAIT); | |
10303 | } while (rc == MBX_NOT_FINISHED); | |
10304 | if (rc != MBX_SUCCESS) | |
10305 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
10306 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 10307 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
10308 | } |
10309 | ||
5b75da2f | 10310 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 10311 | phba->work_ha |= work_ha_copy; |
5b75da2f | 10312 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 10313 | lpfc_worker_wake_up(phba); |
dea3101e | 10314 | } |
9399627f | 10315 | return IRQ_HANDLED; |
9940b97b JS |
10316 | unplug_error: |
10317 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10318 | return IRQ_HANDLED; | |
dea3101e | 10319 | |
3772a991 | 10320 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
10321 | |
10322 | /** | |
3772a991 | 10323 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
10324 | * @irq: Interrupt number. |
10325 | * @dev_id: The device context pointer. | |
10326 | * | |
10327 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
10328 | * service routine when device with SLI-3 interface spec is enabled with |
10329 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10330 | * ring event in the HBA. However, when the device is enabled with either | |
10331 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10332 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10333 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10334 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
10335 | * the intrrupt context. This function is called without any lock held. | |
10336 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
10337 | * |
10338 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10339 | * returns IRQ_NONE. | |
10340 | **/ | |
10341 | irqreturn_t | |
3772a991 | 10342 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
10343 | { |
10344 | struct lpfc_hba *phba; | |
10345 | uint32_t ha_copy; | |
10346 | unsigned long status; | |
5b75da2f | 10347 | unsigned long iflag; |
9399627f JS |
10348 | |
10349 | /* Get the driver's phba structure from the dev_id and | |
10350 | * assume the HBA is not interrupting. | |
10351 | */ | |
10352 | phba = (struct lpfc_hba *) dev_id; | |
10353 | ||
10354 | if (unlikely(!phba)) | |
10355 | return IRQ_NONE; | |
10356 | ||
10357 | /* | |
10358 | * Stuff needs to be attented to when this function is invoked as an | |
10359 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
10360 | */ | |
10361 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
10362 | /* Check device state for handling interrupt */ |
10363 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10364 | return IRQ_NONE; |
10365 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
10366 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
10367 | return IRQ_HANDLED; | |
9399627f | 10368 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 10369 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
10370 | /* |
10371 | * If there is deferred error attention, do not check for | |
10372 | * any interrupt. | |
10373 | */ | |
10374 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 10375 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
10376 | return IRQ_NONE; |
10377 | } | |
9399627f JS |
10378 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
10379 | phba->HAregaddr); | |
10380 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 10381 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
10382 | } else |
10383 | ha_copy = phba->ha_copy; | |
dea3101e | 10384 | |
10385 | /* | |
9399627f | 10386 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 10387 | */ |
9399627f JS |
10388 | ha_copy &= ~(phba->work_ha_mask); |
10389 | ||
10390 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 10391 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 10392 | if (status & HA_RXMASK) |
dea3101e | 10393 | lpfc_sli_handle_fast_ring_event(phba, |
10394 | &phba->sli.ring[LPFC_FCP_RING], | |
10395 | status); | |
a4bc3379 JS |
10396 | |
10397 | if (phba->cfg_multi_ring_support == 2) { | |
10398 | /* | |
9399627f JS |
10399 | * Process all events on extra ring. Take the optimized path |
10400 | * for extra ring IO. | |
a4bc3379 | 10401 | */ |
9399627f | 10402 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 10403 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 10404 | if (status & HA_RXMASK) { |
a4bc3379 JS |
10405 | lpfc_sli_handle_fast_ring_event(phba, |
10406 | &phba->sli.ring[LPFC_EXTRA_RING], | |
10407 | status); | |
10408 | } | |
10409 | } | |
dea3101e | 10410 | return IRQ_HANDLED; |
3772a991 | 10411 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
10412 | |
10413 | /** | |
3772a991 | 10414 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
10415 | * @irq: Interrupt number. |
10416 | * @dev_id: The device context pointer. | |
10417 | * | |
3772a991 JS |
10418 | * This function is the HBA device-level interrupt handler to device with |
10419 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
10420 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
10421 | * requires driver attention. This function invokes the slow-path interrupt | |
10422 | * attention handling function and fast-path interrupt attention handling | |
10423 | * function in turn to process the relevant HBA attention events. This | |
10424 | * function is called without any lock held. It gets the hbalock to access | |
10425 | * and update SLI data structures. | |
9399627f JS |
10426 | * |
10427 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
10428 | * returns IRQ_NONE. | |
10429 | **/ | |
10430 | irqreturn_t | |
3772a991 | 10431 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
10432 | { |
10433 | struct lpfc_hba *phba; | |
10434 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
10435 | unsigned long status1, status2; | |
a747c9ce | 10436 | uint32_t hc_copy; |
9399627f JS |
10437 | |
10438 | /* | |
10439 | * Get the driver's phba structure from the dev_id and | |
10440 | * assume the HBA is not interrupting. | |
10441 | */ | |
10442 | phba = (struct lpfc_hba *) dev_id; | |
10443 | ||
10444 | if (unlikely(!phba)) | |
10445 | return IRQ_NONE; | |
10446 | ||
3772a991 JS |
10447 | /* Check device state for handling interrupt */ |
10448 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
10449 | return IRQ_NONE; |
10450 | ||
10451 | spin_lock(&phba->hbalock); | |
9940b97b JS |
10452 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
10453 | spin_unlock(&phba->hbalock); | |
10454 | return IRQ_HANDLED; | |
10455 | } | |
10456 | ||
9399627f JS |
10457 | if (unlikely(!phba->ha_copy)) { |
10458 | spin_unlock(&phba->hbalock); | |
10459 | return IRQ_NONE; | |
10460 | } else if (phba->ha_copy & HA_ERATT) { | |
10461 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
10462 | /* ERATT polling has handled ERATT */ | |
10463 | phba->ha_copy &= ~HA_ERATT; | |
10464 | else | |
10465 | /* Indicate interrupt handler handles ERATT */ | |
10466 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
10467 | } | |
10468 | ||
a257bf90 JS |
10469 | /* |
10470 | * If there is deferred error attention, do not check for any interrupt. | |
10471 | */ | |
10472 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 10473 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
10474 | return IRQ_NONE; |
10475 | } | |
10476 | ||
9399627f | 10477 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
10478 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
10479 | spin_unlock(&phba->hbalock); | |
10480 | return IRQ_HANDLED; | |
10481 | } | |
a747c9ce JS |
10482 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
10483 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
10484 | phba->HCregaddr); | |
9399627f | 10485 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 10486 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
10487 | readl(phba->HAregaddr); /* flush */ |
10488 | spin_unlock(&phba->hbalock); | |
10489 | ||
10490 | /* | |
10491 | * Invokes slow-path host attention interrupt handling as appropriate. | |
10492 | */ | |
10493 | ||
10494 | /* status of events with mailbox and link attention */ | |
10495 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
10496 | ||
10497 | /* status of events with ELS ring */ | |
10498 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
10499 | status2 >>= (4*LPFC_ELS_RING); | |
10500 | ||
10501 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 10502 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
10503 | else |
10504 | sp_irq_rc = IRQ_NONE; | |
10505 | ||
10506 | /* | |
10507 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10508 | */ | |
10509 | ||
10510 | /* status of events with FCP ring */ | |
10511 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
10512 | status1 >>= (4*LPFC_FCP_RING); | |
10513 | ||
10514 | /* status of events with extra ring */ | |
10515 | if (phba->cfg_multi_ring_support == 2) { | |
10516 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
10517 | status2 >>= (4*LPFC_EXTRA_RING); | |
10518 | } else | |
10519 | status2 = 0; | |
10520 | ||
10521 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 10522 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
10523 | else |
10524 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 10525 | |
9399627f JS |
10526 | /* Return device-level interrupt handling status */ |
10527 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 10528 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
10529 | |
10530 | /** | |
10531 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
10532 | * @phba: pointer to lpfc hba data structure. | |
10533 | * | |
10534 | * This routine is invoked by the worker thread to process all the pending | |
10535 | * SLI4 FCP abort XRI events. | |
10536 | **/ | |
10537 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
10538 | { | |
10539 | struct lpfc_cq_event *cq_event; | |
10540 | ||
10541 | /* First, declare the fcp xri abort event has been handled */ | |
10542 | spin_lock_irq(&phba->hbalock); | |
10543 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
10544 | spin_unlock_irq(&phba->hbalock); | |
10545 | /* Now, handle all the fcp xri abort events */ | |
10546 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
10547 | /* Get the first event from the head of the event queue */ | |
10548 | spin_lock_irq(&phba->hbalock); | |
10549 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
10550 | cq_event, struct lpfc_cq_event, list); | |
10551 | spin_unlock_irq(&phba->hbalock); | |
10552 | /* Notify aborted XRI for FCP work queue */ | |
10553 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10554 | /* Free the event processed back to the free pool */ | |
10555 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10556 | } | |
10557 | } | |
10558 | ||
10559 | /** | |
10560 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
10561 | * @phba: pointer to lpfc hba data structure. | |
10562 | * | |
10563 | * This routine is invoked by the worker thread to process all the pending | |
10564 | * SLI4 els abort xri events. | |
10565 | **/ | |
10566 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
10567 | { | |
10568 | struct lpfc_cq_event *cq_event; | |
10569 | ||
10570 | /* First, declare the els xri abort event has been handled */ | |
10571 | spin_lock_irq(&phba->hbalock); | |
10572 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
10573 | spin_unlock_irq(&phba->hbalock); | |
10574 | /* Now, handle all the els xri abort events */ | |
10575 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
10576 | /* Get the first event from the head of the event queue */ | |
10577 | spin_lock_irq(&phba->hbalock); | |
10578 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
10579 | cq_event, struct lpfc_cq_event, list); | |
10580 | spin_unlock_irq(&phba->hbalock); | |
10581 | /* Notify aborted XRI for ELS work queue */ | |
10582 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
10583 | /* Free the event processed back to the free pool */ | |
10584 | lpfc_sli4_cq_event_release(phba, cq_event); | |
10585 | } | |
10586 | } | |
10587 | ||
341af102 JS |
10588 | /** |
10589 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
10590 | * @phba: pointer to lpfc hba data structure | |
10591 | * @pIocbIn: pointer to the rspiocbq | |
10592 | * @pIocbOut: pointer to the cmdiocbq | |
10593 | * @wcqe: pointer to the complete wcqe | |
10594 | * | |
10595 | * This routine transfers the fields of a command iocbq to a response iocbq | |
10596 | * by copying all the IOCB fields from command iocbq and transferring the | |
10597 | * completion status information from the complete wcqe. | |
10598 | **/ | |
4f774513 | 10599 | static void |
341af102 JS |
10600 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
10601 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
10602 | struct lpfc_iocbq *pIocbOut, |
10603 | struct lpfc_wcqe_complete *wcqe) | |
10604 | { | |
341af102 | 10605 | unsigned long iflags; |
4f774513 JS |
10606 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
10607 | ||
10608 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
10609 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 JS |
10610 | /* Map WCQE parameters into irspiocb parameters */ |
10611 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | |
10612 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | |
10613 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
10614 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
10615 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
10616 | wcqe->total_data_placed; | |
10617 | else | |
10618 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 10619 | else { |
4f774513 | 10620 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
10621 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
10622 | } | |
341af102 JS |
10623 | |
10624 | /* Pick up HBA exchange busy condition */ | |
10625 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
10626 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10627 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
10628 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10629 | } | |
4f774513 JS |
10630 | } |
10631 | ||
45ed1190 JS |
10632 | /** |
10633 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
10634 | * @phba: Pointer to HBA context object. | |
10635 | * @wcqe: Pointer to work-queue completion queue entry. | |
10636 | * | |
10637 | * This routine handles an ELS work-queue completion event and construct | |
10638 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
10639 | * discovery engine to handle. | |
10640 | * | |
10641 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
10642 | **/ | |
10643 | static struct lpfc_iocbq * | |
10644 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
10645 | struct lpfc_iocbq *irspiocbq) | |
10646 | { | |
10647 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
10648 | struct lpfc_iocbq *cmdiocbq; | |
10649 | struct lpfc_wcqe_complete *wcqe; | |
10650 | unsigned long iflags; | |
10651 | ||
10652 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
10653 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10654 | pring->stats.iocb_event++; | |
10655 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
10656 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
10657 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10658 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10659 | ||
10660 | if (unlikely(!cmdiocbq)) { | |
10661 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10662 | "0386 ELS complete with no corresponding " | |
10663 | "cmdiocb: iotag (%d)\n", | |
10664 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
10665 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
10666 | return NULL; | |
10667 | } | |
10668 | ||
10669 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 10670 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
10671 | |
10672 | return irspiocbq; | |
10673 | } | |
10674 | ||
04c68496 JS |
10675 | /** |
10676 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
10677 | * @phba: Pointer to HBA context object. | |
10678 | * @cqe: Pointer to mailbox completion queue entry. | |
10679 | * | |
10680 | * This routine process a mailbox completion queue entry with asynchrous | |
10681 | * event. | |
10682 | * | |
10683 | * Return: true if work posted to worker thread, otherwise false. | |
10684 | **/ | |
10685 | static bool | |
10686 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
10687 | { | |
10688 | struct lpfc_cq_event *cq_event; | |
10689 | unsigned long iflags; | |
10690 | ||
10691 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
10692 | "0392 Async Event: word0:x%x, word1:x%x, " | |
10693 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
10694 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
10695 | ||
10696 | /* Allocate a new internal CQ_EVENT entry */ | |
10697 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
10698 | if (!cq_event) { | |
10699 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10700 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
10701 | return false; | |
10702 | } | |
10703 | ||
10704 | /* Move the CQE into an asynchronous event entry */ | |
10705 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
10706 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10707 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
10708 | /* Set the async event flag */ | |
10709 | phba->hba_flag |= ASYNC_EVENT; | |
10710 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10711 | ||
10712 | return true; | |
10713 | } | |
10714 | ||
10715 | /** | |
10716 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
10717 | * @phba: Pointer to HBA context object. | |
10718 | * @cqe: Pointer to mailbox completion queue entry. | |
10719 | * | |
10720 | * This routine process a mailbox completion queue entry with mailbox | |
10721 | * completion event. | |
10722 | * | |
10723 | * Return: true if work posted to worker thread, otherwise false. | |
10724 | **/ | |
10725 | static bool | |
10726 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
10727 | { | |
10728 | uint32_t mcqe_status; | |
10729 | MAILBOX_t *mbox, *pmbox; | |
10730 | struct lpfc_mqe *mqe; | |
10731 | struct lpfc_vport *vport; | |
10732 | struct lpfc_nodelist *ndlp; | |
10733 | struct lpfc_dmabuf *mp; | |
10734 | unsigned long iflags; | |
10735 | LPFC_MBOXQ_t *pmb; | |
10736 | bool workposted = false; | |
10737 | int rc; | |
10738 | ||
10739 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
10740 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
10741 | goto out_no_mqe_complete; | |
10742 | ||
10743 | /* Get the reference to the active mbox command */ | |
10744 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10745 | pmb = phba->sli.mbox_active; | |
10746 | if (unlikely(!pmb)) { | |
10747 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
10748 | "1832 No pending MBOX command to handle\n"); | |
10749 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10750 | goto out_no_mqe_complete; | |
10751 | } | |
10752 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10753 | mqe = &pmb->u.mqe; | |
10754 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
10755 | mbox = phba->mbox; | |
10756 | vport = pmb->vport; | |
10757 | ||
10758 | /* Reset heartbeat timer */ | |
10759 | phba->last_completion_time = jiffies; | |
10760 | del_timer(&phba->sli.mbox_tmo); | |
10761 | ||
10762 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
10763 | if (pmb->mbox_cmpl && mbox) | |
10764 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
04c68496 | 10765 | |
73d91e50 JS |
10766 | /* |
10767 | * For mcqe errors, conditionally move a modified error code to | |
10768 | * the mbox so that the error will not be missed. | |
10769 | */ | |
10770 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
10771 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
10772 | if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS) | |
10773 | bf_set(lpfc_mqe_status, mqe, | |
10774 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
10775 | } | |
04c68496 JS |
10776 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { |
10777 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
10778 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
10779 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
10780 | mcqe_status, | |
10781 | pmbox->un.varWords[0], 0); | |
10782 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
10783 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
10784 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
10785 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
10786 | * RID of the PPI using the same mbox buffer. | |
10787 | */ | |
10788 | lpfc_unreg_login(phba, vport->vpi, | |
10789 | pmbox->un.varWords[0], pmb); | |
10790 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
10791 | pmb->context1 = mp; | |
10792 | pmb->context2 = ndlp; | |
10793 | pmb->vport = vport; | |
10794 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
10795 | if (rc != MBX_BUSY) | |
10796 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
10797 | LOG_SLI, "0385 rc should " | |
10798 | "have been MBX_BUSY\n"); | |
10799 | if (rc != MBX_NOT_FINISHED) | |
10800 | goto send_current_mbox; | |
10801 | } | |
10802 | } | |
10803 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
10804 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
10805 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
10806 | ||
10807 | /* There is mailbox completion work to do */ | |
10808 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10809 | __lpfc_mbox_cmpl_put(phba, pmb); | |
10810 | phba->work_ha |= HA_MBATT; | |
10811 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10812 | workposted = true; | |
10813 | ||
10814 | send_current_mbox: | |
10815 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10816 | /* Release the mailbox command posting token */ | |
10817 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
10818 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
10819 | phba->sli.mbox_active = NULL; | |
10820 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10821 | /* Wake up worker thread to post the next pending mailbox command */ | |
10822 | lpfc_worker_wake_up(phba); | |
10823 | out_no_mqe_complete: | |
10824 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
10825 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
10826 | return workposted; | |
10827 | } | |
10828 | ||
10829 | /** | |
10830 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
10831 | * @phba: Pointer to HBA context object. | |
10832 | * @cqe: Pointer to mailbox completion queue entry. | |
10833 | * | |
10834 | * This routine process a mailbox completion queue entry, it invokes the | |
10835 | * proper mailbox complete handling or asynchrous event handling routine | |
10836 | * according to the MCQE's async bit. | |
10837 | * | |
10838 | * Return: true if work posted to worker thread, otherwise false. | |
10839 | **/ | |
10840 | static bool | |
10841 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
10842 | { | |
10843 | struct lpfc_mcqe mcqe; | |
10844 | bool workposted; | |
10845 | ||
10846 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
10847 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
10848 | ||
10849 | /* Invoke the proper event handling routine */ | |
10850 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
10851 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
10852 | else | |
10853 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
10854 | return workposted; | |
10855 | } | |
10856 | ||
4f774513 JS |
10857 | /** |
10858 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
10859 | * @phba: Pointer to HBA context object. | |
10860 | * @wcqe: Pointer to work-queue completion queue entry. | |
10861 | * | |
10862 | * This routine handles an ELS work-queue completion event. | |
10863 | * | |
10864 | * Return: true if work posted to worker thread, otherwise false. | |
10865 | **/ | |
10866 | static bool | |
10867 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | |
10868 | struct lpfc_wcqe_complete *wcqe) | |
10869 | { | |
4f774513 JS |
10870 | struct lpfc_iocbq *irspiocbq; |
10871 | unsigned long iflags; | |
2a9bf3d0 | 10872 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
4f774513 | 10873 | |
45ed1190 | 10874 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
10875 | irspiocbq = lpfc_sli_get_iocbq(phba); |
10876 | if (!irspiocbq) { | |
10877 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
10878 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
10879 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
10880 | pring->txq_cnt, phba->iocb_cnt, | |
10881 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
10882 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 10883 | return false; |
4f774513 | 10884 | } |
4f774513 | 10885 | |
45ed1190 JS |
10886 | /* Save off the slow-path queue event for work thread to process */ |
10887 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 10888 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 10889 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
10890 | &phba->sli4_hba.sp_queue_event); |
10891 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 10892 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 10893 | |
45ed1190 | 10894 | return true; |
4f774513 JS |
10895 | } |
10896 | ||
10897 | /** | |
10898 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
10899 | * @phba: Pointer to HBA context object. | |
10900 | * @wcqe: Pointer to work-queue completion queue entry. | |
10901 | * | |
10902 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
10903 | * proper WQ release routine to the slow-path WQ. | |
10904 | **/ | |
10905 | static void | |
10906 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
10907 | struct lpfc_wcqe_release *wcqe) | |
10908 | { | |
10909 | /* Check for the slow-path ELS work queue */ | |
10910 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
10911 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
10912 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
10913 | else | |
10914 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10915 | "2579 Slow-path wqe consume event carries " | |
10916 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
10917 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
10918 | phba->sli4_hba.els_wq->queue_id); | |
10919 | } | |
10920 | ||
10921 | /** | |
10922 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
10923 | * @phba: Pointer to HBA context object. | |
10924 | * @cq: Pointer to a WQ completion queue. | |
10925 | * @wcqe: Pointer to work-queue completion queue entry. | |
10926 | * | |
10927 | * This routine handles an XRI abort event. | |
10928 | * | |
10929 | * Return: true if work posted to worker thread, otherwise false. | |
10930 | **/ | |
10931 | static bool | |
10932 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
10933 | struct lpfc_queue *cq, | |
10934 | struct sli4_wcqe_xri_aborted *wcqe) | |
10935 | { | |
10936 | bool workposted = false; | |
10937 | struct lpfc_cq_event *cq_event; | |
10938 | unsigned long iflags; | |
10939 | ||
10940 | /* Allocate a new internal CQ_EVENT entry */ | |
10941 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
10942 | if (!cq_event) { | |
10943 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10944 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
10945 | return false; | |
10946 | } | |
10947 | ||
10948 | /* Move the CQE into the proper xri abort event list */ | |
10949 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
10950 | switch (cq->subtype) { | |
10951 | case LPFC_FCP: | |
10952 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10953 | list_add_tail(&cq_event->list, | |
10954 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
10955 | /* Set the fcp xri abort event flag */ | |
10956 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
10957 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10958 | workposted = true; | |
10959 | break; | |
10960 | case LPFC_ELS: | |
10961 | spin_lock_irqsave(&phba->hbalock, iflags); | |
10962 | list_add_tail(&cq_event->list, | |
10963 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
10964 | /* Set the els xri abort event flag */ | |
10965 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
10966 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
10967 | workposted = true; | |
10968 | break; | |
10969 | default: | |
10970 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10971 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
10972 | cq->subtype); | |
10973 | workposted = false; | |
10974 | break; | |
10975 | } | |
10976 | return workposted; | |
10977 | } | |
10978 | ||
4f774513 JS |
10979 | /** |
10980 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
10981 | * @phba: Pointer to HBA context object. | |
10982 | * @rcqe: Pointer to receive-queue completion queue entry. | |
10983 | * | |
10984 | * This routine process a receive-queue completion queue entry. | |
10985 | * | |
10986 | * Return: true if work posted to worker thread, otherwise false. | |
10987 | **/ | |
10988 | static bool | |
4d9ab994 | 10989 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 10990 | { |
4f774513 JS |
10991 | bool workposted = false; |
10992 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
10993 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
10994 | struct hbq_dmabuf *dma_buf; | |
7851fe2c | 10995 | uint32_t status, rq_id; |
4f774513 JS |
10996 | unsigned long iflags; |
10997 | ||
7851fe2c JS |
10998 | if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1) |
10999 | rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe); | |
11000 | else | |
11001 | rq_id = bf_get(lpfc_rcqe_rq_id, rcqe); | |
11002 | if (rq_id != hrq->queue_id) | |
4f774513 JS |
11003 | goto out; |
11004 | ||
4d9ab994 | 11005 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
11006 | switch (status) { |
11007 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
11008 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11009 | "2537 Receive Frame Truncated!!\n"); | |
11010 | case FC_STATUS_RQ_SUCCESS: | |
5ffc266e | 11011 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
11012 | spin_lock_irqsave(&phba->hbalock, iflags); |
11013 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
11014 | if (!dma_buf) { | |
11015 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11016 | goto out; | |
11017 | } | |
4d9ab994 | 11018 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 11019 | /* save off the frame for the word thread to process */ |
4d9ab994 | 11020 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 11021 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 11022 | /* Frame received */ |
45ed1190 | 11023 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
11024 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
11025 | workposted = true; | |
11026 | break; | |
11027 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
11028 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
11029 | /* Post more buffers if possible */ | |
11030 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11031 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
11032 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11033 | workposted = true; | |
11034 | break; | |
11035 | } | |
11036 | out: | |
11037 | return workposted; | |
4f774513 JS |
11038 | } |
11039 | ||
4d9ab994 JS |
11040 | /** |
11041 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
11042 | * @phba: Pointer to HBA context object. | |
11043 | * @cq: Pointer to the completion queue. | |
11044 | * @wcqe: Pointer to a completion queue entry. | |
11045 | * | |
25985edc | 11046 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
11047 | * entry. |
11048 | * | |
11049 | * Return: true if work posted to worker thread, otherwise false. | |
11050 | **/ | |
11051 | static bool | |
11052 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11053 | struct lpfc_cqe *cqe) | |
11054 | { | |
45ed1190 | 11055 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
11056 | bool workposted = false; |
11057 | ||
11058 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 11059 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
11060 | |
11061 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 11062 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 11063 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 11064 | /* Process the WQ/RQ complete event */ |
bc73905a | 11065 | phba->last_completion_time = jiffies; |
4d9ab994 | 11066 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
45ed1190 | 11067 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
11068 | break; |
11069 | case CQE_CODE_RELEASE_WQE: | |
11070 | /* Process the WQ release event */ | |
11071 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 11072 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
11073 | break; |
11074 | case CQE_CODE_XRI_ABORTED: | |
11075 | /* Process the WQ XRI abort event */ | |
bc73905a | 11076 | phba->last_completion_time = jiffies; |
4d9ab994 | 11077 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 11078 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
11079 | break; |
11080 | case CQE_CODE_RECEIVE: | |
7851fe2c | 11081 | case CQE_CODE_RECEIVE_V1: |
4d9ab994 | 11082 | /* Process the RQ event */ |
bc73905a | 11083 | phba->last_completion_time = jiffies; |
4d9ab994 | 11084 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 11085 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
11086 | break; |
11087 | default: | |
11088 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11089 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 11090 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
11091 | break; |
11092 | } | |
11093 | return workposted; | |
11094 | } | |
11095 | ||
4f774513 JS |
11096 | /** |
11097 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
11098 | * @phba: Pointer to HBA context object. | |
11099 | * @eqe: Pointer to fast-path event queue entry. | |
11100 | * | |
11101 | * This routine process a event queue entry from the slow-path event queue. | |
11102 | * It will check the MajorCode and MinorCode to determine this is for a | |
11103 | * completion event on a completion queue, if not, an error shall be logged | |
11104 | * and just return. Otherwise, it will get to the corresponding completion | |
11105 | * queue and process all the entries on that completion queue, rearm the | |
11106 | * completion queue, and then return. | |
11107 | * | |
11108 | **/ | |
11109 | static void | |
11110 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
11111 | { | |
11112 | struct lpfc_queue *cq = NULL, *childq, *speq; | |
11113 | struct lpfc_cqe *cqe; | |
11114 | bool workposted = false; | |
11115 | int ecount = 0; | |
11116 | uint16_t cqid; | |
11117 | ||
cb5172ea | 11118 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
4f774513 JS |
11119 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
11120 | "0359 Not a valid slow-path completion " | |
11121 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
11122 | bf_get_le32(lpfc_eqe_major_code, eqe), |
11123 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
11124 | return; |
11125 | } | |
11126 | ||
11127 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 11128 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
11129 | |
11130 | /* Search for completion queue pointer matching this cqid */ | |
11131 | speq = phba->sli4_hba.sp_eq; | |
11132 | list_for_each_entry(childq, &speq->child_list, list) { | |
11133 | if (childq->queue_id == cqid) { | |
11134 | cq = childq; | |
11135 | break; | |
11136 | } | |
11137 | } | |
11138 | if (unlikely(!cq)) { | |
75baf696 JS |
11139 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
11140 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11141 | "0365 Slow-path CQ identifier " | |
11142 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
11143 | return; |
11144 | } | |
11145 | ||
11146 | /* Process all the entries to the CQ */ | |
11147 | switch (cq->type) { | |
11148 | case LPFC_MCQ: | |
11149 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
11150 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
73d91e50 | 11151 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11152 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11153 | } | |
11154 | break; | |
11155 | case LPFC_WCQ: | |
11156 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
0558056c JS |
11157 | if (cq->subtype == LPFC_FCP) |
11158 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, | |
11159 | cqe); | |
11160 | else | |
11161 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, | |
11162 | cqe); | |
73d91e50 | 11163 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11164 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11165 | } | |
11166 | break; | |
11167 | default: | |
11168 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11169 | "0370 Invalid completion queue type (%d)\n", | |
11170 | cq->type); | |
11171 | return; | |
11172 | } | |
11173 | ||
11174 | /* Catch the no cq entry condition, log an error */ | |
11175 | if (unlikely(ecount == 0)) | |
11176 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11177 | "0371 No entry from the CQ: identifier " | |
11178 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
11179 | ||
11180 | /* In any case, flash and re-arm the RCQ */ | |
11181 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
11182 | ||
11183 | /* wake up worker thread if there are works to be done */ | |
11184 | if (workposted) | |
11185 | lpfc_worker_wake_up(phba); | |
11186 | } | |
11187 | ||
11188 | /** | |
11189 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
11190 | * @eqe: Pointer to fast-path completion queue entry. | |
11191 | * | |
11192 | * This routine process a fast-path work queue completion entry from fast-path | |
11193 | * event queue for FCP command response completion. | |
11194 | **/ | |
11195 | static void | |
11196 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | |
11197 | struct lpfc_wcqe_complete *wcqe) | |
11198 | { | |
11199 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | |
11200 | struct lpfc_iocbq *cmdiocbq; | |
11201 | struct lpfc_iocbq irspiocbq; | |
11202 | unsigned long iflags; | |
11203 | ||
11204 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11205 | pring->stats.iocb_event++; | |
11206 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11207 | ||
11208 | /* Check for response status */ | |
11209 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
11210 | /* If resource errors reported from HBA, reduce queue | |
11211 | * depth of the SCSI device. | |
11212 | */ | |
11213 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
11214 | IOSTAT_LOCAL_REJECT) && | |
11215 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
11216 | phba->lpfc_rampdown_queue_depth(phba); | |
11217 | } | |
11218 | /* Log the error status */ | |
11219 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11220 | "0373 FCP complete error: status=x%x, " | |
11221 | "hw_status=x%x, total_data_specified=%d, " | |
11222 | "parameter=x%x, word3=x%x\n", | |
11223 | bf_get(lpfc_wcqe_c_status, wcqe), | |
11224 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
11225 | wcqe->total_data_placed, wcqe->parameter, | |
11226 | wcqe->word3); | |
11227 | } | |
11228 | ||
11229 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
11230 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11231 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
11232 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11233 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11234 | if (unlikely(!cmdiocbq)) { | |
11235 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11236 | "0374 FCP complete with no corresponding " | |
11237 | "cmdiocb: iotag (%d)\n", | |
11238 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11239 | return; | |
11240 | } | |
11241 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
11242 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11243 | "0375 FCP cmdiocb not callback function " | |
11244 | "iotag: (%d)\n", | |
11245 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
11246 | return; | |
11247 | } | |
11248 | ||
11249 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 11250 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 11251 | |
0f65ff68 JS |
11252 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
11253 | spin_lock_irqsave(&phba->hbalock, iflags); | |
11254 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
11255 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
11256 | } | |
11257 | ||
4f774513 JS |
11258 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
11259 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
11260 | } | |
11261 | ||
11262 | /** | |
11263 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
11264 | * @phba: Pointer to HBA context object. | |
11265 | * @cq: Pointer to completion queue. | |
11266 | * @wcqe: Pointer to work-queue completion queue entry. | |
11267 | * | |
11268 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
11269 | * proper WQ release routine to the slow-path WQ. | |
11270 | **/ | |
11271 | static void | |
11272 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11273 | struct lpfc_wcqe_release *wcqe) | |
11274 | { | |
11275 | struct lpfc_queue *childwq; | |
11276 | bool wqid_matched = false; | |
11277 | uint16_t fcp_wqid; | |
11278 | ||
11279 | /* Check for fast-path FCP work queue release */ | |
11280 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
11281 | list_for_each_entry(childwq, &cq->child_list, list) { | |
11282 | if (childwq->queue_id == fcp_wqid) { | |
11283 | lpfc_sli4_wq_release(childwq, | |
11284 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
11285 | wqid_matched = true; | |
11286 | break; | |
11287 | } | |
11288 | } | |
11289 | /* Report warning log message if no match found */ | |
11290 | if (wqid_matched != true) | |
11291 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11292 | "2580 Fast-path wqe consume event carries " | |
11293 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
11294 | } | |
11295 | ||
11296 | /** | |
11297 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
11298 | * @cq: Pointer to the completion queue. | |
11299 | * @eqe: Pointer to fast-path completion queue entry. | |
11300 | * | |
11301 | * This routine process a fast-path work queue completion entry from fast-path | |
11302 | * event queue for FCP command response completion. | |
11303 | **/ | |
11304 | static int | |
11305 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11306 | struct lpfc_cqe *cqe) | |
11307 | { | |
11308 | struct lpfc_wcqe_release wcqe; | |
11309 | bool workposted = false; | |
11310 | ||
11311 | /* Copy the work queue CQE and convert endian order if needed */ | |
11312 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
11313 | ||
11314 | /* Check and process for different type of WCQE and dispatch */ | |
11315 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
11316 | case CQE_CODE_COMPL_WQE: | |
11317 | /* Process the WQ complete event */ | |
98fc5dd9 | 11318 | phba->last_completion_time = jiffies; |
4f774513 JS |
11319 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
11320 | (struct lpfc_wcqe_complete *)&wcqe); | |
11321 | break; | |
11322 | case CQE_CODE_RELEASE_WQE: | |
11323 | /* Process the WQ release event */ | |
11324 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
11325 | (struct lpfc_wcqe_release *)&wcqe); | |
11326 | break; | |
11327 | case CQE_CODE_XRI_ABORTED: | |
11328 | /* Process the WQ XRI abort event */ | |
bc73905a | 11329 | phba->last_completion_time = jiffies; |
4f774513 JS |
11330 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
11331 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
11332 | break; | |
11333 | default: | |
11334 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11335 | "0144 Not a valid WCQE code: x%x\n", | |
11336 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
11337 | break; | |
11338 | } | |
11339 | return workposted; | |
11340 | } | |
11341 | ||
11342 | /** | |
11343 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | |
11344 | * @phba: Pointer to HBA context object. | |
11345 | * @eqe: Pointer to fast-path event queue entry. | |
11346 | * | |
11347 | * This routine process a event queue entry from the fast-path event queue. | |
11348 | * It will check the MajorCode and MinorCode to determine this is for a | |
11349 | * completion event on a completion queue, if not, an error shall be logged | |
11350 | * and just return. Otherwise, it will get to the corresponding completion | |
11351 | * queue and process all the entries on the completion queue, rearm the | |
11352 | * completion queue, and then return. | |
11353 | **/ | |
11354 | static void | |
11355 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | |
11356 | uint32_t fcp_cqidx) | |
11357 | { | |
11358 | struct lpfc_queue *cq; | |
11359 | struct lpfc_cqe *cqe; | |
11360 | bool workposted = false; | |
11361 | uint16_t cqid; | |
11362 | int ecount = 0; | |
11363 | ||
cb5172ea | 11364 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 JS |
11365 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
11366 | "0366 Not a valid fast-path completion " | |
11367 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
11368 | bf_get_le32(lpfc_eqe_major_code, eqe), |
11369 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
11370 | return; |
11371 | } | |
11372 | ||
11373 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | |
11374 | if (unlikely(!cq)) { | |
75baf696 JS |
11375 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
11376 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11377 | "0367 Fast-path completion queue " | |
11378 | "does not exist\n"); | |
4f774513 JS |
11379 | return; |
11380 | } | |
11381 | ||
11382 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 11383 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
11384 | if (unlikely(cqid != cq->queue_id)) { |
11385 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11386 | "0368 Miss-matched fast-path completion " | |
11387 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
11388 | cqid, cq->queue_id); | |
11389 | return; | |
11390 | } | |
11391 | ||
11392 | /* Process all the entries to the CQ */ | |
11393 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
11394 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
73d91e50 | 11395 | if (!(++ecount % cq->entry_repost)) |
4f774513 JS |
11396 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); |
11397 | } | |
11398 | ||
11399 | /* Catch the no cq entry condition */ | |
11400 | if (unlikely(ecount == 0)) | |
11401 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11402 | "0369 No entry from fast-path completion " | |
11403 | "queue fcpcqid=%d\n", cq->queue_id); | |
11404 | ||
11405 | /* In any case, flash and re-arm the CQ */ | |
11406 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
11407 | ||
11408 | /* wake up worker thread if there are works to be done */ | |
11409 | if (workposted) | |
11410 | lpfc_worker_wake_up(phba); | |
11411 | } | |
11412 | ||
11413 | static void | |
11414 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
11415 | { | |
11416 | struct lpfc_eqe *eqe; | |
11417 | ||
11418 | /* walk all the EQ entries and drop on the floor */ | |
11419 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
11420 | ; | |
11421 | ||
11422 | /* Clear and re-arm the EQ */ | |
11423 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
11424 | } | |
11425 | ||
11426 | /** | |
11427 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | |
11428 | * @irq: Interrupt number. | |
11429 | * @dev_id: The device context pointer. | |
11430 | * | |
11431 | * This function is directly called from the PCI layer as an interrupt | |
11432 | * service routine when device with SLI-4 interface spec is enabled with | |
11433 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
11434 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
11435 | * interrupt mode, this function is called as part of the device-level | |
11436 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | |
11437 | * undergoing initialization, the interrupt handler will not process the | |
11438 | * interrupt. The link attention and ELS ring attention events are handled | |
11439 | * by the worker thread. The interrupt handler signals the worker thread | |
11440 | * and returns for these events. This function is called without any lock | |
11441 | * held. It gets the hbalock to access and update SLI data structures. | |
11442 | * | |
11443 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
11444 | * returns IRQ_NONE. | |
11445 | **/ | |
11446 | irqreturn_t | |
11447 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | |
11448 | { | |
11449 | struct lpfc_hba *phba; | |
11450 | struct lpfc_queue *speq; | |
11451 | struct lpfc_eqe *eqe; | |
11452 | unsigned long iflag; | |
11453 | int ecount = 0; | |
11454 | ||
11455 | /* | |
11456 | * Get the driver's phba structure from the dev_id | |
11457 | */ | |
11458 | phba = (struct lpfc_hba *)dev_id; | |
11459 | ||
11460 | if (unlikely(!phba)) | |
11461 | return IRQ_NONE; | |
11462 | ||
11463 | /* Get to the EQ struct associated with this vector */ | |
11464 | speq = phba->sli4_hba.sp_eq; | |
5350d872 JS |
11465 | if (unlikely(!speq)) |
11466 | return IRQ_NONE; | |
4f774513 JS |
11467 | |
11468 | /* Check device state for handling interrupt */ | |
11469 | if (unlikely(lpfc_intr_state_check(phba))) { | |
11470 | /* Check again for link_state with lock held */ | |
11471 | spin_lock_irqsave(&phba->hbalock, iflag); | |
11472 | if (phba->link_state < LPFC_LINK_DOWN) | |
11473 | /* Flush, clear interrupt, and rearm the EQ */ | |
11474 | lpfc_sli4_eq_flush(phba, speq); | |
11475 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
11476 | return IRQ_NONE; | |
11477 | } | |
11478 | ||
11479 | /* | |
11480 | * Process all the event on FCP slow-path EQ | |
11481 | */ | |
11482 | while ((eqe = lpfc_sli4_eq_get(speq))) { | |
11483 | lpfc_sli4_sp_handle_eqe(phba, eqe); | |
73d91e50 | 11484 | if (!(++ecount % speq->entry_repost)) |
4f774513 JS |
11485 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); |
11486 | } | |
11487 | ||
11488 | /* Always clear and re-arm the slow-path EQ */ | |
11489 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | |
11490 | ||
11491 | /* Catch the no cq entry condition */ | |
11492 | if (unlikely(ecount == 0)) { | |
11493 | if (phba->intr_type == MSIX) | |
11494 | /* MSI-X treated interrupt served as no EQ share INT */ | |
11495 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11496 | "0357 MSI-X interrupt with no EQE\n"); | |
11497 | else | |
11498 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
11499 | return IRQ_NONE; | |
11500 | } | |
11501 | ||
11502 | return IRQ_HANDLED; | |
11503 | } /* lpfc_sli4_sp_intr_handler */ | |
11504 | ||
11505 | /** | |
11506 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | |
11507 | * @irq: Interrupt number. | |
11508 | * @dev_id: The device context pointer. | |
11509 | * | |
11510 | * This function is directly called from the PCI layer as an interrupt | |
11511 | * service routine when device with SLI-4 interface spec is enabled with | |
11512 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
11513 | * ring event in the HBA. However, when the device is enabled with either | |
11514 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
11515 | * device-level interrupt handler. When the PCI slot is in error recovery | |
11516 | * or the HBA is undergoing initialization, the interrupt handler will not | |
11517 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
11518 | * the intrrupt context. This function is called without any lock held. | |
11519 | * It gets the hbalock to access and update SLI data structures. Note that, | |
11520 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
11521 | * equal to that of FCP CQ index. | |
11522 | * | |
11523 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
11524 | * returns IRQ_NONE. | |
11525 | **/ | |
11526 | irqreturn_t | |
11527 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | |
11528 | { | |
11529 | struct lpfc_hba *phba; | |
11530 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
11531 | struct lpfc_queue *fpeq; | |
11532 | struct lpfc_eqe *eqe; | |
11533 | unsigned long iflag; | |
11534 | int ecount = 0; | |
11535 | uint32_t fcp_eqidx; | |
11536 | ||
11537 | /* Get the driver's phba structure from the dev_id */ | |
11538 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
11539 | phba = fcp_eq_hdl->phba; | |
11540 | fcp_eqidx = fcp_eq_hdl->idx; | |
11541 | ||
11542 | if (unlikely(!phba)) | |
11543 | return IRQ_NONE; | |
5350d872 JS |
11544 | if (unlikely(!phba->sli4_hba.fp_eq)) |
11545 | return IRQ_NONE; | |
4f774513 JS |
11546 | |
11547 | /* Get to the EQ struct associated with this vector */ | |
11548 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | |
11549 | ||
11550 | /* Check device state for handling interrupt */ | |
11551 | if (unlikely(lpfc_intr_state_check(phba))) { | |
11552 | /* Check again for link_state with lock held */ | |
11553 | spin_lock_irqsave(&phba->hbalock, iflag); | |
11554 | if (phba->link_state < LPFC_LINK_DOWN) | |
11555 | /* Flush, clear interrupt, and rearm the EQ */ | |
11556 | lpfc_sli4_eq_flush(phba, fpeq); | |
11557 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
11558 | return IRQ_NONE; | |
11559 | } | |
11560 | ||
11561 | /* | |
11562 | * Process all the event on FCP fast-path EQ | |
11563 | */ | |
11564 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
11565 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | |
73d91e50 | 11566 | if (!(++ecount % fpeq->entry_repost)) |
4f774513 JS |
11567 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); |
11568 | } | |
11569 | ||
11570 | /* Always clear and re-arm the fast-path EQ */ | |
11571 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
11572 | ||
11573 | if (unlikely(ecount == 0)) { | |
11574 | if (phba->intr_type == MSIX) | |
11575 | /* MSI-X treated interrupt served as no EQ share INT */ | |
11576 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11577 | "0358 MSI-X interrupt with no EQE\n"); | |
11578 | else | |
11579 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
11580 | return IRQ_NONE; | |
11581 | } | |
11582 | ||
11583 | return IRQ_HANDLED; | |
11584 | } /* lpfc_sli4_fp_intr_handler */ | |
11585 | ||
11586 | /** | |
11587 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
11588 | * @irq: Interrupt number. | |
11589 | * @dev_id: The device context pointer. | |
11590 | * | |
11591 | * This function is the device-level interrupt handler to device with SLI-4 | |
11592 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
11593 | * interrupt mode is enabled and there is an event in the HBA which requires | |
11594 | * driver attention. This function invokes the slow-path interrupt attention | |
11595 | * handling function and fast-path interrupt attention handling function in | |
11596 | * turn to process the relevant HBA attention events. This function is called | |
11597 | * without any lock held. It gets the hbalock to access and update SLI data | |
11598 | * structures. | |
11599 | * | |
11600 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
11601 | * returns IRQ_NONE. | |
11602 | **/ | |
11603 | irqreturn_t | |
11604 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
11605 | { | |
11606 | struct lpfc_hba *phba; | |
11607 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
11608 | bool fp_handled = false; | |
11609 | uint32_t fcp_eqidx; | |
11610 | ||
11611 | /* Get the driver's phba structure from the dev_id */ | |
11612 | phba = (struct lpfc_hba *)dev_id; | |
11613 | ||
11614 | if (unlikely(!phba)) | |
11615 | return IRQ_NONE; | |
11616 | ||
11617 | /* | |
11618 | * Invokes slow-path host attention interrupt handling as appropriate. | |
11619 | */ | |
11620 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | |
11621 | ||
11622 | /* | |
11623 | * Invoke fast-path host attention interrupt handling as appropriate. | |
11624 | */ | |
11625 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
11626 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | |
11627 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | |
11628 | if (fp_irq_rc == IRQ_HANDLED) | |
11629 | fp_handled |= true; | |
11630 | } | |
11631 | ||
11632 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | |
11633 | } /* lpfc_sli4_intr_handler */ | |
11634 | ||
11635 | /** | |
11636 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
11637 | * @queue: The queue structure to free. | |
11638 | * | |
b595076a | 11639 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
11640 | * the host resident queue. This function must be called after destroying the |
11641 | * queue on the HBA. | |
11642 | **/ | |
11643 | void | |
11644 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
11645 | { | |
11646 | struct lpfc_dmabuf *dmabuf; | |
11647 | ||
11648 | if (!queue) | |
11649 | return; | |
11650 | ||
11651 | while (!list_empty(&queue->page_list)) { | |
11652 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
11653 | list); | |
49198b37 | 11654 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
11655 | dmabuf->virt, dmabuf->phys); |
11656 | kfree(dmabuf); | |
11657 | } | |
11658 | kfree(queue); | |
11659 | return; | |
11660 | } | |
11661 | ||
11662 | /** | |
11663 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
11664 | * @phba: The HBA that this queue is being created on. | |
11665 | * @entry_size: The size of each queue entry for this queue. | |
11666 | * @entry count: The number of entries that this queue will handle. | |
11667 | * | |
11668 | * This function allocates a queue structure and the DMAable memory used for | |
11669 | * the host resident queue. This function must be called before creating the | |
11670 | * queue on the HBA. | |
11671 | **/ | |
11672 | struct lpfc_queue * | |
11673 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
11674 | uint32_t entry_count) | |
11675 | { | |
11676 | struct lpfc_queue *queue; | |
11677 | struct lpfc_dmabuf *dmabuf; | |
11678 | int x, total_qe_count; | |
11679 | void *dma_pointer; | |
cb5172ea | 11680 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 11681 | |
cb5172ea JS |
11682 | if (!phba->sli4_hba.pc_sli4_params.supported) |
11683 | hw_page_size = SLI4_PAGE_SIZE; | |
11684 | ||
4f774513 JS |
11685 | queue = kzalloc(sizeof(struct lpfc_queue) + |
11686 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
11687 | if (!queue) | |
11688 | return NULL; | |
cb5172ea JS |
11689 | queue->page_count = (ALIGN(entry_size * entry_count, |
11690 | hw_page_size))/hw_page_size; | |
4f774513 JS |
11691 | INIT_LIST_HEAD(&queue->list); |
11692 | INIT_LIST_HEAD(&queue->page_list); | |
11693 | INIT_LIST_HEAD(&queue->child_list); | |
11694 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
11695 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
11696 | if (!dmabuf) | |
11697 | goto out_fail; | |
11698 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 11699 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
11700 | GFP_KERNEL); |
11701 | if (!dmabuf->virt) { | |
11702 | kfree(dmabuf); | |
11703 | goto out_fail; | |
11704 | } | |
cb5172ea | 11705 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11706 | dmabuf->buffer_tag = x; |
11707 | list_add_tail(&dmabuf->list, &queue->page_list); | |
11708 | /* initialize queue's entry array */ | |
11709 | dma_pointer = dmabuf->virt; | |
11710 | for (; total_qe_count < entry_count && | |
cb5172ea | 11711 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
11712 | total_qe_count++, dma_pointer += entry_size) { |
11713 | queue->qe[total_qe_count].address = dma_pointer; | |
11714 | } | |
11715 | } | |
11716 | queue->entry_size = entry_size; | |
11717 | queue->entry_count = entry_count; | |
73d91e50 JS |
11718 | |
11719 | /* | |
11720 | * entry_repost is calculated based on the number of entries in the | |
11721 | * queue. This works out except for RQs. If buffers are NOT initially | |
11722 | * posted for every RQE, entry_repost should be adjusted accordingly. | |
11723 | */ | |
11724 | queue->entry_repost = (entry_count >> 3); | |
11725 | if (queue->entry_repost < LPFC_QUEUE_MIN_REPOST) | |
11726 | queue->entry_repost = LPFC_QUEUE_MIN_REPOST; | |
4f774513 JS |
11727 | queue->phba = phba; |
11728 | ||
11729 | return queue; | |
11730 | out_fail: | |
11731 | lpfc_sli4_queue_free(queue); | |
11732 | return NULL; | |
11733 | } | |
11734 | ||
11735 | /** | |
11736 | * lpfc_eq_create - Create an Event Queue on the HBA | |
11737 | * @phba: HBA structure that indicates port to create a queue on. | |
11738 | * @eq: The queue structure to use to create the event queue. | |
11739 | * @imax: The maximum interrupt per second limit. | |
11740 | * | |
11741 | * This function creates an event queue, as detailed in @eq, on a port, | |
11742 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
11743 | * | |
11744 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
11745 | * is used to get the entry count and entry size that are necessary to | |
11746 | * determine the number of pages to allocate and use for this queue. This | |
11747 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
11748 | * event queue. This function is asynchronous and will wait for the mailbox | |
11749 | * command to finish before continuing. | |
11750 | * | |
11751 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11752 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11753 | * fails this function will return -ENXIO. | |
4f774513 JS |
11754 | **/ |
11755 | uint32_t | |
11756 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
11757 | { | |
11758 | struct lpfc_mbx_eq_create *eq_create; | |
11759 | LPFC_MBOXQ_t *mbox; | |
11760 | int rc, length, status = 0; | |
11761 | struct lpfc_dmabuf *dmabuf; | |
11762 | uint32_t shdr_status, shdr_add_status; | |
11763 | union lpfc_sli4_cfg_shdr *shdr; | |
11764 | uint16_t dmult; | |
49198b37 JS |
11765 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
11766 | ||
11767 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
11768 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
11769 | |
11770 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11771 | if (!mbox) | |
11772 | return -ENOMEM; | |
11773 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
11774 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11775 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11776 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
11777 | length, LPFC_SLI4_MBX_EMBED); | |
11778 | eq_create = &mbox->u.mqe.un.eq_create; | |
11779 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
11780 | eq->page_count); | |
11781 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
11782 | LPFC_EQE_SIZE); | |
11783 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
11784 | /* Calculate delay multiper from maximum interrupt per second */ | |
11785 | dmult = LPFC_DMULT_CONST/imax - 1; | |
11786 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
11787 | dmult); | |
11788 | switch (eq->entry_count) { | |
11789 | default: | |
11790 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11791 | "0360 Unsupported EQ count. (%d)\n", | |
11792 | eq->entry_count); | |
11793 | if (eq->entry_count < 256) | |
11794 | return -EINVAL; | |
11795 | /* otherwise default to smallest count (drop through) */ | |
11796 | case 256: | |
11797 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11798 | LPFC_EQ_CNT_256); | |
11799 | break; | |
11800 | case 512: | |
11801 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11802 | LPFC_EQ_CNT_512); | |
11803 | break; | |
11804 | case 1024: | |
11805 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11806 | LPFC_EQ_CNT_1024); | |
11807 | break; | |
11808 | case 2048: | |
11809 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11810 | LPFC_EQ_CNT_2048); | |
11811 | break; | |
11812 | case 4096: | |
11813 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
11814 | LPFC_EQ_CNT_4096); | |
11815 | break; | |
11816 | } | |
11817 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 11818 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11819 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
11820 | putPaddrLow(dmabuf->phys); | |
11821 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11822 | putPaddrHigh(dmabuf->phys); | |
11823 | } | |
11824 | mbox->vport = phba->pport; | |
11825 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11826 | mbox->context1 = NULL; | |
11827 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11828 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
11829 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11830 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11831 | if (shdr_status || shdr_add_status || rc) { | |
11832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11833 | "2500 EQ_CREATE mailbox failed with " | |
11834 | "status x%x add_status x%x, mbx status x%x\n", | |
11835 | shdr_status, shdr_add_status, rc); | |
11836 | status = -ENXIO; | |
11837 | } | |
11838 | eq->type = LPFC_EQ; | |
11839 | eq->subtype = LPFC_NONE; | |
11840 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
11841 | if (eq->queue_id == 0xFFFF) | |
11842 | status = -ENXIO; | |
11843 | eq->host_index = 0; | |
11844 | eq->hba_index = 0; | |
11845 | ||
8fa38513 | 11846 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
11847 | return status; |
11848 | } | |
11849 | ||
11850 | /** | |
11851 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
11852 | * @phba: HBA structure that indicates port to create a queue on. | |
11853 | * @cq: The queue structure to use to create the completion queue. | |
11854 | * @eq: The event queue to bind this completion queue to. | |
11855 | * | |
11856 | * This function creates a completion queue, as detailed in @wq, on a port, | |
11857 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
11858 | * | |
11859 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
11860 | * is used to get the entry count and entry size that are necessary to | |
11861 | * determine the number of pages to allocate and use for this queue. The @eq | |
11862 | * is used to indicate which event queue to bind this completion queue to. This | |
11863 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
11864 | * completion queue. This function is asynchronous and will wait for the mailbox | |
11865 | * command to finish before continuing. | |
11866 | * | |
11867 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
11868 | * memory this function will return -ENOMEM. If the queue create mailbox command |
11869 | * fails this function will return -ENXIO. | |
4f774513 JS |
11870 | **/ |
11871 | uint32_t | |
11872 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
11873 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
11874 | { | |
11875 | struct lpfc_mbx_cq_create *cq_create; | |
11876 | struct lpfc_dmabuf *dmabuf; | |
11877 | LPFC_MBOXQ_t *mbox; | |
11878 | int rc, length, status = 0; | |
11879 | uint32_t shdr_status, shdr_add_status; | |
11880 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
11881 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
11882 | ||
11883 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
11884 | hw_page_size = SLI4_PAGE_SIZE; | |
11885 | ||
4f774513 JS |
11886 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
11887 | if (!mbox) | |
11888 | return -ENOMEM; | |
11889 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
11890 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11891 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11892 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
11893 | length, LPFC_SLI4_MBX_EMBED); | |
11894 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 11895 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
11896 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
11897 | cq->page_count); | |
11898 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
11899 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
11900 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
11901 | phba->sli4_hba.pc_sli4_params.cqv); | |
11902 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
11903 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
11904 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
11905 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
11906 | eq->queue_id); | |
11907 | } else { | |
11908 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
11909 | eq->queue_id); | |
11910 | } | |
4f774513 JS |
11911 | switch (cq->entry_count) { |
11912 | default: | |
11913 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11914 | "0361 Unsupported CQ count. (%d)\n", | |
11915 | cq->entry_count); | |
11916 | if (cq->entry_count < 256) | |
11917 | return -EINVAL; | |
11918 | /* otherwise default to smallest count (drop through) */ | |
11919 | case 256: | |
11920 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
11921 | LPFC_CQ_CNT_256); | |
11922 | break; | |
11923 | case 512: | |
11924 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
11925 | LPFC_CQ_CNT_512); | |
11926 | break; | |
11927 | case 1024: | |
11928 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
11929 | LPFC_CQ_CNT_1024); | |
11930 | break; | |
11931 | } | |
11932 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 11933 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11934 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
11935 | putPaddrLow(dmabuf->phys); | |
11936 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11937 | putPaddrHigh(dmabuf->phys); | |
11938 | } | |
11939 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11940 | ||
11941 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
11942 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
11943 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11944 | if (shdr_status || shdr_add_status || rc) { | |
11945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11946 | "2501 CQ_CREATE mailbox failed with " | |
11947 | "status x%x add_status x%x, mbx status x%x\n", | |
11948 | shdr_status, shdr_add_status, rc); | |
11949 | status = -ENXIO; | |
11950 | goto out; | |
11951 | } | |
11952 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
11953 | if (cq->queue_id == 0xFFFF) { | |
11954 | status = -ENXIO; | |
11955 | goto out; | |
11956 | } | |
11957 | /* link the cq onto the parent eq child list */ | |
11958 | list_add_tail(&cq->list, &eq->child_list); | |
11959 | /* Set up completion queue's type and subtype */ | |
11960 | cq->type = type; | |
11961 | cq->subtype = subtype; | |
11962 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 11963 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
11964 | cq->host_index = 0; |
11965 | cq->hba_index = 0; | |
4f774513 | 11966 | |
8fa38513 JS |
11967 | out: |
11968 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
11969 | return status; |
11970 | } | |
11971 | ||
b19a061a JS |
11972 | /** |
11973 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
11974 | * @phba: HBA structure that indicates port to create a queue on. | |
11975 | * @mq: The queue structure to use to create the mailbox queue. | |
11976 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
11977 | * @cq: The completion queue to associate with this cq. | |
11978 | * | |
11979 | * This function provides failback (fb) functionality when the | |
11980 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
11981 | * to mq_create_ext otherwise. | |
11982 | * | |
11983 | * This routine cannot fail as all attributes were previously accessed and | |
11984 | * initialized in mq_create_ext. | |
11985 | **/ | |
11986 | static void | |
11987 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
11988 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
11989 | { | |
11990 | struct lpfc_mbx_mq_create *mq_create; | |
11991 | struct lpfc_dmabuf *dmabuf; | |
11992 | int length; | |
11993 | ||
11994 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
11995 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11996 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11997 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
11998 | length, LPFC_SLI4_MBX_EMBED); | |
11999 | mq_create = &mbox->u.mqe.un.mq_create; | |
12000 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
12001 | mq->page_count); | |
12002 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
12003 | cq->queue_id); | |
12004 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
12005 | switch (mq->entry_count) { | |
12006 | case 16: | |
5a6f133e JS |
12007 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12008 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
12009 | break; |
12010 | case 32: | |
5a6f133e JS |
12011 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12012 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
12013 | break; |
12014 | case 64: | |
5a6f133e JS |
12015 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12016 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
12017 | break; |
12018 | case 128: | |
5a6f133e JS |
12019 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
12020 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
12021 | break; |
12022 | } | |
12023 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
12024 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
12025 | putPaddrLow(dmabuf->phys); | |
12026 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12027 | putPaddrHigh(dmabuf->phys); | |
12028 | } | |
12029 | } | |
12030 | ||
04c68496 JS |
12031 | /** |
12032 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
12033 | * @phba: HBA structure that indicates port to create a queue on. | |
12034 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
12035 | * @cq: The completion queue to associate with this cq. |
12036 | * @subtype: The queue's subtype. | |
04c68496 JS |
12037 | * |
12038 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
12039 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
12040 | * | |
12041 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
12042 | * is used to get the entry count and entry size that are necessary to | |
12043 | * determine the number of pages to allocate and use for this queue. This | |
12044 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
12045 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
12046 | * command to finish before continuing. | |
12047 | * | |
12048 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12049 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12050 | * fails this function will return -ENXIO. | |
04c68496 | 12051 | **/ |
b19a061a | 12052 | int32_t |
04c68496 JS |
12053 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
12054 | struct lpfc_queue *cq, uint32_t subtype) | |
12055 | { | |
12056 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 12057 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
12058 | struct lpfc_dmabuf *dmabuf; |
12059 | LPFC_MBOXQ_t *mbox; | |
12060 | int rc, length, status = 0; | |
12061 | uint32_t shdr_status, shdr_add_status; | |
12062 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 12063 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 12064 | |
49198b37 JS |
12065 | if (!phba->sli4_hba.pc_sli4_params.supported) |
12066 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 12067 | |
04c68496 JS |
12068 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12069 | if (!mbox) | |
12070 | return -ENOMEM; | |
b19a061a | 12071 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
12072 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
12073 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 12074 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 12075 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
12076 | |
12077 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 12078 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
12079 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
12080 | &mq_create_ext->u.request, mq->page_count); | |
12081 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
12082 | &mq_create_ext->u.request, 1); | |
12083 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
12084 | &mq_create_ext->u.request, 1); |
12085 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
12086 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
12087 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
12088 | &mq_create_ext->u.request, 1); | |
12089 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
12090 | &mq_create_ext->u.request, 1); | |
b19a061a | 12091 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
12092 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12093 | phba->sli4_hba.pc_sli4_params.mqv); | |
12094 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
12095 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
12096 | cq->queue_id); | |
12097 | else | |
12098 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
12099 | cq->queue_id); | |
04c68496 JS |
12100 | switch (mq->entry_count) { |
12101 | default: | |
12102 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12103 | "0362 Unsupported MQ count. (%d)\n", | |
12104 | mq->entry_count); | |
12105 | if (mq->entry_count < 16) | |
12106 | return -EINVAL; | |
12107 | /* otherwise default to smallest count (drop through) */ | |
12108 | case 16: | |
5a6f133e JS |
12109 | bf_set(lpfc_mq_context_ring_size, |
12110 | &mq_create_ext->u.request.context, | |
12111 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
12112 | break; |
12113 | case 32: | |
5a6f133e JS |
12114 | bf_set(lpfc_mq_context_ring_size, |
12115 | &mq_create_ext->u.request.context, | |
12116 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
12117 | break; |
12118 | case 64: | |
5a6f133e JS |
12119 | bf_set(lpfc_mq_context_ring_size, |
12120 | &mq_create_ext->u.request.context, | |
12121 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
12122 | break; |
12123 | case 128: | |
5a6f133e JS |
12124 | bf_set(lpfc_mq_context_ring_size, |
12125 | &mq_create_ext->u.request.context, | |
12126 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
12127 | break; |
12128 | } | |
12129 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 12130 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 12131 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 12132 | putPaddrLow(dmabuf->phys); |
b19a061a | 12133 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
12134 | putPaddrHigh(dmabuf->phys); |
12135 | } | |
12136 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
12137 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
12138 | &mq_create_ext->u.response); | |
12139 | if (rc != MBX_SUCCESS) { | |
12140 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12141 | "2795 MQ_CREATE_EXT failed with " | |
12142 | "status x%x. Failback to MQ_CREATE.\n", | |
12143 | rc); | |
12144 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
12145 | mq_create = &mbox->u.mqe.un.mq_create; | |
12146 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12147 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
12148 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
12149 | &mq_create->u.response); | |
12150 | } | |
12151 | ||
04c68496 | 12152 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
12153 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12154 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12155 | if (shdr_status || shdr_add_status || rc) { | |
12156 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12157 | "2502 MQ_CREATE mailbox failed with " | |
12158 | "status x%x add_status x%x, mbx status x%x\n", | |
12159 | shdr_status, shdr_add_status, rc); | |
12160 | status = -ENXIO; | |
12161 | goto out; | |
12162 | } | |
04c68496 JS |
12163 | if (mq->queue_id == 0xFFFF) { |
12164 | status = -ENXIO; | |
12165 | goto out; | |
12166 | } | |
12167 | mq->type = LPFC_MQ; | |
2a622bfb | 12168 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
12169 | mq->subtype = subtype; |
12170 | mq->host_index = 0; | |
12171 | mq->hba_index = 0; | |
12172 | ||
12173 | /* link the mq onto the parent cq child list */ | |
12174 | list_add_tail(&mq->list, &cq->child_list); | |
12175 | out: | |
8fa38513 | 12176 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
12177 | return status; |
12178 | } | |
12179 | ||
4f774513 JS |
12180 | /** |
12181 | * lpfc_wq_create - Create a Work Queue on the HBA | |
12182 | * @phba: HBA structure that indicates port to create a queue on. | |
12183 | * @wq: The queue structure to use to create the work queue. | |
12184 | * @cq: The completion queue to bind this work queue to. | |
12185 | * @subtype: The subtype of the work queue indicating its functionality. | |
12186 | * | |
12187 | * This function creates a work queue, as detailed in @wq, on a port, described | |
12188 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
12189 | * | |
12190 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
12191 | * is used to get the entry count and entry size that are necessary to | |
12192 | * determine the number of pages to allocate and use for this queue. The @cq | |
12193 | * is used to indicate which completion queue to bind this work queue to. This | |
12194 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
12195 | * work queue. This function is asynchronous and will wait for the mailbox | |
12196 | * command to finish before continuing. | |
12197 | * | |
12198 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12199 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12200 | * fails this function will return -ENXIO. | |
4f774513 JS |
12201 | **/ |
12202 | uint32_t | |
12203 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
12204 | struct lpfc_queue *cq, uint32_t subtype) | |
12205 | { | |
12206 | struct lpfc_mbx_wq_create *wq_create; | |
12207 | struct lpfc_dmabuf *dmabuf; | |
12208 | LPFC_MBOXQ_t *mbox; | |
12209 | int rc, length, status = 0; | |
12210 | uint32_t shdr_status, shdr_add_status; | |
12211 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 12212 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 12213 | struct dma_address *page; |
49198b37 JS |
12214 | |
12215 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
12216 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12217 | |
12218 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12219 | if (!mbox) | |
12220 | return -ENOMEM; | |
12221 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
12222 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12223 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12224 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
12225 | length, LPFC_SLI4_MBX_EMBED); | |
12226 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 12227 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
12228 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
12229 | wq->page_count); | |
12230 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
12231 | cq->queue_id); | |
5a6f133e JS |
12232 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12233 | phba->sli4_hba.pc_sli4_params.wqv); | |
12234 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { | |
12235 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, | |
12236 | wq->entry_count); | |
12237 | switch (wq->entry_size) { | |
12238 | default: | |
12239 | case 64: | |
12240 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
12241 | &wq_create->u.request_1, | |
12242 | LPFC_WQ_WQE_SIZE_64); | |
12243 | break; | |
12244 | case 128: | |
12245 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
12246 | &wq_create->u.request_1, | |
12247 | LPFC_WQ_WQE_SIZE_128); | |
12248 | break; | |
12249 | } | |
12250 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
12251 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
12252 | page = wq_create->u.request_1.page; | |
12253 | } else { | |
12254 | page = wq_create->u.request.page; | |
12255 | } | |
4f774513 | 12256 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 12257 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
12258 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
12259 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 JS |
12260 | } |
12261 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12262 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12263 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12264 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12265 | if (shdr_status || shdr_add_status || rc) { | |
12266 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12267 | "2503 WQ_CREATE mailbox failed with " | |
12268 | "status x%x add_status x%x, mbx status x%x\n", | |
12269 | shdr_status, shdr_add_status, rc); | |
12270 | status = -ENXIO; | |
12271 | goto out; | |
12272 | } | |
12273 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
12274 | if (wq->queue_id == 0xFFFF) { | |
12275 | status = -ENXIO; | |
12276 | goto out; | |
12277 | } | |
12278 | wq->type = LPFC_WQ; | |
2a622bfb | 12279 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
12280 | wq->subtype = subtype; |
12281 | wq->host_index = 0; | |
12282 | wq->hba_index = 0; | |
ff78d8f9 | 12283 | wq->entry_repost = LPFC_RELEASE_NOTIFICATION_INTERVAL; |
4f774513 JS |
12284 | |
12285 | /* link the wq onto the parent cq child list */ | |
12286 | list_add_tail(&wq->list, &cq->child_list); | |
12287 | out: | |
8fa38513 | 12288 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12289 | return status; |
12290 | } | |
12291 | ||
73d91e50 JS |
12292 | /** |
12293 | * lpfc_rq_adjust_repost - Adjust entry_repost for an RQ | |
12294 | * @phba: HBA structure that indicates port to create a queue on. | |
12295 | * @rq: The queue structure to use for the receive queue. | |
12296 | * @qno: The associated HBQ number | |
12297 | * | |
12298 | * | |
12299 | * For SLI4 we need to adjust the RQ repost value based on | |
12300 | * the number of buffers that are initially posted to the RQ. | |
12301 | */ | |
12302 | void | |
12303 | lpfc_rq_adjust_repost(struct lpfc_hba *phba, struct lpfc_queue *rq, int qno) | |
12304 | { | |
12305 | uint32_t cnt; | |
12306 | ||
12307 | cnt = lpfc_hbq_defs[qno]->entry_count; | |
12308 | ||
12309 | /* Recalc repost for RQs based on buffers initially posted */ | |
12310 | cnt = (cnt >> 3); | |
12311 | if (cnt < LPFC_QUEUE_MIN_REPOST) | |
12312 | cnt = LPFC_QUEUE_MIN_REPOST; | |
12313 | ||
12314 | rq->entry_repost = cnt; | |
12315 | } | |
12316 | ||
4f774513 JS |
12317 | /** |
12318 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
12319 | * @phba: HBA structure that indicates port to create a queue on. | |
12320 | * @hrq: The queue structure to use to create the header receive queue. | |
12321 | * @drq: The queue structure to use to create the data receive queue. | |
12322 | * @cq: The completion queue to bind this work queue to. | |
12323 | * | |
12324 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
12325 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
12326 | * to the HBA. | |
12327 | * | |
12328 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
12329 | * struct is used to get the entry count that is necessary to determine the | |
12330 | * number of pages to use for this queue. The @cq is used to indicate which | |
12331 | * completion queue to bind received buffers that are posted to these queues to. | |
12332 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
12333 | * receive queue pair. This function is asynchronous and will wait for the | |
12334 | * mailbox command to finish before continuing. | |
12335 | * | |
12336 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
12337 | * memory this function will return -ENOMEM. If the queue create mailbox command |
12338 | * fails this function will return -ENXIO. | |
4f774513 JS |
12339 | **/ |
12340 | uint32_t | |
12341 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
12342 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
12343 | { | |
12344 | struct lpfc_mbx_rq_create *rq_create; | |
12345 | struct lpfc_dmabuf *dmabuf; | |
12346 | LPFC_MBOXQ_t *mbox; | |
12347 | int rc, length, status = 0; | |
12348 | uint32_t shdr_status, shdr_add_status; | |
12349 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
12350 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
12351 | ||
12352 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
12353 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
12354 | |
12355 | if (hrq->entry_count != drq->entry_count) | |
12356 | return -EINVAL; | |
12357 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12358 | if (!mbox) | |
12359 | return -ENOMEM; | |
12360 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
12361 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12362 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12363 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
12364 | length, LPFC_SLI4_MBX_EMBED); | |
12365 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
12366 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
12367 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
12368 | phba->sli4_hba.pc_sli4_params.rqv); | |
12369 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
12370 | bf_set(lpfc_rq_context_rqe_count_1, | |
12371 | &rq_create->u.request.context, | |
12372 | hrq->entry_count); | |
12373 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
12374 | bf_set(lpfc_rq_context_rqe_size, |
12375 | &rq_create->u.request.context, | |
12376 | LPFC_RQE_SIZE_8); | |
12377 | bf_set(lpfc_rq_context_page_size, | |
12378 | &rq_create->u.request.context, | |
12379 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
12380 | } else { |
12381 | switch (hrq->entry_count) { | |
12382 | default: | |
12383 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12384 | "2535 Unsupported RQ count. (%d)\n", | |
12385 | hrq->entry_count); | |
12386 | if (hrq->entry_count < 512) | |
12387 | return -EINVAL; | |
12388 | /* otherwise default to smallest count (drop through) */ | |
12389 | case 512: | |
12390 | bf_set(lpfc_rq_context_rqe_count, | |
12391 | &rq_create->u.request.context, | |
12392 | LPFC_RQ_RING_SIZE_512); | |
12393 | break; | |
12394 | case 1024: | |
12395 | bf_set(lpfc_rq_context_rqe_count, | |
12396 | &rq_create->u.request.context, | |
12397 | LPFC_RQ_RING_SIZE_1024); | |
12398 | break; | |
12399 | case 2048: | |
12400 | bf_set(lpfc_rq_context_rqe_count, | |
12401 | &rq_create->u.request.context, | |
12402 | LPFC_RQ_RING_SIZE_2048); | |
12403 | break; | |
12404 | case 4096: | |
12405 | bf_set(lpfc_rq_context_rqe_count, | |
12406 | &rq_create->u.request.context, | |
12407 | LPFC_RQ_RING_SIZE_4096); | |
12408 | break; | |
12409 | } | |
12410 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
12411 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
12412 | } |
12413 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
12414 | cq->queue_id); | |
12415 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
12416 | hrq->page_count); | |
4f774513 | 12417 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 12418 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
12419 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
12420 | putPaddrLow(dmabuf->phys); | |
12421 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12422 | putPaddrHigh(dmabuf->phys); | |
12423 | } | |
12424 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12425 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
12426 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
12427 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12428 | if (shdr_status || shdr_add_status || rc) { | |
12429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12430 | "2504 RQ_CREATE mailbox failed with " | |
12431 | "status x%x add_status x%x, mbx status x%x\n", | |
12432 | shdr_status, shdr_add_status, rc); | |
12433 | status = -ENXIO; | |
12434 | goto out; | |
12435 | } | |
12436 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
12437 | if (hrq->queue_id == 0xFFFF) { | |
12438 | status = -ENXIO; | |
12439 | goto out; | |
12440 | } | |
12441 | hrq->type = LPFC_HRQ; | |
2a622bfb | 12442 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
12443 | hrq->subtype = subtype; |
12444 | hrq->host_index = 0; | |
12445 | hrq->hba_index = 0; | |
12446 | ||
12447 | /* now create the data queue */ | |
12448 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12449 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
12450 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
12451 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
12452 | phba->sli4_hba.pc_sli4_params.rqv); | |
12453 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
12454 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 12455 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 12456 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
12457 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
12458 | LPFC_RQE_SIZE_8); | |
12459 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
12460 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
12461 | } else { |
12462 | switch (drq->entry_count) { | |
12463 | default: | |
12464 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12465 | "2536 Unsupported RQ count. (%d)\n", | |
12466 | drq->entry_count); | |
12467 | if (drq->entry_count < 512) | |
12468 | return -EINVAL; | |
12469 | /* otherwise default to smallest count (drop through) */ | |
12470 | case 512: | |
12471 | bf_set(lpfc_rq_context_rqe_count, | |
12472 | &rq_create->u.request.context, | |
12473 | LPFC_RQ_RING_SIZE_512); | |
12474 | break; | |
12475 | case 1024: | |
12476 | bf_set(lpfc_rq_context_rqe_count, | |
12477 | &rq_create->u.request.context, | |
12478 | LPFC_RQ_RING_SIZE_1024); | |
12479 | break; | |
12480 | case 2048: | |
12481 | bf_set(lpfc_rq_context_rqe_count, | |
12482 | &rq_create->u.request.context, | |
12483 | LPFC_RQ_RING_SIZE_2048); | |
12484 | break; | |
12485 | case 4096: | |
12486 | bf_set(lpfc_rq_context_rqe_count, | |
12487 | &rq_create->u.request.context, | |
12488 | LPFC_RQ_RING_SIZE_4096); | |
12489 | break; | |
12490 | } | |
12491 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
12492 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
12493 | } |
12494 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
12495 | cq->queue_id); | |
12496 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
12497 | drq->page_count); | |
4f774513 JS |
12498 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
12499 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
12500 | putPaddrLow(dmabuf->phys); | |
12501 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
12502 | putPaddrHigh(dmabuf->phys); | |
12503 | } | |
12504 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
12505 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12506 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
12507 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12508 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12509 | if (shdr_status || shdr_add_status || rc) { | |
12510 | status = -ENXIO; | |
12511 | goto out; | |
12512 | } | |
12513 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
12514 | if (drq->queue_id == 0xFFFF) { | |
12515 | status = -ENXIO; | |
12516 | goto out; | |
12517 | } | |
12518 | drq->type = LPFC_DRQ; | |
2a622bfb | 12519 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
12520 | drq->subtype = subtype; |
12521 | drq->host_index = 0; | |
12522 | drq->hba_index = 0; | |
12523 | ||
12524 | /* link the header and data RQs onto the parent cq child list */ | |
12525 | list_add_tail(&hrq->list, &cq->child_list); | |
12526 | list_add_tail(&drq->list, &cq->child_list); | |
12527 | ||
12528 | out: | |
8fa38513 | 12529 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
12530 | return status; |
12531 | } | |
12532 | ||
12533 | /** | |
12534 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
12535 | * @eq: The queue structure associated with the queue to destroy. | |
12536 | * | |
12537 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
12538 | * command, specific to the type of queue, to the HBA. | |
12539 | * | |
12540 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
12541 | * | |
12542 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12543 | * command fails this function will return -ENXIO. |
4f774513 JS |
12544 | **/ |
12545 | uint32_t | |
12546 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
12547 | { | |
12548 | LPFC_MBOXQ_t *mbox; | |
12549 | int rc, length, status = 0; | |
12550 | uint32_t shdr_status, shdr_add_status; | |
12551 | union lpfc_sli4_cfg_shdr *shdr; | |
12552 | ||
12553 | if (!eq) | |
12554 | return -ENODEV; | |
12555 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
12556 | if (!mbox) | |
12557 | return -ENOMEM; | |
12558 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
12559 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12560 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12561 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
12562 | length, LPFC_SLI4_MBX_EMBED); | |
12563 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
12564 | eq->queue_id); | |
12565 | mbox->vport = eq->phba->pport; | |
12566 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12567 | ||
12568 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
12569 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12570 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12571 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
12572 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12573 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12574 | if (shdr_status || shdr_add_status || rc) { | |
12575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12576 | "2505 EQ_DESTROY mailbox failed with " | |
12577 | "status x%x add_status x%x, mbx status x%x\n", | |
12578 | shdr_status, shdr_add_status, rc); | |
12579 | status = -ENXIO; | |
12580 | } | |
12581 | ||
12582 | /* Remove eq from any list */ | |
12583 | list_del_init(&eq->list); | |
8fa38513 | 12584 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
12585 | return status; |
12586 | } | |
12587 | ||
12588 | /** | |
12589 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
12590 | * @cq: The queue structure associated with the queue to destroy. | |
12591 | * | |
12592 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
12593 | * command, specific to the type of queue, to the HBA. | |
12594 | * | |
12595 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
12596 | * | |
12597 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12598 | * command fails this function will return -ENXIO. |
4f774513 JS |
12599 | **/ |
12600 | uint32_t | |
12601 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
12602 | { | |
12603 | LPFC_MBOXQ_t *mbox; | |
12604 | int rc, length, status = 0; | |
12605 | uint32_t shdr_status, shdr_add_status; | |
12606 | union lpfc_sli4_cfg_shdr *shdr; | |
12607 | ||
12608 | if (!cq) | |
12609 | return -ENODEV; | |
12610 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
12611 | if (!mbox) | |
12612 | return -ENOMEM; | |
12613 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
12614 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12615 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12616 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
12617 | length, LPFC_SLI4_MBX_EMBED); | |
12618 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
12619 | cq->queue_id); | |
12620 | mbox->vport = cq->phba->pport; | |
12621 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12622 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
12623 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12624 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12625 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
12626 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12627 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12628 | if (shdr_status || shdr_add_status || rc) { | |
12629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12630 | "2506 CQ_DESTROY mailbox failed with " | |
12631 | "status x%x add_status x%x, mbx status x%x\n", | |
12632 | shdr_status, shdr_add_status, rc); | |
12633 | status = -ENXIO; | |
12634 | } | |
12635 | /* Remove cq from any list */ | |
12636 | list_del_init(&cq->list); | |
8fa38513 | 12637 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
12638 | return status; |
12639 | } | |
12640 | ||
04c68496 JS |
12641 | /** |
12642 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
12643 | * @qm: The queue structure associated with the queue to destroy. | |
12644 | * | |
12645 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
12646 | * command, specific to the type of queue, to the HBA. | |
12647 | * | |
12648 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
12649 | * | |
12650 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12651 | * command fails this function will return -ENXIO. |
04c68496 JS |
12652 | **/ |
12653 | uint32_t | |
12654 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
12655 | { | |
12656 | LPFC_MBOXQ_t *mbox; | |
12657 | int rc, length, status = 0; | |
12658 | uint32_t shdr_status, shdr_add_status; | |
12659 | union lpfc_sli4_cfg_shdr *shdr; | |
12660 | ||
12661 | if (!mq) | |
12662 | return -ENODEV; | |
12663 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
12664 | if (!mbox) | |
12665 | return -ENOMEM; | |
12666 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
12667 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12668 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
12669 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
12670 | length, LPFC_SLI4_MBX_EMBED); | |
12671 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
12672 | mq->queue_id); | |
12673 | mbox->vport = mq->phba->pport; | |
12674 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12675 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
12676 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12677 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12678 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
12679 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12680 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12681 | if (shdr_status || shdr_add_status || rc) { | |
12682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12683 | "2507 MQ_DESTROY mailbox failed with " | |
12684 | "status x%x add_status x%x, mbx status x%x\n", | |
12685 | shdr_status, shdr_add_status, rc); | |
12686 | status = -ENXIO; | |
12687 | } | |
12688 | /* Remove mq from any list */ | |
12689 | list_del_init(&mq->list); | |
8fa38513 | 12690 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
12691 | return status; |
12692 | } | |
12693 | ||
4f774513 JS |
12694 | /** |
12695 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
12696 | * @wq: The queue structure associated with the queue to destroy. | |
12697 | * | |
12698 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
12699 | * command, specific to the type of queue, to the HBA. | |
12700 | * | |
12701 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
12702 | * | |
12703 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12704 | * command fails this function will return -ENXIO. |
4f774513 JS |
12705 | **/ |
12706 | uint32_t | |
12707 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
12708 | { | |
12709 | LPFC_MBOXQ_t *mbox; | |
12710 | int rc, length, status = 0; | |
12711 | uint32_t shdr_status, shdr_add_status; | |
12712 | union lpfc_sli4_cfg_shdr *shdr; | |
12713 | ||
12714 | if (!wq) | |
12715 | return -ENODEV; | |
12716 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
12717 | if (!mbox) | |
12718 | return -ENOMEM; | |
12719 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
12720 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12721 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12722 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
12723 | length, LPFC_SLI4_MBX_EMBED); | |
12724 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
12725 | wq->queue_id); | |
12726 | mbox->vport = wq->phba->pport; | |
12727 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12728 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
12729 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12730 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
12731 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12732 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12733 | if (shdr_status || shdr_add_status || rc) { | |
12734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12735 | "2508 WQ_DESTROY mailbox failed with " | |
12736 | "status x%x add_status x%x, mbx status x%x\n", | |
12737 | shdr_status, shdr_add_status, rc); | |
12738 | status = -ENXIO; | |
12739 | } | |
12740 | /* Remove wq from any list */ | |
12741 | list_del_init(&wq->list); | |
8fa38513 | 12742 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
12743 | return status; |
12744 | } | |
12745 | ||
12746 | /** | |
12747 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
12748 | * @rq: The queue structure associated with the queue to destroy. | |
12749 | * | |
12750 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
12751 | * command, specific to the type of queue, to the HBA. | |
12752 | * | |
12753 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
12754 | * | |
12755 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 12756 | * command fails this function will return -ENXIO. |
4f774513 JS |
12757 | **/ |
12758 | uint32_t | |
12759 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
12760 | struct lpfc_queue *drq) | |
12761 | { | |
12762 | LPFC_MBOXQ_t *mbox; | |
12763 | int rc, length, status = 0; | |
12764 | uint32_t shdr_status, shdr_add_status; | |
12765 | union lpfc_sli4_cfg_shdr *shdr; | |
12766 | ||
12767 | if (!hrq || !drq) | |
12768 | return -ENODEV; | |
12769 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
12770 | if (!mbox) | |
12771 | return -ENOMEM; | |
12772 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 12773 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
12774 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
12775 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
12776 | length, LPFC_SLI4_MBX_EMBED); | |
12777 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
12778 | hrq->queue_id); | |
12779 | mbox->vport = hrq->phba->pport; | |
12780 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
12781 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
12782 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12783 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12784 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
12785 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12786 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12787 | if (shdr_status || shdr_add_status || rc) { | |
12788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12789 | "2509 RQ_DESTROY mailbox failed with " | |
12790 | "status x%x add_status x%x, mbx status x%x\n", | |
12791 | shdr_status, shdr_add_status, rc); | |
12792 | if (rc != MBX_TIMEOUT) | |
12793 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
12794 | return -ENXIO; | |
12795 | } | |
12796 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
12797 | drq->queue_id); | |
12798 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
12799 | shdr = (union lpfc_sli4_cfg_shdr *) | |
12800 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
12801 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12802 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12803 | if (shdr_status || shdr_add_status || rc) { | |
12804 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12805 | "2510 RQ_DESTROY mailbox failed with " | |
12806 | "status x%x add_status x%x, mbx status x%x\n", | |
12807 | shdr_status, shdr_add_status, rc); | |
12808 | status = -ENXIO; | |
12809 | } | |
12810 | list_del_init(&hrq->list); | |
12811 | list_del_init(&drq->list); | |
8fa38513 | 12812 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
12813 | return status; |
12814 | } | |
12815 | ||
12816 | /** | |
12817 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
12818 | * @phba: The virtual port for which this call being executed. | |
12819 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
12820 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
12821 | * @xritag: the xritag that ties this io to the SGL pages. | |
12822 | * | |
12823 | * This routine will post the sgl pages for the IO that has the xritag | |
12824 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
12825 | * creation and persists for as long as the driver is loaded. | |
12826 | * if the caller has fewer than 256 scatter gather segments to map then | |
12827 | * pdma_phys_addr1 should be 0. | |
12828 | * If the caller needs to map more than 256 scatter gather segment then | |
12829 | * pdma_phys_addr1 should be a valid physical address. | |
12830 | * physical address for SGLs must be 64 byte aligned. | |
12831 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
12832 | * the second sgl can have between 1 and 256 entries. | |
12833 | * | |
12834 | * Return codes: | |
12835 | * 0 - Success | |
12836 | * -ENXIO, -ENOMEM - Failure | |
12837 | **/ | |
12838 | int | |
12839 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
12840 | dma_addr_t pdma_phys_addr0, | |
12841 | dma_addr_t pdma_phys_addr1, | |
12842 | uint16_t xritag) | |
12843 | { | |
12844 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
12845 | LPFC_MBOXQ_t *mbox; | |
12846 | int rc; | |
12847 | uint32_t shdr_status, shdr_add_status; | |
6d368e53 | 12848 | uint32_t mbox_tmo; |
4f774513 JS |
12849 | union lpfc_sli4_cfg_shdr *shdr; |
12850 | ||
12851 | if (xritag == NO_XRI) { | |
12852 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12853 | "0364 Invalid param:\n"); | |
12854 | return -EINVAL; | |
12855 | } | |
12856 | ||
12857 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12858 | if (!mbox) | |
12859 | return -ENOMEM; | |
12860 | ||
12861 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12862 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
12863 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 12864 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
12865 | |
12866 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
12867 | &mbox->u.mqe.un.post_sgl_pages; | |
12868 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
12869 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
12870 | ||
12871 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
12872 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
12873 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
12874 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
12875 | ||
12876 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
12877 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
12878 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
12879 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
12880 | if (!phba->sli4_hba.intr_enable) | |
12881 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6d368e53 | 12882 | else { |
a183a15f | 12883 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
12884 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
12885 | } | |
4f774513 JS |
12886 | /* The IOCTL status is embedded in the mailbox subheader. */ |
12887 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
12888 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12889 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12890 | if (rc != MBX_TIMEOUT) | |
12891 | mempool_free(mbox, phba->mbox_mem_pool); | |
12892 | if (shdr_status || shdr_add_status || rc) { | |
12893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12894 | "2511 POST_SGL mailbox failed with " | |
12895 | "status x%x add_status x%x, mbx status x%x\n", | |
12896 | shdr_status, shdr_add_status, rc); | |
12897 | rc = -ENXIO; | |
12898 | } | |
12899 | return 0; | |
12900 | } | |
4f774513 | 12901 | |
6d368e53 | 12902 | /** |
88a2cfbb | 12903 | * lpfc_sli4_alloc_xri - Get an available rpi in the device's range |
6d368e53 JS |
12904 | * @phba: pointer to lpfc hba data structure. |
12905 | * | |
12906 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb JS |
12907 | * HBA consistent with the SLI-4 interface spec. This routine |
12908 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to | |
12909 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6d368e53 | 12910 | * |
88a2cfbb JS |
12911 | * Returns |
12912 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful | |
12913 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | |
12914 | **/ | |
6d368e53 JS |
12915 | uint16_t |
12916 | lpfc_sli4_alloc_xri(struct lpfc_hba *phba) | |
12917 | { | |
12918 | unsigned long xri; | |
12919 | ||
12920 | /* | |
12921 | * Fetch the next logical xri. Because this index is logical, | |
12922 | * the driver starts at 0 each time. | |
12923 | */ | |
12924 | spin_lock_irq(&phba->hbalock); | |
12925 | xri = find_next_zero_bit(phba->sli4_hba.xri_bmask, | |
12926 | phba->sli4_hba.max_cfg_param.max_xri, 0); | |
12927 | if (xri >= phba->sli4_hba.max_cfg_param.max_xri) { | |
12928 | spin_unlock_irq(&phba->hbalock); | |
12929 | return NO_XRI; | |
12930 | } else { | |
12931 | set_bit(xri, phba->sli4_hba.xri_bmask); | |
12932 | phba->sli4_hba.max_cfg_param.xri_used++; | |
12933 | phba->sli4_hba.xri_count++; | |
12934 | } | |
12935 | ||
12936 | spin_unlock_irq(&phba->hbalock); | |
12937 | return xri; | |
12938 | } | |
12939 | ||
12940 | /** | |
12941 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
12942 | * @phba: pointer to lpfc hba data structure. | |
12943 | * | |
12944 | * This routine is invoked to release an xri to the pool of | |
12945 | * available rpis maintained by the driver. | |
12946 | **/ | |
12947 | void | |
12948 | __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
12949 | { | |
12950 | if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) { | |
12951 | phba->sli4_hba.xri_count--; | |
12952 | phba->sli4_hba.max_cfg_param.xri_used--; | |
12953 | } | |
12954 | } | |
12955 | ||
12956 | /** | |
12957 | * lpfc_sli4_free_xri - Release an xri for reuse. | |
12958 | * @phba: pointer to lpfc hba data structure. | |
12959 | * | |
12960 | * This routine is invoked to release an xri to the pool of | |
12961 | * available rpis maintained by the driver. | |
12962 | **/ | |
12963 | void | |
12964 | lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri) | |
12965 | { | |
12966 | spin_lock_irq(&phba->hbalock); | |
12967 | __lpfc_sli4_free_xri(phba, xri); | |
12968 | spin_unlock_irq(&phba->hbalock); | |
12969 | } | |
12970 | ||
4f774513 JS |
12971 | /** |
12972 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
12973 | * @phba: Pointer to HBA context object. | |
12974 | * | |
12975 | * This function gets an xritag for the iocb. If there is no unused xritag | |
12976 | * it will return 0xffff. | |
12977 | * The function returns the allocated xritag if successful, else returns zero. | |
12978 | * Zero is not a valid xritag. | |
12979 | * The caller is not required to hold any lock. | |
12980 | **/ | |
12981 | uint16_t | |
12982 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
12983 | { | |
6d368e53 | 12984 | uint16_t xri_index; |
4f774513 | 12985 | |
6d368e53 JS |
12986 | xri_index = lpfc_sli4_alloc_xri(phba); |
12987 | if (xri_index != NO_XRI) | |
12988 | return xri_index; | |
12989 | ||
12990 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4f774513 JS |
12991 | "2004 Failed to allocate XRI.last XRITAG is %d" |
12992 | " Max XRI is %d, Used XRI is %d\n", | |
6d368e53 | 12993 | xri_index, |
4f774513 JS |
12994 | phba->sli4_hba.max_cfg_param.max_xri, |
12995 | phba->sli4_hba.max_cfg_param.xri_used); | |
6d368e53 | 12996 | return NO_XRI; |
4f774513 JS |
12997 | } |
12998 | ||
12999 | /** | |
6d368e53 | 13000 | * lpfc_sli4_post_els_sgl_list - post a block of ELS sgls to the port. |
4f774513 JS |
13001 | * @phba: pointer to lpfc hba data structure. |
13002 | * | |
13003 | * This routine is invoked to post a block of driver's sgl pages to the | |
13004 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
13005 | * is only called when the driver is loading and after all IO has been | |
13006 | * stopped. | |
13007 | **/ | |
13008 | int | |
6d368e53 | 13009 | lpfc_sli4_post_els_sgl_list(struct lpfc_hba *phba) |
4f774513 JS |
13010 | { |
13011 | struct lpfc_sglq *sglq_entry; | |
13012 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
13013 | struct sgl_page_pairs *sgl_pg_pairs; | |
13014 | void *viraddr; | |
13015 | LPFC_MBOXQ_t *mbox; | |
13016 | uint32_t reqlen, alloclen, pg_pairs; | |
13017 | uint32_t mbox_tmo; | |
6d368e53 | 13018 | uint16_t xritag_start = 0, lxri = 0; |
4f774513 JS |
13019 | int els_xri_cnt, rc = 0; |
13020 | uint32_t shdr_status, shdr_add_status; | |
13021 | union lpfc_sli4_cfg_shdr *shdr; | |
13022 | ||
13023 | /* The number of sgls to be posted */ | |
13024 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
13025 | ||
13026 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
13027 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 13028 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
13029 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
13030 | "2559 Block sgl registration required DMA " | |
13031 | "size (%d) great than a page\n", reqlen); | |
13032 | return -ENOMEM; | |
13033 | } | |
13034 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6d368e53 | 13035 | if (!mbox) |
4f774513 | 13036 | return -ENOMEM; |
4f774513 JS |
13037 | |
13038 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
13039 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13040 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
13041 | LPFC_SLI4_MBX_NEMBED); | |
13042 | ||
13043 | if (alloclen < reqlen) { | |
13044 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13045 | "0285 Allocated DMA memory size (%d) is " | |
13046 | "less than the requested DMA memory " | |
13047 | "size (%d)\n", alloclen, reqlen); | |
13048 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13049 | return -ENOMEM; | |
13050 | } | |
4f774513 | 13051 | /* Set up the SGL pages in the non-embedded DMA pages */ |
6d368e53 | 13052 | viraddr = mbox->sge_array->addr[0]; |
4f774513 JS |
13053 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; |
13054 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13055 | ||
13056 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | |
13057 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | |
6d368e53 JS |
13058 | |
13059 | /* | |
13060 | * Assign the sglq a physical xri only if the driver has not | |
13061 | * initialized those resources. A port reset only needs | |
13062 | * the sglq's posted. | |
13063 | */ | |
13064 | if (bf_get(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
13065 | LPFC_XRI_RSRC_RDY) { | |
13066 | lxri = lpfc_sli4_next_xritag(phba); | |
13067 | if (lxri == NO_XRI) { | |
13068 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13069 | return -ENOMEM; | |
13070 | } | |
13071 | sglq_entry->sli4_lxritag = lxri; | |
13072 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
13073 | } | |
13074 | ||
4f774513 JS |
13075 | /* Set up the sge entry */ |
13076 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13077 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
13078 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13079 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
13080 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13081 | cpu_to_le32(putPaddrLow(0)); | |
13082 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13083 | cpu_to_le32(putPaddrHigh(0)); | |
6d368e53 | 13084 | |
4f774513 JS |
13085 | /* Keep the first xritag on the list */ |
13086 | if (pg_pairs == 0) | |
13087 | xritag_start = sglq_entry->sli4_xritag; | |
13088 | sgl_pg_pairs++; | |
13089 | } | |
6d368e53 JS |
13090 | |
13091 | /* Complete initialization and perform endian conversion. */ | |
4f774513 | 13092 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); |
6a9c52cf | 13093 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
4f774513 | 13094 | sgl->word0 = cpu_to_le32(sgl->word0); |
4f774513 JS |
13095 | if (!phba->sli4_hba.intr_enable) |
13096 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13097 | else { | |
a183a15f | 13098 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
13099 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13100 | } | |
13101 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13102 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13103 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13104 | if (rc != MBX_TIMEOUT) | |
13105 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13106 | if (shdr_status || shdr_add_status || rc) { | |
13107 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13108 | "2513 POST_SGL_BLOCK mailbox command failed " | |
13109 | "status x%x add_status x%x mbx status x%x\n", | |
13110 | shdr_status, shdr_add_status, rc); | |
13111 | rc = -ENXIO; | |
13112 | } | |
6d368e53 JS |
13113 | |
13114 | if (rc == 0) | |
13115 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
13116 | LPFC_XRI_RSRC_RDY); | |
13117 | return rc; | |
13118 | } | |
13119 | ||
13120 | /** | |
13121 | * lpfc_sli4_post_els_sgl_list_ext - post a block of ELS sgls to the port. | |
13122 | * @phba: pointer to lpfc hba data structure. | |
13123 | * | |
13124 | * This routine is invoked to post a block of driver's sgl pages to the | |
13125 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
13126 | * is only called when the driver is loading and after all IO has been | |
13127 | * stopped. | |
13128 | **/ | |
13129 | int | |
13130 | lpfc_sli4_post_els_sgl_list_ext(struct lpfc_hba *phba) | |
13131 | { | |
13132 | struct lpfc_sglq *sglq_entry; | |
13133 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
13134 | struct sgl_page_pairs *sgl_pg_pairs; | |
13135 | void *viraddr; | |
13136 | LPFC_MBOXQ_t *mbox; | |
13137 | uint32_t reqlen, alloclen, index; | |
13138 | uint32_t mbox_tmo; | |
13139 | uint16_t rsrc_start, rsrc_size, els_xri_cnt; | |
13140 | uint16_t xritag_start = 0, lxri = 0; | |
13141 | struct lpfc_rsrc_blks *rsrc_blk; | |
13142 | int cnt, ttl_cnt, rc = 0; | |
13143 | int loop_cnt; | |
13144 | uint32_t shdr_status, shdr_add_status; | |
13145 | union lpfc_sli4_cfg_shdr *shdr; | |
13146 | ||
13147 | /* The number of sgls to be posted */ | |
13148 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
13149 | ||
13150 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
13151 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
13152 | if (reqlen > SLI4_PAGE_SIZE) { | |
13153 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
13154 | "2989 Block sgl registration required DMA " | |
13155 | "size (%d) great than a page\n", reqlen); | |
13156 | return -ENOMEM; | |
13157 | } | |
13158 | ||
13159 | cnt = 0; | |
13160 | ttl_cnt = 0; | |
13161 | list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, | |
13162 | list) { | |
13163 | rsrc_start = rsrc_blk->rsrc_start; | |
13164 | rsrc_size = rsrc_blk->rsrc_size; | |
13165 | ||
13166 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13167 | "3014 Working ELS Extent start %d, cnt %d\n", | |
13168 | rsrc_start, rsrc_size); | |
13169 | ||
13170 | loop_cnt = min(els_xri_cnt, rsrc_size); | |
13171 | if (ttl_cnt + loop_cnt >= els_xri_cnt) { | |
13172 | loop_cnt = els_xri_cnt - ttl_cnt; | |
13173 | ttl_cnt = els_xri_cnt; | |
13174 | } | |
13175 | ||
13176 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13177 | if (!mbox) | |
13178 | return -ENOMEM; | |
13179 | /* | |
13180 | * Allocate DMA memory and set up the non-embedded mailbox | |
13181 | * command. | |
13182 | */ | |
13183 | alloclen = lpfc_sli4_config(phba, mbox, | |
13184 | LPFC_MBOX_SUBSYSTEM_FCOE, | |
13185 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
13186 | reqlen, LPFC_SLI4_MBX_NEMBED); | |
13187 | if (alloclen < reqlen) { | |
13188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13189 | "2987 Allocated DMA memory size (%d) " | |
13190 | "is less than the requested DMA memory " | |
13191 | "size (%d)\n", alloclen, reqlen); | |
13192 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13193 | return -ENOMEM; | |
13194 | } | |
13195 | ||
13196 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
13197 | viraddr = mbox->sge_array->addr[0]; | |
13198 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
13199 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13200 | ||
13201 | /* | |
13202 | * The starting resource may not begin at zero. Control | |
13203 | * the loop variants via the block resource parameters, | |
13204 | * but handle the sge pointers with a zero-based index | |
13205 | * that doesn't get reset per loop pass. | |
13206 | */ | |
13207 | for (index = rsrc_start; | |
13208 | index < rsrc_start + loop_cnt; | |
13209 | index++) { | |
13210 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[cnt]; | |
13211 | ||
13212 | /* | |
13213 | * Assign the sglq a physical xri only if the driver | |
13214 | * has not initialized those resources. A port reset | |
13215 | * only needs the sglq's posted. | |
13216 | */ | |
13217 | if (bf_get(lpfc_xri_rsrc_rdy, | |
13218 | &phba->sli4_hba.sli4_flags) != | |
13219 | LPFC_XRI_RSRC_RDY) { | |
13220 | lxri = lpfc_sli4_next_xritag(phba); | |
13221 | if (lxri == NO_XRI) { | |
13222 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13223 | rc = -ENOMEM; | |
13224 | goto err_exit; | |
13225 | } | |
13226 | sglq_entry->sli4_lxritag = lxri; | |
13227 | sglq_entry->sli4_xritag = | |
13228 | phba->sli4_hba.xri_ids[lxri]; | |
13229 | } | |
13230 | ||
13231 | /* Set up the sge entry */ | |
13232 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13233 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
13234 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13235 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
13236 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13237 | cpu_to_le32(putPaddrLow(0)); | |
13238 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13239 | cpu_to_le32(putPaddrHigh(0)); | |
13240 | ||
13241 | /* Track the starting physical XRI for the mailbox. */ | |
13242 | if (index == rsrc_start) | |
13243 | xritag_start = sglq_entry->sli4_xritag; | |
13244 | sgl_pg_pairs++; | |
13245 | cnt++; | |
13246 | } | |
13247 | ||
13248 | /* Complete initialization and perform endian conversion. */ | |
13249 | rsrc_blk->rsrc_used += loop_cnt; | |
13250 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
13251 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, loop_cnt); | |
13252 | sgl->word0 = cpu_to_le32(sgl->word0); | |
13253 | ||
13254 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13255 | "3015 Post ELS Extent SGL, start %d, " | |
13256 | "cnt %d, used %d\n", | |
13257 | xritag_start, loop_cnt, rsrc_blk->rsrc_used); | |
13258 | if (!phba->sli4_hba.intr_enable) | |
13259 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13260 | else { | |
a183a15f | 13261 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
13262 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13263 | } | |
13264 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13265 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
13266 | &shdr->response); | |
13267 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
13268 | &shdr->response); | |
13269 | if (rc != MBX_TIMEOUT) | |
13270 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13271 | if (shdr_status || shdr_add_status || rc) { | |
13272 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13273 | "2988 POST_SGL_BLOCK mailbox " | |
13274 | "command failed status x%x " | |
13275 | "add_status x%x mbx status x%x\n", | |
13276 | shdr_status, shdr_add_status, rc); | |
13277 | rc = -ENXIO; | |
13278 | goto err_exit; | |
13279 | } | |
13280 | if (ttl_cnt >= els_xri_cnt) | |
13281 | break; | |
13282 | } | |
13283 | ||
13284 | err_exit: | |
13285 | if (rc == 0) | |
13286 | bf_set(lpfc_xri_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
13287 | LPFC_XRI_RSRC_RDY); | |
4f774513 JS |
13288 | return rc; |
13289 | } | |
13290 | ||
13291 | /** | |
13292 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
13293 | * @phba: pointer to lpfc hba data structure. | |
13294 | * @sblist: pointer to scsi buffer list. | |
13295 | * @count: number of scsi buffers on the list. | |
13296 | * | |
13297 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
13298 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
13299 | * No Lock is held. | |
13300 | * | |
13301 | **/ | |
13302 | int | |
13303 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | |
13304 | int cnt) | |
13305 | { | |
13306 | struct lpfc_scsi_buf *psb; | |
13307 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
13308 | struct sgl_page_pairs *sgl_pg_pairs; | |
13309 | void *viraddr; | |
13310 | LPFC_MBOXQ_t *mbox; | |
13311 | uint32_t reqlen, alloclen, pg_pairs; | |
13312 | uint32_t mbox_tmo; | |
13313 | uint16_t xritag_start = 0; | |
13314 | int rc = 0; | |
13315 | uint32_t shdr_status, shdr_add_status; | |
13316 | dma_addr_t pdma_phys_bpl1; | |
13317 | union lpfc_sli4_cfg_shdr *shdr; | |
13318 | ||
13319 | /* Calculate the requested length of the dma memory */ | |
13320 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
13321 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 13322 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
13323 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
13324 | "0217 Block sgl registration required DMA " | |
13325 | "size (%d) great than a page\n", reqlen); | |
13326 | return -ENOMEM; | |
13327 | } | |
13328 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13329 | if (!mbox) { | |
13330 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13331 | "0283 Failed to allocate mbox cmd memory\n"); | |
13332 | return -ENOMEM; | |
13333 | } | |
13334 | ||
13335 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
13336 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13337 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
13338 | LPFC_SLI4_MBX_NEMBED); | |
13339 | ||
13340 | if (alloclen < reqlen) { | |
13341 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13342 | "2561 Allocated DMA memory size (%d) is " | |
13343 | "less than the requested DMA memory " | |
13344 | "size (%d)\n", alloclen, reqlen); | |
13345 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13346 | return -ENOMEM; | |
13347 | } | |
6d368e53 | 13348 | |
4f774513 | 13349 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
13350 | viraddr = mbox->sge_array->addr[0]; |
13351 | ||
13352 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
13353 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
13354 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13355 | ||
13356 | pg_pairs = 0; | |
13357 | list_for_each_entry(psb, sblist, list) { | |
13358 | /* Set up the sge entry */ | |
13359 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13360 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
13361 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13362 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
13363 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
13364 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
13365 | else | |
13366 | pdma_phys_bpl1 = 0; | |
13367 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13368 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
13369 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13370 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
13371 | /* Keep the first xritag on the list */ | |
13372 | if (pg_pairs == 0) | |
13373 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
13374 | sgl_pg_pairs++; | |
13375 | pg_pairs++; | |
13376 | } | |
13377 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
13378 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
13379 | /* Perform endian conversion if necessary */ | |
13380 | sgl->word0 = cpu_to_le32(sgl->word0); | |
13381 | ||
13382 | if (!phba->sli4_hba.intr_enable) | |
13383 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13384 | else { | |
a183a15f | 13385 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
4f774513 JS |
13386 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13387 | } | |
13388 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13389 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13390 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
13391 | if (rc != MBX_TIMEOUT) | |
13392 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13393 | if (shdr_status || shdr_add_status || rc) { | |
13394 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13395 | "2564 POST_SGL_BLOCK mailbox command failed " | |
13396 | "status x%x add_status x%x mbx status x%x\n", | |
13397 | shdr_status, shdr_add_status, rc); | |
13398 | rc = -ENXIO; | |
13399 | } | |
13400 | return rc; | |
13401 | } | |
13402 | ||
6d368e53 JS |
13403 | /** |
13404 | * lpfc_sli4_post_scsi_sgl_blk_ext - post a block of scsi sgls to the port. | |
13405 | * @phba: pointer to lpfc hba data structure. | |
13406 | * @sblist: pointer to scsi buffer list. | |
13407 | * @count: number of scsi buffers on the list. | |
13408 | * | |
13409 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
13410 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
13411 | * No Lock is held. | |
13412 | * | |
13413 | **/ | |
13414 | int | |
13415 | lpfc_sli4_post_scsi_sgl_blk_ext(struct lpfc_hba *phba, struct list_head *sblist, | |
13416 | int cnt) | |
13417 | { | |
13418 | struct lpfc_scsi_buf *psb = NULL; | |
13419 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
13420 | struct sgl_page_pairs *sgl_pg_pairs; | |
13421 | void *viraddr; | |
13422 | LPFC_MBOXQ_t *mbox; | |
13423 | uint32_t reqlen, alloclen, pg_pairs; | |
13424 | uint32_t mbox_tmo; | |
13425 | uint16_t xri_start = 0, scsi_xri_start; | |
13426 | uint16_t rsrc_range; | |
13427 | int rc = 0, avail_cnt; | |
13428 | uint32_t shdr_status, shdr_add_status; | |
13429 | dma_addr_t pdma_phys_bpl1; | |
13430 | union lpfc_sli4_cfg_shdr *shdr; | |
13431 | struct lpfc_rsrc_blks *rsrc_blk; | |
13432 | uint32_t xri_cnt = 0; | |
13433 | ||
13434 | /* Calculate the total requested length of the dma memory */ | |
13435 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
13436 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
13437 | if (reqlen > SLI4_PAGE_SIZE) { | |
13438 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
13439 | "2932 Block sgl registration required DMA " | |
13440 | "size (%d) great than a page\n", reqlen); | |
13441 | return -ENOMEM; | |
13442 | } | |
13443 | ||
13444 | /* | |
13445 | * The use of extents requires the driver to post the sgl headers | |
13446 | * in multiple postings to meet the contiguous resource assignment. | |
13447 | */ | |
13448 | psb = list_prepare_entry(psb, sblist, list); | |
13449 | scsi_xri_start = phba->sli4_hba.scsi_xri_start; | |
13450 | list_for_each_entry(rsrc_blk, &phba->sli4_hba.lpfc_xri_blk_list, | |
13451 | list) { | |
13452 | rsrc_range = rsrc_blk->rsrc_start + rsrc_blk->rsrc_size; | |
13453 | if (rsrc_range < scsi_xri_start) | |
13454 | continue; | |
13455 | else if (rsrc_blk->rsrc_used >= rsrc_blk->rsrc_size) | |
13456 | continue; | |
13457 | else | |
13458 | avail_cnt = rsrc_blk->rsrc_size - rsrc_blk->rsrc_used; | |
13459 | ||
13460 | reqlen = (avail_cnt * sizeof(struct sgl_page_pairs)) + | |
13461 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
13462 | /* | |
13463 | * Allocate DMA memory and set up the non-embedded mailbox | |
13464 | * command. The mbox is used to post an SGL page per loop | |
13465 | * but the DMA memory has a use-once semantic so the mailbox | |
13466 | * is used and freed per loop pass. | |
13467 | */ | |
13468 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13469 | if (!mbox) { | |
13470 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13471 | "2933 Failed to allocate mbox cmd " | |
13472 | "memory\n"); | |
13473 | return -ENOMEM; | |
13474 | } | |
13475 | alloclen = lpfc_sli4_config(phba, mbox, | |
13476 | LPFC_MBOX_SUBSYSTEM_FCOE, | |
13477 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
13478 | reqlen, | |
13479 | LPFC_SLI4_MBX_NEMBED); | |
13480 | if (alloclen < reqlen) { | |
13481 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13482 | "2934 Allocated DMA memory size (%d) " | |
13483 | "is less than the requested DMA memory " | |
13484 | "size (%d)\n", alloclen, reqlen); | |
13485 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13486 | return -ENOMEM; | |
13487 | } | |
13488 | ||
13489 | /* Get the first SGE entry from the non-embedded DMA memory */ | |
13490 | viraddr = mbox->sge_array->addr[0]; | |
13491 | ||
13492 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
13493 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
13494 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
13495 | ||
13496 | /* pg_pairs tracks posted SGEs per loop iteration. */ | |
13497 | pg_pairs = 0; | |
13498 | list_for_each_entry_continue(psb, sblist, list) { | |
13499 | /* Set up the sge entry */ | |
13500 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
13501 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
13502 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
13503 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
13504 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
13505 | pdma_phys_bpl1 = psb->dma_phys_bpl + | |
13506 | SGL_PAGE_SIZE; | |
13507 | else | |
13508 | pdma_phys_bpl1 = 0; | |
13509 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
13510 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
13511 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
13512 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
13513 | /* Keep the first xri for this extent. */ | |
13514 | if (pg_pairs == 0) | |
13515 | xri_start = psb->cur_iocbq.sli4_xritag; | |
13516 | sgl_pg_pairs++; | |
13517 | pg_pairs++; | |
13518 | xri_cnt++; | |
13519 | ||
13520 | /* | |
13521 | * Track two exit conditions - the loop has constructed | |
13522 | * all of the caller's SGE pairs or all available | |
13523 | * resource IDs in this extent are consumed. | |
13524 | */ | |
13525 | if ((xri_cnt == cnt) || (pg_pairs >= avail_cnt)) | |
13526 | break; | |
13527 | } | |
13528 | rsrc_blk->rsrc_used += pg_pairs; | |
13529 | bf_set(lpfc_post_sgl_pages_xri, sgl, xri_start); | |
13530 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
13531 | ||
13532 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13533 | "3016 Post SCSI Extent SGL, start %d, cnt %d " | |
13534 | "blk use %d\n", | |
13535 | xri_start, pg_pairs, rsrc_blk->rsrc_used); | |
13536 | /* Perform endian conversion if necessary */ | |
13537 | sgl->word0 = cpu_to_le32(sgl->word0); | |
13538 | if (!phba->sli4_hba.intr_enable) | |
13539 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
13540 | else { | |
a183a15f | 13541 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
6d368e53 JS |
13542 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
13543 | } | |
13544 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
13545 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
13546 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
13547 | &shdr->response); | |
13548 | if (rc != MBX_TIMEOUT) | |
13549 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
13550 | if (shdr_status || shdr_add_status || rc) { | |
13551 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13552 | "2935 POST_SGL_BLOCK mailbox command " | |
13553 | "failed status x%x add_status x%x " | |
13554 | "mbx status x%x\n", | |
13555 | shdr_status, shdr_add_status, rc); | |
13556 | return -ENXIO; | |
13557 | } | |
13558 | ||
13559 | /* Post only what is requested. */ | |
13560 | if (xri_cnt >= cnt) | |
13561 | break; | |
13562 | } | |
13563 | return rc; | |
13564 | } | |
13565 | ||
4f774513 JS |
13566 | /** |
13567 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
13568 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
13569 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13570 | * | |
13571 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
13572 | * valid type of frame that the LPFC driver will handle. This function will | |
13573 | * return a zero if the frame is a valid frame or a non zero value when the | |
13574 | * frame does not pass the check. | |
13575 | **/ | |
13576 | static int | |
13577 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
13578 | { | |
474ffb74 TH |
13579 | /* make rctl_names static to save stack space */ |
13580 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
13581 | char *type_names[] = FC_TYPE_NAMES_INIT; |
13582 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 13583 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
13584 | |
13585 | switch (fc_hdr->fh_r_ctl) { | |
13586 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
13587 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
13588 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
13589 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
13590 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
13591 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
13592 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
13593 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
13594 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
13595 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
13596 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
13597 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
13598 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
13599 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
13600 | case FC_RCTL_BA_RMC: /* remove connection */ | |
13601 | case FC_RCTL_BA_ACC: /* basic accept */ | |
13602 | case FC_RCTL_BA_RJT: /* basic reject */ | |
13603 | case FC_RCTL_BA_PRMT: | |
13604 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
13605 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
13606 | case FC_RCTL_P_RJT: /* port reject */ | |
13607 | case FC_RCTL_F_RJT: /* fabric reject */ | |
13608 | case FC_RCTL_P_BSY: /* port busy */ | |
13609 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
13610 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
13611 | case FC_RCTL_LCR: /* link credit reset */ | |
13612 | case FC_RCTL_END: /* end */ | |
13613 | break; | |
13614 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
13615 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13616 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
13617 | return lpfc_fc_frame_check(phba, fc_hdr); | |
13618 | default: | |
13619 | goto drop; | |
13620 | } | |
13621 | switch (fc_hdr->fh_type) { | |
13622 | case FC_TYPE_BLS: | |
13623 | case FC_TYPE_ELS: | |
13624 | case FC_TYPE_FCP: | |
13625 | case FC_TYPE_CT: | |
13626 | break; | |
13627 | case FC_TYPE_IP: | |
13628 | case FC_TYPE_ILS: | |
13629 | default: | |
13630 | goto drop; | |
13631 | } | |
546fc854 | 13632 | |
4f774513 | 13633 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
13634 | "2538 Received frame rctl:%s type:%s " |
13635 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", | |
4f774513 | 13636 | rctl_names[fc_hdr->fh_r_ctl], |
546fc854 JS |
13637 | type_names[fc_hdr->fh_type], |
13638 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), | |
13639 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
13640 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); | |
4f774513 JS |
13641 | return 0; |
13642 | drop: | |
13643 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
13644 | "2539 Dropped frame rctl:%s type:%s\n", | |
13645 | rctl_names[fc_hdr->fh_r_ctl], | |
13646 | type_names[fc_hdr->fh_type]); | |
13647 | return 1; | |
13648 | } | |
13649 | ||
13650 | /** | |
13651 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
13652 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13653 | * | |
13654 | * This function processes the FC header to retrieve the VFI from the VF | |
13655 | * header, if one exists. This function will return the VFI if one exists | |
13656 | * or 0 if no VSAN Header exists. | |
13657 | **/ | |
13658 | static uint32_t | |
13659 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
13660 | { | |
13661 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
13662 | ||
13663 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
13664 | return 0; | |
13665 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
13666 | } | |
13667 | ||
13668 | /** | |
13669 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
13670 | * @phba: Pointer to the HBA structure to search for the vport on | |
13671 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
13672 | * @fcfi: The FC Fabric ID that the frame came from | |
13673 | * | |
13674 | * This function searches the @phba for a vport that matches the content of the | |
13675 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
13676 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
13677 | * returns the matching vport pointer or NULL if unable to match frame to a | |
13678 | * vport. | |
13679 | **/ | |
13680 | static struct lpfc_vport * | |
13681 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
13682 | uint16_t fcfi) | |
13683 | { | |
13684 | struct lpfc_vport **vports; | |
13685 | struct lpfc_vport *vport = NULL; | |
13686 | int i; | |
13687 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
13688 | fc_hdr->fh_d_id[1] << 8 | | |
13689 | fc_hdr->fh_d_id[2]); | |
bf08611b JS |
13690 | if (did == Fabric_DID) |
13691 | return phba->pport; | |
4f774513 JS |
13692 | vports = lpfc_create_vport_work_array(phba); |
13693 | if (vports != NULL) | |
13694 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
13695 | if (phba->fcf.fcfi == fcfi && | |
13696 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
13697 | vports[i]->fc_myDID == did) { | |
13698 | vport = vports[i]; | |
13699 | break; | |
13700 | } | |
13701 | } | |
13702 | lpfc_destroy_vport_work_array(phba, vports); | |
13703 | return vport; | |
13704 | } | |
13705 | ||
45ed1190 JS |
13706 | /** |
13707 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
13708 | * @vport: The vport to work on. | |
13709 | * | |
13710 | * This function updates the receive sequence time stamp for this vport. The | |
13711 | * receive sequence time stamp indicates the time that the last frame of the | |
13712 | * the sequence that has been idle for the longest amount of time was received. | |
13713 | * the driver uses this time stamp to indicate if any received sequences have | |
13714 | * timed out. | |
13715 | **/ | |
13716 | void | |
13717 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
13718 | { | |
13719 | struct lpfc_dmabuf *h_buf; | |
13720 | struct hbq_dmabuf *dmabuf = NULL; | |
13721 | ||
13722 | /* get the oldest sequence on the rcv list */ | |
13723 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
13724 | struct lpfc_dmabuf, list); | |
13725 | if (!h_buf) | |
13726 | return; | |
13727 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13728 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
13729 | } | |
13730 | ||
13731 | /** | |
13732 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
13733 | * @vport: The vport that the received sequences were sent to. | |
13734 | * | |
13735 | * This function cleans up all outstanding received sequences. This is called | |
13736 | * by the driver when a link event or user action invalidates all the received | |
13737 | * sequences. | |
13738 | **/ | |
13739 | void | |
13740 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
13741 | { | |
13742 | struct lpfc_dmabuf *h_buf, *hnext; | |
13743 | struct lpfc_dmabuf *d_buf, *dnext; | |
13744 | struct hbq_dmabuf *dmabuf = NULL; | |
13745 | ||
13746 | /* start with the oldest sequence on the rcv list */ | |
13747 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13748 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13749 | list_del_init(&dmabuf->hbuf.list); | |
13750 | list_for_each_entry_safe(d_buf, dnext, | |
13751 | &dmabuf->dbuf.list, list) { | |
13752 | list_del_init(&d_buf->list); | |
13753 | lpfc_in_buf_free(vport->phba, d_buf); | |
13754 | } | |
13755 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13756 | } | |
13757 | } | |
13758 | ||
13759 | /** | |
13760 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
13761 | * @vport: The vport that the received sequences were sent to. | |
13762 | * | |
13763 | * This function determines whether any received sequences have timed out by | |
13764 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
13765 | * indicates that there is at least one timed out sequence this routine will | |
13766 | * go through the received sequences one at a time from most inactive to most | |
13767 | * active to determine which ones need to be cleaned up. Once it has determined | |
13768 | * that a sequence needs to be cleaned up it will simply free up the resources | |
13769 | * without sending an abort. | |
13770 | **/ | |
13771 | void | |
13772 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
13773 | { | |
13774 | struct lpfc_dmabuf *h_buf, *hnext; | |
13775 | struct lpfc_dmabuf *d_buf, *dnext; | |
13776 | struct hbq_dmabuf *dmabuf = NULL; | |
13777 | unsigned long timeout; | |
13778 | int abort_count = 0; | |
13779 | ||
13780 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13781 | vport->rcv_buffer_time_stamp); | |
13782 | if (list_empty(&vport->rcv_buffer_list) || | |
13783 | time_before(jiffies, timeout)) | |
13784 | return; | |
13785 | /* start with the oldest sequence on the rcv list */ | |
13786 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
13787 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13788 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
13789 | dmabuf->time_stamp); | |
13790 | if (time_before(jiffies, timeout)) | |
13791 | break; | |
13792 | abort_count++; | |
13793 | list_del_init(&dmabuf->hbuf.list); | |
13794 | list_for_each_entry_safe(d_buf, dnext, | |
13795 | &dmabuf->dbuf.list, list) { | |
13796 | list_del_init(&d_buf->list); | |
13797 | lpfc_in_buf_free(vport->phba, d_buf); | |
13798 | } | |
13799 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
13800 | } | |
13801 | if (abort_count) | |
13802 | lpfc_update_rcv_time_stamp(vport); | |
13803 | } | |
13804 | ||
4f774513 JS |
13805 | /** |
13806 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
13807 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
13808 | * | |
13809 | * This function searches through the existing incomplete sequences that have | |
13810 | * been sent to this @vport. If the frame matches one of the incomplete | |
13811 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
13812 | * make up that sequence. If no sequence is found that matches this frame then | |
13813 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
13814 | * This function returns a pointer to the first dmabuf in the sequence list that | |
13815 | * the frame was linked to. | |
13816 | **/ | |
13817 | static struct hbq_dmabuf * | |
13818 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
13819 | { | |
13820 | struct fc_frame_header *new_hdr; | |
13821 | struct fc_frame_header *temp_hdr; | |
13822 | struct lpfc_dmabuf *d_buf; | |
13823 | struct lpfc_dmabuf *h_buf; | |
13824 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13825 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
13826 | ||
4d9ab994 | 13827 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 13828 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
13829 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
13830 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
13831 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13832 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13833 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13834 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13835 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13836 | continue; | |
13837 | /* found a pending sequence that matches this frame */ | |
13838 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13839 | break; | |
13840 | } | |
13841 | if (!seq_dmabuf) { | |
13842 | /* | |
13843 | * This indicates first frame received for this sequence. | |
13844 | * Queue the buffer on the vport's rcv_buffer_list. | |
13845 | */ | |
13846 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 13847 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13848 | return dmabuf; |
13849 | } | |
13850 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
13851 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
13852 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
13853 | list_del_init(&seq_dmabuf->hbuf.list); |
13854 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13855 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 13856 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
13857 | return dmabuf; |
13858 | } | |
45ed1190 JS |
13859 | /* move this sequence to the tail to indicate a young sequence */ |
13860 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
13861 | seq_dmabuf->time_stamp = jiffies; | |
13862 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
13863 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
13864 | temp_hdr = dmabuf->hbuf.virt; | |
13865 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
13866 | return seq_dmabuf; | |
13867 | } | |
4f774513 JS |
13868 | /* find the correct place in the sequence to insert this frame */ |
13869 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
13870 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
13871 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
13872 | /* | |
13873 | * If the frame's sequence count is greater than the frame on | |
13874 | * the list then insert the frame right after this frame | |
13875 | */ | |
eeead811 JS |
13876 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
13877 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
13878 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
13879 | return seq_dmabuf; | |
13880 | } | |
13881 | } | |
13882 | return NULL; | |
13883 | } | |
13884 | ||
6669f9bb JS |
13885 | /** |
13886 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
13887 | * @vport: pointer to a vitural port | |
13888 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
13889 | * | |
13890 | * This function tries to abort from the partially assembed sequence, described | |
13891 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
13892 | * partially assembled sequence held by the driver. If so, it shall free up all | |
13893 | * the frames from the partially assembled sequence. | |
13894 | * | |
13895 | * Return | |
13896 | * true -- if there is matching partially assembled sequence present and all | |
13897 | * the frames freed with the sequence; | |
13898 | * false -- if there is no matching partially assembled sequence present so | |
13899 | * nothing got aborted in the lower layer driver | |
13900 | **/ | |
13901 | static bool | |
13902 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
13903 | struct hbq_dmabuf *dmabuf) | |
13904 | { | |
13905 | struct fc_frame_header *new_hdr; | |
13906 | struct fc_frame_header *temp_hdr; | |
13907 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
13908 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
13909 | ||
13910 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
13911 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
13912 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
13913 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
13914 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
13915 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
13916 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
13917 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
13918 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
13919 | continue; | |
13920 | /* found a pending sequence that matches this frame */ | |
13921 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
13922 | break; | |
13923 | } | |
13924 | ||
13925 | /* Free up all the frames from the partially assembled sequence */ | |
13926 | if (seq_dmabuf) { | |
13927 | list_for_each_entry_safe(d_buf, n_buf, | |
13928 | &seq_dmabuf->dbuf.list, list) { | |
13929 | list_del_init(&d_buf->list); | |
13930 | lpfc_in_buf_free(vport->phba, d_buf); | |
13931 | } | |
13932 | return true; | |
13933 | } | |
13934 | return false; | |
13935 | } | |
13936 | ||
13937 | /** | |
546fc854 | 13938 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
13939 | * @phba: Pointer to HBA context object. |
13940 | * @cmd_iocbq: pointer to the command iocbq structure. | |
13941 | * @rsp_iocbq: pointer to the response iocbq structure. | |
13942 | * | |
546fc854 | 13943 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
13944 | * event. It properly releases the memory allocated to the sequence abort |
13945 | * accept iocb. | |
13946 | **/ | |
13947 | static void | |
546fc854 | 13948 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
13949 | struct lpfc_iocbq *cmd_iocbq, |
13950 | struct lpfc_iocbq *rsp_iocbq) | |
13951 | { | |
13952 | if (cmd_iocbq) | |
13953 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
13954 | } | |
13955 | ||
6d368e53 JS |
13956 | /** |
13957 | * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver. | |
13958 | * @phba: Pointer to HBA context object. | |
13959 | * @xri: xri id in transaction. | |
13960 | * | |
13961 | * This function validates the xri maps to the known range of XRIs allocated an | |
13962 | * used by the driver. | |
13963 | **/ | |
7851fe2c | 13964 | uint16_t |
6d368e53 JS |
13965 | lpfc_sli4_xri_inrange(struct lpfc_hba *phba, |
13966 | uint16_t xri) | |
13967 | { | |
13968 | int i; | |
13969 | ||
13970 | for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) { | |
13971 | if (xri == phba->sli4_hba.xri_ids[i]) | |
13972 | return i; | |
13973 | } | |
13974 | return NO_XRI; | |
13975 | } | |
13976 | ||
13977 | ||
6669f9bb | 13978 | /** |
546fc854 | 13979 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
13980 | * @phba: Pointer to HBA context object. |
13981 | * @fc_hdr: pointer to a FC frame header. | |
13982 | * | |
546fc854 | 13983 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
13984 | * event after aborting the sequence handling. |
13985 | **/ | |
13986 | static void | |
546fc854 | 13987 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
6669f9bb JS |
13988 | struct fc_frame_header *fc_hdr) |
13989 | { | |
13990 | struct lpfc_iocbq *ctiocb = NULL; | |
13991 | struct lpfc_nodelist *ndlp; | |
5ffc266e JS |
13992 | uint16_t oxid, rxid; |
13993 | uint32_t sid, fctl; | |
6669f9bb | 13994 | IOCB_t *icmd; |
546fc854 | 13995 | int rc; |
6669f9bb JS |
13996 | |
13997 | if (!lpfc_is_link_up(phba)) | |
13998 | return; | |
13999 | ||
14000 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
14001 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 14002 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
14003 | |
14004 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
14005 | if (!ndlp) { | |
14006 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
14007 | "1268 Find ndlp returned NULL for oxid:x%x " | |
14008 | "SID:x%x\n", oxid, sid); | |
14009 | return; | |
14010 | } | |
6d368e53 | 14011 | if (lpfc_sli4_xri_inrange(phba, rxid)) |
19ca7609 | 14012 | lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); |
6669f9bb | 14013 | |
546fc854 | 14014 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
14015 | ctiocb = lpfc_sli_get_iocbq(phba); |
14016 | if (!ctiocb) | |
14017 | return; | |
14018 | ||
5ffc266e JS |
14019 | /* Extract the F_CTL field from FC_HDR */ |
14020 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
14021 | ||
6669f9bb | 14022 | icmd = &ctiocb->iocb; |
6669f9bb | 14023 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 14024 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
14025 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
14026 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
14027 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
14028 | ||
14029 | /* Fill in the rest of iocb fields */ | |
14030 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
14031 | icmd->ulpBdeCount = 0; | |
14032 | icmd->ulpLe = 1; | |
14033 | icmd->ulpClass = CLASS3; | |
6d368e53 | 14034 | icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]; |
be858b65 | 14035 | ctiocb->context1 = ndlp; |
6669f9bb | 14036 | |
6669f9bb JS |
14037 | ctiocb->iocb_cmpl = NULL; |
14038 | ctiocb->vport = phba->pport; | |
546fc854 | 14039 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
6d368e53 | 14040 | ctiocb->sli4_lxritag = NO_XRI; |
546fc854 JS |
14041 | ctiocb->sli4_xritag = NO_XRI; |
14042 | ||
14043 | /* If the oxid maps to the FCP XRI range or if it is out of range, | |
14044 | * send a BLS_RJT. The driver no longer has that exchange. | |
14045 | * Override the IOCB for a BA_RJT. | |
14046 | */ | |
14047 | if (oxid > (phba->sli4_hba.max_cfg_param.max_xri + | |
14048 | phba->sli4_hba.max_cfg_param.xri_base) || | |
14049 | oxid > (lpfc_sli4_get_els_iocb_cnt(phba) + | |
14050 | phba->sli4_hba.max_cfg_param.xri_base)) { | |
14051 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
14052 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
14053 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
14054 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
14055 | } | |
6669f9bb | 14056 | |
5ffc266e JS |
14057 | if (fctl & FC_FC_EX_CTX) { |
14058 | /* ABTS sent by responder to CT exchange, construction | |
14059 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
14060 | * field and RX_ID from ABTS for RX_ID field. | |
14061 | */ | |
546fc854 JS |
14062 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
14063 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); | |
5ffc266e JS |
14064 | } else { |
14065 | /* ABTS sent by initiator to CT exchange, construction | |
14066 | * of BA_ACC will need to allocate a new XRI as for the | |
14067 | * XRI_TAG and RX_ID fields. | |
14068 | */ | |
546fc854 JS |
14069 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
14070 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI); | |
5ffc266e | 14071 | } |
546fc854 | 14072 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 14073 | |
546fc854 | 14074 | /* Xmit CT abts response on exchange <xid> */ |
6669f9bb | 14075 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
14076 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
14077 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
14078 | ||
14079 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
14080 | if (rc == IOCB_ERROR) { | |
14081 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
14082 | "2925 Failed to issue CT ABTS RSP x%x on " | |
14083 | "xri x%x, Data x%x\n", | |
14084 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
14085 | phba->link_state); | |
14086 | lpfc_sli_release_iocbq(phba, ctiocb); | |
14087 | } | |
6669f9bb JS |
14088 | } |
14089 | ||
14090 | /** | |
14091 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
14092 | * @vport: Pointer to the vport on which this sequence was received | |
14093 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14094 | * | |
14095 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
14096 | * receive sequence is only partially assembed by the driver, it shall abort | |
14097 | * the partially assembled frames for the sequence. Otherwise, if the | |
14098 | * unsolicited receive sequence has been completely assembled and passed to | |
14099 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
14100 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
14101 | * accept to accept the abort. | |
14102 | **/ | |
14103 | void | |
14104 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
14105 | struct hbq_dmabuf *dmabuf) | |
14106 | { | |
14107 | struct lpfc_hba *phba = vport->phba; | |
14108 | struct fc_frame_header fc_hdr; | |
5ffc266e | 14109 | uint32_t fctl; |
6669f9bb JS |
14110 | bool abts_par; |
14111 | ||
6669f9bb JS |
14112 | /* Make a copy of fc_hdr before the dmabuf being released */ |
14113 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 14114 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 14115 | |
5ffc266e JS |
14116 | if (fctl & FC_FC_EX_CTX) { |
14117 | /* | |
14118 | * ABTS sent by responder to exchange, just free the buffer | |
14119 | */ | |
6669f9bb | 14120 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
14121 | } else { |
14122 | /* | |
14123 | * ABTS sent by initiator to exchange, need to do cleanup | |
14124 | */ | |
14125 | /* Try to abort partially assembled seq */ | |
14126 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
14127 | ||
14128 | /* Send abort to ULP if partially seq abort failed */ | |
14129 | if (abts_par == false) | |
14130 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
14131 | else | |
14132 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14133 | } | |
6669f9bb | 14134 | /* Send basic accept (BA_ACC) to the abort requester */ |
546fc854 | 14135 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
6669f9bb JS |
14136 | } |
14137 | ||
4f774513 JS |
14138 | /** |
14139 | * lpfc_seq_complete - Indicates if a sequence is complete | |
14140 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14141 | * | |
14142 | * This function checks the sequence, starting with the frame described by | |
14143 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
14144 | * the frames associated with this sequence are linked to the @dmabuf using the | |
14145 | * dbuf list. This function looks for two major things. 1) That the first frame | |
14146 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
14147 | * set. 3) That there are no holes in the sequence count. The function will | |
14148 | * return 1 when the sequence is complete, otherwise it will return 0. | |
14149 | **/ | |
14150 | static int | |
14151 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
14152 | { | |
14153 | struct fc_frame_header *hdr; | |
14154 | struct lpfc_dmabuf *d_buf; | |
14155 | struct hbq_dmabuf *seq_dmabuf; | |
14156 | uint32_t fctl; | |
14157 | int seq_count = 0; | |
14158 | ||
14159 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
14160 | /* make sure first fame of sequence has a sequence count of zero */ | |
14161 | if (hdr->fh_seq_cnt != seq_count) | |
14162 | return 0; | |
14163 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
14164 | hdr->fh_f_ctl[1] << 8 | | |
14165 | hdr->fh_f_ctl[2]); | |
14166 | /* If last frame of sequence we can return success. */ | |
14167 | if (fctl & FC_FC_END_SEQ) | |
14168 | return 1; | |
14169 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
14170 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14171 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14172 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 14173 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
14174 | return 0; |
14175 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
14176 | hdr->fh_f_ctl[1] << 8 | | |
14177 | hdr->fh_f_ctl[2]); | |
14178 | /* If last frame of sequence we can return success. */ | |
14179 | if (fctl & FC_FC_END_SEQ) | |
14180 | return 1; | |
14181 | } | |
14182 | return 0; | |
14183 | } | |
14184 | ||
14185 | /** | |
14186 | * lpfc_prep_seq - Prep sequence for ULP processing | |
14187 | * @vport: Pointer to the vport on which this sequence was received | |
14188 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
14189 | * | |
14190 | * This function takes a sequence, described by a list of frames, and creates | |
14191 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
14192 | * used to issue to the generic unsolicited sequence handler. This routine | |
14193 | * returns a pointer to the first iocbq in the list. If the function is unable | |
14194 | * to allocate an iocbq then it throw out the received frames that were not | |
14195 | * able to be described and return a pointer to the first iocbq. If unable to | |
14196 | * allocate any iocbqs (including the first) this function will return NULL. | |
14197 | **/ | |
14198 | static struct lpfc_iocbq * | |
14199 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
14200 | { | |
7851fe2c | 14201 | struct hbq_dmabuf *hbq_buf; |
4f774513 JS |
14202 | struct lpfc_dmabuf *d_buf, *n_buf; |
14203 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
14204 | struct fc_frame_header *fc_hdr; | |
14205 | uint32_t sid; | |
7851fe2c | 14206 | uint32_t len, tot_len; |
eeead811 | 14207 | struct ulp_bde64 *pbde; |
4f774513 JS |
14208 | |
14209 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14210 | /* remove from receive buffer list */ | |
14211 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 14212 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 14213 | /* get the Remote Port's SID */ |
6669f9bb | 14214 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
7851fe2c | 14215 | tot_len = 0; |
4f774513 JS |
14216 | /* Get an iocbq struct to fill in. */ |
14217 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
14218 | if (first_iocbq) { | |
14219 | /* Initialize the first IOCB. */ | |
8fa38513 | 14220 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 JS |
14221 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
14222 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
7851fe2c JS |
14223 | first_iocbq->iocb.ulpContext = NO_XRI; |
14224 | first_iocbq->iocb.unsli3.rcvsli3.ox_id = | |
14225 | be16_to_cpu(fc_hdr->fh_ox_id); | |
14226 | /* iocbq is prepped for internal consumption. Physical vpi. */ | |
14227 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
14228 | vport->phba->vpi_ids[vport->vpi]; | |
4f774513 JS |
14229 | /* put the first buffer into the first IOCBq */ |
14230 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
14231 | first_iocbq->context3 = NULL; | |
14232 | first_iocbq->iocb.ulpBdeCount = 1; | |
14233 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
14234 | LPFC_DATA_BUF_SIZE; | |
14235 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
7851fe2c | 14236 | tot_len = bf_get(lpfc_rcqe_length, |
4d9ab994 | 14237 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); |
7851fe2c | 14238 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; |
4f774513 JS |
14239 | } |
14240 | iocbq = first_iocbq; | |
14241 | /* | |
14242 | * Each IOCBq can have two Buffers assigned, so go through the list | |
14243 | * of buffers for this sequence and save two buffers in each IOCBq | |
14244 | */ | |
14245 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
14246 | if (!iocbq) { | |
14247 | lpfc_in_buf_free(vport->phba, d_buf); | |
14248 | continue; | |
14249 | } | |
14250 | if (!iocbq->context3) { | |
14251 | iocbq->context3 = d_buf; | |
14252 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
14253 | pbde = (struct ulp_bde64 *) |
14254 | &iocbq->iocb.unsli3.sli3Words[4]; | |
14255 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
7851fe2c JS |
14256 | |
14257 | /* We need to get the size out of the right CQE */ | |
14258 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14259 | len = bf_get(lpfc_rcqe_length, | |
14260 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
14261 | iocbq->iocb.unsli3.rcvsli3.acc_len += len; | |
14262 | tot_len += len; | |
4f774513 JS |
14263 | } else { |
14264 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
14265 | if (!iocbq) { | |
14266 | if (first_iocbq) { | |
14267 | first_iocbq->iocb.ulpStatus = | |
14268 | IOSTAT_FCP_RSP_ERROR; | |
14269 | first_iocbq->iocb.un.ulpWord[4] = | |
14270 | IOERR_NO_RESOURCES; | |
14271 | } | |
14272 | lpfc_in_buf_free(vport->phba, d_buf); | |
14273 | continue; | |
14274 | } | |
14275 | iocbq->context2 = d_buf; | |
14276 | iocbq->context3 = NULL; | |
14277 | iocbq->iocb.ulpBdeCount = 1; | |
14278 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
14279 | LPFC_DATA_BUF_SIZE; | |
7851fe2c JS |
14280 | |
14281 | /* We need to get the size out of the right CQE */ | |
14282 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
14283 | len = bf_get(lpfc_rcqe_length, | |
14284 | &hbq_buf->cq_event.cqe.rcqe_cmpl); | |
14285 | tot_len += len; | |
14286 | iocbq->iocb.unsli3.rcvsli3.acc_len = tot_len; | |
14287 | ||
4f774513 JS |
14288 | iocbq->iocb.un.rcvels.remoteID = sid; |
14289 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
14290 | } | |
14291 | } | |
14292 | return first_iocbq; | |
14293 | } | |
14294 | ||
6669f9bb JS |
14295 | static void |
14296 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
14297 | struct hbq_dmabuf *seq_dmabuf) | |
14298 | { | |
14299 | struct fc_frame_header *fc_hdr; | |
14300 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
14301 | struct lpfc_hba *phba = vport->phba; | |
14302 | ||
14303 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
14304 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
14305 | if (!iocbq) { | |
14306 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14307 | "2707 Ring %d handler: Failed to allocate " | |
14308 | "iocb Rctl x%x Type x%x received\n", | |
14309 | LPFC_ELS_RING, | |
14310 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
14311 | return; | |
14312 | } | |
14313 | if (!lpfc_complete_unsol_iocb(phba, | |
14314 | &phba->sli.ring[LPFC_ELS_RING], | |
14315 | iocbq, fc_hdr->fh_r_ctl, | |
14316 | fc_hdr->fh_type)) | |
6d368e53 | 14317 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6669f9bb JS |
14318 | "2540 Ring %d handler: unexpected Rctl " |
14319 | "x%x Type x%x received\n", | |
14320 | LPFC_ELS_RING, | |
14321 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
14322 | ||
14323 | /* Free iocb created in lpfc_prep_seq */ | |
14324 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
14325 | &iocbq->list, list) { | |
14326 | list_del_init(&curr_iocb->list); | |
14327 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
14328 | } | |
14329 | lpfc_sli_release_iocbq(phba, iocbq); | |
14330 | } | |
14331 | ||
4f774513 JS |
14332 | /** |
14333 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
14334 | * @phba: Pointer to HBA context object. | |
14335 | * | |
14336 | * This function is called with no lock held. This function processes all | |
14337 | * the received buffers and gives it to upper layers when a received buffer | |
14338 | * indicates that it is the final frame in the sequence. The interrupt | |
14339 | * service routine processes received buffers at interrupt contexts and adds | |
14340 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
14341 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
14342 | * appropriate receive function when the final frame in a sequence is received. | |
14343 | **/ | |
4d9ab994 JS |
14344 | void |
14345 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
14346 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 14347 | { |
4d9ab994 | 14348 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
14349 | struct fc_frame_header *fc_hdr; |
14350 | struct lpfc_vport *vport; | |
14351 | uint32_t fcfi; | |
4f774513 | 14352 | |
4f774513 | 14353 | /* Process each received buffer */ |
4d9ab994 JS |
14354 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
14355 | /* check to see if this a valid type of frame */ | |
14356 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
14357 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14358 | return; | |
14359 | } | |
7851fe2c JS |
14360 | if ((bf_get(lpfc_cqe_code, |
14361 | &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1)) | |
14362 | fcfi = bf_get(lpfc_rcqe_fcf_id_v1, | |
14363 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
14364 | else | |
14365 | fcfi = bf_get(lpfc_rcqe_fcf_id, | |
14366 | &dmabuf->cq_event.cqe.rcqe_cmpl); | |
4d9ab994 | 14367 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); |
c868595d | 14368 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
4d9ab994 JS |
14369 | /* throw out the frame */ |
14370 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14371 | return; | |
14372 | } | |
6669f9bb JS |
14373 | /* Handle the basic abort sequence (BA_ABTS) event */ |
14374 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
14375 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
14376 | return; | |
14377 | } | |
14378 | ||
4d9ab994 JS |
14379 | /* Link this frame */ |
14380 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
14381 | if (!seq_dmabuf) { | |
14382 | /* unable to add frame to vport - throw it out */ | |
14383 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
14384 | return; | |
14385 | } | |
14386 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 14387 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 14388 | return; |
def9c7a9 | 14389 | |
6669f9bb JS |
14390 | /* Send the complete sequence to the upper layer protocol */ |
14391 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 14392 | } |
6fb120a7 JS |
14393 | |
14394 | /** | |
14395 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
14396 | * @phba: pointer to lpfc hba data structure. | |
14397 | * | |
14398 | * This routine is invoked to post rpi header templates to the | |
14399 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
14400 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
14401 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
14402 | * |
14403 | * This routine does not require any locks. It's usage is expected | |
14404 | * to be driver load or reset recovery when the driver is | |
14405 | * sequential. | |
14406 | * | |
14407 | * Return codes | |
af901ca1 | 14408 | * 0 - successful |
d439d286 | 14409 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
14410 | * When this error occurs, the driver is not guaranteed |
14411 | * to have any rpi regions posted to the device and | |
14412 | * must either attempt to repost the regions or take a | |
14413 | * fatal error. | |
14414 | **/ | |
14415 | int | |
14416 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
14417 | { | |
14418 | struct lpfc_rpi_hdr *rpi_page; | |
14419 | uint32_t rc = 0; | |
6d368e53 JS |
14420 | uint16_t lrpi = 0; |
14421 | ||
14422 | /* SLI4 ports that support extents do not require RPI headers. */ | |
14423 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
14424 | goto exit; | |
14425 | if (phba->sli4_hba.extents_in_use) | |
14426 | return -EIO; | |
6fb120a7 | 14427 | |
6fb120a7 | 14428 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
6d368e53 JS |
14429 | /* |
14430 | * Assign the rpi headers a physical rpi only if the driver | |
14431 | * has not initialized those resources. A port reset only | |
14432 | * needs the headers posted. | |
14433 | */ | |
14434 | if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) != | |
14435 | LPFC_RPI_RSRC_RDY) | |
14436 | rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
14437 | ||
6fb120a7 JS |
14438 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); |
14439 | if (rc != MBX_SUCCESS) { | |
14440 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14441 | "2008 Error %d posting all rpi " | |
14442 | "headers\n", rc); | |
14443 | rc = -EIO; | |
14444 | break; | |
14445 | } | |
14446 | } | |
14447 | ||
6d368e53 JS |
14448 | exit: |
14449 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, | |
14450 | LPFC_RPI_RSRC_RDY); | |
6fb120a7 JS |
14451 | return rc; |
14452 | } | |
14453 | ||
14454 | /** | |
14455 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
14456 | * @phba: pointer to lpfc hba data structure. | |
14457 | * @rpi_page: pointer to the rpi memory region. | |
14458 | * | |
14459 | * This routine is invoked to post a single rpi header to the | |
14460 | * HBA consistent with the SLI-4 interface spec. This memory region | |
14461 | * maps up to 64 rpi context regions. | |
14462 | * | |
14463 | * Return codes | |
af901ca1 | 14464 | * 0 - successful |
d439d286 JS |
14465 | * -ENOMEM - No available memory |
14466 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
14467 | **/ |
14468 | int | |
14469 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
14470 | { | |
14471 | LPFC_MBOXQ_t *mboxq; | |
14472 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
14473 | uint32_t rc = 0; | |
6fb120a7 JS |
14474 | uint32_t shdr_status, shdr_add_status; |
14475 | union lpfc_sli4_cfg_shdr *shdr; | |
14476 | ||
6d368e53 JS |
14477 | /* SLI4 ports that support extents do not require RPI headers. */ |
14478 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
14479 | return rc; | |
14480 | if (phba->sli4_hba.extents_in_use) | |
14481 | return -EIO; | |
14482 | ||
6fb120a7 JS |
14483 | /* The port is notified of the header region via a mailbox command. */ |
14484 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14485 | if (!mboxq) { | |
14486 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14487 | "2001 Unable to allocate memory for issuing " | |
14488 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
14489 | return -ENOMEM; | |
14490 | } | |
14491 | ||
14492 | /* Post all rpi memory regions to the port. */ | |
14493 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
6fb120a7 JS |
14494 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
14495 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
14496 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
14497 | sizeof(struct lpfc_sli4_cfg_mhdr), |
14498 | LPFC_SLI4_MBX_EMBED); | |
6d368e53 JS |
14499 | |
14500 | ||
14501 | /* Post the physical rpi to the port for this rpi header. */ | |
6fb120a7 JS |
14502 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, |
14503 | rpi_page->start_rpi); | |
6d368e53 JS |
14504 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
14505 | hdr_tmpl, rpi_page->page_count); | |
14506 | ||
6fb120a7 JS |
14507 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); |
14508 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 14509 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
14510 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
14511 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14512 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14513 | if (rc != MBX_TIMEOUT) | |
14514 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14515 | if (shdr_status || shdr_add_status || rc) { | |
14516 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14517 | "2514 POST_RPI_HDR mailbox failed with " | |
14518 | "status x%x add_status x%x, mbx status x%x\n", | |
14519 | shdr_status, shdr_add_status, rc); | |
14520 | rc = -ENXIO; | |
14521 | } | |
14522 | return rc; | |
14523 | } | |
14524 | ||
14525 | /** | |
14526 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
14527 | * @phba: pointer to lpfc hba data structure. | |
14528 | * | |
14529 | * This routine is invoked to post rpi header templates to the | |
14530 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
14531 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
14532 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
14533 | * |
14534 | * Returns | |
af901ca1 | 14535 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
14536 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
14537 | **/ | |
14538 | int | |
14539 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
14540 | { | |
6d368e53 JS |
14541 | unsigned long rpi; |
14542 | uint16_t max_rpi, rpi_limit; | |
14543 | uint16_t rpi_remaining, lrpi = 0; | |
6fb120a7 JS |
14544 | struct lpfc_rpi_hdr *rpi_hdr; |
14545 | ||
14546 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
6fb120a7 JS |
14547 | rpi_limit = phba->sli4_hba.next_rpi; |
14548 | ||
14549 | /* | |
6d368e53 JS |
14550 | * Fetch the next logical rpi. Because this index is logical, |
14551 | * the driver starts at 0 each time. | |
6fb120a7 JS |
14552 | */ |
14553 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
14554 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0); |
14555 | if (rpi >= rpi_limit) | |
6fb120a7 JS |
14556 | rpi = LPFC_RPI_ALLOC_ERROR; |
14557 | else { | |
14558 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
14559 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
14560 | phba->sli4_hba.rpi_count++; | |
14561 | } | |
14562 | ||
14563 | /* | |
14564 | * Don't try to allocate more rpi header regions if the device limit | |
6d368e53 | 14565 | * has been exhausted. |
6fb120a7 JS |
14566 | */ |
14567 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
14568 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
14569 | spin_unlock_irq(&phba->hbalock); | |
14570 | return rpi; | |
14571 | } | |
14572 | ||
6d368e53 JS |
14573 | /* |
14574 | * RPI header postings are not required for SLI4 ports capable of | |
14575 | * extents. | |
14576 | */ | |
14577 | if (!phba->sli4_hba.rpi_hdrs_in_use) { | |
14578 | spin_unlock_irq(&phba->hbalock); | |
14579 | return rpi; | |
14580 | } | |
14581 | ||
6fb120a7 JS |
14582 | /* |
14583 | * If the driver is running low on rpi resources, allocate another | |
14584 | * page now. Note that the next_rpi value is used because | |
14585 | * it represents how many are actually in use whereas max_rpi notes | |
14586 | * how many are supported max by the device. | |
14587 | */ | |
6d368e53 | 14588 | rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count; |
6fb120a7 JS |
14589 | spin_unlock_irq(&phba->hbalock); |
14590 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
14591 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
14592 | if (!rpi_hdr) { | |
14593 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14594 | "2002 Error Could not grow rpi " | |
14595 | "count\n"); | |
14596 | } else { | |
6d368e53 JS |
14597 | lrpi = rpi_hdr->start_rpi; |
14598 | rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi]; | |
6fb120a7 JS |
14599 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); |
14600 | } | |
14601 | } | |
14602 | ||
14603 | return rpi; | |
14604 | } | |
14605 | ||
d7c47992 JS |
14606 | /** |
14607 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14608 | * @phba: pointer to lpfc hba data structure. | |
14609 | * | |
14610 | * This routine is invoked to release an rpi to the pool of | |
14611 | * available rpis maintained by the driver. | |
14612 | **/ | |
14613 | void | |
14614 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14615 | { | |
14616 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
14617 | phba->sli4_hba.rpi_count--; | |
14618 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
14619 | } | |
14620 | } | |
14621 | ||
6fb120a7 JS |
14622 | /** |
14623 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
14624 | * @phba: pointer to lpfc hba data structure. | |
14625 | * | |
14626 | * This routine is invoked to release an rpi to the pool of | |
14627 | * available rpis maintained by the driver. | |
14628 | **/ | |
14629 | void | |
14630 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
14631 | { | |
14632 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 14633 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
14634 | spin_unlock_irq(&phba->hbalock); |
14635 | } | |
14636 | ||
14637 | /** | |
14638 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
14639 | * @phba: pointer to lpfc hba data structure. | |
14640 | * | |
14641 | * This routine is invoked to remove the memory region that | |
14642 | * provided rpi via a bitmask. | |
14643 | **/ | |
14644 | void | |
14645 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
14646 | { | |
14647 | kfree(phba->sli4_hba.rpi_bmask); | |
6d368e53 JS |
14648 | kfree(phba->sli4_hba.rpi_ids); |
14649 | bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0); | |
6fb120a7 JS |
14650 | } |
14651 | ||
14652 | /** | |
14653 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
14654 | * @phba: pointer to lpfc hba data structure. | |
14655 | * | |
14656 | * This routine is invoked to remove the memory region that | |
14657 | * provided rpi via a bitmask. | |
14658 | **/ | |
14659 | int | |
14660 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | |
14661 | { | |
14662 | LPFC_MBOXQ_t *mboxq; | |
14663 | struct lpfc_hba *phba = ndlp->phba; | |
14664 | int rc; | |
14665 | ||
14666 | /* The port is notified of the header region via a mailbox command. */ | |
14667 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14668 | if (!mboxq) | |
14669 | return -ENOMEM; | |
14670 | ||
14671 | /* Post all rpi memory regions to the port. */ | |
14672 | lpfc_resume_rpi(mboxq, ndlp); | |
14673 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14674 | if (rc == MBX_NOT_FINISHED) { | |
14675 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
14676 | "2010 Resume RPI Mailbox failed " | |
14677 | "status %d, mbxStatus x%x\n", rc, | |
14678 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
14679 | mempool_free(mboxq, phba->mbox_mem_pool); | |
14680 | return -EIO; | |
14681 | } | |
14682 | return 0; | |
14683 | } | |
14684 | ||
14685 | /** | |
14686 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 14687 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 14688 | * |
76a95d75 | 14689 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
14690 | * |
14691 | * Returns: | |
14692 | * 0 success | |
14693 | * -Evalue otherwise | |
14694 | **/ | |
14695 | int | |
76a95d75 | 14696 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
14697 | { |
14698 | LPFC_MBOXQ_t *mboxq; | |
14699 | int rc = 0; | |
6a9c52cf | 14700 | int retval = MBX_SUCCESS; |
6fb120a7 | 14701 | uint32_t mbox_tmo; |
76a95d75 | 14702 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
14703 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14704 | if (!mboxq) | |
14705 | return -ENOMEM; | |
76a95d75 | 14706 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
a183a15f | 14707 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
6fb120a7 | 14708 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
6fb120a7 | 14709 | if (rc != MBX_SUCCESS) { |
76a95d75 | 14710 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
14711 | "2022 INIT VPI Mailbox failed " |
14712 | "status %d, mbxStatus x%x\n", rc, | |
14713 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 14714 | retval = -EIO; |
6fb120a7 | 14715 | } |
6a9c52cf | 14716 | if (rc != MBX_TIMEOUT) |
76a95d75 | 14717 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
14718 | |
14719 | return retval; | |
6fb120a7 JS |
14720 | } |
14721 | ||
14722 | /** | |
14723 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
14724 | * @phba: pointer to lpfc hba data structure. | |
14725 | * @mboxq: Pointer to mailbox object. | |
14726 | * | |
14727 | * This routine is invoked to manually add a single FCF record. The caller | |
14728 | * must pass a completely initialized FCF_Record. This routine takes | |
14729 | * care of the nonembedded mailbox operations. | |
14730 | **/ | |
14731 | static void | |
14732 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
14733 | { | |
14734 | void *virt_addr; | |
14735 | union lpfc_sli4_cfg_shdr *shdr; | |
14736 | uint32_t shdr_status, shdr_add_status; | |
14737 | ||
14738 | virt_addr = mboxq->sge_array->addr[0]; | |
14739 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
14740 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
14741 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
14742 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
14743 | ||
14744 | if ((shdr_status || shdr_add_status) && | |
14745 | (shdr_status != STATUS_FCF_IN_USE)) | |
14746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14747 | "2558 ADD_FCF_RECORD mailbox failed with " | |
14748 | "status x%x add_status x%x\n", | |
14749 | shdr_status, shdr_add_status); | |
14750 | ||
14751 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14752 | } | |
14753 | ||
14754 | /** | |
14755 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
14756 | * @phba: pointer to lpfc hba data structure. | |
14757 | * @fcf_record: pointer to the initialized fcf record to add. | |
14758 | * | |
14759 | * This routine is invoked to manually add a single FCF record. The caller | |
14760 | * must pass a completely initialized FCF_Record. This routine takes | |
14761 | * care of the nonembedded mailbox operations. | |
14762 | **/ | |
14763 | int | |
14764 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
14765 | { | |
14766 | int rc = 0; | |
14767 | LPFC_MBOXQ_t *mboxq; | |
14768 | uint8_t *bytep; | |
14769 | void *virt_addr; | |
14770 | dma_addr_t phys_addr; | |
14771 | struct lpfc_mbx_sge sge; | |
14772 | uint32_t alloc_len, req_len; | |
14773 | uint32_t fcfindex; | |
14774 | ||
14775 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14776 | if (!mboxq) { | |
14777 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14778 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
14779 | return -ENOMEM; | |
14780 | } | |
14781 | ||
14782 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
14783 | sizeof(uint32_t); | |
14784 | ||
14785 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
14786 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
14787 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
14788 | req_len, LPFC_SLI4_MBX_NEMBED); | |
14789 | if (alloc_len < req_len) { | |
14790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14791 | "2523 Allocated DMA memory size (x%x) is " | |
14792 | "less than the requested DMA memory " | |
14793 | "size (x%x)\n", alloc_len, req_len); | |
14794 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14795 | return -ENOMEM; | |
14796 | } | |
14797 | ||
14798 | /* | |
14799 | * Get the first SGE entry from the non-embedded DMA memory. This | |
14800 | * routine only uses a single SGE. | |
14801 | */ | |
14802 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
14803 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
14804 | virt_addr = mboxq->sge_array->addr[0]; |
14805 | /* | |
14806 | * Configure the FCF record for FCFI 0. This is the driver's | |
14807 | * hardcoded default and gets used in nonFIP mode. | |
14808 | */ | |
14809 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
14810 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
14811 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
14812 | ||
14813 | /* | |
14814 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
14815 | * the FCoE header plus word10. The data copy needs to be endian | |
14816 | * correct. | |
14817 | */ | |
14818 | bytep += sizeof(uint32_t); | |
14819 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
14820 | mboxq->vport = phba->pport; | |
14821 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
14822 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14823 | if (rc == MBX_NOT_FINISHED) { | |
14824 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14825 | "2515 ADD_FCF_RECORD mailbox failed with " | |
14826 | "status 0x%x\n", rc); | |
14827 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14828 | rc = -EIO; | |
14829 | } else | |
14830 | rc = 0; | |
14831 | ||
14832 | return rc; | |
14833 | } | |
14834 | ||
14835 | /** | |
14836 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
14837 | * @phba: pointer to lpfc hba data structure. | |
14838 | * @fcf_record: pointer to the fcf record to write the default data. | |
14839 | * @fcf_index: FCF table entry index. | |
14840 | * | |
14841 | * This routine is invoked to build the driver's default FCF record. The | |
14842 | * values used are hardcoded. This routine handles memory initialization. | |
14843 | * | |
14844 | **/ | |
14845 | void | |
14846 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
14847 | struct fcf_record *fcf_record, | |
14848 | uint16_t fcf_index) | |
14849 | { | |
14850 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
14851 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
14852 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
14853 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
14854 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
14855 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
14856 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
14857 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
14858 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
14859 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
14860 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
14861 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
14862 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
14863 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 14864 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
14865 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
14866 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
14867 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
14868 | /* Set the VLAN bit map */ | |
14869 | if (phba->valid_vlan) { | |
14870 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
14871 | = 1 << (phba->vlan_id % 8); | |
14872 | } | |
14873 | } | |
14874 | ||
14875 | /** | |
0c9ab6f5 | 14876 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
14877 | * @phba: pointer to lpfc hba data structure. |
14878 | * @fcf_index: FCF table entry offset. | |
14879 | * | |
0c9ab6f5 JS |
14880 | * This routine is invoked to scan the entire FCF table by reading FCF |
14881 | * record and processing it one at a time starting from the @fcf_index | |
14882 | * for initial FCF discovery or fast FCF failover rediscovery. | |
14883 | * | |
25985edc | 14884 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 14885 | * otherwise. |
6fb120a7 JS |
14886 | **/ |
14887 | int | |
0c9ab6f5 | 14888 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
14889 | { |
14890 | int rc = 0, error; | |
14891 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 14892 | |
32b9793f | 14893 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
6fb120a7 JS |
14894 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
14895 | if (!mboxq) { | |
14896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
14897 | "2000 Failed to allocate mbox for " | |
14898 | "READ_FCF cmd\n"); | |
4d9ab994 | 14899 | error = -ENOMEM; |
0c9ab6f5 | 14900 | goto fail_fcf_scan; |
6fb120a7 | 14901 | } |
ecfd03c6 | 14902 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 14903 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
14904 | if (rc) { |
14905 | error = -EINVAL; | |
0c9ab6f5 | 14906 | goto fail_fcf_scan; |
6fb120a7 | 14907 | } |
ecfd03c6 | 14908 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 14909 | mboxq->vport = phba->pport; |
0c9ab6f5 | 14910 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
14911 | |
14912 | spin_lock_irq(&phba->hbalock); | |
14913 | phba->hba_flag |= FCF_TS_INPROG; | |
14914 | spin_unlock_irq(&phba->hbalock); | |
14915 | ||
6fb120a7 | 14916 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 14917 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 14918 | error = -EIO; |
ecfd03c6 | 14919 | else { |
38b92ef8 JS |
14920 | /* Reset eligible FCF count for new scan */ |
14921 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 14922 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 14923 | error = 0; |
32b9793f | 14924 | } |
0c9ab6f5 | 14925 | fail_fcf_scan: |
4d9ab994 JS |
14926 | if (error) { |
14927 | if (mboxq) | |
14928 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 14929 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 14930 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 14931 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
14932 | spin_unlock_irq(&phba->hbalock); |
14933 | } | |
6fb120a7 JS |
14934 | return error; |
14935 | } | |
a0c87cbd | 14936 | |
0c9ab6f5 | 14937 | /** |
a93ff37a | 14938 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
14939 | * @phba: pointer to lpfc hba data structure. |
14940 | * @fcf_index: FCF table entry offset. | |
14941 | * | |
14942 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 14943 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 14944 | * |
25985edc | 14945 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
14946 | * otherwise. |
14947 | **/ | |
14948 | int | |
14949 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
14950 | { | |
14951 | int rc = 0, error; | |
14952 | LPFC_MBOXQ_t *mboxq; | |
14953 | ||
14954 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
14955 | if (!mboxq) { | |
14956 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
14957 | "2763 Failed to allocate mbox for " | |
14958 | "READ_FCF cmd\n"); | |
14959 | error = -ENOMEM; | |
14960 | goto fail_fcf_read; | |
14961 | } | |
14962 | /* Construct the read FCF record mailbox command */ | |
14963 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
14964 | if (rc) { | |
14965 | error = -EINVAL; | |
14966 | goto fail_fcf_read; | |
14967 | } | |
14968 | /* Issue the mailbox command asynchronously */ | |
14969 | mboxq->vport = phba->pport; | |
14970 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
14971 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
14972 | if (rc == MBX_NOT_FINISHED) | |
14973 | error = -EIO; | |
14974 | else | |
14975 | error = 0; | |
14976 | ||
14977 | fail_fcf_read: | |
14978 | if (error && mboxq) | |
14979 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
14980 | return error; | |
14981 | } | |
14982 | ||
14983 | /** | |
14984 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
14985 | * @phba: pointer to lpfc hba data structure. | |
14986 | * @fcf_index: FCF table entry offset. | |
14987 | * | |
14988 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 14989 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 14990 | * |
25985edc | 14991 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
14992 | * otherwise. |
14993 | **/ | |
14994 | int | |
14995 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
14996 | { | |
14997 | int rc = 0, error; | |
14998 | LPFC_MBOXQ_t *mboxq; | |
14999 | ||
15000 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15001 | if (!mboxq) { | |
15002 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
15003 | "2758 Failed to allocate mbox for " | |
15004 | "READ_FCF cmd\n"); | |
15005 | error = -ENOMEM; | |
15006 | goto fail_fcf_read; | |
15007 | } | |
15008 | /* Construct the read FCF record mailbox command */ | |
15009 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
15010 | if (rc) { | |
15011 | error = -EINVAL; | |
15012 | goto fail_fcf_read; | |
15013 | } | |
15014 | /* Issue the mailbox command asynchronously */ | |
15015 | mboxq->vport = phba->pport; | |
15016 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
15017 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
15018 | if (rc == MBX_NOT_FINISHED) | |
15019 | error = -EIO; | |
15020 | else | |
15021 | error = 0; | |
15022 | ||
15023 | fail_fcf_read: | |
15024 | if (error && mboxq) | |
15025 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
15026 | return error; | |
15027 | } | |
15028 | ||
7d791df7 JS |
15029 | /** |
15030 | * lpfc_check_next_fcf_pri | |
15031 | * phba pointer to the lpfc_hba struct for this port. | |
15032 | * This routine is called from the lpfc_sli4_fcf_rr_next_index_get | |
15033 | * routine when the rr_bmask is empty. The FCF indecies are put into the | |
15034 | * rr_bmask based on their priority level. Starting from the highest priority | |
15035 | * to the lowest. The most likely FCF candidate will be in the highest | |
15036 | * priority group. When this routine is called it searches the fcf_pri list for | |
15037 | * next lowest priority group and repopulates the rr_bmask with only those | |
15038 | * fcf_indexes. | |
15039 | * returns: | |
15040 | * 1=success 0=failure | |
15041 | **/ | |
15042 | int | |
15043 | lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba) | |
15044 | { | |
15045 | uint16_t next_fcf_pri; | |
15046 | uint16_t last_index; | |
15047 | struct lpfc_fcf_pri *fcf_pri; | |
15048 | int rc; | |
15049 | int ret = 0; | |
15050 | ||
15051 | last_index = find_first_bit(phba->fcf.fcf_rr_bmask, | |
15052 | LPFC_SLI4_FCF_TBL_INDX_MAX); | |
15053 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
15054 | "3060 Last IDX %d\n", last_index); | |
15055 | if (list_empty(&phba->fcf.fcf_pri_list)) { | |
15056 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
15057 | "3061 Last IDX %d\n", last_index); | |
15058 | return 0; /* Empty rr list */ | |
15059 | } | |
15060 | next_fcf_pri = 0; | |
15061 | /* | |
15062 | * Clear the rr_bmask and set all of the bits that are at this | |
15063 | * priority. | |
15064 | */ | |
15065 | memset(phba->fcf.fcf_rr_bmask, 0, | |
15066 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
15067 | spin_lock_irq(&phba->hbalock); | |
15068 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15069 | if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED) | |
15070 | continue; | |
15071 | /* | |
15072 | * the 1st priority that has not FLOGI failed | |
15073 | * will be the highest. | |
15074 | */ | |
15075 | if (!next_fcf_pri) | |
15076 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
15077 | spin_unlock_irq(&phba->hbalock); | |
15078 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
15079 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
15080 | fcf_pri->fcf_rec.fcf_index); | |
15081 | if (rc) | |
15082 | return 0; | |
15083 | } | |
15084 | spin_lock_irq(&phba->hbalock); | |
15085 | } | |
15086 | /* | |
15087 | * if next_fcf_pri was not set above and the list is not empty then | |
15088 | * we have failed flogis on all of them. So reset flogi failed | |
15089 | * and start at the begining. | |
15090 | */ | |
15091 | if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) { | |
15092 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15093 | fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED; | |
15094 | /* | |
15095 | * the 1st priority that has not FLOGI failed | |
15096 | * will be the highest. | |
15097 | */ | |
15098 | if (!next_fcf_pri) | |
15099 | next_fcf_pri = fcf_pri->fcf_rec.priority; | |
15100 | spin_unlock_irq(&phba->hbalock); | |
15101 | if (fcf_pri->fcf_rec.priority == next_fcf_pri) { | |
15102 | rc = lpfc_sli4_fcf_rr_index_set(phba, | |
15103 | fcf_pri->fcf_rec.fcf_index); | |
15104 | if (rc) | |
15105 | return 0; | |
15106 | } | |
15107 | spin_lock_irq(&phba->hbalock); | |
15108 | } | |
15109 | } else | |
15110 | ret = 1; | |
15111 | spin_unlock_irq(&phba->hbalock); | |
15112 | ||
15113 | return ret; | |
15114 | } | |
0c9ab6f5 JS |
15115 | /** |
15116 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
15117 | * @phba: pointer to lpfc hba data structure. | |
15118 | * | |
15119 | * This routine is to get the next eligible FCF record index in a round | |
15120 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 15121 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
15122 | * shall be returned, otherwise, the next eligible FCF record's index |
15123 | * shall be returned. | |
15124 | **/ | |
15125 | uint16_t | |
15126 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
15127 | { | |
15128 | uint16_t next_fcf_index; | |
15129 | ||
3804dc84 | 15130 | /* Search start from next bit of currently registered FCF index */ |
7d791df7 | 15131 | next_priority: |
3804dc84 JS |
15132 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % |
15133 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
15134 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
15135 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
15136 | next_fcf_index); |
15137 | ||
0c9ab6f5 | 15138 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
7d791df7 JS |
15139 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
15140 | /* | |
15141 | * If we have wrapped then we need to clear the bits that | |
15142 | * have been tested so that we can detect when we should | |
15143 | * change the priority level. | |
15144 | */ | |
0c9ab6f5 JS |
15145 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
15146 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
7d791df7 JS |
15147 | } |
15148 | ||
3804dc84 JS |
15149 | |
15150 | /* Check roundrobin failover list empty condition */ | |
7d791df7 JS |
15151 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX || |
15152 | next_fcf_index == phba->fcf.current_rec.fcf_indx) { | |
15153 | /* | |
15154 | * If next fcf index is not found check if there are lower | |
15155 | * Priority level fcf's in the fcf_priority list. | |
15156 | * Set up the rr_bmask with all of the avaiable fcf bits | |
15157 | * at that level and continue the selection process. | |
15158 | */ | |
15159 | if (lpfc_check_next_fcf_pri_level(phba)) | |
15160 | goto next_priority; | |
3804dc84 JS |
15161 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, |
15162 | "2844 No roundrobin failover FCF available\n"); | |
7d791df7 JS |
15163 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) |
15164 | return LPFC_FCOE_FCF_NEXT_NONE; | |
15165 | else { | |
15166 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
15167 | "3063 Only FCF available idx %d, flag %x\n", | |
15168 | next_fcf_index, | |
15169 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag); | |
15170 | return next_fcf_index; | |
15171 | } | |
3804dc84 JS |
15172 | } |
15173 | ||
7d791df7 JS |
15174 | if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX && |
15175 | phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag & | |
15176 | LPFC_FCF_FLOGI_FAILED) | |
15177 | goto next_priority; | |
15178 | ||
3804dc84 | 15179 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
15180 | "2845 Get next roundrobin failover FCF (x%x)\n", |
15181 | next_fcf_index); | |
15182 | ||
0c9ab6f5 JS |
15183 | return next_fcf_index; |
15184 | } | |
15185 | ||
15186 | /** | |
15187 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
15188 | * @phba: pointer to lpfc hba data structure. | |
15189 | * | |
15190 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 15191 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
15192 | * does not go beyond the range of the driver allocated bmask dimension |
15193 | * before setting the bit. | |
15194 | * | |
15195 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
15196 | * -EINVAL. | |
15197 | **/ | |
15198 | int | |
15199 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
15200 | { | |
15201 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
15202 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
15203 | "2610 FCF (x%x) reached driver's book " |
15204 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
15205 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
15206 | return -EINVAL; | |
15207 | } | |
15208 | /* Set the eligible FCF record index bmask */ | |
15209 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
15210 | ||
3804dc84 | 15211 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 15212 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
15213 | "bmask\n", fcf_index); |
15214 | ||
0c9ab6f5 JS |
15215 | return 0; |
15216 | } | |
15217 | ||
15218 | /** | |
3804dc84 | 15219 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
15220 | * @phba: pointer to lpfc hba data structure. |
15221 | * | |
15222 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 15223 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
15224 | * does not go beyond the range of the driver allocated bmask dimension |
15225 | * before clearing the bit. | |
15226 | **/ | |
15227 | void | |
15228 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
15229 | { | |
7d791df7 | 15230 | struct lpfc_fcf_pri *fcf_pri; |
0c9ab6f5 JS |
15231 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { |
15232 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
15233 | "2762 FCF (x%x) reached driver's book " |
15234 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
15235 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
15236 | return; | |
15237 | } | |
15238 | /* Clear the eligible FCF record index bmask */ | |
7d791df7 JS |
15239 | spin_lock_irq(&phba->hbalock); |
15240 | list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) { | |
15241 | if (fcf_pri->fcf_rec.fcf_index == fcf_index) { | |
15242 | list_del_init(&fcf_pri->list); | |
15243 | break; | |
15244 | } | |
15245 | } | |
15246 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 15247 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); |
3804dc84 JS |
15248 | |
15249 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 15250 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 15251 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
15252 | } |
15253 | ||
ecfd03c6 JS |
15254 | /** |
15255 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
15256 | * @phba: pointer to lpfc hba data structure. | |
15257 | * | |
15258 | * This routine is the completion routine for the rediscover FCF table mailbox | |
15259 | * command. If the mailbox command returned failure, it will try to stop the | |
15260 | * FCF rediscover wait timer. | |
15261 | **/ | |
15262 | void | |
15263 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
15264 | { | |
15265 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
15266 | uint32_t shdr_status, shdr_add_status; | |
15267 | ||
15268 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
15269 | ||
15270 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
15271 | &redisc_fcf->header.cfg_shdr.response); | |
15272 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
15273 | &redisc_fcf->header.cfg_shdr.response); | |
15274 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 15275 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
15276 | "2746 Requesting for FCF rediscovery failed " |
15277 | "status x%x add_status x%x\n", | |
15278 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 15279 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 15280 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 15281 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
15282 | spin_unlock_irq(&phba->hbalock); |
15283 | /* | |
15284 | * CVL event triggered FCF rediscover request failed, | |
15285 | * last resort to re-try current registered FCF entry. | |
15286 | */ | |
15287 | lpfc_retry_pport_discovery(phba); | |
15288 | } else { | |
15289 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 15290 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
15291 | spin_unlock_irq(&phba->hbalock); |
15292 | /* | |
15293 | * DEAD FCF event triggered FCF rediscover request | |
15294 | * failed, last resort to fail over as a link down | |
15295 | * to FCF registration. | |
15296 | */ | |
15297 | lpfc_sli4_fcf_dead_failthrough(phba); | |
15298 | } | |
0c9ab6f5 JS |
15299 | } else { |
15300 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 15301 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
15302 | /* |
15303 | * Start FCF rediscovery wait timer for pending FCF | |
15304 | * before rescan FCF record table. | |
15305 | */ | |
15306 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 15307 | } |
ecfd03c6 JS |
15308 | |
15309 | mempool_free(mbox, phba->mbox_mem_pool); | |
15310 | } | |
15311 | ||
15312 | /** | |
3804dc84 | 15313 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
15314 | * @phba: pointer to lpfc hba data structure. |
15315 | * | |
15316 | * This routine is invoked to request for rediscovery of the entire FCF table | |
15317 | * by the port. | |
15318 | **/ | |
15319 | int | |
15320 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
15321 | { | |
15322 | LPFC_MBOXQ_t *mbox; | |
15323 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
15324 | int rc, length; | |
15325 | ||
0c9ab6f5 JS |
15326 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
15327 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
15328 | ||
ecfd03c6 JS |
15329 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15330 | if (!mbox) { | |
15331 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15332 | "2745 Failed to allocate mbox for " | |
15333 | "requesting FCF rediscover.\n"); | |
15334 | return -ENOMEM; | |
15335 | } | |
15336 | ||
15337 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
15338 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
15339 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
15340 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
15341 | length, LPFC_SLI4_MBX_EMBED); | |
15342 | ||
15343 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
15344 | /* Set count to 0 for invalidating the entire FCF database */ | |
15345 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
15346 | ||
15347 | /* Issue the mailbox command asynchronously */ | |
15348 | mbox->vport = phba->pport; | |
15349 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
15350 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
15351 | ||
15352 | if (rc == MBX_NOT_FINISHED) { | |
15353 | mempool_free(mbox, phba->mbox_mem_pool); | |
15354 | return -EIO; | |
15355 | } | |
15356 | return 0; | |
15357 | } | |
15358 | ||
fc2b989b JS |
15359 | /** |
15360 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
15361 | * @phba: pointer to lpfc hba data structure. | |
15362 | * | |
15363 | * This function is the failover routine as a last resort to the FCF DEAD | |
15364 | * event when driver failed to perform fast FCF failover. | |
15365 | **/ | |
15366 | void | |
15367 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
15368 | { | |
15369 | uint32_t link_state; | |
15370 | ||
15371 | /* | |
15372 | * Last resort as FCF DEAD event failover will treat this as | |
15373 | * a link down, but save the link state because we don't want | |
15374 | * it to be changed to Link Down unless it is already down. | |
15375 | */ | |
15376 | link_state = phba->link_state; | |
15377 | lpfc_linkdown(phba); | |
15378 | phba->link_state = link_state; | |
15379 | ||
15380 | /* Unregister FCF if no devices connected to it */ | |
15381 | lpfc_unregister_unused_fcf(phba); | |
15382 | } | |
15383 | ||
a0c87cbd | 15384 | /** |
026abb87 | 15385 | * lpfc_sli_get_config_region23 - Get sli3 port region 23 data. |
a0c87cbd | 15386 | * @phba: pointer to lpfc hba data structure. |
026abb87 | 15387 | * @rgn23_data: pointer to configure region 23 data. |
a0c87cbd | 15388 | * |
026abb87 JS |
15389 | * This function gets SLI3 port configure region 23 data through memory dump |
15390 | * mailbox command. When it successfully retrieves data, the size of the data | |
15391 | * will be returned, otherwise, 0 will be returned. | |
a0c87cbd | 15392 | **/ |
026abb87 JS |
15393 | static uint32_t |
15394 | lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
a0c87cbd JS |
15395 | { |
15396 | LPFC_MBOXQ_t *pmb = NULL; | |
15397 | MAILBOX_t *mb; | |
026abb87 | 15398 | uint32_t offset = 0; |
a0c87cbd JS |
15399 | int rc; |
15400 | ||
026abb87 JS |
15401 | if (!rgn23_data) |
15402 | return 0; | |
15403 | ||
a0c87cbd JS |
15404 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
15405 | if (!pmb) { | |
15406 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
026abb87 JS |
15407 | "2600 failed to allocate mailbox memory\n"); |
15408 | return 0; | |
a0c87cbd JS |
15409 | } |
15410 | mb = &pmb->u.mb; | |
15411 | ||
a0c87cbd JS |
15412 | do { |
15413 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
15414 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
15415 | ||
15416 | if (rc != MBX_SUCCESS) { | |
15417 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
026abb87 JS |
15418 | "2601 failed to read config " |
15419 | "region 23, rc 0x%x Status 0x%x\n", | |
15420 | rc, mb->mbxStatus); | |
a0c87cbd JS |
15421 | mb->un.varDmp.word_cnt = 0; |
15422 | } | |
15423 | /* | |
15424 | * dump mem may return a zero when finished or we got a | |
15425 | * mailbox error, either way we are done. | |
15426 | */ | |
15427 | if (mb->un.varDmp.word_cnt == 0) | |
15428 | break; | |
15429 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
15430 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
15431 | ||
15432 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
026abb87 JS |
15433 | rgn23_data + offset, |
15434 | mb->un.varDmp.word_cnt); | |
a0c87cbd JS |
15435 | offset += mb->un.varDmp.word_cnt; |
15436 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
15437 | ||
026abb87 JS |
15438 | mempool_free(pmb, phba->mbox_mem_pool); |
15439 | return offset; | |
15440 | } | |
15441 | ||
15442 | /** | |
15443 | * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data. | |
15444 | * @phba: pointer to lpfc hba data structure. | |
15445 | * @rgn23_data: pointer to configure region 23 data. | |
15446 | * | |
15447 | * This function gets SLI4 port configure region 23 data through memory dump | |
15448 | * mailbox command. When it successfully retrieves data, the size of the data | |
15449 | * will be returned, otherwise, 0 will be returned. | |
15450 | **/ | |
15451 | static uint32_t | |
15452 | lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data) | |
15453 | { | |
15454 | LPFC_MBOXQ_t *mboxq = NULL; | |
15455 | struct lpfc_dmabuf *mp = NULL; | |
15456 | struct lpfc_mqe *mqe; | |
15457 | uint32_t data_length = 0; | |
15458 | int rc; | |
15459 | ||
15460 | if (!rgn23_data) | |
15461 | return 0; | |
15462 | ||
15463 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15464 | if (!mboxq) { | |
15465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15466 | "3105 failed to allocate mailbox memory\n"); | |
15467 | return 0; | |
15468 | } | |
15469 | ||
15470 | if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) | |
15471 | goto out; | |
15472 | mqe = &mboxq->u.mqe; | |
15473 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
15474 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
15475 | if (rc) | |
15476 | goto out; | |
15477 | data_length = mqe->un.mb_words[5]; | |
15478 | if (data_length == 0) | |
15479 | goto out; | |
15480 | if (data_length > DMP_RGN23_SIZE) { | |
15481 | data_length = 0; | |
15482 | goto out; | |
15483 | } | |
15484 | lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length); | |
15485 | out: | |
15486 | mempool_free(mboxq, phba->mbox_mem_pool); | |
15487 | if (mp) { | |
15488 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
15489 | kfree(mp); | |
15490 | } | |
15491 | return data_length; | |
15492 | } | |
15493 | ||
15494 | /** | |
15495 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
15496 | * @phba: pointer to lpfc hba data structure. | |
15497 | * | |
15498 | * This function read region 23 and parse TLV for port status to | |
15499 | * decide if the user disaled the port. If the TLV indicates the | |
15500 | * port is disabled, the hba_flag is set accordingly. | |
15501 | **/ | |
15502 | void | |
15503 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
15504 | { | |
15505 | uint8_t *rgn23_data = NULL; | |
15506 | uint32_t if_type, data_size, sub_tlv_len, tlv_offset; | |
15507 | uint32_t offset = 0; | |
15508 | ||
15509 | /* Get adapter Region 23 data */ | |
15510 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
15511 | if (!rgn23_data) | |
15512 | goto out; | |
15513 | ||
15514 | if (phba->sli_rev < LPFC_SLI_REV4) | |
15515 | data_size = lpfc_sli_get_config_region23(phba, rgn23_data); | |
15516 | else { | |
15517 | if_type = bf_get(lpfc_sli_intf_if_type, | |
15518 | &phba->sli4_hba.sli_intf); | |
15519 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) | |
15520 | goto out; | |
15521 | data_size = lpfc_sli4_get_config_region23(phba, rgn23_data); | |
15522 | } | |
a0c87cbd JS |
15523 | |
15524 | if (!data_size) | |
15525 | goto out; | |
15526 | ||
15527 | /* Check the region signature first */ | |
15528 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
15529 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15530 | "2619 Config region 23 has bad signature\n"); | |
15531 | goto out; | |
15532 | } | |
15533 | offset += 4; | |
15534 | ||
15535 | /* Check the data structure version */ | |
15536 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
15537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15538 | "2620 Config region 23 has bad version\n"); | |
15539 | goto out; | |
15540 | } | |
15541 | offset += 4; | |
15542 | ||
15543 | /* Parse TLV entries in the region */ | |
15544 | while (offset < data_size) { | |
15545 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
15546 | break; | |
15547 | /* | |
15548 | * If the TLV is not driver specific TLV or driver id is | |
15549 | * not linux driver id, skip the record. | |
15550 | */ | |
15551 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
15552 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
15553 | (rgn23_data[offset + 3] != 0)) { | |
15554 | offset += rgn23_data[offset + 1] * 4 + 4; | |
15555 | continue; | |
15556 | } | |
15557 | ||
15558 | /* Driver found a driver specific TLV in the config region */ | |
15559 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
15560 | offset += 4; | |
15561 | tlv_offset = 0; | |
15562 | ||
15563 | /* | |
15564 | * Search for configured port state sub-TLV. | |
15565 | */ | |
15566 | while ((offset < data_size) && | |
15567 | (tlv_offset < sub_tlv_len)) { | |
15568 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
15569 | offset += 4; | |
15570 | tlv_offset += 4; | |
15571 | break; | |
15572 | } | |
15573 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
15574 | offset += rgn23_data[offset + 1] * 4 + 4; | |
15575 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
15576 | continue; | |
15577 | } | |
15578 | ||
15579 | /* This HBA contains PORT_STE configured */ | |
15580 | if (!rgn23_data[offset + 2]) | |
15581 | phba->hba_flag |= LINK_DISABLED; | |
15582 | ||
15583 | goto out; | |
15584 | } | |
15585 | } | |
026abb87 | 15586 | |
a0c87cbd | 15587 | out: |
a0c87cbd JS |
15588 | kfree(rgn23_data); |
15589 | return; | |
15590 | } | |
695a814e | 15591 | |
52d52440 JS |
15592 | /** |
15593 | * lpfc_wr_object - write an object to the firmware | |
15594 | * @phba: HBA structure that indicates port to create a queue on. | |
15595 | * @dmabuf_list: list of dmabufs to write to the port. | |
15596 | * @size: the total byte value of the objects to write to the port. | |
15597 | * @offset: the current offset to be used to start the transfer. | |
15598 | * | |
15599 | * This routine will create a wr_object mailbox command to send to the port. | |
15600 | * the mailbox command will be constructed using the dma buffers described in | |
15601 | * @dmabuf_list to create a list of BDEs. This routine will fill in as many | |
15602 | * BDEs that the imbedded mailbox can support. The @offset variable will be | |
15603 | * used to indicate the starting offset of the transfer and will also return | |
15604 | * the offset after the write object mailbox has completed. @size is used to | |
15605 | * determine the end of the object and whether the eof bit should be set. | |
15606 | * | |
15607 | * Return 0 is successful and offset will contain the the new offset to use | |
15608 | * for the next write. | |
15609 | * Return negative value for error cases. | |
15610 | **/ | |
15611 | int | |
15612 | lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list, | |
15613 | uint32_t size, uint32_t *offset) | |
15614 | { | |
15615 | struct lpfc_mbx_wr_object *wr_object; | |
15616 | LPFC_MBOXQ_t *mbox; | |
15617 | int rc = 0, i = 0; | |
15618 | uint32_t shdr_status, shdr_add_status; | |
15619 | uint32_t mbox_tmo; | |
15620 | union lpfc_sli4_cfg_shdr *shdr; | |
15621 | struct lpfc_dmabuf *dmabuf; | |
15622 | uint32_t written = 0; | |
15623 | ||
15624 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
15625 | if (!mbox) | |
15626 | return -ENOMEM; | |
15627 | ||
15628 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
15629 | LPFC_MBOX_OPCODE_WRITE_OBJECT, | |
15630 | sizeof(struct lpfc_mbx_wr_object) - | |
15631 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); | |
15632 | ||
15633 | wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object; | |
15634 | wr_object->u.request.write_offset = *offset; | |
15635 | sprintf((uint8_t *)wr_object->u.request.object_name, "/"); | |
15636 | wr_object->u.request.object_name[0] = | |
15637 | cpu_to_le32(wr_object->u.request.object_name[0]); | |
15638 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0); | |
15639 | list_for_each_entry(dmabuf, dmabuf_list, list) { | |
15640 | if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size) | |
15641 | break; | |
15642 | wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys); | |
15643 | wr_object->u.request.bde[i].addrHigh = | |
15644 | putPaddrHigh(dmabuf->phys); | |
15645 | if (written + SLI4_PAGE_SIZE >= size) { | |
15646 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
15647 | (size - written); | |
15648 | written += (size - written); | |
15649 | bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1); | |
15650 | } else { | |
15651 | wr_object->u.request.bde[i].tus.f.bdeSize = | |
15652 | SLI4_PAGE_SIZE; | |
15653 | written += SLI4_PAGE_SIZE; | |
15654 | } | |
15655 | i++; | |
15656 | } | |
15657 | wr_object->u.request.bde_count = i; | |
15658 | bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written); | |
15659 | if (!phba->sli4_hba.intr_enable) | |
15660 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
15661 | else { | |
a183a15f | 15662 | mbox_tmo = lpfc_mbox_tmo_val(phba, mbox); |
52d52440 JS |
15663 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); |
15664 | } | |
15665 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
15666 | shdr = (union lpfc_sli4_cfg_shdr *) &wr_object->header.cfg_shdr; | |
15667 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
15668 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
15669 | if (rc != MBX_TIMEOUT) | |
15670 | mempool_free(mbox, phba->mbox_mem_pool); | |
15671 | if (shdr_status || shdr_add_status || rc) { | |
15672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
15673 | "3025 Write Object mailbox failed with " | |
15674 | "status x%x add_status x%x, mbx status x%x\n", | |
15675 | shdr_status, shdr_add_status, rc); | |
15676 | rc = -ENXIO; | |
15677 | } else | |
15678 | *offset += wr_object->u.response.actual_write_length; | |
15679 | return rc; | |
15680 | } | |
15681 | ||
695a814e JS |
15682 | /** |
15683 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
15684 | * @vport: pointer to vport data structure. | |
15685 | * | |
15686 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
15687 | * and REG_VPI mailbox commands associated with the vport. This function | |
15688 | * is called when driver want to restart discovery of the vport due to | |
15689 | * a Clear Virtual Link event. | |
15690 | **/ | |
15691 | void | |
15692 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
15693 | { | |
15694 | struct lpfc_hba *phba = vport->phba; | |
15695 | LPFC_MBOXQ_t *mb, *nextmb; | |
15696 | struct lpfc_dmabuf *mp; | |
78730cfe | 15697 | struct lpfc_nodelist *ndlp; |
d439d286 | 15698 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 15699 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 15700 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 15701 | uint8_t restart_loop; |
695a814e | 15702 | |
d439d286 | 15703 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
15704 | spin_lock_irq(&phba->hbalock); |
15705 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
15706 | if (mb->vport != vport) | |
15707 | continue; | |
15708 | ||
15709 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
15710 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
15711 | continue; | |
15712 | ||
d439d286 JS |
15713 | list_del(&mb->list); |
15714 | list_add_tail(&mb->list, &mbox_cmd_list); | |
15715 | } | |
15716 | /* Clean up active mailbox command with the vport */ | |
15717 | mb = phba->sli.mbox_active; | |
15718 | if (mb && (mb->vport == vport)) { | |
15719 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
15720 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
15721 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
15722 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
15723 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
15724 | /* Put reference count for delayed processing */ | |
15725 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
15726 | /* Unregister the RPI when mailbox complete */ | |
15727 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
15728 | } | |
15729 | } | |
63e801ce JS |
15730 | /* Cleanup any mailbox completions which are not yet processed */ |
15731 | do { | |
15732 | restart_loop = 0; | |
15733 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
15734 | /* | |
15735 | * If this mailox is already processed or it is | |
15736 | * for another vport ignore it. | |
15737 | */ | |
15738 | if ((mb->vport != vport) || | |
15739 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
15740 | continue; | |
15741 | ||
15742 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
15743 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
15744 | continue; | |
15745 | ||
15746 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
15747 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
15748 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
15749 | /* Unregister the RPI when mailbox complete */ | |
15750 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
15751 | restart_loop = 1; | |
15752 | spin_unlock_irq(&phba->hbalock); | |
15753 | spin_lock(shost->host_lock); | |
15754 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15755 | spin_unlock(shost->host_lock); | |
15756 | spin_lock_irq(&phba->hbalock); | |
15757 | break; | |
15758 | } | |
15759 | } | |
15760 | } while (restart_loop); | |
15761 | ||
d439d286 JS |
15762 | spin_unlock_irq(&phba->hbalock); |
15763 | ||
15764 | /* Release the cleaned-up mailbox commands */ | |
15765 | while (!list_empty(&mbox_cmd_list)) { | |
15766 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
15767 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
15768 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
15769 | if (mp) { | |
15770 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
15771 | kfree(mp); | |
15772 | } | |
78730cfe | 15773 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 15774 | mb->context2 = NULL; |
78730cfe | 15775 | if (ndlp) { |
ec21b3b0 | 15776 | spin_lock(shost->host_lock); |
589a52d6 | 15777 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 15778 | spin_unlock(shost->host_lock); |
78730cfe | 15779 | lpfc_nlp_put(ndlp); |
78730cfe | 15780 | } |
695a814e | 15781 | } |
695a814e JS |
15782 | mempool_free(mb, phba->mbox_mem_pool); |
15783 | } | |
d439d286 JS |
15784 | |
15785 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
15786 | if (act_mbx_ndlp) { | |
15787 | spin_lock(shost->host_lock); | |
15788 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
15789 | spin_unlock(shost->host_lock); | |
15790 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 15791 | } |
695a814e JS |
15792 | } |
15793 | ||
2a9bf3d0 JS |
15794 | /** |
15795 | * lpfc_drain_txq - Drain the txq | |
15796 | * @phba: Pointer to HBA context object. | |
15797 | * | |
15798 | * This function attempt to submit IOCBs on the txq | |
15799 | * to the adapter. For SLI4 adapters, the txq contains | |
15800 | * ELS IOCBs that have been deferred because the there | |
15801 | * are no SGLs. This congestion can occur with large | |
15802 | * vport counts during node discovery. | |
15803 | **/ | |
15804 | ||
15805 | uint32_t | |
15806 | lpfc_drain_txq(struct lpfc_hba *phba) | |
15807 | { | |
15808 | LIST_HEAD(completions); | |
15809 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
15810 | struct lpfc_iocbq *piocbq = 0; | |
15811 | unsigned long iflags = 0; | |
15812 | char *fail_msg = NULL; | |
15813 | struct lpfc_sglq *sglq; | |
15814 | union lpfc_wqe wqe; | |
15815 | ||
15816 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15817 | if (pring->txq_cnt > pring->txq_max) | |
15818 | pring->txq_max = pring->txq_cnt; | |
15819 | ||
15820 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15821 | ||
15822 | while (pring->txq_cnt) { | |
15823 | spin_lock_irqsave(&phba->hbalock, iflags); | |
15824 | ||
19ca7609 JS |
15825 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
15826 | sglq = __lpfc_sli_get_sglq(phba, piocbq); | |
2a9bf3d0 | 15827 | if (!sglq) { |
19ca7609 | 15828 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
15829 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
15830 | break; | |
15831 | } else { | |
2a9bf3d0 JS |
15832 | if (!piocbq) { |
15833 | /* The txq_cnt out of sync. This should | |
15834 | * never happen | |
15835 | */ | |
15836 | sglq = __lpfc_clear_active_sglq(phba, | |
6d368e53 | 15837 | sglq->sli4_lxritag); |
2a9bf3d0 JS |
15838 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
15839 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15840 | "2823 txq empty and txq_cnt is %d\n ", | |
15841 | pring->txq_cnt); | |
15842 | break; | |
15843 | } | |
15844 | } | |
15845 | ||
15846 | /* The xri and iocb resources secured, | |
15847 | * attempt to issue request | |
15848 | */ | |
6d368e53 | 15849 | piocbq->sli4_lxritag = sglq->sli4_lxritag; |
2a9bf3d0 JS |
15850 | piocbq->sli4_xritag = sglq->sli4_xritag; |
15851 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
15852 | fail_msg = "to convert bpl to sgl"; | |
15853 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
15854 | fail_msg = "to convert iocb to wqe"; | |
15855 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
15856 | fail_msg = " - Wq is full"; | |
15857 | else | |
15858 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
15859 | ||
15860 | if (fail_msg) { | |
15861 | /* Failed means we can't issue and need to cancel */ | |
15862 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
15863 | "2822 IOCB failed %s iotag 0x%x " | |
15864 | "xri 0x%x\n", | |
15865 | fail_msg, | |
15866 | piocbq->iotag, piocbq->sli4_xritag); | |
15867 | list_add_tail(&piocbq->list, &completions); | |
15868 | } | |
15869 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
15870 | } | |
15871 | ||
2a9bf3d0 JS |
15872 | /* Cancel all the IOCBs that cannot be issued */ |
15873 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
15874 | IOERR_SLI_ABORTED); | |
15875 | ||
15876 | return pring->txq_cnt; | |
15877 | } |