]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
792581de | 4 | * Copyright (C) 2004-2011 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | |
91886523 | 28 | #include <scsi/scsi.h> |
dea3101e JB |
29 | #include <scsi/scsi_cmnd.h> |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_host.h> | |
f888ba3c | 32 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 33 | #include <scsi/fc/fc_fs.h> |
0d878419 | 34 | #include <linux/aer.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e JB |
37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e JB |
41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_crtn.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_compat.h" | |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
04c68496 | 48 | #include "lpfc_vport.h" |
dea3101e JB |
49 | |
50 | /* There are only four IOCB completion types. */ | |
51 | typedef enum _lpfc_iocb_type { | |
52 | LPFC_UNKNOWN_IOCB, | |
53 | LPFC_UNSOL_IOCB, | |
54 | LPFC_SOL_IOCB, | |
55 | LPFC_ABORT_IOCB | |
56 | } lpfc_iocb_type; | |
57 | ||
4f774513 JS |
58 | |
59 | /* Provide function prototypes local to this module. */ | |
60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
61 | uint32_t); | |
62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
63 | uint8_t *, uint32_t *); |
64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
65 | struct lpfc_iocbq *); | |
6669f9bb JS |
66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
67 | struct hbq_dmabuf *); | |
4f774513 JS |
68 | static IOCB_t * |
69 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
70 | { | |
71 | return &iocbq->iocb; | |
72 | } | |
73 | ||
74 | /** | |
75 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
76 | * @q: The Work Queue to operate on. | |
77 | * @wqe: The work Queue Entry to put on the Work queue. | |
78 | * | |
79 | * This routine will copy the contents of @wqe to the next available entry on | |
80 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
81 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
82 | * successful. If no entries are available on @q then this function will return | |
83 | * -ENOMEM. | |
84 | * The caller is expected to hold the hbalock when calling this routine. | |
85 | **/ | |
86 | static uint32_t | |
87 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
88 | { | |
89 | union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe; | |
90 | struct lpfc_register doorbell; | |
91 | uint32_t host_index; | |
92 | ||
93 | /* If the host has not yet processed the next entry then we are done */ | |
94 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
95 | return -ENOMEM; | |
96 | /* set consumption flag every once in a while */ | |
97 | if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL)) | |
f0d9bccc | 98 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
fedd3b7b JS |
99 | if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED) |
100 | bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id); | |
4f774513 JS |
101 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); |
102 | ||
103 | /* Update the host index before invoking device */ | |
104 | host_index = q->host_index; | |
105 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
106 | ||
107 | /* Ring Doorbell */ | |
108 | doorbell.word0 = 0; | |
109 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); | |
110 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); | |
111 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); | |
112 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); | |
113 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ | |
114 | ||
115 | return 0; | |
116 | } | |
117 | ||
118 | /** | |
119 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
120 | * @q: The Work Queue to operate on. | |
121 | * @index: The index to advance the hba index to. | |
122 | * | |
123 | * This routine will update the HBA index of a queue to reflect consumption of | |
124 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
125 | * an entry the host calls this function to update the queue's internal | |
126 | * pointers. This routine returns the number of entries that were consumed by | |
127 | * the HBA. | |
128 | **/ | |
129 | static uint32_t | |
130 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
131 | { | |
132 | uint32_t released = 0; | |
133 | ||
134 | if (q->hba_index == index) | |
135 | return 0; | |
136 | do { | |
137 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
138 | released++; | |
139 | } while (q->hba_index != index); | |
140 | return released; | |
141 | } | |
142 | ||
143 | /** | |
144 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
145 | * @q: The Mailbox Queue to operate on. | |
146 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
147 | * | |
148 | * This routine will copy the contents of @mqe to the next available entry on | |
149 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
150 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
151 | * successful. If no entries are available on @q then this function will return | |
152 | * -ENOMEM. | |
153 | * The caller is expected to hold the hbalock when calling this routine. | |
154 | **/ | |
155 | static uint32_t | |
156 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
157 | { | |
158 | struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe; | |
159 | struct lpfc_register doorbell; | |
160 | uint32_t host_index; | |
161 | ||
162 | /* If the host has not yet processed the next entry then we are done */ | |
163 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
164 | return -ENOMEM; | |
165 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | |
166 | /* Save off the mailbox pointer for completion */ | |
167 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
168 | ||
169 | /* Update the host index before invoking device */ | |
170 | host_index = q->host_index; | |
171 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
172 | ||
173 | /* Ring Doorbell */ | |
174 | doorbell.word0 = 0; | |
175 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
176 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
177 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
178 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ | |
179 | return 0; | |
180 | } | |
181 | ||
182 | /** | |
183 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
184 | * @q: The Mailbox Queue to operate on. | |
185 | * | |
186 | * This routine will update the HBA index of a queue to reflect consumption of | |
187 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
188 | * an entry the host calls this function to update the queue's internal | |
189 | * pointers. This routine returns the number of entries that were consumed by | |
190 | * the HBA. | |
191 | **/ | |
192 | static uint32_t | |
193 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
194 | { | |
195 | /* Clear the mailbox pointer for completion */ | |
196 | q->phba->mbox = NULL; | |
197 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
198 | return 1; | |
199 | } | |
200 | ||
201 | /** | |
202 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
203 | * @q: The Event Queue to get the first valid EQE from | |
204 | * | |
205 | * This routine will get the first valid Event Queue Entry from @q, update | |
206 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
207 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
208 | * processed, but not popped back to the HBA then this routine will return NULL. | |
209 | **/ | |
210 | static struct lpfc_eqe * | |
211 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
212 | { | |
213 | struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe; | |
214 | ||
215 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 216 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
217 | return NULL; |
218 | /* If the host has not yet processed the next entry then we are done */ | |
219 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | |
220 | return NULL; | |
221 | ||
222 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
223 | return eqe; | |
224 | } | |
225 | ||
226 | /** | |
227 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
228 | * @q: The Event Queue that the host has completed processing for. | |
229 | * @arm: Indicates whether the host wants to arms this CQ. | |
230 | * | |
231 | * This routine will mark all Event Queue Entries on @q, from the last | |
232 | * known completed entry to the last entry that was processed, as completed | |
233 | * by clearing the valid bit for each completion queue entry. Then it will | |
234 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
235 | * The internal host index in the @q will be updated by this routine to indicate | |
236 | * that the host has finished processing the entries. The @arm parameter | |
237 | * indicates that the queue should be rearmed when ringing the doorbell. | |
238 | * | |
239 | * This function will return the number of EQEs that were popped. | |
240 | **/ | |
241 | uint32_t | |
242 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
243 | { | |
244 | uint32_t released = 0; | |
245 | struct lpfc_eqe *temp_eqe; | |
246 | struct lpfc_register doorbell; | |
247 | ||
248 | /* while there are valid entries */ | |
249 | while (q->hba_index != q->host_index) { | |
250 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 251 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
252 | released++; |
253 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
254 | } | |
255 | if (unlikely(released == 0 && !arm)) | |
256 | return 0; | |
257 | ||
258 | /* ring doorbell for number popped */ | |
259 | doorbell.word0 = 0; | |
260 | if (arm) { | |
261 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
262 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
263 | } | |
264 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
265 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
266 | bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id); | |
267 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
a747c9ce JS |
268 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
269 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
270 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
271 | return released; |
272 | } | |
273 | ||
274 | /** | |
275 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
276 | * @q: The Completion Queue to get the first valid CQE from | |
277 | * | |
278 | * This routine will get the first valid Completion Queue Entry from @q, update | |
279 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
280 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
281 | * processed, but not popped back to the HBA then this routine will return NULL. | |
282 | **/ | |
283 | static struct lpfc_cqe * | |
284 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
285 | { | |
286 | struct lpfc_cqe *cqe; | |
287 | ||
288 | /* If the next CQE is not valid then we are done */ | |
cb5172ea | 289 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
290 | return NULL; |
291 | /* If the host has not yet processed the next entry then we are done */ | |
292 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | |
293 | return NULL; | |
294 | ||
295 | cqe = q->qe[q->hba_index].cqe; | |
296 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
297 | return cqe; | |
298 | } | |
299 | ||
300 | /** | |
301 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
302 | * @q: The Completion Queue that the host has completed processing for. | |
303 | * @arm: Indicates whether the host wants to arms this CQ. | |
304 | * | |
305 | * This routine will mark all Completion queue entries on @q, from the last | |
306 | * known completed entry to the last entry that was processed, as completed | |
307 | * by clearing the valid bit for each completion queue entry. Then it will | |
308 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
309 | * The internal host index in the @q will be updated by this routine to indicate | |
310 | * that the host has finished processing the entries. The @arm parameter | |
311 | * indicates that the queue should be rearmed when ringing the doorbell. | |
312 | * | |
313 | * This function will return the number of CQEs that were released. | |
314 | **/ | |
315 | uint32_t | |
316 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
317 | { | |
318 | uint32_t released = 0; | |
319 | struct lpfc_cqe *temp_qe; | |
320 | struct lpfc_register doorbell; | |
321 | ||
322 | /* while there are valid entries */ | |
323 | while (q->hba_index != q->host_index) { | |
324 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 325 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
326 | released++; |
327 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
328 | } | |
329 | if (unlikely(released == 0 && !arm)) | |
330 | return 0; | |
331 | ||
332 | /* ring doorbell for number popped */ | |
333 | doorbell.word0 = 0; | |
334 | if (arm) | |
335 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
336 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
337 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
338 | bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id); | |
339 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
340 | return released; | |
341 | } | |
342 | ||
343 | /** | |
344 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
345 | * @q: The Header Receive Queue to operate on. | |
346 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
347 | * | |
348 | * This routine will copy the contents of @wqe to the next available entry on | |
349 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
350 | * HBA to start processing the Receive Queue Entry. This function returns the | |
351 | * index that the rqe was copied to if successful. If no entries are available | |
352 | * on @q then this function will return -ENOMEM. | |
353 | * The caller is expected to hold the hbalock when calling this routine. | |
354 | **/ | |
355 | static int | |
356 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
357 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
358 | { | |
359 | struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe; | |
360 | struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe; | |
361 | struct lpfc_register doorbell; | |
362 | int put_index = hq->host_index; | |
363 | ||
364 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) | |
365 | return -EINVAL; | |
366 | if (hq->host_index != dq->host_index) | |
367 | return -EINVAL; | |
368 | /* If the host has not yet processed the next entry then we are done */ | |
369 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
370 | return -EBUSY; | |
371 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
372 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
373 | ||
374 | /* Update the host index to point to the next slot */ | |
375 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
376 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
377 | ||
378 | /* Ring The Header Receive Queue Doorbell */ | |
379 | if (!(hq->host_index % LPFC_RQ_POST_BATCH)) { | |
380 | doorbell.word0 = 0; | |
381 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | |
382 | LPFC_RQ_POST_BATCH); | |
383 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); | |
384 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); | |
385 | } | |
386 | return put_index; | |
387 | } | |
388 | ||
389 | /** | |
390 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
391 | * @q: The Header Receive Queue to operate on. | |
392 | * | |
393 | * This routine will update the HBA index of a queue to reflect consumption of | |
394 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
395 | * consumed an entry the host calls this function to update the queue's | |
396 | * internal pointers. This routine returns the number of entries that were | |
397 | * consumed by the HBA. | |
398 | **/ | |
399 | static uint32_t | |
400 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
401 | { | |
402 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) | |
403 | return 0; | |
404 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
405 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
406 | return 1; | |
407 | } | |
408 | ||
e59058c4 | 409 | /** |
3621a710 | 410 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
411 | * @phba: Pointer to HBA context object. |
412 | * @pring: Pointer to driver SLI ring object. | |
413 | * | |
414 | * This function returns pointer to next command iocb entry | |
415 | * in the command ring. The caller must hold hbalock to prevent | |
416 | * other threads consume the next command iocb. | |
417 | * SLI-2/SLI-3 provide different sized iocbs. | |
418 | **/ | |
ed957684 JS |
419 | static inline IOCB_t * |
420 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
421 | { | |
422 | return (IOCB_t *) (((char *) pring->cmdringaddr) + | |
423 | pring->cmdidx * phba->iocb_cmd_size); | |
424 | } | |
425 | ||
e59058c4 | 426 | /** |
3621a710 | 427 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
428 | * @phba: Pointer to HBA context object. |
429 | * @pring: Pointer to driver SLI ring object. | |
430 | * | |
431 | * This function returns pointer to next response iocb entry | |
432 | * in the response ring. The caller must hold hbalock to make sure | |
433 | * that no other thread consume the next response iocb. | |
434 | * SLI-2/SLI-3 provide different sized iocbs. | |
435 | **/ | |
ed957684 JS |
436 | static inline IOCB_t * |
437 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
438 | { | |
439 | return (IOCB_t *) (((char *) pring->rspringaddr) + | |
440 | pring->rspidx * phba->iocb_rsp_size); | |
441 | } | |
442 | ||
e59058c4 | 443 | /** |
3621a710 | 444 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
445 | * @phba: Pointer to HBA context object. |
446 | * | |
447 | * This function is called with hbalock held. This function | |
448 | * allocates a new driver iocb object from the iocb pool. If the | |
449 | * allocation is successful, it returns pointer to the newly | |
450 | * allocated iocb object else it returns NULL. | |
451 | **/ | |
2e0fef85 JS |
452 | static struct lpfc_iocbq * |
453 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
0bd4ca25 JSEC |
454 | { |
455 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
456 | struct lpfc_iocbq * iocbq = NULL; | |
457 | ||
458 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
2a9bf3d0 JS |
459 | |
460 | if (iocbq) | |
461 | phba->iocb_cnt++; | |
462 | if (phba->iocb_cnt > phba->iocb_max) | |
463 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
464 | return iocbq; |
465 | } | |
466 | ||
da0436e9 JS |
467 | /** |
468 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
469 | * @phba: Pointer to HBA context object. | |
470 | * @xritag: XRI value. | |
471 | * | |
472 | * This function clears the sglq pointer from the array of acive | |
473 | * sglq's. The xritag that is passed in is used to index into the | |
474 | * array. Before the xritag can be used it needs to be adjusted | |
475 | * by subtracting the xribase. | |
476 | * | |
477 | * Returns sglq ponter = success, NULL = Failure. | |
478 | **/ | |
479 | static struct lpfc_sglq * | |
480 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
481 | { | |
482 | uint16_t adj_xri; | |
483 | struct lpfc_sglq *sglq; | |
484 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
485 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) | |
486 | return NULL; | |
487 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; | |
488 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL; | |
489 | return sglq; | |
490 | } | |
491 | ||
492 | /** | |
493 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
494 | * @phba: Pointer to HBA context object. | |
495 | * @xritag: XRI value. | |
496 | * | |
497 | * This function returns the sglq pointer from the array of acive | |
498 | * sglq's. The xritag that is passed in is used to index into the | |
499 | * array. Before the xritag can be used it needs to be adjusted | |
500 | * by subtracting the xribase. | |
501 | * | |
502 | * Returns sglq ponter = success, NULL = Failure. | |
503 | **/ | |
0f65ff68 | 504 | struct lpfc_sglq * |
da0436e9 JS |
505 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
506 | { | |
507 | uint16_t adj_xri; | |
508 | struct lpfc_sglq *sglq; | |
509 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
510 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) | |
511 | return NULL; | |
512 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; | |
513 | return sglq; | |
514 | } | |
515 | ||
19ca7609 JS |
516 | /** |
517 | * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap. | |
518 | * @phba: Pointer to HBA context object. | |
519 | * @ndlp: nodelist pointer for this target. | |
520 | * @xritag: xri used in this exchange. | |
521 | * @rxid: Remote Exchange ID. | |
522 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
523 | * | |
524 | * This function is called with hbalock held. | |
525 | * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an | |
526 | * rrq struct and adds it to the active_rrq_list. | |
527 | * | |
528 | * returns 0 for rrq slot for this xri | |
529 | * < 0 Were not able to get rrq mem or invalid parameter. | |
530 | **/ | |
531 | static int | |
532 | __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
533 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) | |
534 | { | |
535 | uint16_t adj_xri; | |
536 | struct lpfc_node_rrq *rrq; | |
537 | int empty; | |
1151e3ec JS |
538 | uint32_t did = 0; |
539 | ||
540 | ||
541 | if (!ndlp) | |
542 | return -EINVAL; | |
543 | ||
544 | if (!phba->cfg_enable_rrq) | |
545 | return -EINVAL; | |
546 | ||
547 | if (phba->pport->load_flag & FC_UNLOADING) { | |
548 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
549 | goto out; | |
550 | } | |
551 | did = ndlp->nlp_DID; | |
19ca7609 JS |
552 | |
553 | /* | |
554 | * set the active bit even if there is no mem available. | |
555 | */ | |
556 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
1151e3ec JS |
557 | |
558 | if (NLP_CHK_FREE_REQ(ndlp)) | |
559 | goto out; | |
560 | ||
561 | if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING)) | |
562 | goto out; | |
563 | ||
19ca7609 | 564 | if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) |
1151e3ec JS |
565 | goto out; |
566 | ||
19ca7609 JS |
567 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); |
568 | if (rrq) { | |
569 | rrq->send_rrq = send_rrq; | |
570 | rrq->xritag = xritag; | |
571 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); | |
572 | rrq->ndlp = ndlp; | |
573 | rrq->nlp_DID = ndlp->nlp_DID; | |
574 | rrq->vport = ndlp->vport; | |
575 | rrq->rxid = rxid; | |
576 | empty = list_empty(&phba->active_rrq_list); | |
1151e3ec | 577 | rrq->send_rrq = send_rrq; |
19ca7609 JS |
578 | list_add_tail(&rrq->list, &phba->active_rrq_list); |
579 | if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) { | |
580 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
581 | if (empty) | |
582 | lpfc_worker_wake_up(phba); | |
583 | } | |
584 | return 0; | |
585 | } | |
1151e3ec JS |
586 | out: |
587 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
588 | "2921 Can't set rrq active xri:0x%x rxid:0x%x" | |
589 | " DID:0x%x Send:%d\n", | |
590 | xritag, rxid, did, send_rrq); | |
591 | return -EINVAL; | |
19ca7609 JS |
592 | } |
593 | ||
594 | /** | |
1151e3ec | 595 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. |
19ca7609 JS |
596 | * @phba: Pointer to HBA context object. |
597 | * @xritag: xri used in this exchange. | |
598 | * @rrq: The RRQ to be cleared. | |
599 | * | |
19ca7609 | 600 | **/ |
1151e3ec JS |
601 | void |
602 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
603 | uint16_t xritag, | |
604 | struct lpfc_node_rrq *rrq) | |
19ca7609 JS |
605 | { |
606 | uint16_t adj_xri; | |
1151e3ec | 607 | struct lpfc_nodelist *ndlp = NULL; |
19ca7609 | 608 | |
1151e3ec JS |
609 | if ((rrq->vport) && NLP_CHK_NODE_ACT(rrq->ndlp)) |
610 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
19ca7609 JS |
611 | |
612 | /* The target DID could have been swapped (cable swap) | |
613 | * we should use the ndlp from the findnode if it is | |
614 | * available. | |
615 | */ | |
1151e3ec | 616 | if ((!ndlp) && rrq->ndlp) |
19ca7609 JS |
617 | ndlp = rrq->ndlp; |
618 | ||
1151e3ec JS |
619 | if (!ndlp) |
620 | goto out; | |
621 | ||
19ca7609 JS |
622 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; |
623 | if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) { | |
624 | rrq->send_rrq = 0; | |
625 | rrq->xritag = 0; | |
626 | rrq->rrq_stop_time = 0; | |
627 | } | |
1151e3ec | 628 | out: |
19ca7609 JS |
629 | mempool_free(rrq, phba->rrq_pool); |
630 | } | |
631 | ||
632 | /** | |
633 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
634 | * @phba: Pointer to HBA context object. | |
635 | * | |
636 | * This function is called with hbalock held. This function | |
637 | * Checks if stop_time (ratov from setting rrq active) has | |
638 | * been reached, if it has and the send_rrq flag is set then | |
639 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
640 | * then it will just call the routine to clear the rrq and | |
641 | * free the rrq resource. | |
642 | * The timer is set to the next rrq that is going to expire before | |
643 | * leaving the routine. | |
644 | * | |
645 | **/ | |
646 | void | |
647 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
648 | { | |
649 | struct lpfc_node_rrq *rrq; | |
650 | struct lpfc_node_rrq *nextrrq; | |
651 | unsigned long next_time; | |
652 | unsigned long iflags; | |
1151e3ec | 653 | LIST_HEAD(send_rrq); |
19ca7609 JS |
654 | |
655 | spin_lock_irqsave(&phba->hbalock, iflags); | |
656 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
657 | next_time = jiffies + HZ * (phba->fc_ratov + 1); | |
658 | list_for_each_entry_safe(rrq, nextrrq, | |
1151e3ec JS |
659 | &phba->active_rrq_list, list) { |
660 | if (time_after(jiffies, rrq->rrq_stop_time)) | |
661 | list_move(&rrq->list, &send_rrq); | |
662 | else if (time_before(rrq->rrq_stop_time, next_time)) | |
19ca7609 JS |
663 | next_time = rrq->rrq_stop_time; |
664 | } | |
665 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
666 | if (!list_empty(&phba->active_rrq_list)) | |
667 | mod_timer(&phba->rrq_tmr, next_time); | |
1151e3ec JS |
668 | list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) { |
669 | list_del(&rrq->list); | |
670 | if (!rrq->send_rrq) | |
671 | /* this call will free the rrq */ | |
672 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
673 | else if (lpfc_send_rrq(phba, rrq)) { | |
674 | /* if we send the rrq then the completion handler | |
675 | * will clear the bit in the xribitmap. | |
676 | */ | |
677 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
678 | rrq); | |
679 | } | |
680 | } | |
19ca7609 JS |
681 | } |
682 | ||
683 | /** | |
684 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
685 | * @vport: Pointer to vport context object. | |
686 | * @xri: The xri used in the exchange. | |
687 | * @did: The targets DID for this exchange. | |
688 | * | |
689 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
690 | * rrq = rrq for this xri and target. | |
691 | **/ | |
692 | struct lpfc_node_rrq * | |
693 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
694 | { | |
695 | struct lpfc_hba *phba = vport->phba; | |
696 | struct lpfc_node_rrq *rrq; | |
697 | struct lpfc_node_rrq *nextrrq; | |
698 | unsigned long iflags; | |
699 | ||
700 | if (phba->sli_rev != LPFC_SLI_REV4) | |
701 | return NULL; | |
702 | spin_lock_irqsave(&phba->hbalock, iflags); | |
703 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
704 | if (rrq->vport == vport && rrq->xritag == xri && | |
705 | rrq->nlp_DID == did){ | |
706 | list_del(&rrq->list); | |
707 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
708 | return rrq; | |
709 | } | |
710 | } | |
711 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
712 | return NULL; | |
713 | } | |
714 | ||
715 | /** | |
716 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
717 | * @vport: Pointer to vport context object. | |
1151e3ec JS |
718 | * @ndlp: Pointer to the lpfc_node_list structure. |
719 | * If ndlp is NULL Remove all active RRQs for this vport from the | |
720 | * phba->active_rrq_list and clear the rrq. | |
721 | * If ndlp is not NULL then only remove rrqs for this vport & this ndlp. | |
19ca7609 JS |
722 | **/ |
723 | void | |
1151e3ec | 724 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp) |
19ca7609 JS |
725 | |
726 | { | |
727 | struct lpfc_hba *phba = vport->phba; | |
728 | struct lpfc_node_rrq *rrq; | |
729 | struct lpfc_node_rrq *nextrrq; | |
730 | unsigned long iflags; | |
1151e3ec | 731 | LIST_HEAD(rrq_list); |
19ca7609 JS |
732 | |
733 | if (phba->sli_rev != LPFC_SLI_REV4) | |
734 | return; | |
1151e3ec JS |
735 | if (!ndlp) { |
736 | lpfc_sli4_vport_delete_els_xri_aborted(vport); | |
737 | lpfc_sli4_vport_delete_fcp_xri_aborted(vport); | |
19ca7609 | 738 | } |
1151e3ec JS |
739 | spin_lock_irqsave(&phba->hbalock, iflags); |
740 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) | |
741 | if ((rrq->vport == vport) && (!ndlp || rrq->ndlp == ndlp)) | |
742 | list_move(&rrq->list, &rrq_list); | |
19ca7609 | 743 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
1151e3ec JS |
744 | |
745 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
746 | list_del(&rrq->list); | |
747 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
748 | } | |
19ca7609 JS |
749 | } |
750 | ||
751 | /** | |
752 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. | |
753 | * @phba: Pointer to HBA context object. | |
754 | * | |
755 | * Remove all rrqs from the phba->active_rrq_list and free them by | |
756 | * calling __lpfc_clr_active_rrq | |
757 | * | |
758 | **/ | |
759 | void | |
760 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) | |
761 | { | |
762 | struct lpfc_node_rrq *rrq; | |
763 | struct lpfc_node_rrq *nextrrq; | |
764 | unsigned long next_time; | |
765 | unsigned long iflags; | |
1151e3ec | 766 | LIST_HEAD(rrq_list); |
19ca7609 JS |
767 | |
768 | if (phba->sli_rev != LPFC_SLI_REV4) | |
769 | return; | |
770 | spin_lock_irqsave(&phba->hbalock, iflags); | |
771 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
772 | next_time = jiffies + HZ * (phba->fc_ratov * 2); | |
1151e3ec JS |
773 | list_splice_init(&phba->active_rrq_list, &rrq_list); |
774 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
775 | ||
776 | list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) { | |
19ca7609 | 777 | list_del(&rrq->list); |
1151e3ec | 778 | lpfc_clr_rrq_active(phba, rrq->xritag, rrq); |
19ca7609 | 779 | } |
19ca7609 JS |
780 | if (!list_empty(&phba->active_rrq_list)) |
781 | mod_timer(&phba->rrq_tmr, next_time); | |
782 | } | |
783 | ||
784 | ||
785 | /** | |
1151e3ec | 786 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. |
19ca7609 JS |
787 | * @phba: Pointer to HBA context object. |
788 | * @ndlp: Targets nodelist pointer for this exchange. | |
789 | * @xritag the xri in the bitmap to test. | |
790 | * | |
791 | * This function is called with hbalock held. This function | |
792 | * returns 0 = rrq not active for this xri | |
793 | * 1 = rrq is valid for this xri. | |
794 | **/ | |
1151e3ec JS |
795 | int |
796 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
19ca7609 JS |
797 | uint16_t xritag) |
798 | { | |
799 | uint16_t adj_xri; | |
800 | ||
801 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
802 | if (!ndlp) | |
803 | return 0; | |
804 | if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) | |
805 | return 1; | |
806 | else | |
807 | return 0; | |
808 | } | |
809 | ||
810 | /** | |
811 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
812 | * @phba: Pointer to HBA context object. | |
813 | * @ndlp: nodelist pointer for this target. | |
814 | * @xritag: xri used in this exchange. | |
815 | * @rxid: Remote Exchange ID. | |
816 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
817 | * | |
818 | * This function takes the hbalock. | |
819 | * The active bit is always set in the active rrq xri_bitmap even | |
820 | * if there is no slot avaiable for the other rrq information. | |
821 | * | |
822 | * returns 0 rrq actived for this xri | |
823 | * < 0 No memory or invalid ndlp. | |
824 | **/ | |
825 | int | |
826 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
827 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) | |
828 | { | |
829 | int ret; | |
830 | unsigned long iflags; | |
831 | ||
832 | spin_lock_irqsave(&phba->hbalock, iflags); | |
833 | ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq); | |
834 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
835 | return ret; | |
836 | } | |
837 | ||
da0436e9 JS |
838 | /** |
839 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
840 | * @phba: Pointer to HBA context object. | |
19ca7609 | 841 | * @piocb: Pointer to the iocbq. |
da0436e9 JS |
842 | * |
843 | * This function is called with hbalock held. This function | |
844 | * Gets a new driver sglq object from the sglq list. If the | |
845 | * list is not empty then it is successful, it returns pointer to the newly | |
846 | * allocated sglq object else it returns NULL. | |
847 | **/ | |
848 | static struct lpfc_sglq * | |
19ca7609 | 849 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
850 | { |
851 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
852 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 853 | struct lpfc_sglq *start_sglq = NULL; |
da0436e9 | 854 | uint16_t adj_xri; |
19ca7609 JS |
855 | struct lpfc_scsi_buf *lpfc_cmd; |
856 | struct lpfc_nodelist *ndlp; | |
857 | int found = 0; | |
858 | ||
859 | if (piocbq->iocb_flag & LPFC_IO_FCP) { | |
860 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
861 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 JS |
862 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
863 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
19ca7609 | 864 | ndlp = piocbq->context_un.ndlp; |
19ca7609 JS |
865 | else |
866 | ndlp = piocbq->context1; | |
867 | ||
da0436e9 | 868 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
869 | start_sglq = sglq; |
870 | while (!found) { | |
871 | if (!sglq) | |
872 | return NULL; | |
873 | adj_xri = sglq->sli4_xritag - | |
874 | phba->sli4_hba.max_cfg_param.xri_base; | |
1151e3ec | 875 | if (lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { |
19ca7609 JS |
876 | /* This xri has an rrq outstanding for this DID. |
877 | * put it back in the list and get another xri. | |
878 | */ | |
879 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
880 | sglq = NULL; | |
881 | list_remove_head(lpfc_sgl_list, sglq, | |
882 | struct lpfc_sglq, list); | |
883 | if (sglq == start_sglq) { | |
884 | sglq = NULL; | |
885 | break; | |
886 | } else | |
887 | continue; | |
888 | } | |
889 | sglq->ndlp = ndlp; | |
890 | found = 1; | |
891 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq; | |
892 | sglq->state = SGL_ALLOCATED; | |
893 | } | |
da0436e9 JS |
894 | return sglq; |
895 | } | |
896 | ||
e59058c4 | 897 | /** |
3621a710 | 898 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
899 | * @phba: Pointer to HBA context object. |
900 | * | |
901 | * This function is called with no lock held. This function | |
902 | * allocates a new driver iocb object from the iocb pool. If the | |
903 | * allocation is successful, it returns pointer to the newly | |
904 | * allocated iocb object else it returns NULL. | |
905 | **/ | |
2e0fef85 JS |
906 | struct lpfc_iocbq * |
907 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
908 | { | |
909 | struct lpfc_iocbq * iocbq = NULL; | |
910 | unsigned long iflags; | |
911 | ||
912 | spin_lock_irqsave(&phba->hbalock, iflags); | |
913 | iocbq = __lpfc_sli_get_iocbq(phba); | |
914 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
915 | return iocbq; | |
916 | } | |
917 | ||
4f774513 JS |
918 | /** |
919 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
920 | * @phba: Pointer to HBA context object. | |
921 | * @iocbq: Pointer to driver iocb object. | |
922 | * | |
923 | * This function is called with hbalock held to release driver | |
924 | * iocb object to the iocb pool. The iotag in the iocb object | |
925 | * does not change for each use of the iocb object. This function | |
926 | * clears all other fields of the iocb object when it is freed. | |
927 | * The sqlq structure that holds the xritag and phys and virtual | |
928 | * mappings for the scatter gather list is retrieved from the | |
929 | * active array of sglq. The get of the sglq pointer also clears | |
930 | * the entry in the array. If the status of the IO indiactes that | |
931 | * this IO was aborted then the sglq entry it put on the | |
932 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
933 | * IO has good status or fails for any other reason then the sglq | |
934 | * entry is added to the free list (lpfc_sgl_list). | |
935 | **/ | |
936 | static void | |
937 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
938 | { | |
939 | struct lpfc_sglq *sglq; | |
940 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
941 | unsigned long iflag = 0; |
942 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
943 | |
944 | if (iocbq->sli4_xritag == NO_XRI) | |
945 | sglq = NULL; | |
946 | else | |
947 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag); | |
948 | if (sglq) { | |
0f65ff68 JS |
949 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
950 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
951 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
952 | iflag); | |
953 | list_add(&sglq->list, | |
954 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
955 | spin_unlock_irqrestore( | |
956 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
957 | } else { |
958 | sglq->state = SGL_FREED; | |
19ca7609 | 959 | sglq->ndlp = NULL; |
fedd3b7b JS |
960 | list_add_tail(&sglq->list, |
961 | &phba->sli4_hba.lpfc_sgl_list); | |
2a9bf3d0 JS |
962 | |
963 | /* Check if TXQ queue needs to be serviced */ | |
589a52d6 | 964 | if (pring->txq_cnt) |
2a9bf3d0 | 965 | lpfc_worker_wake_up(phba); |
0f65ff68 | 966 | } |
4f774513 JS |
967 | } |
968 | ||
969 | ||
970 | /* | |
971 | * Clean all volatile data fields, preserve iotag and node struct. | |
972 | */ | |
973 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
974 | iocbq->sli4_xritag = NO_XRI; | |
975 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
976 | } | |
977 | ||
2a9bf3d0 | 978 | |
e59058c4 | 979 | /** |
3772a991 | 980 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
981 | * @phba: Pointer to HBA context object. |
982 | * @iocbq: Pointer to driver iocb object. | |
983 | * | |
984 | * This function is called with hbalock held to release driver | |
985 | * iocb object to the iocb pool. The iotag in the iocb object | |
986 | * does not change for each use of the iocb object. This function | |
987 | * clears all other fields of the iocb object when it is freed. | |
988 | **/ | |
a6ababd2 | 989 | static void |
3772a991 | 990 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 991 | { |
2e0fef85 | 992 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
993 | |
994 | /* | |
995 | * Clean all volatile data fields, preserve iotag and node struct. | |
996 | */ | |
997 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 998 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
999 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1000 | } | |
1001 | ||
3772a991 JS |
1002 | /** |
1003 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1004 | * @phba: Pointer to HBA context object. | |
1005 | * @iocbq: Pointer to driver iocb object. | |
1006 | * | |
1007 | * This function is called with hbalock held to release driver | |
1008 | * iocb object to the iocb pool. The iotag in the iocb object | |
1009 | * does not change for each use of the iocb object. This function | |
1010 | * clears all other fields of the iocb object when it is freed. | |
1011 | **/ | |
1012 | static void | |
1013 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1014 | { | |
1015 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1016 | phba->iocb_cnt--; |
3772a991 JS |
1017 | } |
1018 | ||
e59058c4 | 1019 | /** |
3621a710 | 1020 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1021 | * @phba: Pointer to HBA context object. |
1022 | * @iocbq: Pointer to driver iocb object. | |
1023 | * | |
1024 | * This function is called with no lock held to release the iocb to | |
1025 | * iocb pool. | |
1026 | **/ | |
2e0fef85 JS |
1027 | void |
1028 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1029 | { | |
1030 | unsigned long iflags; | |
1031 | ||
1032 | /* | |
1033 | * Clean all volatile data fields, preserve iotag and node struct. | |
1034 | */ | |
1035 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1036 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1037 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1038 | } | |
1039 | ||
a257bf90 JS |
1040 | /** |
1041 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1042 | * @phba: Pointer to HBA context object. | |
1043 | * @iocblist: List of IOCBs. | |
1044 | * @ulpstatus: ULP status in IOCB command field. | |
1045 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1046 | * | |
1047 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1048 | * on the list by invoking the complete callback function associated with the | |
1049 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1050 | * fields. | |
1051 | **/ | |
1052 | void | |
1053 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1054 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1055 | { | |
1056 | struct lpfc_iocbq *piocb; | |
1057 | ||
1058 | while (!list_empty(iocblist)) { | |
1059 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
1060 | ||
1061 | if (!piocb->iocb_cmpl) | |
1062 | lpfc_sli_release_iocbq(phba, piocb); | |
1063 | else { | |
1064 | piocb->iocb.ulpStatus = ulpstatus; | |
1065 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1066 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1067 | } | |
1068 | } | |
1069 | return; | |
1070 | } | |
1071 | ||
e59058c4 | 1072 | /** |
3621a710 JS |
1073 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1074 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1075 | * |
1076 | * This function is called by ring event handler function to get the iocb type. | |
1077 | * This function translates the iocb command to an iocb command type used to | |
1078 | * decide the final disposition of each completed IOCB. | |
1079 | * The function returns | |
1080 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1081 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1082 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1083 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1084 | * | |
1085 | * The caller is not required to hold any lock. | |
1086 | **/ | |
dea3101e JB |
1087 | static lpfc_iocb_type |
1088 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1089 | { | |
1090 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1091 | ||
1092 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1093 | return 0; | |
1094 | ||
1095 | switch (iocb_cmnd) { | |
1096 | case CMD_XMIT_SEQUENCE_CR: | |
1097 | case CMD_XMIT_SEQUENCE_CX: | |
1098 | case CMD_XMIT_BCAST_CN: | |
1099 | case CMD_XMIT_BCAST_CX: | |
1100 | case CMD_ELS_REQUEST_CR: | |
1101 | case CMD_ELS_REQUEST_CX: | |
1102 | case CMD_CREATE_XRI_CR: | |
1103 | case CMD_CREATE_XRI_CX: | |
1104 | case CMD_GET_RPI_CN: | |
1105 | case CMD_XMIT_ELS_RSP_CX: | |
1106 | case CMD_GET_RPI_CR: | |
1107 | case CMD_FCP_IWRITE_CR: | |
1108 | case CMD_FCP_IWRITE_CX: | |
1109 | case CMD_FCP_IREAD_CR: | |
1110 | case CMD_FCP_IREAD_CX: | |
1111 | case CMD_FCP_ICMND_CR: | |
1112 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1113 | case CMD_FCP_TSEND_CX: |
1114 | case CMD_FCP_TRSP_CX: | |
1115 | case CMD_FCP_TRECEIVE_CX: | |
1116 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
1117 | case CMD_ADAPTER_MSG: |
1118 | case CMD_ADAPTER_DUMP: | |
1119 | case CMD_XMIT_SEQUENCE64_CR: | |
1120 | case CMD_XMIT_SEQUENCE64_CX: | |
1121 | case CMD_XMIT_BCAST64_CN: | |
1122 | case CMD_XMIT_BCAST64_CX: | |
1123 | case CMD_ELS_REQUEST64_CR: | |
1124 | case CMD_ELS_REQUEST64_CX: | |
1125 | case CMD_FCP_IWRITE64_CR: | |
1126 | case CMD_FCP_IWRITE64_CX: | |
1127 | case CMD_FCP_IREAD64_CR: | |
1128 | case CMD_FCP_IREAD64_CX: | |
1129 | case CMD_FCP_ICMND64_CR: | |
1130 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1131 | case CMD_FCP_TSEND64_CX: |
1132 | case CMD_FCP_TRSP64_CX: | |
1133 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
1134 | case CMD_GEN_REQUEST64_CR: |
1135 | case CMD_GEN_REQUEST64_CX: | |
1136 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1137 | case DSSCMD_IWRITE64_CR: |
1138 | case DSSCMD_IWRITE64_CX: | |
1139 | case DSSCMD_IREAD64_CR: | |
1140 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
1141 | type = LPFC_SOL_IOCB; |
1142 | break; | |
1143 | case CMD_ABORT_XRI_CN: | |
1144 | case CMD_ABORT_XRI_CX: | |
1145 | case CMD_CLOSE_XRI_CN: | |
1146 | case CMD_CLOSE_XRI_CX: | |
1147 | case CMD_XRI_ABORTED_CX: | |
1148 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1149 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
1150 | type = LPFC_ABORT_IOCB; |
1151 | break; | |
1152 | case CMD_RCV_SEQUENCE_CX: | |
1153 | case CMD_RCV_ELS_REQ_CX: | |
1154 | case CMD_RCV_SEQUENCE64_CX: | |
1155 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1156 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1157 | case CMD_IOCB_RCV_SEQ64_CX: |
1158 | case CMD_IOCB_RCV_ELS64_CX: | |
1159 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1160 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
1161 | type = LPFC_UNSOL_IOCB; |
1162 | break; | |
3163f725 JS |
1163 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1164 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1165 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1166 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1167 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1168 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1169 | case CMD_IOCB_RET_HBQE64_CN: | |
1170 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1171 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1172 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1173 | case CMD_IOCB_LOGENTRY_CN: | |
1174 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1175 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1176 | __func__, iocb_cmnd); |
3163f725 JS |
1177 | type = LPFC_UNKNOWN_IOCB; |
1178 | break; | |
dea3101e JB |
1179 | default: |
1180 | type = LPFC_UNKNOWN_IOCB; | |
1181 | break; | |
1182 | } | |
1183 | ||
1184 | return type; | |
1185 | } | |
1186 | ||
e59058c4 | 1187 | /** |
3621a710 | 1188 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1189 | * @phba: Pointer to HBA context object. |
1190 | * | |
1191 | * This function is called from SLI initialization code | |
1192 | * to configure every ring of the HBA's SLI interface. The | |
1193 | * caller is not required to hold any lock. This function issues | |
1194 | * a config_ring mailbox command for each ring. | |
1195 | * This function returns zero if successful else returns a negative | |
1196 | * error code. | |
1197 | **/ | |
dea3101e | 1198 | static int |
ed957684 | 1199 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
1200 | { |
1201 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1202 | LPFC_MBOXQ_t *pmb; |
1203 | MAILBOX_t *pmbox; | |
1204 | int i, rc, ret = 0; | |
dea3101e | 1205 | |
ed957684 JS |
1206 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1207 | if (!pmb) | |
1208 | return -ENOMEM; | |
04c68496 | 1209 | pmbox = &pmb->u.mb; |
ed957684 | 1210 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1211 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
1212 | lpfc_config_ring(phba, i, pmb); |
1213 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1214 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1216 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
1217 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1218 | "ring %d\n", | |
e8b62011 JS |
1219 | rc, pmbox->mbxCommand, |
1220 | pmbox->mbxStatus, i); | |
2e0fef85 | 1221 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1222 | ret = -ENXIO; |
1223 | break; | |
dea3101e JB |
1224 | } |
1225 | } | |
ed957684 JS |
1226 | mempool_free(pmb, phba->mbox_mem_pool); |
1227 | return ret; | |
dea3101e JB |
1228 | } |
1229 | ||
e59058c4 | 1230 | /** |
3621a710 | 1231 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1232 | * @phba: Pointer to HBA context object. |
1233 | * @pring: Pointer to driver SLI ring object. | |
1234 | * @piocb: Pointer to the driver iocb object. | |
1235 | * | |
1236 | * This function is called with hbalock held. The function adds the | |
1237 | * new iocb to txcmplq of the given ring. This function always returns | |
1238 | * 0. If this function is called for ELS ring, this function checks if | |
1239 | * there is a vport associated with the ELS command. This function also | |
1240 | * starts els_tmofunc timer if this is an ELS command. | |
1241 | **/ | |
dea3101e | 1242 | static int |
2e0fef85 JS |
1243 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1244 | struct lpfc_iocbq *piocb) | |
dea3101e | 1245 | { |
dea3101e | 1246 | list_add_tail(&piocb->list, &pring->txcmplq); |
2a9bf3d0 | 1247 | piocb->iocb_flag |= LPFC_IO_ON_Q; |
dea3101e | 1248 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
1249 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
1250 | pring->txcmplq_max = pring->txcmplq_cnt; | |
1251 | ||
92d7f7b0 JS |
1252 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1253 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
1254 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
1255 | if (!piocb->vport) | |
1256 | BUG(); | |
1257 | else | |
1258 | mod_timer(&piocb->vport->els_tmofunc, | |
1259 | jiffies + HZ * (phba->fc_ratov << 1)); | |
1260 | } | |
1261 | ||
dea3101e | 1262 | |
2e0fef85 | 1263 | return 0; |
dea3101e JB |
1264 | } |
1265 | ||
e59058c4 | 1266 | /** |
3621a710 | 1267 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1268 | * @phba: Pointer to HBA context object. |
1269 | * @pring: Pointer to driver SLI ring object. | |
1270 | * | |
1271 | * This function is called with hbalock held to get next | |
1272 | * iocb in txq of the given ring. If there is any iocb in | |
1273 | * the txq, the function returns first iocb in the list after | |
1274 | * removing the iocb from the list, else it returns NULL. | |
1275 | **/ | |
2a9bf3d0 | 1276 | struct lpfc_iocbq * |
2e0fef85 | 1277 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1278 | { |
dea3101e JB |
1279 | struct lpfc_iocbq *cmd_iocb; |
1280 | ||
858c9f6c JS |
1281 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
1282 | if (cmd_iocb != NULL) | |
dea3101e | 1283 | pring->txq_cnt--; |
2e0fef85 | 1284 | return cmd_iocb; |
dea3101e JB |
1285 | } |
1286 | ||
e59058c4 | 1287 | /** |
3621a710 | 1288 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1289 | * @phba: Pointer to HBA context object. |
1290 | * @pring: Pointer to driver SLI ring object. | |
1291 | * | |
1292 | * This function is called with hbalock held and the caller must post the | |
1293 | * iocb without releasing the lock. If the caller releases the lock, | |
1294 | * iocb slot returned by the function is not guaranteed to be available. | |
1295 | * The function returns pointer to the next available iocb slot if there | |
1296 | * is available slot in the ring, else it returns NULL. | |
1297 | * If the get index of the ring is ahead of the put index, the function | |
1298 | * will post an error attention event to the worker thread to take the | |
1299 | * HBA to offline state. | |
1300 | **/ | |
dea3101e JB |
1301 | static IOCB_t * |
1302 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1303 | { | |
34b02dcd | 1304 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 1305 | uint32_t max_cmd_idx = pring->numCiocb; |
dea3101e JB |
1306 | if ((pring->next_cmdidx == pring->cmdidx) && |
1307 | (++pring->next_cmdidx >= max_cmd_idx)) | |
1308 | pring->next_cmdidx = 0; | |
1309 | ||
1310 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { | |
1311 | ||
1312 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
1313 | ||
1314 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { | |
1315 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 1316 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1317 | "is bigger than cmd ring %d\n", |
e8b62011 | 1318 | pring->ringno, |
dea3101e JB |
1319 | pring->local_getidx, max_cmd_idx); |
1320 | ||
2e0fef85 | 1321 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1322 | /* |
1323 | * All error attention handlers are posted to | |
1324 | * worker thread | |
1325 | */ | |
1326 | phba->work_ha |= HA_ERATT; | |
1327 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1328 | |
5e9d9b82 | 1329 | lpfc_worker_wake_up(phba); |
dea3101e JB |
1330 | |
1331 | return NULL; | |
1332 | } | |
1333 | ||
1334 | if (pring->local_getidx == pring->next_cmdidx) | |
1335 | return NULL; | |
1336 | } | |
1337 | ||
ed957684 | 1338 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
1339 | } |
1340 | ||
e59058c4 | 1341 | /** |
3621a710 | 1342 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1343 | * @phba: Pointer to HBA context object. |
1344 | * @iocbq: Pointer to driver iocb object. | |
1345 | * | |
1346 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1347 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1348 | * array and assigns a new iotag. | |
1349 | * The function returns the allocated iotag if successful, else returns zero. | |
1350 | * Zero is not a valid iotag. | |
1351 | * The caller is not required to hold any lock. | |
1352 | **/ | |
604a3e30 | 1353 | uint16_t |
2e0fef85 | 1354 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1355 | { |
2e0fef85 JS |
1356 | struct lpfc_iocbq **new_arr; |
1357 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1358 | size_t new_len; |
1359 | struct lpfc_sli *psli = &phba->sli; | |
1360 | uint16_t iotag; | |
dea3101e | 1361 | |
2e0fef85 | 1362 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1363 | iotag = psli->last_iotag; |
1364 | if(++iotag < psli->iocbq_lookup_len) { | |
1365 | psli->last_iotag = iotag; | |
1366 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1367 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1368 | iocbq->iotag = iotag; |
1369 | return iotag; | |
2e0fef85 | 1370 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1371 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1372 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1373 | spin_unlock_irq(&phba->hbalock); |
1374 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1375 | GFP_KERNEL); |
1376 | if (new_arr) { | |
2e0fef85 | 1377 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1378 | old_arr = psli->iocbq_lookup; |
1379 | if (new_len <= psli->iocbq_lookup_len) { | |
1380 | /* highly unprobable case */ | |
1381 | kfree(new_arr); | |
1382 | iotag = psli->last_iotag; | |
1383 | if(++iotag < psli->iocbq_lookup_len) { | |
1384 | psli->last_iotag = iotag; | |
1385 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1386 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1387 | iocbq->iotag = iotag; |
1388 | return iotag; | |
1389 | } | |
2e0fef85 | 1390 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1391 | return 0; |
1392 | } | |
1393 | if (psli->iocbq_lookup) | |
1394 | memcpy(new_arr, old_arr, | |
1395 | ((psli->last_iotag + 1) * | |
311464ec | 1396 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1397 | psli->iocbq_lookup = new_arr; |
1398 | psli->iocbq_lookup_len = new_len; | |
1399 | psli->last_iotag = iotag; | |
1400 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1401 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1402 | iocbq->iotag = iotag; |
1403 | kfree(old_arr); | |
1404 | return iotag; | |
1405 | } | |
8f6d98d2 | 1406 | } else |
2e0fef85 | 1407 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1408 | |
bc73905a | 1409 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1410 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1411 | psli->last_iotag); | |
dea3101e | 1412 | |
604a3e30 | 1413 | return 0; |
dea3101e JB |
1414 | } |
1415 | ||
e59058c4 | 1416 | /** |
3621a710 | 1417 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1418 | * @phba: Pointer to HBA context object. |
1419 | * @pring: Pointer to driver SLI ring object. | |
1420 | * @iocb: Pointer to iocb slot in the ring. | |
1421 | * @nextiocb: Pointer to driver iocb object which need to be | |
1422 | * posted to firmware. | |
1423 | * | |
1424 | * This function is called with hbalock held to post a new iocb to | |
1425 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1426 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1427 | * a completion call back for this iocb else the function will free the | |
1428 | * iocb object. | |
1429 | **/ | |
dea3101e JB |
1430 | static void |
1431 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1432 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1433 | { | |
1434 | /* | |
604a3e30 | 1435 | * Set up an iotag |
dea3101e | 1436 | */ |
604a3e30 | 1437 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1438 | |
e2a0a9d6 | 1439 | |
a58cbd52 JS |
1440 | if (pring->ringno == LPFC_ELS_RING) { |
1441 | lpfc_debugfs_slow_ring_trc(phba, | |
1442 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1443 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1444 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1445 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1446 | } | |
1447 | ||
dea3101e JB |
1448 | /* |
1449 | * Issue iocb command to adapter | |
1450 | */ | |
92d7f7b0 | 1451 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1452 | wmb(); |
1453 | pring->stats.iocb_cmd++; | |
1454 | ||
1455 | /* | |
1456 | * If there is no completion routine to call, we can release the | |
1457 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1458 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1459 | */ | |
1460 | if (nextiocb->iocb_cmpl) | |
1461 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1462 | else |
2e0fef85 | 1463 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1464 | |
1465 | /* | |
1466 | * Let the HBA know what IOCB slot will be the next one the | |
1467 | * driver will put a command into. | |
1468 | */ | |
1469 | pring->cmdidx = pring->next_cmdidx; | |
ed957684 | 1470 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
dea3101e JB |
1471 | } |
1472 | ||
e59058c4 | 1473 | /** |
3621a710 | 1474 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1475 | * @phba: Pointer to HBA context object. |
1476 | * @pring: Pointer to driver SLI ring object. | |
1477 | * | |
1478 | * The caller is not required to hold any lock for calling this function. | |
1479 | * This function updates the chip attention bits for the ring to inform firmware | |
1480 | * that there are pending work to be done for this ring and requests an | |
1481 | * interrupt when there is space available in the ring. This function is | |
1482 | * called when the driver is unable to post more iocbs to the ring due | |
1483 | * to unavailability of space in the ring. | |
1484 | **/ | |
dea3101e | 1485 | static void |
2e0fef85 | 1486 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1487 | { |
1488 | int ringno = pring->ringno; | |
1489 | ||
1490 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1491 | ||
1492 | wmb(); | |
1493 | ||
1494 | /* | |
1495 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1496 | * The HBA will tell us when an IOCB entry is available. | |
1497 | */ | |
1498 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1499 | readl(phba->CAregaddr); /* flush */ | |
1500 | ||
1501 | pring->stats.iocb_cmd_full++; | |
1502 | } | |
1503 | ||
e59058c4 | 1504 | /** |
3621a710 | 1505 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1506 | * @phba: Pointer to HBA context object. |
1507 | * @pring: Pointer to driver SLI ring object. | |
1508 | * | |
1509 | * This function updates the chip attention register bit for the | |
1510 | * given ring to inform HBA that there is more work to be done | |
1511 | * in this ring. The caller is not required to hold any lock. | |
1512 | **/ | |
dea3101e | 1513 | static void |
2e0fef85 | 1514 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1515 | { |
1516 | int ringno = pring->ringno; | |
1517 | ||
1518 | /* | |
1519 | * Tell the HBA that there is work to do in this ring. | |
1520 | */ | |
34b02dcd JS |
1521 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1522 | wmb(); | |
1523 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1524 | readl(phba->CAregaddr); /* flush */ | |
1525 | } | |
dea3101e JB |
1526 | } |
1527 | ||
e59058c4 | 1528 | /** |
3621a710 | 1529 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1530 | * @phba: Pointer to HBA context object. |
1531 | * @pring: Pointer to driver SLI ring object. | |
1532 | * | |
1533 | * This function is called with hbalock held to post pending iocbs | |
1534 | * in the txq to the firmware. This function is called when driver | |
1535 | * detects space available in the ring. | |
1536 | **/ | |
dea3101e | 1537 | static void |
2e0fef85 | 1538 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1539 | { |
1540 | IOCB_t *iocb; | |
1541 | struct lpfc_iocbq *nextiocb; | |
1542 | ||
1543 | /* | |
1544 | * Check to see if: | |
1545 | * (a) there is anything on the txq to send | |
1546 | * (b) link is up | |
1547 | * (c) link attention events can be processed (fcp ring only) | |
1548 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1549 | */ | |
1550 | if (pring->txq_cnt && | |
2e0fef85 | 1551 | lpfc_is_link_up(phba) && |
dea3101e | 1552 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1553 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1554 | |
1555 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1556 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1557 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1558 | ||
1559 | if (iocb) | |
1560 | lpfc_sli_update_ring(phba, pring); | |
1561 | else | |
1562 | lpfc_sli_update_full_ring(phba, pring); | |
1563 | } | |
1564 | ||
1565 | return; | |
1566 | } | |
1567 | ||
e59058c4 | 1568 | /** |
3621a710 | 1569 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1570 | * @phba: Pointer to HBA context object. |
1571 | * @hbqno: HBQ number. | |
1572 | * | |
1573 | * This function is called with hbalock held to get the next | |
1574 | * available slot for the given HBQ. If there is free slot | |
1575 | * available for the HBQ it will return pointer to the next available | |
1576 | * HBQ entry else it will return NULL. | |
1577 | **/ | |
a6ababd2 | 1578 | static struct lpfc_hbq_entry * |
ed957684 JS |
1579 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1580 | { | |
1581 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1582 | ||
1583 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1584 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1585 | hbqp->next_hbqPutIdx = 0; | |
1586 | ||
1587 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1588 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1589 | uint32_t getidx = le32_to_cpu(raw_index); |
1590 | ||
1591 | hbqp->local_hbqGetIdx = getidx; | |
1592 | ||
1593 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1594 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1595 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1596 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1597 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1598 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1599 | hbqp->entry_count); |
1600 | ||
1601 | phba->link_state = LPFC_HBA_ERROR; | |
1602 | return NULL; | |
1603 | } | |
1604 | ||
1605 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1606 | return NULL; | |
1607 | } | |
1608 | ||
51ef4c26 JS |
1609 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1610 | hbqp->hbqPutIdx; | |
ed957684 JS |
1611 | } |
1612 | ||
e59058c4 | 1613 | /** |
3621a710 | 1614 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1615 | * @phba: Pointer to HBA context object. |
1616 | * | |
1617 | * This function is called with no lock held to free all the | |
1618 | * hbq buffers while uninitializing the SLI interface. It also | |
1619 | * frees the HBQ buffers returned by the firmware but not yet | |
1620 | * processed by the upper layers. | |
1621 | **/ | |
ed957684 JS |
1622 | void |
1623 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1624 | { | |
92d7f7b0 JS |
1625 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1626 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1627 | unsigned long flags; |
51ef4c26 | 1628 | int i, hbq_count; |
3163f725 | 1629 | uint32_t hbqno; |
ed957684 | 1630 | |
51ef4c26 | 1631 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1632 | /* Return all memory used by all HBQs */ |
3163f725 | 1633 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1634 | for (i = 0; i < hbq_count; ++i) { |
1635 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1636 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1637 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1638 | list_del(&hbq_buf->dbuf.list); | |
1639 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1640 | } | |
a8adb832 | 1641 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1642 | } |
3163f725 | 1643 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1644 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1645 | list) { | |
3163f725 JS |
1646 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1647 | list_del(&hbq_buf->dbuf.list); | |
1648 | if (hbq_buf->tag == -1) { | |
1649 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1650 | (phba, hbq_buf); | |
1651 | } else { | |
1652 | hbqno = hbq_buf->tag >> 16; | |
1653 | if (hbqno >= LPFC_MAX_HBQS) | |
1654 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1655 | (phba, hbq_buf); | |
1656 | else | |
1657 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1658 | hbq_buf); | |
1659 | } | |
1660 | } | |
1661 | ||
1662 | /* Mark the HBQs not in use */ | |
1663 | phba->hbq_in_use = 0; | |
1664 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1665 | } |
1666 | ||
e59058c4 | 1667 | /** |
3621a710 | 1668 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1669 | * @phba: Pointer to HBA context object. |
1670 | * @hbqno: HBQ number. | |
1671 | * @hbq_buf: Pointer to HBQ buffer. | |
1672 | * | |
1673 | * This function is called with the hbalock held to post a | |
1674 | * hbq buffer to the firmware. If the function finds an empty | |
1675 | * slot in the HBQ, it will post the buffer. The function will return | |
1676 | * pointer to the hbq entry if it successfully post the buffer | |
1677 | * else it will return NULL. | |
1678 | **/ | |
3772a991 | 1679 | static int |
ed957684 | 1680 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1681 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1682 | { |
1683 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1684 | } | |
1685 | ||
1686 | /** | |
1687 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1688 | * @phba: Pointer to HBA context object. | |
1689 | * @hbqno: HBQ number. | |
1690 | * @hbq_buf: Pointer to HBQ buffer. | |
1691 | * | |
1692 | * This function is called with the hbalock held to post a hbq buffer to the | |
1693 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1694 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1695 | * it successfully post the buffer else it will return an error. | |
1696 | **/ | |
1697 | static int | |
1698 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1699 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1700 | { |
1701 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1702 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1703 | |
1704 | /* Get next HBQ entry slot to use */ | |
1705 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1706 | if (hbqe) { | |
1707 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1708 | ||
92d7f7b0 JS |
1709 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1710 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1711 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1712 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1713 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1714 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1715 | /* Sync SLIM */ | |
ed957684 JS |
1716 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1717 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1718 | /* flush */ |
ed957684 | 1719 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1720 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1721 | return 0; |
1722 | } else | |
1723 | return -ENOMEM; | |
ed957684 JS |
1724 | } |
1725 | ||
4f774513 JS |
1726 | /** |
1727 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1728 | * @phba: Pointer to HBA context object. | |
1729 | * @hbqno: HBQ number. | |
1730 | * @hbq_buf: Pointer to HBQ buffer. | |
1731 | * | |
1732 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1733 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1734 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1735 | **/ | |
1736 | static int | |
1737 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1738 | struct hbq_dmabuf *hbq_buf) | |
1739 | { | |
1740 | int rc; | |
1741 | struct lpfc_rqe hrqe; | |
1742 | struct lpfc_rqe drqe; | |
1743 | ||
1744 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1745 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1746 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1747 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1748 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1749 | &hrqe, &drqe); | |
1750 | if (rc < 0) | |
1751 | return rc; | |
1752 | hbq_buf->tag = rc; | |
1753 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1754 | return 0; | |
1755 | } | |
1756 | ||
e59058c4 | 1757 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1758 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1759 | .rn = 1, | |
def9c7a9 | 1760 | .entry_count = 256, |
92d7f7b0 JS |
1761 | .mask_count = 0, |
1762 | .profile = 0, | |
51ef4c26 | 1763 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1764 | .buffer_count = 0, |
a257bf90 JS |
1765 | .init_count = 40, |
1766 | .add_count = 40, | |
92d7f7b0 | 1767 | }; |
ed957684 | 1768 | |
e59058c4 | 1769 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1770 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1771 | .rn = 1, | |
1772 | .entry_count = 200, | |
1773 | .mask_count = 0, | |
1774 | .profile = 0, | |
1775 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1776 | .buffer_count = 0, | |
1777 | .init_count = 0, | |
1778 | .add_count = 5, | |
1779 | }; | |
1780 | ||
e59058c4 | 1781 | /* Array of HBQs */ |
78b2d852 | 1782 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1783 | &lpfc_els_hbq, |
51ef4c26 | 1784 | &lpfc_extra_hbq, |
92d7f7b0 | 1785 | }; |
ed957684 | 1786 | |
e59058c4 | 1787 | /** |
3621a710 | 1788 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1789 | * @phba: Pointer to HBA context object. |
1790 | * @hbqno: HBQ number. | |
1791 | * @count: Number of HBQ buffers to be posted. | |
1792 | * | |
d7c255b2 JS |
1793 | * This function is called with no lock held to post more hbq buffers to the |
1794 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1795 | * posted. | |
e59058c4 | 1796 | **/ |
311464ec | 1797 | static int |
92d7f7b0 | 1798 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1799 | { |
d7c255b2 | 1800 | uint32_t i, posted = 0; |
3163f725 | 1801 | unsigned long flags; |
92d7f7b0 | 1802 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1803 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1804 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1805 | return 0; |
51ef4c26 | 1806 | |
d7c255b2 JS |
1807 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1808 | lpfc_hbq_defs[hbqno]->entry_count) | |
1809 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1810 | phba->hbqs[hbqno].buffer_count; | |
1811 | if (!count) | |
1812 | return 0; | |
1813 | /* Allocate HBQ entries */ | |
1814 | for (i = 0; i < count; i++) { | |
1815 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1816 | if (!hbq_buffer) | |
1817 | break; | |
1818 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1819 | } | |
3163f725 JS |
1820 | /* Check whether HBQ is still in use */ |
1821 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1822 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1823 | goto err; |
1824 | while (!list_empty(&hbq_buf_list)) { | |
1825 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1826 | dbuf.list); | |
1827 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1828 | (hbqno << 16)); | |
3772a991 | 1829 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1830 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1831 | posted++; |
1832 | } else | |
51ef4c26 | 1833 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1834 | } |
3163f725 | 1835 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1836 | return posted; |
1837 | err: | |
eafe1df9 | 1838 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1839 | while (!list_empty(&hbq_buf_list)) { |
1840 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1841 | dbuf.list); | |
1842 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1843 | } | |
1844 | return 0; | |
ed957684 JS |
1845 | } |
1846 | ||
e59058c4 | 1847 | /** |
3621a710 | 1848 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1849 | * @phba: Pointer to HBA context object. |
1850 | * @qno: HBQ number. | |
1851 | * | |
1852 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1853 | * is called with no lock held. The function returns the number of HBQ entries |
1854 | * successfully allocated. | |
e59058c4 | 1855 | **/ |
92d7f7b0 JS |
1856 | int |
1857 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1858 | { |
def9c7a9 JS |
1859 | if (phba->sli_rev == LPFC_SLI_REV4) |
1860 | return 0; | |
1861 | else | |
1862 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1863 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1864 | } |
ed957684 | 1865 | |
e59058c4 | 1866 | /** |
3621a710 | 1867 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1868 | * @phba: Pointer to HBA context object. |
1869 | * @qno: HBQ queue number. | |
1870 | * | |
1871 | * This function is called from SLI initialization code path with | |
1872 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1873 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1874 | **/ |
a6ababd2 | 1875 | static int |
92d7f7b0 JS |
1876 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1877 | { | |
def9c7a9 JS |
1878 | if (phba->sli_rev == LPFC_SLI_REV4) |
1879 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1880 | lpfc_hbq_defs[qno]->entry_count); | |
1881 | else | |
1882 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1883 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1884 | } |
1885 | ||
3772a991 JS |
1886 | /** |
1887 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1888 | * @phba: Pointer to HBA context object. | |
1889 | * @hbqno: HBQ number. | |
1890 | * | |
1891 | * This function removes the first hbq buffer on an hbq list and returns a | |
1892 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1893 | **/ | |
1894 | static struct hbq_dmabuf * | |
1895 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1896 | { | |
1897 | struct lpfc_dmabuf *d_buf; | |
1898 | ||
1899 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1900 | if (!d_buf) | |
1901 | return NULL; | |
1902 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1903 | } | |
1904 | ||
e59058c4 | 1905 | /** |
3621a710 | 1906 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1907 | * @phba: Pointer to HBA context object. |
1908 | * @tag: Tag of the hbq buffer. | |
1909 | * | |
1910 | * This function is called with hbalock held. This function searches | |
1911 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1912 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1913 | * it returns NULL. | |
1914 | **/ | |
a6ababd2 | 1915 | static struct hbq_dmabuf * |
92d7f7b0 | 1916 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1917 | { |
92d7f7b0 JS |
1918 | struct lpfc_dmabuf *d_buf; |
1919 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1920 | uint32_t hbqno; |
1921 | ||
1922 | hbqno = tag >> 16; | |
a0a74e45 | 1923 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1924 | return NULL; |
ed957684 | 1925 | |
3772a991 | 1926 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1927 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1928 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1929 | if (hbq_buf->tag == tag) { |
3772a991 | 1930 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1931 | return hbq_buf; |
ed957684 JS |
1932 | } |
1933 | } | |
3772a991 | 1934 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1935 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1936 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1937 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1938 | return NULL; |
ed957684 JS |
1939 | } |
1940 | ||
e59058c4 | 1941 | /** |
3621a710 | 1942 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1943 | * @phba: Pointer to HBA context object. |
1944 | * @hbq_buffer: Pointer to HBQ buffer. | |
1945 | * | |
1946 | * This function is called with hbalock. This function gives back | |
1947 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1948 | * post the buffer, it will free the buffer. | |
1949 | **/ | |
ed957684 | 1950 | void |
51ef4c26 | 1951 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
1952 | { |
1953 | uint32_t hbqno; | |
1954 | ||
51ef4c26 JS |
1955 | if (hbq_buffer) { |
1956 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 1957 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 1958 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
1959 | } |
1960 | } | |
1961 | ||
e59058c4 | 1962 | /** |
3621a710 | 1963 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
1964 | * @mbxCommand: mailbox command code. |
1965 | * | |
1966 | * This function is called by the mailbox event handler function to verify | |
1967 | * that the completed mailbox command is a legitimate mailbox command. If the | |
1968 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
1969 | * and the mailbox event handler will take the HBA offline. | |
1970 | **/ | |
dea3101e JB |
1971 | static int |
1972 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
1973 | { | |
1974 | uint8_t ret; | |
1975 | ||
1976 | switch (mbxCommand) { | |
1977 | case MBX_LOAD_SM: | |
1978 | case MBX_READ_NV: | |
1979 | case MBX_WRITE_NV: | |
a8adb832 | 1980 | case MBX_WRITE_VPARMS: |
dea3101e JB |
1981 | case MBX_RUN_BIU_DIAG: |
1982 | case MBX_INIT_LINK: | |
1983 | case MBX_DOWN_LINK: | |
1984 | case MBX_CONFIG_LINK: | |
1985 | case MBX_CONFIG_RING: | |
1986 | case MBX_RESET_RING: | |
1987 | case MBX_READ_CONFIG: | |
1988 | case MBX_READ_RCONFIG: | |
1989 | case MBX_READ_SPARM: | |
1990 | case MBX_READ_STATUS: | |
1991 | case MBX_READ_RPI: | |
1992 | case MBX_READ_XRI: | |
1993 | case MBX_READ_REV: | |
1994 | case MBX_READ_LNK_STAT: | |
1995 | case MBX_REG_LOGIN: | |
1996 | case MBX_UNREG_LOGIN: | |
dea3101e JB |
1997 | case MBX_CLEAR_LA: |
1998 | case MBX_DUMP_MEMORY: | |
1999 | case MBX_DUMP_CONTEXT: | |
2000 | case MBX_RUN_DIAGS: | |
2001 | case MBX_RESTART: | |
2002 | case MBX_UPDATE_CFG: | |
2003 | case MBX_DOWN_LOAD: | |
2004 | case MBX_DEL_LD_ENTRY: | |
2005 | case MBX_RUN_PROGRAM: | |
2006 | case MBX_SET_MASK: | |
09372820 | 2007 | case MBX_SET_VARIABLE: |
dea3101e | 2008 | case MBX_UNREG_D_ID: |
41415862 | 2009 | case MBX_KILL_BOARD: |
dea3101e | 2010 | case MBX_CONFIG_FARP: |
41415862 | 2011 | case MBX_BEACON: |
dea3101e JB |
2012 | case MBX_LOAD_AREA: |
2013 | case MBX_RUN_BIU_DIAG64: | |
2014 | case MBX_CONFIG_PORT: | |
2015 | case MBX_READ_SPARM64: | |
2016 | case MBX_READ_RPI64: | |
2017 | case MBX_REG_LOGIN64: | |
76a95d75 | 2018 | case MBX_READ_TOPOLOGY: |
09372820 | 2019 | case MBX_WRITE_WWN: |
dea3101e JB |
2020 | case MBX_SET_DEBUG: |
2021 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2022 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2023 | case MBX_REG_VPI: |
2024 | case MBX_UNREG_VPI: | |
858c9f6c | 2025 | case MBX_HEARTBEAT: |
84774a4d JS |
2026 | case MBX_PORT_CAPABILITIES: |
2027 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2028 | case MBX_SLI4_CONFIG: |
2029 | case MBX_SLI4_REQ_FTRS: | |
2030 | case MBX_REG_FCFI: | |
2031 | case MBX_UNREG_FCFI: | |
2032 | case MBX_REG_VFI: | |
2033 | case MBX_UNREG_VFI: | |
2034 | case MBX_INIT_VPI: | |
2035 | case MBX_INIT_VFI: | |
2036 | case MBX_RESUME_RPI: | |
c7495937 JS |
2037 | case MBX_READ_EVENT_LOG_STATUS: |
2038 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2039 | case MBX_SECURITY_MGMT: |
2040 | case MBX_AUTH_PORT: | |
dea3101e JB |
2041 | ret = mbxCommand; |
2042 | break; | |
2043 | default: | |
2044 | ret = MBX_SHUTDOWN; | |
2045 | break; | |
2046 | } | |
2e0fef85 | 2047 | return ret; |
dea3101e | 2048 | } |
e59058c4 JS |
2049 | |
2050 | /** | |
3621a710 | 2051 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2052 | * @phba: Pointer to HBA context object. |
2053 | * @pmboxq: Pointer to mailbox command. | |
2054 | * | |
2055 | * This is completion handler function for mailbox commands issued from | |
2056 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2057 | * mailbox event handler function with no lock held. This function | |
2058 | * will wake up thread waiting on the wait queue pointed by context1 | |
2059 | * of the mailbox. | |
2060 | **/ | |
04c68496 | 2061 | void |
2e0fef85 | 2062 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
2063 | { |
2064 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2065 | unsigned long drvr_flag; |
dea3101e JB |
2066 | |
2067 | /* | |
2068 | * If pdone_q is empty, the driver thread gave up waiting and | |
2069 | * continued running. | |
2070 | */ | |
7054a606 | 2071 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2072 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
2073 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2074 | if (pdone_q) | |
2075 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2076 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
2077 | return; |
2078 | } | |
2079 | ||
e59058c4 JS |
2080 | |
2081 | /** | |
3621a710 | 2082 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2083 | * @phba: Pointer to HBA context object. |
2084 | * @pmb: Pointer to mailbox object. | |
2085 | * | |
2086 | * This function is the default mailbox completion handler. It | |
2087 | * frees the memory resources associated with the completed mailbox | |
2088 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2089 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2090 | **/ | |
dea3101e | 2091 | void |
2e0fef85 | 2092 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2093 | { |
d439d286 | 2094 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2095 | struct lpfc_dmabuf *mp; |
d439d286 | 2096 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2097 | struct Scsi_Host *shost; |
04c68496 | 2098 | uint16_t rpi, vpi; |
7054a606 JS |
2099 | int rc; |
2100 | ||
dea3101e | 2101 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2102 | |
dea3101e JB |
2103 | if (mp) { |
2104 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2105 | kfree(mp); | |
2106 | } | |
7054a606 JS |
2107 | |
2108 | /* | |
2109 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2110 | * is in re-discovery driver need to cleanup the RPI. | |
2111 | */ | |
2e0fef85 | 2112 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2113 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2114 | !pmb->u.mb.mbxStatus) { | |
2115 | rpi = pmb->u.mb.un.varWords[0]; | |
2116 | vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base; | |
2117 | lpfc_unreg_login(phba, vpi, rpi, pmb); | |
92d7f7b0 | 2118 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2119 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2120 | if (rc != MBX_NOT_FINISHED) | |
2121 | return; | |
2122 | } | |
2123 | ||
695a814e JS |
2124 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2125 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2126 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2127 | shost = lpfc_shost_from_vport(vport); |
2128 | spin_lock_irq(shost->host_lock); | |
2129 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2130 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2131 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2132 | } |
2133 | ||
d439d286 JS |
2134 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2135 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2136 | lpfc_nlp_put(ndlp); | |
2137 | pmb->context2 = NULL; | |
2138 | } | |
2139 | ||
dcf2a4e0 JS |
2140 | /* Check security permission status on INIT_LINK mailbox command */ |
2141 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2142 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2143 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2144 | "2860 SLI authentication is required " | |
2145 | "for INIT_LINK but has not done yet\n"); | |
2146 | ||
04c68496 JS |
2147 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2148 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2149 | else | |
2150 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e JB |
2151 | } |
2152 | ||
e59058c4 | 2153 | /** |
3621a710 | 2154 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2155 | * @phba: Pointer to HBA context object. |
2156 | * | |
2157 | * This function is called with no lock held. This function processes all | |
2158 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2159 | * service routine processes mailbox completion interrupt and adds completed | |
2160 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2161 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2162 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2163 | * function returns the mailbox commands to the upper layer by calling the | |
2164 | * completion handler function of each mailbox. | |
2165 | **/ | |
dea3101e | 2166 | int |
2e0fef85 | 2167 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2168 | { |
92d7f7b0 | 2169 | MAILBOX_t *pmbox; |
dea3101e | 2170 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2171 | int rc; |
2172 | LIST_HEAD(cmplq); | |
dea3101e JB |
2173 | |
2174 | phba->sli.slistat.mbox_event++; | |
2175 | ||
92d7f7b0 JS |
2176 | /* Get all completed mailboxe buffers into the cmplq */ |
2177 | spin_lock_irq(&phba->hbalock); | |
2178 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2179 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2180 | |
92d7f7b0 JS |
2181 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2182 | do { | |
2183 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2184 | if (pmb == NULL) | |
2185 | break; | |
2e0fef85 | 2186 | |
04c68496 | 2187 | pmbox = &pmb->u.mb; |
dea3101e | 2188 | |
858c9f6c JS |
2189 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2190 | if (pmb->vport) { | |
2191 | lpfc_debugfs_disc_trc(pmb->vport, | |
2192 | LPFC_DISC_TRC_MBOX_VPORT, | |
2193 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2194 | (uint32_t)pmbox->mbxCommand, | |
2195 | pmbox->un.varWords[0], | |
2196 | pmbox->un.varWords[1]); | |
2197 | } | |
2198 | else { | |
2199 | lpfc_debugfs_disc_trc(phba->pport, | |
2200 | LPFC_DISC_TRC_MBOX, | |
2201 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2202 | (uint32_t)pmbox->mbxCommand, | |
2203 | pmbox->un.varWords[0], | |
2204 | pmbox->un.varWords[1]); | |
2205 | } | |
2206 | } | |
2207 | ||
dea3101e JB |
2208 | /* |
2209 | * It is a fatal error if unknown mbox command completion. | |
2210 | */ | |
2211 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2212 | MBX_SHUTDOWN) { | |
af901ca1 | 2213 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2214 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2215 | "(%d):0323 Unknown Mailbox command " |
04c68496 | 2216 | "x%x (x%x) Cmpl\n", |
92d7f7b0 | 2217 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 JS |
2218 | pmbox->mbxCommand, |
2219 | lpfc_sli4_mbox_opcode_get(phba, pmb)); | |
2e0fef85 | 2220 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2221 | phba->work_hs = HS_FFER3; |
2222 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2223 | continue; |
dea3101e JB |
2224 | } |
2225 | ||
dea3101e JB |
2226 | if (pmbox->mbxStatus) { |
2227 | phba->sli.slistat.mbox_stat_err++; | |
2228 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2229 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 JS |
2230 | lpfc_printf_log(phba, KERN_INFO, |
2231 | LOG_MBOX | LOG_SLI, | |
e8b62011 | 2232 | "(%d):0305 Mbox cmd cmpl " |
92d7f7b0 | 2233 | "error - RETRYing Data: x%x " |
04c68496 | 2234 | "(x%x) x%x x%x x%x\n", |
92d7f7b0 JS |
2235 | pmb->vport ? pmb->vport->vpi :0, |
2236 | pmbox->mbxCommand, | |
04c68496 JS |
2237 | lpfc_sli4_mbox_opcode_get(phba, |
2238 | pmb), | |
92d7f7b0 JS |
2239 | pmbox->mbxStatus, |
2240 | pmbox->un.varWords[0], | |
2241 | pmb->vport->port_state); | |
dea3101e JB |
2242 | pmbox->mbxStatus = 0; |
2243 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2244 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2245 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2246 | continue; |
dea3101e JB |
2247 | } |
2248 | } | |
2249 | ||
2250 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2251 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
04c68496 | 2252 | "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p " |
dea3101e | 2253 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2254 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2255 | pmbox->mbxCommand, |
04c68496 | 2256 | lpfc_sli4_mbox_opcode_get(phba, pmb), |
dea3101e JB |
2257 | pmb->mbox_cmpl, |
2258 | *((uint32_t *) pmbox), | |
2259 | pmbox->un.varWords[0], | |
2260 | pmbox->un.varWords[1], | |
2261 | pmbox->un.varWords[2], | |
2262 | pmbox->un.varWords[3], | |
2263 | pmbox->un.varWords[4], | |
2264 | pmbox->un.varWords[5], | |
2265 | pmbox->un.varWords[6], | |
2266 | pmbox->un.varWords[7]); | |
2267 | ||
92d7f7b0 | 2268 | if (pmb->mbox_cmpl) |
dea3101e | 2269 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2270 | } while (1); |
2271 | return 0; | |
2272 | } | |
dea3101e | 2273 | |
e59058c4 | 2274 | /** |
3621a710 | 2275 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2276 | * @phba: Pointer to HBA context object. |
2277 | * @pring: Pointer to driver SLI ring object. | |
2278 | * @tag: buffer tag. | |
2279 | * | |
2280 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2281 | * is set in the tag the buffer is posted for a particular exchange, | |
2282 | * the function will return the buffer without replacing the buffer. | |
2283 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2284 | * returns the buffer and also posts another buffer to the firmware. | |
2285 | **/ | |
76bb24ef JS |
2286 | static struct lpfc_dmabuf * |
2287 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2288 | struct lpfc_sli_ring *pring, |
2289 | uint32_t tag) | |
76bb24ef | 2290 | { |
9f1e1b50 JS |
2291 | struct hbq_dmabuf *hbq_entry; |
2292 | ||
76bb24ef JS |
2293 | if (tag & QUE_BUFTAG_BIT) |
2294 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2295 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2296 | if (!hbq_entry) | |
2297 | return NULL; | |
2298 | return &hbq_entry->dbuf; | |
76bb24ef | 2299 | } |
57127f15 | 2300 | |
3772a991 JS |
2301 | /** |
2302 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2303 | * @phba: Pointer to HBA context object. | |
2304 | * @pring: Pointer to driver SLI ring object. | |
2305 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2306 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2307 | * @fch_type: the type for the first frame of the sequence. | |
2308 | * | |
2309 | * This function is called with no lock held. This function uses the r_ctl and | |
2310 | * type of the received sequence to find the correct callback function to call | |
2311 | * to process the sequence. | |
2312 | **/ | |
2313 | static int | |
2314 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2315 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2316 | uint32_t fch_type) | |
2317 | { | |
2318 | int i; | |
2319 | ||
2320 | /* unSolicited Responses */ | |
2321 | if (pring->prt[0].profile) { | |
2322 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2323 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2324 | saveq); | |
2325 | return 1; | |
2326 | } | |
2327 | /* We must search, based on rctl / type | |
2328 | for the right routine */ | |
2329 | for (i = 0; i < pring->num_mask; i++) { | |
2330 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2331 | (pring->prt[i].type == fch_type)) { | |
2332 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2333 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2334 | (phba, pring, saveq); | |
2335 | return 1; | |
2336 | } | |
2337 | } | |
2338 | return 0; | |
2339 | } | |
e59058c4 JS |
2340 | |
2341 | /** | |
3621a710 | 2342 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2343 | * @phba: Pointer to HBA context object. |
2344 | * @pring: Pointer to driver SLI ring object. | |
2345 | * @saveq: Pointer to the unsolicited iocb. | |
2346 | * | |
2347 | * This function is called with no lock held by the ring event handler | |
2348 | * when there is an unsolicited iocb posted to the response ring by the | |
2349 | * firmware. This function gets the buffer associated with the iocbs | |
2350 | * and calls the event handler for the ring. This function handles both | |
2351 | * qring buffers and hbq buffers. | |
2352 | * When the function returns 1 the caller can free the iocb object otherwise | |
2353 | * upper layer functions will free the iocb objects. | |
2354 | **/ | |
dea3101e JB |
2355 | static int |
2356 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2357 | struct lpfc_iocbq *saveq) | |
2358 | { | |
2359 | IOCB_t * irsp; | |
2360 | WORD5 * w5p; | |
2361 | uint32_t Rctl, Type; | |
3772a991 | 2362 | uint32_t match; |
76bb24ef | 2363 | struct lpfc_iocbq *iocbq; |
3163f725 | 2364 | struct lpfc_dmabuf *dmzbuf; |
dea3101e JB |
2365 | |
2366 | match = 0; | |
2367 | irsp = &(saveq->iocb); | |
57127f15 JS |
2368 | |
2369 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2370 | if (pring->lpfc_sli_rcv_async_status) | |
2371 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2372 | else | |
2373 | lpfc_printf_log(phba, | |
2374 | KERN_WARNING, | |
2375 | LOG_SLI, | |
2376 | "0316 Ring %d handler: unexpected " | |
2377 | "ASYNC_STATUS iocb received evt_code " | |
2378 | "0x%x\n", | |
2379 | pring->ringno, | |
2380 | irsp->un.asyncstat.evt_code); | |
2381 | return 1; | |
2382 | } | |
2383 | ||
3163f725 JS |
2384 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2385 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2386 | if (irsp->ulpBdeCount > 0) { | |
2387 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2388 | irsp->un.ulpWord[3]); | |
2389 | lpfc_in_buf_free(phba, dmzbuf); | |
2390 | } | |
2391 | ||
2392 | if (irsp->ulpBdeCount > 1) { | |
2393 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2394 | irsp->unsli3.sli3Words[3]); | |
2395 | lpfc_in_buf_free(phba, dmzbuf); | |
2396 | } | |
2397 | ||
2398 | if (irsp->ulpBdeCount > 2) { | |
2399 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2400 | irsp->unsli3.sli3Words[7]); | |
2401 | lpfc_in_buf_free(phba, dmzbuf); | |
2402 | } | |
2403 | ||
2404 | return 1; | |
2405 | } | |
2406 | ||
92d7f7b0 | 2407 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2408 | if (irsp->ulpBdeCount != 0) { |
2409 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2410 | irsp->un.ulpWord[3]); | |
2411 | if (!saveq->context2) | |
2412 | lpfc_printf_log(phba, | |
2413 | KERN_ERR, | |
2414 | LOG_SLI, | |
2415 | "0341 Ring %d Cannot find buffer for " | |
2416 | "an unsolicited iocb. tag 0x%x\n", | |
2417 | pring->ringno, | |
2418 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2419 | } |
2420 | if (irsp->ulpBdeCount == 2) { | |
2421 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2422 | irsp->unsli3.sli3Words[7]); | |
2423 | if (!saveq->context3) | |
2424 | lpfc_printf_log(phba, | |
2425 | KERN_ERR, | |
2426 | LOG_SLI, | |
2427 | "0342 Ring %d Cannot find buffer for an" | |
2428 | " unsolicited iocb. tag 0x%x\n", | |
2429 | pring->ringno, | |
2430 | irsp->unsli3.sli3Words[7]); | |
2431 | } | |
2432 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2433 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2434 | if (irsp->ulpBdeCount != 0) { |
2435 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2436 | irsp->un.ulpWord[3]); | |
9c2face6 | 2437 | if (!iocbq->context2) |
76bb24ef JS |
2438 | lpfc_printf_log(phba, |
2439 | KERN_ERR, | |
2440 | LOG_SLI, | |
2441 | "0343 Ring %d Cannot find " | |
2442 | "buffer for an unsolicited iocb" | |
2443 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2444 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2445 | } |
2446 | if (irsp->ulpBdeCount == 2) { | |
2447 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2448 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2449 | if (!iocbq->context3) |
76bb24ef JS |
2450 | lpfc_printf_log(phba, |
2451 | KERN_ERR, | |
2452 | LOG_SLI, | |
2453 | "0344 Ring %d Cannot find " | |
2454 | "buffer for an unsolicited " | |
2455 | "iocb. tag 0x%x\n", | |
2456 | pring->ringno, | |
2457 | irsp->unsli3.sli3Words[7]); | |
2458 | } | |
2459 | } | |
92d7f7b0 | 2460 | } |
9c2face6 JS |
2461 | if (irsp->ulpBdeCount != 0 && |
2462 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2463 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2464 | int found = 0; | |
2465 | ||
2466 | /* search continue save q for same XRI */ | |
2467 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
2468 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { | |
2469 | list_add_tail(&saveq->list, &iocbq->list); | |
2470 | found = 1; | |
2471 | break; | |
2472 | } | |
2473 | } | |
2474 | if (!found) | |
2475 | list_add_tail(&saveq->clist, | |
2476 | &pring->iocb_continue_saveq); | |
2477 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2478 | list_del_init(&iocbq->clist); | |
2479 | saveq = iocbq; | |
2480 | irsp = &(saveq->iocb); | |
2481 | } else | |
2482 | return 0; | |
2483 | } | |
2484 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2485 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2486 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2487 | Rctl = FC_RCTL_ELS_REQ; |
2488 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2489 | } else { |
2490 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2491 | Rctl = w5p->hcsw.Rctl; | |
2492 | Type = w5p->hcsw.Type; | |
2493 | ||
2494 | /* Firmware Workaround */ | |
2495 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2496 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2497 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2498 | Rctl = FC_RCTL_ELS_REQ; |
2499 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2500 | w5p->hcsw.Rctl = Rctl; |
2501 | w5p->hcsw.Type = Type; | |
2502 | } | |
2503 | } | |
92d7f7b0 | 2504 | |
3772a991 | 2505 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2506 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2507 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2508 | "Type x%x received\n", |
e8b62011 | 2509 | pring->ringno, Rctl, Type); |
3772a991 | 2510 | |
92d7f7b0 | 2511 | return 1; |
dea3101e JB |
2512 | } |
2513 | ||
e59058c4 | 2514 | /** |
3621a710 | 2515 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2516 | * @phba: Pointer to HBA context object. |
2517 | * @pring: Pointer to driver SLI ring object. | |
2518 | * @prspiocb: Pointer to response iocb object. | |
2519 | * | |
2520 | * This function looks up the iocb_lookup table to get the command iocb | |
2521 | * corresponding to the given response iocb using the iotag of the | |
2522 | * response iocb. This function is called with the hbalock held. | |
2523 | * This function returns the command iocb object if it finds the command | |
2524 | * iocb else returns NULL. | |
2525 | **/ | |
dea3101e | 2526 | static struct lpfc_iocbq * |
2e0fef85 JS |
2527 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2528 | struct lpfc_sli_ring *pring, | |
2529 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2530 | { |
dea3101e JB |
2531 | struct lpfc_iocbq *cmd_iocb = NULL; |
2532 | uint16_t iotag; | |
2533 | ||
604a3e30 JB |
2534 | iotag = prspiocb->iocb.ulpIoTag; |
2535 | ||
2536 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2537 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2538 | list_del_init(&cmd_iocb->list); |
2a9bf3d0 JS |
2539 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2540 | pring->txcmplq_cnt--; | |
2541 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2542 | } | |
604a3e30 | 2543 | return cmd_iocb; |
dea3101e JB |
2544 | } |
2545 | ||
dea3101e | 2546 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2547 | "0317 iotag x%x is out off " |
604a3e30 | 2548 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2549 | iotag, phba->sli.last_iotag, |
604a3e30 | 2550 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
2551 | return NULL; |
2552 | } | |
2553 | ||
3772a991 JS |
2554 | /** |
2555 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2556 | * @phba: Pointer to HBA context object. | |
2557 | * @pring: Pointer to driver SLI ring object. | |
2558 | * @iotag: IOCB tag. | |
2559 | * | |
2560 | * This function looks up the iocb_lookup table to get the command iocb | |
2561 | * corresponding to the given iotag. This function is called with the | |
2562 | * hbalock held. | |
2563 | * This function returns the command iocb object if it finds the command | |
2564 | * iocb else returns NULL. | |
2565 | **/ | |
2566 | static struct lpfc_iocbq * | |
2567 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2568 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2569 | { | |
2570 | struct lpfc_iocbq *cmd_iocb; | |
2571 | ||
2572 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2573 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
2574 | list_del_init(&cmd_iocb->list); | |
2a9bf3d0 JS |
2575 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2576 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2577 | pring->txcmplq_cnt--; | |
2578 | } | |
3772a991 JS |
2579 | return cmd_iocb; |
2580 | } | |
2581 | ||
2582 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2583 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2584 | iotag, phba->sli.last_iotag); | |
2585 | return NULL; | |
2586 | } | |
2587 | ||
e59058c4 | 2588 | /** |
3621a710 | 2589 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2590 | * @phba: Pointer to HBA context object. |
2591 | * @pring: Pointer to driver SLI ring object. | |
2592 | * @saveq: Pointer to the response iocb to be processed. | |
2593 | * | |
2594 | * This function is called by the ring event handler for non-fcp | |
2595 | * rings when there is a new response iocb in the response ring. | |
2596 | * The caller is not required to hold any locks. This function | |
2597 | * gets the command iocb associated with the response iocb and | |
2598 | * calls the completion handler for the command iocb. If there | |
2599 | * is no completion handler, the function will free the resources | |
2600 | * associated with command iocb. If the response iocb is for | |
2601 | * an already aborted command iocb, the status of the completion | |
2602 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2603 | * This function always returns 1. | |
2604 | **/ | |
dea3101e | 2605 | static int |
2e0fef85 | 2606 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
2607 | struct lpfc_iocbq *saveq) |
2608 | { | |
2e0fef85 | 2609 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
2610 | int rc = 1; |
2611 | unsigned long iflag; | |
2612 | ||
2613 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2614 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2615 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2616 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2617 | ||
dea3101e JB |
2618 | if (cmdiocbp) { |
2619 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2620 | /* |
2621 | * If an ELS command failed send an event to mgmt | |
2622 | * application. | |
2623 | */ | |
2624 | if (saveq->iocb.ulpStatus && | |
2625 | (pring->ringno == LPFC_ELS_RING) && | |
2626 | (cmdiocbp->iocb.ulpCommand == | |
2627 | CMD_ELS_REQUEST64_CR)) | |
2628 | lpfc_send_els_failure_event(phba, | |
2629 | cmdiocbp, saveq); | |
2630 | ||
dea3101e JB |
2631 | /* |
2632 | * Post all ELS completions to the worker thread. | |
2633 | * All other are passed to the completion callback. | |
2634 | */ | |
2635 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2636 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2637 | (cmdiocbp->iocb_flag & | |
2638 | LPFC_DRIVER_ABORTED)) { | |
2639 | spin_lock_irqsave(&phba->hbalock, | |
2640 | iflag); | |
07951076 JS |
2641 | cmdiocbp->iocb_flag &= |
2642 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2643 | spin_unlock_irqrestore(&phba->hbalock, |
2644 | iflag); | |
07951076 JS |
2645 | saveq->iocb.ulpStatus = |
2646 | IOSTAT_LOCAL_REJECT; | |
2647 | saveq->iocb.un.ulpWord[4] = | |
2648 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2649 | |
2650 | /* Firmware could still be in progress | |
2651 | * of DMAing payload, so don't free data | |
2652 | * buffer till after a hbeat. | |
2653 | */ | |
341af102 JS |
2654 | spin_lock_irqsave(&phba->hbalock, |
2655 | iflag); | |
0ff10d46 | 2656 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2657 | spin_unlock_irqrestore(&phba->hbalock, |
2658 | iflag); | |
2659 | } | |
0f65ff68 JS |
2660 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2661 | if (saveq->iocb_flag & | |
2662 | LPFC_EXCHANGE_BUSY) { | |
2663 | /* Set cmdiocb flag for the | |
2664 | * exchange busy so sgl (xri) | |
2665 | * will not be released until | |
2666 | * the abort xri is received | |
2667 | * from hba. | |
2668 | */ | |
2669 | spin_lock_irqsave( | |
2670 | &phba->hbalock, iflag); | |
2671 | cmdiocbp->iocb_flag |= | |
2672 | LPFC_EXCHANGE_BUSY; | |
2673 | spin_unlock_irqrestore( | |
2674 | &phba->hbalock, iflag); | |
2675 | } | |
2676 | if (cmdiocbp->iocb_flag & | |
2677 | LPFC_DRIVER_ABORTED) { | |
2678 | /* | |
2679 | * Clear LPFC_DRIVER_ABORTED | |
2680 | * bit in case it was driver | |
2681 | * initiated abort. | |
2682 | */ | |
2683 | spin_lock_irqsave( | |
2684 | &phba->hbalock, iflag); | |
2685 | cmdiocbp->iocb_flag &= | |
2686 | ~LPFC_DRIVER_ABORTED; | |
2687 | spin_unlock_irqrestore( | |
2688 | &phba->hbalock, iflag); | |
2689 | cmdiocbp->iocb.ulpStatus = | |
2690 | IOSTAT_LOCAL_REJECT; | |
2691 | cmdiocbp->iocb.un.ulpWord[4] = | |
2692 | IOERR_ABORT_REQUESTED; | |
2693 | /* | |
2694 | * For SLI4, irsiocb contains | |
2695 | * NO_XRI in sli_xritag, it | |
2696 | * shall not affect releasing | |
2697 | * sgl (xri) process. | |
2698 | */ | |
2699 | saveq->iocb.ulpStatus = | |
2700 | IOSTAT_LOCAL_REJECT; | |
2701 | saveq->iocb.un.ulpWord[4] = | |
2702 | IOERR_SLI_ABORTED; | |
2703 | spin_lock_irqsave( | |
2704 | &phba->hbalock, iflag); | |
2705 | saveq->iocb_flag |= | |
2706 | LPFC_DELAY_MEM_FREE; | |
2707 | spin_unlock_irqrestore( | |
2708 | &phba->hbalock, iflag); | |
2709 | } | |
07951076 | 2710 | } |
dea3101e | 2711 | } |
2e0fef85 | 2712 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2713 | } else |
2714 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
2715 | } else { |
2716 | /* | |
2717 | * Unknown initiating command based on the response iotag. | |
2718 | * This could be the case on the ELS ring because of | |
2719 | * lpfc_els_abort(). | |
2720 | */ | |
2721 | if (pring->ringno != LPFC_ELS_RING) { | |
2722 | /* | |
2723 | * Ring <ringno> handler: unexpected completion IoTag | |
2724 | * <IoTag> | |
2725 | */ | |
a257bf90 | 2726 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2727 | "0322 Ring %d handler: " |
2728 | "unexpected completion IoTag x%x " | |
2729 | "Data: x%x x%x x%x x%x\n", | |
2730 | pring->ringno, | |
2731 | saveq->iocb.ulpIoTag, | |
2732 | saveq->iocb.ulpStatus, | |
2733 | saveq->iocb.un.ulpWord[4], | |
2734 | saveq->iocb.ulpCommand, | |
2735 | saveq->iocb.ulpContext); | |
dea3101e JB |
2736 | } |
2737 | } | |
68876920 | 2738 | |
dea3101e JB |
2739 | return rc; |
2740 | } | |
2741 | ||
e59058c4 | 2742 | /** |
3621a710 | 2743 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2744 | * @phba: Pointer to HBA context object. |
2745 | * @pring: Pointer to driver SLI ring object. | |
2746 | * | |
2747 | * This function is called from the iocb ring event handlers when | |
2748 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2749 | * an error attention condition to the worker thread and the worker | |
2750 | * thread will transition the HBA to offline state. | |
2751 | **/ | |
2e0fef85 JS |
2752 | static void |
2753 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2754 | { |
34b02dcd | 2755 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2756 | /* |
025dfdaf | 2757 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2758 | * rsp ring <portRspMax> |
2759 | */ | |
2760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2761 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2762 | "is bigger than rsp ring %d\n", |
e8b62011 | 2763 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
2764 | pring->numRiocb); |
2765 | ||
2e0fef85 | 2766 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2767 | |
2768 | /* | |
2769 | * All error attention handlers are posted to | |
2770 | * worker thread | |
2771 | */ | |
2772 | phba->work_ha |= HA_ERATT; | |
2773 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2774 | |
5e9d9b82 | 2775 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2776 | |
2777 | return; | |
2778 | } | |
2779 | ||
9399627f | 2780 | /** |
3621a710 | 2781 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2782 | * @ptr: Pointer to address of HBA context object. |
2783 | * | |
2784 | * This function is invoked by the Error Attention polling timer when the | |
2785 | * timer times out. It will check the SLI Error Attention register for | |
2786 | * possible attention events. If so, it will post an Error Attention event | |
2787 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2788 | * Error Attention polling timer for the next poll. | |
2789 | **/ | |
2790 | void lpfc_poll_eratt(unsigned long ptr) | |
2791 | { | |
2792 | struct lpfc_hba *phba; | |
2793 | uint32_t eratt = 0; | |
2794 | ||
2795 | phba = (struct lpfc_hba *)ptr; | |
2796 | ||
2797 | /* Check chip HA register for error event */ | |
2798 | eratt = lpfc_sli_check_eratt(phba); | |
2799 | ||
2800 | if (eratt) | |
2801 | /* Tell the worker thread there is work to do */ | |
2802 | lpfc_worker_wake_up(phba); | |
2803 | else | |
2804 | /* Restart the timer for next eratt poll */ | |
2805 | mod_timer(&phba->eratt_poll, jiffies + | |
2806 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2807 | return; | |
2808 | } | |
2809 | ||
875fbdfe | 2810 | |
e59058c4 | 2811 | /** |
3621a710 | 2812 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2813 | * @phba: Pointer to HBA context object. |
2814 | * @pring: Pointer to driver SLI ring object. | |
2815 | * @mask: Host attention register mask for this ring. | |
2816 | * | |
2817 | * This function is called from the interrupt context when there is a ring | |
2818 | * event for the fcp ring. The caller does not hold any lock. | |
2819 | * The function processes each response iocb in the response ring until it | |
25985edc | 2820 | * finds an iocb with LE bit set and chains all the iocbs up to the iocb with |
e59058c4 JS |
2821 | * LE bit set. The function will call the completion handler of the command iocb |
2822 | * if the response iocb indicates a completion for a command iocb or it is | |
2823 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2824 | * function if this is an unsolicited iocb. | |
dea3101e | 2825 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2826 | * to check it explicitly. |
2827 | */ | |
2828 | int | |
2e0fef85 JS |
2829 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2830 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2831 | { |
34b02dcd | 2832 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2833 | IOCB_t *irsp = NULL; |
87f6eaff | 2834 | IOCB_t *entry = NULL; |
dea3101e JB |
2835 | struct lpfc_iocbq *cmdiocbq = NULL; |
2836 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
2837 | uint32_t status; |
2838 | uint32_t portRspPut, portRspMax; | |
2839 | int rc = 1; | |
2840 | lpfc_iocb_type type; | |
2841 | unsigned long iflag; | |
2842 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2843 | |
2e0fef85 | 2844 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2845 | pring->stats.iocb_event++; |
2846 | ||
dea3101e JB |
2847 | /* |
2848 | * The next available response entry should never exceed the maximum | |
2849 | * entries. If it does, treat it as an adapter hardware error. | |
2850 | */ | |
2851 | portRspMax = pring->numRiocb; | |
2852 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2853 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2854 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2855 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2856 | return 1; |
2857 | } | |
45ed1190 JS |
2858 | if (phba->fcp_ring_in_use) { |
2859 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2860 | return 1; | |
2861 | } else | |
2862 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
2863 | |
2864 | rmb(); | |
2865 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
2866 | /* |
2867 | * Fetch an entry off the ring and copy it into a local data | |
2868 | * structure. The copy involves a byte-swap since the | |
2869 | * network byte order and pci byte orders are different. | |
2870 | */ | |
ed957684 | 2871 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2872 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
2873 | |
2874 | if (++pring->rspidx >= portRspMax) | |
2875 | pring->rspidx = 0; | |
2876 | ||
87f6eaff JSEC |
2877 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2878 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2879 | phba->iocb_rsp_size); |
a4bc3379 | 2880 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2881 | irsp = &rspiocbq.iocb; |
2882 | ||
dea3101e JB |
2883 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2884 | pring->stats.iocb_rsp++; | |
2885 | rsp_cmpl++; | |
2886 | ||
2887 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2888 | /* |
2889 | * If resource errors reported from HBA, reduce | |
2890 | * queuedepths of the SCSI device. | |
2891 | */ | |
2892 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2893 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2894 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2895 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2896 | spin_lock_irqsave(&phba->hbalock, iflag); |
2897 | } | |
2898 | ||
dea3101e JB |
2899 | /* Rsp ring <ringno> error: IOCB */ |
2900 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2901 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2902 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2903 | pring->ringno, |
92d7f7b0 JS |
2904 | irsp->un.ulpWord[0], |
2905 | irsp->un.ulpWord[1], | |
2906 | irsp->un.ulpWord[2], | |
2907 | irsp->un.ulpWord[3], | |
2908 | irsp->un.ulpWord[4], | |
2909 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2910 | *(uint32_t *)&irsp->un1, |
2911 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
2912 | } |
2913 | ||
2914 | switch (type) { | |
2915 | case LPFC_ABORT_IOCB: | |
2916 | case LPFC_SOL_IOCB: | |
2917 | /* | |
2918 | * Idle exchange closed via ABTS from port. No iocb | |
2919 | * resources need to be recovered. | |
2920 | */ | |
2921 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2922 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2923 | "0333 IOCB cmd 0x%x" |
dca9479b | 2924 | " processed. Skipping" |
92d7f7b0 | 2925 | " completion\n", |
dca9479b | 2926 | irsp->ulpCommand); |
dea3101e JB |
2927 | break; |
2928 | } | |
2929 | ||
604a3e30 JB |
2930 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2931 | &rspiocbq); | |
0f65ff68 JS |
2932 | if (unlikely(!cmdiocbq)) |
2933 | break; | |
2934 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2935 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2936 | if (cmdiocbq->iocb_cmpl) { | |
2937 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2938 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2939 | &rspiocbq); | |
2940 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2941 | } | |
dea3101e | 2942 | break; |
a4bc3379 | 2943 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2944 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2945 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2946 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2947 | break; |
dea3101e JB |
2948 | default: |
2949 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2950 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2951 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2952 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2953 | MAX_MSG_DATA); | |
898eb71c JP |
2954 | dev_warn(&((phba->pcidev)->dev), |
2955 | "lpfc%d: %s\n", | |
dea3101e JB |
2956 | phba->brd_no, adaptermsg); |
2957 | } else { | |
2958 | /* Unknown IOCB command */ | |
2959 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2960 | "0334 Unknown IOCB command " |
92d7f7b0 | 2961 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2962 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2963 | irsp->ulpStatus, |
2964 | irsp->ulpIoTag, | |
2965 | irsp->ulpContext); | |
dea3101e JB |
2966 | } |
2967 | break; | |
2968 | } | |
2969 | ||
2970 | /* | |
2971 | * The response IOCB has been processed. Update the ring | |
2972 | * pointer in SLIM. If the port response put pointer has not | |
2973 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2974 | * response put pointer. | |
2975 | */ | |
ed957684 | 2976 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e JB |
2977 | |
2978 | if (pring->rspidx == portRspPut) | |
2979 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2980 | } | |
2981 | ||
2982 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
2983 | pring->stats.iocb_rsp_full++; | |
2984 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2985 | writel(status, phba->CAregaddr); | |
2986 | readl(phba->CAregaddr); | |
2987 | } | |
2988 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2989 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2990 | pring->stats.iocb_cmd_empty++; | |
2991 | ||
2992 | /* Force update of the local copy of cmdGetInx */ | |
2993 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2994 | lpfc_sli_resume_iocb(phba, pring); | |
2995 | ||
2996 | if ((pring->lpfc_sli_cmd_available)) | |
2997 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2998 | ||
2999 | } | |
3000 | ||
45ed1190 | 3001 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3002 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3003 | return rc; |
3004 | } | |
3005 | ||
e59058c4 | 3006 | /** |
3772a991 JS |
3007 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3008 | * @phba: Pointer to HBA context object. | |
3009 | * @pring: Pointer to driver SLI ring object. | |
3010 | * @rspiocbp: Pointer to driver response IOCB object. | |
3011 | * | |
3012 | * This function is called from the worker thread when there is a slow-path | |
3013 | * response IOCB to process. This function chains all the response iocbs until | |
3014 | * seeing the iocb with the LE bit set. The function will call | |
3015 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3016 | * completion of a command iocb. The function will call the | |
3017 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3018 | * The function frees the resources or calls the completion handler if this | |
3019 | * iocb is an abort completion. The function returns NULL when the response | |
3020 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3021 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3022 | * response iocb passed in. | |
3023 | **/ | |
3024 | static struct lpfc_iocbq * | |
3025 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3026 | struct lpfc_iocbq *rspiocbp) | |
3027 | { | |
3028 | struct lpfc_iocbq *saveq; | |
3029 | struct lpfc_iocbq *cmdiocbp; | |
3030 | struct lpfc_iocbq *next_iocb; | |
3031 | IOCB_t *irsp = NULL; | |
3032 | uint32_t free_saveq; | |
3033 | uint8_t iocb_cmd_type; | |
3034 | lpfc_iocb_type type; | |
3035 | unsigned long iflag; | |
3036 | int rc; | |
3037 | ||
3038 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3039 | /* First add the response iocb to the countinueq list */ | |
3040 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3041 | pring->iocb_continueq_cnt++; | |
3042 | ||
70f23fd6 | 3043 | /* Now, determine whether the list is completed for processing */ |
3772a991 JS |
3044 | irsp = &rspiocbp->iocb; |
3045 | if (irsp->ulpLe) { | |
3046 | /* | |
3047 | * By default, the driver expects to free all resources | |
3048 | * associated with this iocb completion. | |
3049 | */ | |
3050 | free_saveq = 1; | |
3051 | saveq = list_get_first(&pring->iocb_continueq, | |
3052 | struct lpfc_iocbq, list); | |
3053 | irsp = &(saveq->iocb); | |
3054 | list_del_init(&pring->iocb_continueq); | |
3055 | pring->iocb_continueq_cnt = 0; | |
3056 | ||
3057 | pring->stats.iocb_rsp++; | |
3058 | ||
3059 | /* | |
3060 | * If resource errors reported from HBA, reduce | |
3061 | * queuedepths of the SCSI device. | |
3062 | */ | |
3063 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3064 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3065 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3066 | phba->lpfc_rampdown_queue_depth(phba); | |
3067 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3068 | } | |
3069 | ||
3070 | if (irsp->ulpStatus) { | |
3071 | /* Rsp ring <ringno> error: IOCB */ | |
3072 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3073 | "0328 Rsp Ring %d error: " | |
3074 | "IOCB Data: " | |
3075 | "x%x x%x x%x x%x " | |
3076 | "x%x x%x x%x x%x " | |
3077 | "x%x x%x x%x x%x " | |
3078 | "x%x x%x x%x x%x\n", | |
3079 | pring->ringno, | |
3080 | irsp->un.ulpWord[0], | |
3081 | irsp->un.ulpWord[1], | |
3082 | irsp->un.ulpWord[2], | |
3083 | irsp->un.ulpWord[3], | |
3084 | irsp->un.ulpWord[4], | |
3085 | irsp->un.ulpWord[5], | |
3086 | *(((uint32_t *) irsp) + 6), | |
3087 | *(((uint32_t *) irsp) + 7), | |
3088 | *(((uint32_t *) irsp) + 8), | |
3089 | *(((uint32_t *) irsp) + 9), | |
3090 | *(((uint32_t *) irsp) + 10), | |
3091 | *(((uint32_t *) irsp) + 11), | |
3092 | *(((uint32_t *) irsp) + 12), | |
3093 | *(((uint32_t *) irsp) + 13), | |
3094 | *(((uint32_t *) irsp) + 14), | |
3095 | *(((uint32_t *) irsp) + 15)); | |
3096 | } | |
3097 | ||
3098 | /* | |
3099 | * Fetch the IOCB command type and call the correct completion | |
3100 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3101 | * get freed back to the lpfc_iocb_list by the discovery | |
3102 | * kernel thread. | |
3103 | */ | |
3104 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3105 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3106 | switch (type) { | |
3107 | case LPFC_SOL_IOCB: | |
3108 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3109 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3110 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3111 | break; | |
3112 | ||
3113 | case LPFC_UNSOL_IOCB: | |
3114 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3115 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3116 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3117 | if (!rc) | |
3118 | free_saveq = 0; | |
3119 | break; | |
3120 | ||
3121 | case LPFC_ABORT_IOCB: | |
3122 | cmdiocbp = NULL; | |
3123 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3124 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3125 | saveq); | |
3126 | if (cmdiocbp) { | |
3127 | /* Call the specified completion routine */ | |
3128 | if (cmdiocbp->iocb_cmpl) { | |
3129 | spin_unlock_irqrestore(&phba->hbalock, | |
3130 | iflag); | |
3131 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3132 | saveq); | |
3133 | spin_lock_irqsave(&phba->hbalock, | |
3134 | iflag); | |
3135 | } else | |
3136 | __lpfc_sli_release_iocbq(phba, | |
3137 | cmdiocbp); | |
3138 | } | |
3139 | break; | |
3140 | ||
3141 | case LPFC_UNKNOWN_IOCB: | |
3142 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3143 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3144 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3145 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3146 | MAX_MSG_DATA); | |
3147 | dev_warn(&((phba->pcidev)->dev), | |
3148 | "lpfc%d: %s\n", | |
3149 | phba->brd_no, adaptermsg); | |
3150 | } else { | |
3151 | /* Unknown IOCB command */ | |
3152 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3153 | "0335 Unknown IOCB " | |
3154 | "command Data: x%x " | |
3155 | "x%x x%x x%x\n", | |
3156 | irsp->ulpCommand, | |
3157 | irsp->ulpStatus, | |
3158 | irsp->ulpIoTag, | |
3159 | irsp->ulpContext); | |
3160 | } | |
3161 | break; | |
3162 | } | |
3163 | ||
3164 | if (free_saveq) { | |
3165 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3166 | &saveq->list, list) { | |
3167 | list_del(&rspiocbp->list); | |
3168 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3169 | } | |
3170 | __lpfc_sli_release_iocbq(phba, saveq); | |
3171 | } | |
3172 | rspiocbp = NULL; | |
3173 | } | |
3174 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3175 | return rspiocbp; | |
3176 | } | |
3177 | ||
3178 | /** | |
3179 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3180 | * @phba: Pointer to HBA context object. |
3181 | * @pring: Pointer to driver SLI ring object. | |
3182 | * @mask: Host attention register mask for this ring. | |
3183 | * | |
3772a991 JS |
3184 | * This routine wraps the actual slow_ring event process routine from the |
3185 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3186 | **/ |
3772a991 | 3187 | void |
2e0fef85 JS |
3188 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3189 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3190 | { |
3191 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3192 | } | |
3193 | ||
3194 | /** | |
3195 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3196 | * @phba: Pointer to HBA context object. | |
3197 | * @pring: Pointer to driver SLI ring object. | |
3198 | * @mask: Host attention register mask for this ring. | |
3199 | * | |
3200 | * This function is called from the worker thread when there is a ring event | |
3201 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3202 | * remove each response iocb in the response ring and calls the handle | |
3203 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3204 | **/ | |
3205 | static void | |
3206 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3207 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3208 | { |
34b02dcd | 3209 | struct lpfc_pgp *pgp; |
dea3101e JB |
3210 | IOCB_t *entry; |
3211 | IOCB_t *irsp = NULL; | |
3212 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3213 | uint32_t portRspPut, portRspMax; |
dea3101e | 3214 | unsigned long iflag; |
3772a991 | 3215 | uint32_t status; |
dea3101e | 3216 | |
34b02dcd | 3217 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3218 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3219 | pring->stats.iocb_event++; |
3220 | ||
dea3101e JB |
3221 | /* |
3222 | * The next available response entry should never exceed the maximum | |
3223 | * entries. If it does, treat it as an adapter hardware error. | |
3224 | */ | |
3225 | portRspMax = pring->numRiocb; | |
3226 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3227 | if (portRspPut >= portRspMax) { | |
3228 | /* | |
025dfdaf | 3229 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
3230 | * rsp ring <portRspMax> |
3231 | */ | |
ed957684 | 3232 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3233 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3234 | "is bigger than rsp ring %d\n", |
e8b62011 | 3235 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3236 | |
2e0fef85 JS |
3237 | phba->link_state = LPFC_HBA_ERROR; |
3238 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
3239 | |
3240 | phba->work_hs = HS_FFER3; | |
3241 | lpfc_handle_eratt(phba); | |
3242 | ||
3772a991 | 3243 | return; |
dea3101e JB |
3244 | } |
3245 | ||
3246 | rmb(); | |
dea3101e JB |
3247 | while (pring->rspidx != portRspPut) { |
3248 | /* | |
3249 | * Build a completion list and call the appropriate handler. | |
3250 | * The process is to get the next available response iocb, get | |
3251 | * a free iocb from the list, copy the response data into the | |
3252 | * free iocb, insert to the continuation list, and update the | |
3253 | * next response index to slim. This process makes response | |
3254 | * iocb's in the ring available to DMA as fast as possible but | |
3255 | * pays a penalty for a copy operation. Since the iocb is | |
3256 | * only 32 bytes, this penalty is considered small relative to | |
3257 | * the PCI reads for register values and a slim write. When | |
3258 | * the ulpLe field is set, the entire Command has been | |
3259 | * received. | |
3260 | */ | |
ed957684 JS |
3261 | entry = lpfc_resp_iocb(phba, pring); |
3262 | ||
858c9f6c | 3263 | phba->last_completion_time = jiffies; |
2e0fef85 | 3264 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
3265 | if (rspiocbp == NULL) { |
3266 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3267 | "completion.\n", __func__); |
dea3101e JB |
3268 | break; |
3269 | } | |
3270 | ||
ed957684 JS |
3271 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3272 | phba->iocb_rsp_size); | |
dea3101e JB |
3273 | irsp = &rspiocbp->iocb; |
3274 | ||
3275 | if (++pring->rspidx >= portRspMax) | |
3276 | pring->rspidx = 0; | |
3277 | ||
a58cbd52 JS |
3278 | if (pring->ringno == LPFC_ELS_RING) { |
3279 | lpfc_debugfs_slow_ring_trc(phba, | |
3280 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3281 | *(((uint32_t *) irsp) + 4), | |
3282 | *(((uint32_t *) irsp) + 6), | |
3283 | *(((uint32_t *) irsp) + 7)); | |
3284 | } | |
3285 | ||
ed957684 | 3286 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 3287 | |
3772a991 JS |
3288 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3289 | /* Handle the response IOCB */ | |
3290 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3291 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
3292 | |
3293 | /* | |
3294 | * If the port response put pointer has not been updated, sync | |
3295 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3296 | * response put pointer. | |
3297 | */ | |
3298 | if (pring->rspidx == portRspPut) { | |
3299 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3300 | } | |
3301 | } /* while (pring->rspidx != portRspPut) */ | |
3302 | ||
92d7f7b0 | 3303 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
3304 | /* At least one response entry has been freed */ |
3305 | pring->stats.iocb_rsp_full++; | |
3306 | /* SET RxRE_RSP in Chip Att register */ | |
3307 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3308 | writel(status, phba->CAregaddr); | |
3309 | readl(phba->CAregaddr); /* flush */ | |
3310 | } | |
3311 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3312 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3313 | pring->stats.iocb_cmd_empty++; | |
3314 | ||
3315 | /* Force update of the local copy of cmdGetInx */ | |
3316 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3317 | lpfc_sli_resume_iocb(phba, pring); | |
3318 | ||
3319 | if ((pring->lpfc_sli_cmd_available)) | |
3320 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3321 | ||
3322 | } | |
3323 | ||
2e0fef85 | 3324 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3325 | return; |
dea3101e JB |
3326 | } |
3327 | ||
4f774513 JS |
3328 | /** |
3329 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3330 | * @phba: Pointer to HBA context object. | |
3331 | * @pring: Pointer to driver SLI ring object. | |
3332 | * @mask: Host attention register mask for this ring. | |
3333 | * | |
3334 | * This function is called from the worker thread when there is a pending | |
3335 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3336 | * queue. The caller does not hold any lock. The function will remove each | |
3337 | * response iocb from the response worker queue and calls the handle | |
3338 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3339 | **/ | |
3340 | static void | |
3341 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3342 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3343 | { | |
3344 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3345 | struct hbq_dmabuf *dmabuf; |
3346 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3347 | unsigned long iflag; |
3348 | ||
45ed1190 JS |
3349 | spin_lock_irqsave(&phba->hbalock, iflag); |
3350 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3351 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3352 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3353 | /* Get the response iocb from the head of work queue */ |
3354 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3355 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3356 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3357 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3358 | |
3359 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3360 | case CQE_CODE_COMPL_WQE: | |
3361 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3362 | cq_event); | |
45ed1190 JS |
3363 | /* Translate ELS WCQE to response IOCBQ */ |
3364 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3365 | irspiocbq); | |
3366 | if (irspiocbq) | |
3367 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3368 | irspiocbq); | |
4d9ab994 JS |
3369 | break; |
3370 | case CQE_CODE_RECEIVE: | |
3371 | dmabuf = container_of(cq_event, struct hbq_dmabuf, | |
3372 | cq_event); | |
3373 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3374 | break; | |
3375 | default: | |
3376 | break; | |
3377 | } | |
4f774513 JS |
3378 | } |
3379 | } | |
3380 | ||
e59058c4 | 3381 | /** |
3621a710 | 3382 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3383 | * @phba: Pointer to HBA context object. |
3384 | * @pring: Pointer to driver SLI ring object. | |
3385 | * | |
3386 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3387 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3388 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3389 | * the return of this function. The caller is not required to hold any locks. | |
3390 | **/ | |
2e0fef85 | 3391 | void |
dea3101e JB |
3392 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3393 | { | |
2534ba75 | 3394 | LIST_HEAD(completions); |
dea3101e | 3395 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3396 | |
92d7f7b0 JS |
3397 | if (pring->ringno == LPFC_ELS_RING) { |
3398 | lpfc_fabric_abort_hba(phba); | |
3399 | } | |
3400 | ||
dea3101e JB |
3401 | /* Error everything on txq and txcmplq |
3402 | * First do the txq. | |
3403 | */ | |
2e0fef85 | 3404 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3405 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3406 | pring->txq_cnt = 0; |
dea3101e JB |
3407 | |
3408 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3409 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3410 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3411 | |
2e0fef85 | 3412 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3413 | |
a257bf90 JS |
3414 | /* Cancel all the IOCBs from the completions list */ |
3415 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3416 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3417 | } |
3418 | ||
a8e497d5 | 3419 | /** |
3621a710 | 3420 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3421 | * @phba: Pointer to HBA context object. |
3422 | * | |
3423 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3424 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3425 | * for all the iocb commands in txcmplq, they will just be returned with | |
3426 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3427 | * slot has been permanently disabled. | |
3428 | **/ | |
3429 | void | |
3430 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3431 | { | |
3432 | LIST_HEAD(txq); | |
3433 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3434 | struct lpfc_sli *psli = &phba->sli; |
3435 | struct lpfc_sli_ring *pring; | |
3436 | ||
3437 | /* Currently, only one fcp ring */ | |
3438 | pring = &psli->ring[psli->fcp_ring]; | |
3439 | ||
3440 | spin_lock_irq(&phba->hbalock); | |
3441 | /* Retrieve everything on txq */ | |
3442 | list_splice_init(&pring->txq, &txq); | |
3443 | pring->txq_cnt = 0; | |
3444 | ||
3445 | /* Retrieve everything on the txcmplq */ | |
3446 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3447 | pring->txcmplq_cnt = 0; | |
3448 | spin_unlock_irq(&phba->hbalock); | |
3449 | ||
3450 | /* Flush the txq */ | |
a257bf90 JS |
3451 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3452 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3453 | |
3454 | /* Flush the txcmpq */ | |
a257bf90 JS |
3455 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3456 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3457 | } |
3458 | ||
e59058c4 | 3459 | /** |
3772a991 | 3460 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3461 | * @phba: Pointer to HBA context object. |
3462 | * @mask: Bit mask to be checked. | |
3463 | * | |
3464 | * This function reads the host status register and compares | |
3465 | * with the provided bit mask to check if HBA completed | |
3466 | * the restart. This function will wait in a loop for the | |
3467 | * HBA to complete restart. If the HBA does not restart within | |
3468 | * 15 iterations, the function will reset the HBA again. The | |
3469 | * function returns 1 when HBA fail to restart otherwise returns | |
3470 | * zero. | |
3471 | **/ | |
3772a991 JS |
3472 | static int |
3473 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3474 | { |
41415862 JW |
3475 | uint32_t status; |
3476 | int i = 0; | |
3477 | int retval = 0; | |
dea3101e | 3478 | |
41415862 | 3479 | /* Read the HBA Host Status Register */ |
9940b97b JS |
3480 | if (lpfc_readl(phba->HSregaddr, &status)) |
3481 | return 1; | |
dea3101e | 3482 | |
41415862 JW |
3483 | /* |
3484 | * Check status register every 100ms for 5 retries, then every | |
3485 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3486 | * every 2.5 sec for 4. | |
3487 | * Break our of the loop if errors occurred during init. | |
3488 | */ | |
3489 | while (((status & mask) != mask) && | |
3490 | !(status & HS_FFERM) && | |
3491 | i++ < 20) { | |
dea3101e | 3492 | |
41415862 JW |
3493 | if (i <= 5) |
3494 | msleep(10); | |
3495 | else if (i <= 10) | |
3496 | msleep(500); | |
3497 | else | |
3498 | msleep(2500); | |
dea3101e | 3499 | |
41415862 | 3500 | if (i == 15) { |
2e0fef85 | 3501 | /* Do post */ |
92d7f7b0 | 3502 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3503 | lpfc_sli_brdrestart(phba); |
3504 | } | |
3505 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
3506 | if (lpfc_readl(phba->HSregaddr, &status)) { |
3507 | retval = 1; | |
3508 | break; | |
3509 | } | |
41415862 | 3510 | } |
dea3101e | 3511 | |
41415862 JW |
3512 | /* Check to see if any errors occurred during init */ |
3513 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3514 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3515 | "2751 Adapter failed to restart, " | |
3516 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3517 | status, | |
3518 | readl(phba->MBslimaddr + 0xa8), | |
3519 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3520 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3521 | retval = 1; |
dea3101e | 3522 | } |
dea3101e | 3523 | |
41415862 JW |
3524 | return retval; |
3525 | } | |
dea3101e | 3526 | |
da0436e9 JS |
3527 | /** |
3528 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3529 | * @phba: Pointer to HBA context object. | |
3530 | * @mask: Bit mask to be checked. | |
3531 | * | |
3532 | * This function checks the host status register to check if HBA is | |
3533 | * ready. This function will wait in a loop for the HBA to be ready | |
3534 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3535 | * function again. The function returns 1 when HBA fail to be ready | |
3536 | * otherwise returns zero. | |
3537 | **/ | |
3538 | static int | |
3539 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3540 | { | |
3541 | uint32_t status; | |
3542 | int retval = 0; | |
3543 | ||
3544 | /* Read the HBA Host Status Register */ | |
3545 | status = lpfc_sli4_post_status_check(phba); | |
3546 | ||
3547 | if (status) { | |
3548 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3549 | lpfc_sli_brdrestart(phba); | |
3550 | status = lpfc_sli4_post_status_check(phba); | |
3551 | } | |
3552 | ||
3553 | /* Check to see if any errors occurred during init */ | |
3554 | if (status) { | |
3555 | phba->link_state = LPFC_HBA_ERROR; | |
3556 | retval = 1; | |
3557 | } else | |
3558 | phba->sli4_hba.intr_enable = 0; | |
3559 | ||
3560 | return retval; | |
3561 | } | |
3562 | ||
3563 | /** | |
3564 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3565 | * @phba: Pointer to HBA context object. | |
3566 | * @mask: Bit mask to be checked. | |
3567 | * | |
3568 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3569 | * from the API jump table function pointer from the lpfc_hba struct. | |
3570 | **/ | |
3571 | int | |
3572 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3573 | { | |
3574 | return phba->lpfc_sli_brdready(phba, mask); | |
3575 | } | |
3576 | ||
9290831f JS |
3577 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3578 | ||
e59058c4 | 3579 | /** |
3621a710 | 3580 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3581 | * @phba: Pointer to HBA context object. |
3582 | * | |
3583 | * This function is called before resetting an HBA. This | |
3584 | * function requests HBA to quiesce DMAs before a reset. | |
3585 | **/ | |
2e0fef85 | 3586 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3587 | { |
65a29c16 JS |
3588 | uint32_t __iomem *resp_buf; |
3589 | uint32_t __iomem *mbox_buf; | |
9290831f | 3590 | volatile uint32_t mbox; |
9940b97b | 3591 | uint32_t hc_copy, ha_copy, resp_data; |
9290831f JS |
3592 | int i; |
3593 | uint8_t hdrtype; | |
3594 | ||
3595 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3596 | if (hdrtype != 0x80 || | |
3597 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3598 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3599 | return; | |
3600 | ||
3601 | /* | |
3602 | * Tell the other part of the chip to suspend temporarily all | |
3603 | * its DMA activity. | |
3604 | */ | |
65a29c16 | 3605 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3606 | |
3607 | /* Disable the error attention */ | |
9940b97b JS |
3608 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
3609 | return; | |
9290831f JS |
3610 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); |
3611 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3612 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f | 3613 | |
9940b97b JS |
3614 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3615 | return; | |
3616 | if (ha_copy & HA_ERATT) { | |
9290831f JS |
3617 | /* Clear Chip error bit */ |
3618 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3619 | phba->pport->stopped = 1; |
9290831f JS |
3620 | } |
3621 | ||
3622 | mbox = 0; | |
3623 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3624 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3625 | ||
3626 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3627 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3628 | writel(mbox, mbox_buf); |
3629 | ||
9940b97b JS |
3630 | for (i = 0; i < 50; i++) { |
3631 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3632 | return; | |
3633 | if (resp_data != ~(BARRIER_TEST_PATTERN)) | |
3634 | mdelay(1); | |
3635 | else | |
3636 | break; | |
3637 | } | |
3638 | resp_data = 0; | |
3639 | if (lpfc_readl((resp_buf + 1), &resp_data)) | |
3640 | return; | |
3641 | if (resp_data != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3642 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3643 | phba->pport->stopped) |
9290831f JS |
3644 | goto restore_hc; |
3645 | else | |
3646 | goto clear_errat; | |
3647 | } | |
3648 | ||
3649 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
9940b97b JS |
3650 | resp_data = 0; |
3651 | for (i = 0; i < 500; i++) { | |
3652 | if (lpfc_readl(resp_buf, &resp_data)) | |
3653 | return; | |
3654 | if (resp_data != mbox) | |
3655 | mdelay(1); | |
3656 | else | |
3657 | break; | |
3658 | } | |
9290831f JS |
3659 | |
3660 | clear_errat: | |
3661 | ||
9940b97b JS |
3662 | while (++i < 500) { |
3663 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) | |
3664 | return; | |
3665 | if (!(ha_copy & HA_ERATT)) | |
3666 | mdelay(1); | |
3667 | else | |
3668 | break; | |
3669 | } | |
9290831f JS |
3670 | |
3671 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3672 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3673 | phba->pport->stopped = 1; |
9290831f JS |
3674 | } |
3675 | ||
3676 | restore_hc: | |
2e0fef85 | 3677 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3678 | writel(hc_copy, phba->HCregaddr); |
3679 | readl(phba->HCregaddr); /* flush */ | |
3680 | } | |
3681 | ||
e59058c4 | 3682 | /** |
3621a710 | 3683 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3684 | * @phba: Pointer to HBA context object. |
3685 | * | |
3686 | * This function issues a kill_board mailbox command and waits for | |
3687 | * the error attention interrupt. This function is called for stopping | |
3688 | * the firmware processing. The caller is not required to hold any | |
3689 | * locks. This function calls lpfc_hba_down_post function to free | |
3690 | * any pending commands after the kill. The function will return 1 when it | |
3691 | * fails to kill the board else will return 0. | |
3692 | **/ | |
41415862 | 3693 | int |
2e0fef85 | 3694 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3695 | { |
3696 | struct lpfc_sli *psli; | |
3697 | LPFC_MBOXQ_t *pmb; | |
3698 | uint32_t status; | |
3699 | uint32_t ha_copy; | |
3700 | int retval; | |
3701 | int i = 0; | |
dea3101e | 3702 | |
41415862 | 3703 | psli = &phba->sli; |
dea3101e | 3704 | |
41415862 | 3705 | /* Kill HBA */ |
ed957684 | 3706 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3707 | "0329 Kill HBA Data: x%x x%x\n", |
3708 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3709 | |
98c9ea5c JS |
3710 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3711 | if (!pmb) | |
41415862 | 3712 | return 1; |
41415862 JW |
3713 | |
3714 | /* Disable the error attention */ | |
2e0fef85 | 3715 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
3716 | if (lpfc_readl(phba->HCregaddr, &status)) { |
3717 | spin_unlock_irq(&phba->hbalock); | |
3718 | mempool_free(pmb, phba->mbox_mem_pool); | |
3719 | return 1; | |
3720 | } | |
41415862 JW |
3721 | status &= ~HC_ERINT_ENA; |
3722 | writel(status, phba->HCregaddr); | |
3723 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3724 | phba->link_flag |= LS_IGNORE_ERATT; |
3725 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3726 | |
3727 | lpfc_kill_board(phba, pmb); | |
3728 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3729 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3730 | ||
3731 | if (retval != MBX_SUCCESS) { | |
3732 | if (retval != MBX_BUSY) | |
3733 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3734 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3735 | "2752 KILL_BOARD command failed retval %d\n", | |
3736 | retval); | |
2e0fef85 JS |
3737 | spin_lock_irq(&phba->hbalock); |
3738 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3739 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3740 | return 1; |
3741 | } | |
3742 | ||
f4b4c68f JS |
3743 | spin_lock_irq(&phba->hbalock); |
3744 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3745 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3746 | |
41415862 JW |
3747 | mempool_free(pmb, phba->mbox_mem_pool); |
3748 | ||
3749 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3750 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3751 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3752 | * board is now undefined. | |
3753 | */ | |
9940b97b JS |
3754 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3755 | return 1; | |
41415862 JW |
3756 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { |
3757 | mdelay(100); | |
9940b97b JS |
3758 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
3759 | return 1; | |
41415862 JW |
3760 | } |
3761 | ||
3762 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3763 | if (ha_copy & HA_ERATT) { |
3764 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3765 | phba->pport->stopped = 1; |
9290831f | 3766 | } |
2e0fef85 | 3767 | spin_lock_irq(&phba->hbalock); |
41415862 | 3768 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3769 | psli->mbox_active = NULL; |
2e0fef85 JS |
3770 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3771 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3772 | |
41415862 | 3773 | lpfc_hba_down_post(phba); |
2e0fef85 | 3774 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3775 | |
2e0fef85 | 3776 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
3777 | } |
3778 | ||
e59058c4 | 3779 | /** |
3772a991 | 3780 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3781 | * @phba: Pointer to HBA context object. |
3782 | * | |
3783 | * This function resets the HBA by writing HC_INITFF to the control | |
3784 | * register. After the HBA resets, this function resets all the iocb ring | |
3785 | * indices. This function disables PCI layer parity checking during | |
3786 | * the reset. | |
3787 | * This function returns 0 always. | |
3788 | * The caller is not required to hold any locks. | |
3789 | **/ | |
41415862 | 3790 | int |
2e0fef85 | 3791 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3792 | { |
41415862 | 3793 | struct lpfc_sli *psli; |
dea3101e | 3794 | struct lpfc_sli_ring *pring; |
41415862 | 3795 | uint16_t cfg_value; |
dea3101e | 3796 | int i; |
dea3101e | 3797 | |
41415862 | 3798 | psli = &phba->sli; |
dea3101e | 3799 | |
41415862 JW |
3800 | /* Reset HBA */ |
3801 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3802 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3803 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
3804 | |
3805 | /* perform board reset */ | |
3806 | phba->fc_eventTag = 0; | |
4d9ab994 | 3807 | phba->link_events = 0; |
2e0fef85 JS |
3808 | phba->pport->fc_myDID = 0; |
3809 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3810 | |
41415862 JW |
3811 | /* Turn off parity checking and serr during the physical reset */ |
3812 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3813 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3814 | (cfg_value & | |
3815 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3816 | ||
3772a991 JS |
3817 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3818 | ||
41415862 JW |
3819 | /* Now toggle INITFF bit in the Host Control Register */ |
3820 | writel(HC_INITFF, phba->HCregaddr); | |
3821 | mdelay(1); | |
3822 | readl(phba->HCregaddr); /* flush */ | |
3823 | writel(0, phba->HCregaddr); | |
3824 | readl(phba->HCregaddr); /* flush */ | |
3825 | ||
3826 | /* Restore PCI cmd register */ | |
3827 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
3828 | |
3829 | /* Initialize relevant SLI info */ | |
41415862 JW |
3830 | for (i = 0; i < psli->num_rings; i++) { |
3831 | pring = &psli->ring[i]; | |
dea3101e JB |
3832 | pring->flag = 0; |
3833 | pring->rspidx = 0; | |
3834 | pring->next_cmdidx = 0; | |
3835 | pring->local_getidx = 0; | |
3836 | pring->cmdidx = 0; | |
3837 | pring->missbufcnt = 0; | |
3838 | } | |
dea3101e | 3839 | |
2e0fef85 | 3840 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3841 | return 0; |
3842 | } | |
3843 | ||
e59058c4 | 3844 | /** |
da0436e9 JS |
3845 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3846 | * @phba: Pointer to HBA context object. | |
3847 | * | |
3848 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3849 | * checking during resets the device. The caller is not required to hold | |
3850 | * any locks. | |
3851 | * | |
3852 | * This function returns 0 always. | |
3853 | **/ | |
3854 | int | |
3855 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3856 | { | |
3857 | struct lpfc_sli *psli = &phba->sli; | |
3858 | uint16_t cfg_value; | |
3859 | uint8_t qindx; | |
3860 | ||
3861 | /* Reset HBA */ | |
3862 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3863 | "0295 Reset HBA Data: x%x x%x\n", | |
3864 | phba->pport->port_state, psli->sli_flag); | |
3865 | ||
3866 | /* perform board reset */ | |
3867 | phba->fc_eventTag = 0; | |
4d9ab994 | 3868 | phba->link_events = 0; |
da0436e9 JS |
3869 | phba->pport->fc_myDID = 0; |
3870 | phba->pport->fc_prevDID = 0; | |
3871 | ||
da0436e9 JS |
3872 | spin_lock_irq(&phba->hbalock); |
3873 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3874 | phba->fcf.fcf_flag = 0; | |
3875 | /* Clean up the child queue list for the CQs */ | |
3876 | list_del_init(&phba->sli4_hba.mbx_wq->list); | |
3877 | list_del_init(&phba->sli4_hba.els_wq->list); | |
3878 | list_del_init(&phba->sli4_hba.hdr_rq->list); | |
3879 | list_del_init(&phba->sli4_hba.dat_rq->list); | |
3880 | list_del_init(&phba->sli4_hba.mbx_cq->list); | |
3881 | list_del_init(&phba->sli4_hba.els_cq->list); | |
da0436e9 JS |
3882 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
3883 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | |
3884 | for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++) | |
3885 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); | |
3886 | spin_unlock_irq(&phba->hbalock); | |
3887 | ||
3888 | /* Now physically reset the device */ | |
3889 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3890 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
3891 | |
3892 | /* Turn off parity checking and serr during the physical reset */ | |
3893 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3894 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
3895 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3896 | ||
da0436e9 JS |
3897 | /* Perform FCoE PCI function reset */ |
3898 | lpfc_pci_function_reset(phba); | |
3899 | ||
be858b65 JS |
3900 | /* Restore PCI cmd register */ |
3901 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
3902 | ||
da0436e9 JS |
3903 | return 0; |
3904 | } | |
3905 | ||
3906 | /** | |
3907 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3908 | * @phba: Pointer to HBA context object. |
3909 | * | |
3910 | * This function is called in the SLI initialization code path to | |
3911 | * restart the HBA. The caller is not required to hold any lock. | |
3912 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3913 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3914 | * function to free any pending commands. The function enables | |
3915 | * POST only during the first initialization. The function returns zero. | |
3916 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3917 | * command before the return of this function. | |
3918 | **/ | |
da0436e9 JS |
3919 | static int |
3920 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3921 | { |
3922 | MAILBOX_t *mb; | |
3923 | struct lpfc_sli *psli; | |
41415862 JW |
3924 | volatile uint32_t word0; |
3925 | void __iomem *to_slim; | |
0d878419 | 3926 | uint32_t hba_aer_enabled; |
41415862 | 3927 | |
2e0fef85 | 3928 | spin_lock_irq(&phba->hbalock); |
41415862 | 3929 | |
0d878419 JS |
3930 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3931 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3932 | ||
41415862 JW |
3933 | psli = &phba->sli; |
3934 | ||
3935 | /* Restart HBA */ | |
3936 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3937 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3938 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3939 | |
3940 | word0 = 0; | |
3941 | mb = (MAILBOX_t *) &word0; | |
3942 | mb->mbxCommand = MBX_RESTART; | |
3943 | mb->mbxHc = 1; | |
3944 | ||
9290831f JS |
3945 | lpfc_reset_barrier(phba); |
3946 | ||
41415862 JW |
3947 | to_slim = phba->MBslimaddr; |
3948 | writel(*(uint32_t *) mb, to_slim); | |
3949 | readl(to_slim); /* flush */ | |
3950 | ||
3951 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3952 | if (phba->pport->port_state) |
41415862 | 3953 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 3954 | else |
41415862 | 3955 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 3956 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
3957 | writel(*(uint32_t *) mb, to_slim); |
3958 | readl(to_slim); /* flush */ | |
dea3101e | 3959 | |
41415862 | 3960 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
3961 | phba->pport->stopped = 0; |
3962 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 3963 | phba->hba_flag = 0; |
2e0fef85 | 3964 | spin_unlock_irq(&phba->hbalock); |
41415862 | 3965 | |
64ba8818 JS |
3966 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
3967 | psli->stats_start = get_seconds(); | |
3968 | ||
eaf15d5b JS |
3969 | /* Give the INITFF and Post time to settle. */ |
3970 | mdelay(100); | |
41415862 | 3971 | |
0d878419 JS |
3972 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3973 | if (hba_aer_enabled) | |
3974 | pci_disable_pcie_error_reporting(phba->pcidev); | |
3975 | ||
41415862 | 3976 | lpfc_hba_down_post(phba); |
dea3101e JB |
3977 | |
3978 | return 0; | |
3979 | } | |
3980 | ||
da0436e9 JS |
3981 | /** |
3982 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
3983 | * @phba: Pointer to HBA context object. | |
3984 | * | |
3985 | * This function is called in the SLI initialization code path to restart | |
3986 | * a SLI4 HBA. The caller is not required to hold any lock. | |
3987 | * At the end of the function, it calls lpfc_hba_down_post function to | |
3988 | * free any pending commands. | |
3989 | **/ | |
3990 | static int | |
3991 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
3992 | { | |
3993 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 3994 | uint32_t hba_aer_enabled; |
da0436e9 JS |
3995 | |
3996 | /* Restart HBA */ | |
3997 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3998 | "0296 Restart HBA Data: x%x x%x\n", | |
3999 | phba->pport->port_state, psli->sli_flag); | |
4000 | ||
75baf696 JS |
4001 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
4002 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
4003 | ||
da0436e9 JS |
4004 | lpfc_sli4_brdreset(phba); |
4005 | ||
4006 | spin_lock_irq(&phba->hbalock); | |
4007 | phba->pport->stopped = 0; | |
4008 | phba->link_state = LPFC_INIT_START; | |
4009 | phba->hba_flag = 0; | |
4010 | spin_unlock_irq(&phba->hbalock); | |
4011 | ||
4012 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
4013 | psli->stats_start = get_seconds(); | |
4014 | ||
75baf696 JS |
4015 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4016 | if (hba_aer_enabled) | |
4017 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4018 | ||
da0436e9 JS |
4019 | lpfc_hba_down_post(phba); |
4020 | ||
4021 | return 0; | |
4022 | } | |
4023 | ||
4024 | /** | |
4025 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4026 | * @phba: Pointer to HBA context object. | |
4027 | * | |
4028 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4029 | * API jump table function pointer from the lpfc_hba struct. | |
4030 | **/ | |
4031 | int | |
4032 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4033 | { | |
4034 | return phba->lpfc_sli_brdrestart(phba); | |
4035 | } | |
4036 | ||
e59058c4 | 4037 | /** |
3621a710 | 4038 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4039 | * @phba: Pointer to HBA context object. |
4040 | * | |
4041 | * This function is called after a HBA restart to wait for successful | |
4042 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4043 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4044 | * iteration, the function will restart the HBA again. The function returns | |
4045 | * zero if HBA successfully restarted else returns negative error code. | |
4046 | **/ | |
dea3101e JB |
4047 | static int |
4048 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4049 | { | |
4050 | uint32_t status, i = 0; | |
4051 | ||
4052 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4053 | if (lpfc_readl(phba->HSregaddr, &status)) |
4054 | return -EIO; | |
dea3101e JB |
4055 | |
4056 | /* Check status register to see what current state is */ | |
4057 | i = 0; | |
4058 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4059 | ||
dcf2a4e0 JS |
4060 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4061 | * retries, then every 1 sec for 50 retires for a total of | |
4062 | * ~60 seconds before reset the board again and check every | |
4063 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4064 | * board ready is required by the Falcon FIPS zeroization | |
4065 | * complete, and any reset the board in between shall cause | |
4066 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4067 | */ |
dcf2a4e0 | 4068 | if (i++ >= 200) { |
dea3101e JB |
4069 | /* Adapter failed to init, timeout, status reg |
4070 | <status> */ | |
ed957684 | 4071 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4072 | "0436 Adapter failed to init, " |
09372820 JS |
4073 | "timeout, status reg x%x, " |
4074 | "FW Data: A8 x%x AC x%x\n", status, | |
4075 | readl(phba->MBslimaddr + 0xa8), | |
4076 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4077 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4078 | return -ETIMEDOUT; |
4079 | } | |
4080 | ||
4081 | /* Check to see if any errors occurred during init */ | |
4082 | if (status & HS_FFERM) { | |
4083 | /* ERROR: During chipset initialization */ | |
4084 | /* Adapter failed to init, chipset, status reg | |
4085 | <status> */ | |
ed957684 | 4086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4087 | "0437 Adapter failed to init, " |
09372820 JS |
4088 | "chipset, status reg x%x, " |
4089 | "FW Data: A8 x%x AC x%x\n", status, | |
4090 | readl(phba->MBslimaddr + 0xa8), | |
4091 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4092 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4093 | return -EIO; |
4094 | } | |
4095 | ||
dcf2a4e0 | 4096 | if (i <= 10) |
dea3101e | 4097 | msleep(10); |
dcf2a4e0 JS |
4098 | else if (i <= 100) |
4099 | msleep(100); | |
4100 | else | |
4101 | msleep(1000); | |
dea3101e | 4102 | |
dcf2a4e0 JS |
4103 | if (i == 150) { |
4104 | /* Do post */ | |
92d7f7b0 | 4105 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4106 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4107 | } |
4108 | /* Read the HBA Host Status Register */ | |
9940b97b JS |
4109 | if (lpfc_readl(phba->HSregaddr, &status)) |
4110 | return -EIO; | |
dea3101e JB |
4111 | } |
4112 | ||
4113 | /* Check to see if any errors occurred during init */ | |
4114 | if (status & HS_FFERM) { | |
4115 | /* ERROR: During chipset initialization */ | |
4116 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4118 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4119 | "status reg x%x, " |
4120 | "FW Data: A8 x%x AC x%x\n", status, | |
4121 | readl(phba->MBslimaddr + 0xa8), | |
4122 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4123 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4124 | return -EIO; |
4125 | } | |
4126 | ||
4127 | /* Clear all interrupt enable conditions */ | |
4128 | writel(0, phba->HCregaddr); | |
4129 | readl(phba->HCregaddr); /* flush */ | |
4130 | ||
4131 | /* setup host attn register */ | |
4132 | writel(0xffffffff, phba->HAregaddr); | |
4133 | readl(phba->HAregaddr); /* flush */ | |
4134 | return 0; | |
4135 | } | |
4136 | ||
e59058c4 | 4137 | /** |
3621a710 | 4138 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4139 | * |
4140 | * This function calculates and returns the number of HBQs required to be | |
4141 | * configured. | |
4142 | **/ | |
78b2d852 | 4143 | int |
ed957684 JS |
4144 | lpfc_sli_hbq_count(void) |
4145 | { | |
92d7f7b0 | 4146 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4147 | } |
4148 | ||
e59058c4 | 4149 | /** |
3621a710 | 4150 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4151 | * |
4152 | * This function adds the number of hbq entries in every HBQ to get | |
4153 | * the total number of hbq entries required for the HBA and returns | |
4154 | * the total count. | |
4155 | **/ | |
ed957684 JS |
4156 | static int |
4157 | lpfc_sli_hbq_entry_count(void) | |
4158 | { | |
4159 | int hbq_count = lpfc_sli_hbq_count(); | |
4160 | int count = 0; | |
4161 | int i; | |
4162 | ||
4163 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4164 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4165 | return count; |
4166 | } | |
4167 | ||
e59058c4 | 4168 | /** |
3621a710 | 4169 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4170 | * |
4171 | * This function calculates amount of memory required for all hbq entries | |
4172 | * to be configured and returns the total memory required. | |
4173 | **/ | |
dea3101e | 4174 | int |
ed957684 JS |
4175 | lpfc_sli_hbq_size(void) |
4176 | { | |
4177 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4178 | } | |
4179 | ||
e59058c4 | 4180 | /** |
3621a710 | 4181 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4182 | * @phba: Pointer to HBA context object. |
4183 | * | |
4184 | * This function is called during the SLI initialization to configure | |
4185 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4186 | * required to hold any locks. This function will return zero if successful | |
4187 | * else it will return negative error code. | |
4188 | **/ | |
ed957684 JS |
4189 | static int |
4190 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4191 | { | |
4192 | int hbq_count = lpfc_sli_hbq_count(); | |
4193 | LPFC_MBOXQ_t *pmb; | |
4194 | MAILBOX_t *pmbox; | |
4195 | uint32_t hbqno; | |
4196 | uint32_t hbq_entry_index; | |
ed957684 | 4197 | |
92d7f7b0 JS |
4198 | /* Get a Mailbox buffer to setup mailbox |
4199 | * commands for HBA initialization | |
4200 | */ | |
ed957684 JS |
4201 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4202 | ||
4203 | if (!pmb) | |
4204 | return -ENOMEM; | |
4205 | ||
04c68496 | 4206 | pmbox = &pmb->u.mb; |
ed957684 JS |
4207 | |
4208 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4209 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4210 | phba->hbq_in_use = 1; |
ed957684 JS |
4211 | |
4212 | hbq_entry_index = 0; | |
4213 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4214 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4215 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4216 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4217 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4218 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4219 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4220 | hbq_entry_index, pmb); | |
ed957684 JS |
4221 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4222 | ||
4223 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4224 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4225 | mbxStatus <status>, ring <num> */ | |
4226 | ||
4227 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4228 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4229 | "1805 Adapter failed to init. " |
ed957684 | 4230 | "Data: x%x x%x x%x\n", |
e8b62011 | 4231 | pmbox->mbxCommand, |
ed957684 JS |
4232 | pmbox->mbxStatus, hbqno); |
4233 | ||
4234 | phba->link_state = LPFC_HBA_ERROR; | |
4235 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4236 | return -ENXIO; |
ed957684 JS |
4237 | } |
4238 | } | |
4239 | phba->hbq_count = hbq_count; | |
4240 | ||
ed957684 JS |
4241 | mempool_free(pmb, phba->mbox_mem_pool); |
4242 | ||
92d7f7b0 | 4243 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4244 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4245 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4246 | return 0; |
4247 | } | |
4248 | ||
4f774513 JS |
4249 | /** |
4250 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4251 | * @phba: Pointer to HBA context object. | |
4252 | * | |
4253 | * This function is called during the SLI initialization to configure | |
4254 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4255 | * required to hold any locks. This function will return zero if successful | |
4256 | * else it will return negative error code. | |
4257 | **/ | |
4258 | static int | |
4259 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4260 | { | |
4261 | phba->hbq_in_use = 1; | |
4262 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4263 | phba->hbq_count = 1; | |
4264 | /* Initially populate or replenish the HBQs */ | |
4265 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4266 | return 0; | |
4267 | } | |
4268 | ||
e59058c4 | 4269 | /** |
3621a710 | 4270 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4271 | * @phba: Pointer to HBA context object. |
4272 | * @sli_mode: sli mode - 2/3 | |
4273 | * | |
4274 | * This function is called by the sli intialization code path | |
4275 | * to issue config_port mailbox command. This function restarts the | |
4276 | * HBA firmware and issues a config_port mailbox command to configure | |
4277 | * the SLI interface in the sli mode specified by sli_mode | |
4278 | * variable. The caller is not required to hold any locks. | |
4279 | * The function returns 0 if successful, else returns negative error | |
4280 | * code. | |
4281 | **/ | |
9399627f JS |
4282 | int |
4283 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
4284 | { |
4285 | LPFC_MBOXQ_t *pmb; | |
4286 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4287 | ||
4288 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4289 | if (!pmb) { | |
2e0fef85 | 4290 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4291 | return -ENOMEM; |
4292 | } | |
4293 | ||
ed957684 | 4294 | phba->sli_rev = sli_mode; |
dea3101e | 4295 | while (resetcount < 2 && !done) { |
2e0fef85 | 4296 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4297 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4298 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4299 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4300 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4301 | rc = lpfc_sli_chipset_init(phba); |
4302 | if (rc) | |
4303 | break; | |
4304 | ||
2e0fef85 | 4305 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4306 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4307 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4308 | resetcount++; |
4309 | ||
ed957684 JS |
4310 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4311 | * value of 0 means the call was successful. Any other | |
4312 | * nonzero value is a failure, but if ERESTART is returned, | |
4313 | * the driver may reset the HBA and try again. | |
4314 | */ | |
dea3101e JB |
4315 | rc = lpfc_config_port_prep(phba); |
4316 | if (rc == -ERESTART) { | |
ed957684 | 4317 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4318 | continue; |
34b02dcd | 4319 | } else if (rc) |
dea3101e | 4320 | break; |
2e0fef85 | 4321 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
4322 | lpfc_config_port(phba, pmb); |
4323 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4324 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4325 | LPFC_SLI3_HBQ_ENABLED | | |
4326 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4327 | LPFC_SLI3_BG_ENABLED | |
4328 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4329 | if (rc != MBX_SUCCESS) { |
dea3101e | 4330 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4331 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4332 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4333 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4334 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4335 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4336 | spin_unlock_irq(&phba->hbalock); |
4337 | rc = -ENXIO; | |
04c68496 JS |
4338 | } else { |
4339 | /* Allow asynchronous mailbox command to go through */ | |
4340 | spin_lock_irq(&phba->hbalock); | |
4341 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4342 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4343 | done = 1; |
04c68496 | 4344 | } |
dea3101e | 4345 | } |
ed957684 JS |
4346 | if (!done) { |
4347 | rc = -EINVAL; | |
4348 | goto do_prep_failed; | |
4349 | } | |
04c68496 JS |
4350 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4351 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4352 | rc = -ENXIO; |
4353 | goto do_prep_failed; | |
4354 | } | |
04c68496 | 4355 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4356 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4357 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4358 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4359 | phba->max_vpi : phba->max_vports; | |
4360 | ||
34b02dcd JS |
4361 | } else |
4362 | phba->max_vpi = 0; | |
bc73905a JS |
4363 | phba->fips_level = 0; |
4364 | phba->fips_spec_rev = 0; | |
4365 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4366 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4367 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4368 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4369 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4370 | "2850 Security Crypto Active. FIPS x%d " | |
4371 | "(Spec Rev: x%d)", | |
4372 | phba->fips_level, phba->fips_spec_rev); | |
4373 | } | |
4374 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4376 | "2856 Config Port Security Crypto " | |
4377 | "Error: x%x ", | |
4378 | pmb->u.mb.un.varCfgPort.sec_err); | |
4379 | } | |
04c68496 | 4380 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4381 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4382 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4383 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4384 | |
4385 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4386 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4387 | |
4388 | if (phba->cfg_enable_bg) { | |
04c68496 | 4389 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4390 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4391 | else | |
4392 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4393 | "0443 Adapter did not grant " | |
4394 | "BlockGuard\n"); | |
4395 | } | |
34b02dcd | 4396 | } else { |
8f34f4ce | 4397 | phba->hbq_get = NULL; |
34b02dcd | 4398 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4399 | phba->max_vpi = 0; |
ed957684 | 4400 | } |
92d7f7b0 | 4401 | do_prep_failed: |
ed957684 JS |
4402 | mempool_free(pmb, phba->mbox_mem_pool); |
4403 | return rc; | |
4404 | } | |
4405 | ||
e59058c4 JS |
4406 | |
4407 | /** | |
3621a710 | 4408 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4409 | * @phba: Pointer to HBA context object. |
4410 | * | |
4411 | * This function is the main SLI intialization function. This function | |
4412 | * is called by the HBA intialization code, HBA reset code and HBA | |
4413 | * error attention handler code. Caller is not required to hold any | |
4414 | * locks. This function issues config_port mailbox command to configure | |
4415 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4416 | * calls the config_port_post function to issue init_link mailbox | |
4417 | * command and to start the discovery. The function will return zero | |
4418 | * if successful, else it will return negative error code. | |
4419 | **/ | |
ed957684 JS |
4420 | int |
4421 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4422 | { | |
4423 | uint32_t rc; | |
92d7f7b0 | 4424 | int mode = 3; |
ed957684 JS |
4425 | |
4426 | switch (lpfc_sli_mode) { | |
4427 | case 2: | |
78b2d852 | 4428 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4430 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4431 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4432 | lpfc_sli_mode); |
92d7f7b0 JS |
4433 | break; |
4434 | } | |
ed957684 JS |
4435 | mode = 2; |
4436 | break; | |
4437 | case 0: | |
4438 | case 3: | |
4439 | break; | |
4440 | default: | |
92d7f7b0 | 4441 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4442 | "1819 Unrecognized lpfc_sli_mode " |
4443 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4444 | |
4445 | break; | |
4446 | } | |
4447 | ||
9399627f JS |
4448 | rc = lpfc_sli_config_port(phba, mode); |
4449 | ||
ed957684 | 4450 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4452 | "1820 Unable to select SLI-3. " |
4453 | "Not supported by adapter.\n"); | |
ed957684 | 4454 | if (rc && mode != 2) |
9399627f | 4455 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4456 | if (rc) |
dea3101e JB |
4457 | goto lpfc_sli_hba_setup_error; |
4458 | ||
0d878419 JS |
4459 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4460 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4461 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4462 | if (!rc) { | |
4463 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4464 | "2709 This device supports " | |
4465 | "Advanced Error Reporting (AER)\n"); | |
4466 | spin_lock_irq(&phba->hbalock); | |
4467 | phba->hba_flag |= HBA_AER_ENABLED; | |
4468 | spin_unlock_irq(&phba->hbalock); | |
4469 | } else { | |
4470 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4471 | "2708 This device does not support " | |
4472 | "Advanced Error Reporting (AER)\n"); | |
4473 | phba->cfg_aer_support = 0; | |
4474 | } | |
4475 | } | |
4476 | ||
ed957684 JS |
4477 | if (phba->sli_rev == 3) { |
4478 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4479 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4480 | } else { |
4481 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4482 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4483 | phba->sli3_options = 0; |
ed957684 JS |
4484 | } |
4485 | ||
4486 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4487 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4488 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4489 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
4490 | |
4491 | if (rc) | |
4492 | goto lpfc_sli_hba_setup_error; | |
4493 | ||
9399627f | 4494 | /* Init HBQs */ |
ed957684 JS |
4495 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4496 | rc = lpfc_sli_hbq_setup(phba); | |
4497 | if (rc) | |
4498 | goto lpfc_sli_hba_setup_error; | |
4499 | } | |
04c68496 | 4500 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4501 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4502 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4503 | |
4504 | rc = lpfc_config_port_post(phba); | |
4505 | if (rc) | |
4506 | goto lpfc_sli_hba_setup_error; | |
4507 | ||
ed957684 JS |
4508 | return rc; |
4509 | ||
92d7f7b0 | 4510 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4511 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4512 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4513 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
4514 | return rc; |
4515 | } | |
4516 | ||
e59058c4 | 4517 | /** |
da0436e9 JS |
4518 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4519 | * @phba: Pointer to HBA context object. | |
4520 | * @mboxq: mailbox pointer. | |
4521 | * This function issue a dump mailbox command to read config region | |
4522 | * 23 and parse the records in the region and populate driver | |
4523 | * data structure. | |
e59058c4 | 4524 | **/ |
da0436e9 JS |
4525 | static int |
4526 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, | |
4527 | LPFC_MBOXQ_t *mboxq) | |
dea3101e | 4528 | { |
da0436e9 JS |
4529 | struct lpfc_dmabuf *mp; |
4530 | struct lpfc_mqe *mqe; | |
4531 | uint32_t data_length; | |
4532 | int rc; | |
dea3101e | 4533 | |
da0436e9 JS |
4534 | /* Program the default value of vlan_id and fc_map */ |
4535 | phba->valid_vlan = 0; | |
4536 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4537 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4538 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4539 | |
da0436e9 JS |
4540 | mqe = &mboxq->u.mqe; |
4541 | if (lpfc_dump_fcoe_param(phba, mboxq)) | |
4542 | return -ENOMEM; | |
4543 | ||
4544 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4545 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4546 | ||
4547 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4548 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4549 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4550 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4551 | "CQ: x%x x%x x%x x%x\n", | |
4552 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4553 | bf_get(lpfc_mqe_command, mqe), | |
4554 | bf_get(lpfc_mqe_status, mqe), | |
4555 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4556 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4557 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4558 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4559 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4560 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4561 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4562 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4563 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4564 | mboxq->mcqe.word0, | |
4565 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4566 | mboxq->mcqe.trailer); | |
4567 | ||
4568 | if (rc) { | |
4569 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4570 | kfree(mp); | |
4571 | return -EIO; | |
4572 | } | |
4573 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4574 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4575 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4576 | kfree(mp); | |
da0436e9 | 4577 | return -EIO; |
d11e31dd | 4578 | } |
dea3101e | 4579 | |
da0436e9 JS |
4580 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4581 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4582 | kfree(mp); | |
4583 | return 0; | |
4584 | } | |
e59058c4 JS |
4585 | |
4586 | /** | |
da0436e9 JS |
4587 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4588 | * @phba: pointer to lpfc hba data structure. | |
4589 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4590 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4591 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4592 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4593 | * |
da0436e9 JS |
4594 | * This routine executes a READ_REV SLI4 mailbox command. In |
4595 | * addition, this routine gets the port vpd data. | |
4596 | * | |
4597 | * Return codes | |
af901ca1 | 4598 | * 0 - successful |
d439d286 | 4599 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4600 | **/ |
da0436e9 JS |
4601 | static int |
4602 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4603 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4604 | { |
da0436e9 JS |
4605 | int rc = 0; |
4606 | uint32_t dma_size; | |
4607 | struct lpfc_dmabuf *dmabuf; | |
4608 | struct lpfc_mqe *mqe; | |
dea3101e | 4609 | |
da0436e9 JS |
4610 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4611 | if (!dmabuf) | |
4612 | return -ENOMEM; | |
4613 | ||
4614 | /* | |
4615 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4616 | * mailbox command. | |
a257bf90 | 4617 | */ |
da0436e9 JS |
4618 | dma_size = *vpd_size; |
4619 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4620 | dma_size, | |
4621 | &dmabuf->phys, | |
4622 | GFP_KERNEL); | |
4623 | if (!dmabuf->virt) { | |
4624 | kfree(dmabuf); | |
4625 | return -ENOMEM; | |
a257bf90 | 4626 | } |
da0436e9 | 4627 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4628 | |
da0436e9 JS |
4629 | /* |
4630 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4631 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4632 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4633 | */ |
da0436e9 JS |
4634 | lpfc_read_rev(phba, mboxq); |
4635 | mqe = &mboxq->u.mqe; | |
4636 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4637 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4638 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4639 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4640 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4641 | ||
4642 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4643 | if (rc) { | |
4644 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4645 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4646 | kfree(dmabuf); |
da0436e9 JS |
4647 | return -EIO; |
4648 | } | |
1dcb58e5 | 4649 | |
da0436e9 JS |
4650 | /* |
4651 | * The available vpd length cannot be bigger than the | |
4652 | * DMA buffer passed to the port. Catch the less than | |
4653 | * case and update the caller's size. | |
4654 | */ | |
4655 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4656 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4657 | |
d7c47992 JS |
4658 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4659 | ||
da0436e9 JS |
4660 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4661 | dmabuf->virt, dmabuf->phys); | |
4662 | kfree(dmabuf); | |
4663 | return 0; | |
dea3101e JB |
4664 | } |
4665 | ||
e59058c4 | 4666 | /** |
da0436e9 JS |
4667 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4668 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4669 | * |
da0436e9 JS |
4670 | * This routine is called to explicitly arm the SLI4 device's completion and |
4671 | * event queues | |
4672 | **/ | |
4673 | static void | |
4674 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4675 | { | |
4676 | uint8_t fcp_eqidx; | |
4677 | ||
4678 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4679 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
da0436e9 JS |
4680 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) |
4681 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], | |
4682 | LPFC_QUEUE_REARM); | |
4683 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); | |
4684 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | |
4685 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | |
4686 | LPFC_QUEUE_REARM); | |
4687 | } | |
4688 | ||
4689 | /** | |
4690 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
4691 | * @phba: Pointer to HBA context object. | |
4692 | * | |
4693 | * This function is the main SLI4 device intialization PCI function. This | |
4694 | * function is called by the HBA intialization code, HBA reset code and | |
4695 | * HBA error attention handler code. Caller is not required to hold any | |
4696 | * locks. | |
4697 | **/ | |
4698 | int | |
4699 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
4700 | { | |
4701 | int rc; | |
4702 | LPFC_MBOXQ_t *mboxq; | |
4703 | struct lpfc_mqe *mqe; | |
4704 | uint8_t *vpd; | |
4705 | uint32_t vpd_size; | |
4706 | uint32_t ftr_rsp = 0; | |
4707 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
4708 | struct lpfc_vport *vport = phba->pport; | |
4709 | struct lpfc_dmabuf *mp; | |
4710 | ||
2fcee4bf JS |
4711 | /* |
4712 | * TODO: Why does this routine execute these task in a different | |
4713 | * order from probe? | |
4714 | */ | |
da0436e9 JS |
4715 | /* Perform a PCI function reset to start from clean */ |
4716 | rc = lpfc_pci_function_reset(phba); | |
4717 | if (unlikely(rc)) | |
4718 | return -ENODEV; | |
4719 | ||
4720 | /* Check the HBA Host Status Register for readyness */ | |
4721 | rc = lpfc_sli4_post_status_check(phba); | |
4722 | if (unlikely(rc)) | |
4723 | return -ENODEV; | |
4724 | else { | |
4725 | spin_lock_irq(&phba->hbalock); | |
4726 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
4727 | spin_unlock_irq(&phba->hbalock); | |
4728 | } | |
4729 | ||
4730 | /* | |
4731 | * Allocate a single mailbox container for initializing the | |
4732 | * port. | |
4733 | */ | |
4734 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4735 | if (!mboxq) | |
4736 | return -ENOMEM; | |
4737 | ||
4738 | /* | |
4739 | * Continue initialization with default values even if driver failed | |
4740 | * to read FCoE param config regions | |
4741 | */ | |
4742 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) | |
4743 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
e4e74273 | 4744 | "2570 Failed to read FCoE parameters\n"); |
da0436e9 JS |
4745 | |
4746 | /* Issue READ_REV to collect vpd and FW information. */ | |
49198b37 | 4747 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
4748 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
4749 | if (!vpd) { | |
4750 | rc = -ENOMEM; | |
4751 | goto out_free_mbox; | |
4752 | } | |
4753 | ||
4754 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
4755 | if (unlikely(rc)) { |
4756 | kfree(vpd); | |
4757 | goto out_free_mbox; | |
4758 | } | |
da0436e9 | 4759 | mqe = &mboxq->u.mqe; |
f1126688 JS |
4760 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
4761 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
4762 | phba->hba_flag |= HBA_FCOE_MODE; |
4763 | else | |
4764 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
4765 | |
4766 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
4767 | LPFC_DCBX_CEE_MODE) | |
4768 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
4769 | else | |
4770 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
4771 | ||
c31098ce | 4772 | if (phba->sli_rev != LPFC_SLI_REV4) { |
da0436e9 JS |
4773 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4774 | "0376 READ_REV Error. SLI Level %d " | |
4775 | "FCoE enabled %d\n", | |
76a95d75 | 4776 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 4777 | rc = -EIO; |
76a95d75 JS |
4778 | kfree(vpd); |
4779 | goto out_free_mbox; | |
da0436e9 | 4780 | } |
da0436e9 JS |
4781 | /* |
4782 | * Evaluate the read rev and vpd data. Populate the driver | |
4783 | * state with the results. If this routine fails, the failure | |
4784 | * is not fatal as the driver will use generic values. | |
4785 | */ | |
4786 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
4787 | if (unlikely(!rc)) { | |
4788 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4789 | "0377 Error %d parsing vpd. " | |
4790 | "Using defaults.\n", rc); | |
4791 | rc = 0; | |
4792 | } | |
76a95d75 | 4793 | kfree(vpd); |
da0436e9 | 4794 | |
f1126688 JS |
4795 | /* Save information as VPD data */ |
4796 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
4797 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
4798 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
4799 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
4800 | &mqe->un.read_rev); | |
4801 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
4802 | &mqe->un.read_rev); | |
4803 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
4804 | &mqe->un.read_rev); | |
4805 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
4806 | &mqe->un.read_rev); | |
4807 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
4808 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
4809 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
4810 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
4811 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
4812 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
4813 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4814 | "(%d):0380 READ_REV Status x%x " | |
4815 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
4816 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4817 | bf_get(lpfc_mqe_status, mqe), | |
4818 | phba->vpd.rev.opFwName, | |
4819 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
4820 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
4821 | |
4822 | /* | |
4823 | * Discover the port's supported feature set and match it against the | |
4824 | * hosts requests. | |
4825 | */ | |
4826 | lpfc_request_features(phba, mboxq); | |
4827 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4828 | if (unlikely(rc)) { | |
4829 | rc = -EIO; | |
76a95d75 | 4830 | goto out_free_mbox; |
da0436e9 JS |
4831 | } |
4832 | ||
4833 | /* | |
4834 | * The port must support FCP initiator mode as this is the | |
4835 | * only mode running in the host. | |
4836 | */ | |
4837 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
4838 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4839 | "0378 No support for fcpi mode.\n"); | |
4840 | ftr_rsp++; | |
4841 | } | |
fedd3b7b JS |
4842 | if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs)) |
4843 | phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED; | |
4844 | else | |
4845 | phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED; | |
da0436e9 JS |
4846 | /* |
4847 | * If the port cannot support the host's requested features | |
4848 | * then turn off the global config parameters to disable the | |
4849 | * feature in the driver. This is not a fatal error. | |
4850 | */ | |
4851 | if ((phba->cfg_enable_bg) && | |
4852 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4853 | ftr_rsp++; | |
4854 | ||
4855 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
4856 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4857 | ftr_rsp++; | |
4858 | ||
4859 | if (ftr_rsp) { | |
4860 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4861 | "0379 Feature Mismatch Data: x%08x %08x " | |
4862 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
4863 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
4864 | phba->cfg_enable_npiv, phba->max_vpi); | |
4865 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4866 | phba->cfg_enable_bg = 0; | |
4867 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4868 | phba->cfg_enable_npiv = 0; | |
4869 | } | |
4870 | ||
4871 | /* These SLI3 features are assumed in SLI4 */ | |
4872 | spin_lock_irq(&phba->hbalock); | |
4873 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
4874 | spin_unlock_irq(&phba->hbalock); | |
4875 | ||
4876 | /* Read the port's service parameters. */ | |
9f1177a3 JS |
4877 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
4878 | if (rc) { | |
4879 | phba->link_state = LPFC_HBA_ERROR; | |
4880 | rc = -ENOMEM; | |
76a95d75 | 4881 | goto out_free_mbox; |
9f1177a3 JS |
4882 | } |
4883 | ||
da0436e9 JS |
4884 | mboxq->vport = vport; |
4885 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4886 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4887 | if (rc == MBX_SUCCESS) { | |
4888 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
4889 | rc = 0; | |
4890 | } | |
4891 | ||
4892 | /* | |
4893 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
4894 | * it to the mbuf pool. | |
4895 | */ | |
4896 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4897 | kfree(mp); | |
4898 | mboxq->context1 = NULL; | |
4899 | if (unlikely(rc)) { | |
4900 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4901 | "0382 READ_SPARAM command failed " | |
4902 | "status %d, mbxStatus x%x\n", | |
4903 | rc, bf_get(lpfc_mqe_status, mqe)); | |
4904 | phba->link_state = LPFC_HBA_ERROR; | |
4905 | rc = -EIO; | |
76a95d75 | 4906 | goto out_free_mbox; |
da0436e9 JS |
4907 | } |
4908 | ||
4909 | if (phba->cfg_soft_wwnn) | |
4910 | u64_to_wwn(phba->cfg_soft_wwnn, | |
4911 | vport->fc_sparam.nodeName.u.wwn); | |
4912 | if (phba->cfg_soft_wwpn) | |
4913 | u64_to_wwn(phba->cfg_soft_wwpn, | |
4914 | vport->fc_sparam.portName.u.wwn); | |
4915 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
4916 | sizeof(struct lpfc_name)); | |
4917 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
4918 | sizeof(struct lpfc_name)); | |
4919 | ||
4920 | /* Update the fc_host data structures with new wwn. */ | |
4921 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
4922 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
4923 | ||
4924 | /* Register SGL pool to the device using non-embedded mailbox command */ | |
4925 | rc = lpfc_sli4_post_sgl_list(phba); | |
4926 | if (unlikely(rc)) { | |
4927 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4928 | "0582 Error %d during sgl post operation\n", |
4929 | rc); | |
da0436e9 | 4930 | rc = -ENODEV; |
76a95d75 | 4931 | goto out_free_mbox; |
da0436e9 JS |
4932 | } |
4933 | ||
4934 | /* Register SCSI SGL pool to the device */ | |
4935 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
4936 | if (unlikely(rc)) { | |
4937 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4938 | "0383 Error %d during scsi sgl post " |
4939 | "operation\n", rc); | |
da0436e9 JS |
4940 | /* Some Scsi buffers were moved to the abort scsi list */ |
4941 | /* A pci function reset will repost them */ | |
4942 | rc = -ENODEV; | |
76a95d75 | 4943 | goto out_free_mbox; |
da0436e9 JS |
4944 | } |
4945 | ||
4946 | /* Post the rpi header region to the device. */ | |
4947 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
4948 | if (unlikely(rc)) { | |
4949 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4950 | "0393 Error %d during rpi post operation\n", | |
4951 | rc); | |
4952 | rc = -ENODEV; | |
76a95d75 | 4953 | goto out_free_mbox; |
da0436e9 | 4954 | } |
da0436e9 JS |
4955 | |
4956 | /* Set up all the queues to the device */ | |
4957 | rc = lpfc_sli4_queue_setup(phba); | |
4958 | if (unlikely(rc)) { | |
4959 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4960 | "0381 Error %d during queue setup.\n ", rc); | |
4961 | goto out_stop_timers; | |
4962 | } | |
4963 | ||
4964 | /* Arm the CQs and then EQs on device */ | |
4965 | lpfc_sli4_arm_cqeq_intr(phba); | |
4966 | ||
4967 | /* Indicate device interrupt mode */ | |
4968 | phba->sli4_hba.intr_enable = 1; | |
4969 | ||
4970 | /* Allow asynchronous mailbox command to go through */ | |
4971 | spin_lock_irq(&phba->hbalock); | |
4972 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4973 | spin_unlock_irq(&phba->hbalock); | |
4974 | ||
4975 | /* Post receive buffers to the device */ | |
4976 | lpfc_sli4_rb_setup(phba); | |
4977 | ||
fc2b989b JS |
4978 | /* Reset HBA FCF states after HBA reset */ |
4979 | phba->fcf.fcf_flag = 0; | |
4980 | phba->fcf.current_rec.flag = 0; | |
4981 | ||
da0436e9 | 4982 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
4983 | mod_timer(&vport->els_tmofunc, |
4984 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
4985 | |
4986 | /* Start heart beat timer */ | |
4987 | mod_timer(&phba->hb_tmofunc, | |
4988 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
4989 | phba->hb_outstanding = 0; | |
4990 | phba->last_completion_time = jiffies; | |
4991 | ||
4992 | /* Start error attention (ERATT) polling timer */ | |
4993 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
4994 | ||
75baf696 JS |
4995 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4996 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4997 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4998 | if (!rc) { | |
4999 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5000 | "2829 This device supports " | |
5001 | "Advanced Error Reporting (AER)\n"); | |
5002 | spin_lock_irq(&phba->hbalock); | |
5003 | phba->hba_flag |= HBA_AER_ENABLED; | |
5004 | spin_unlock_irq(&phba->hbalock); | |
5005 | } else { | |
5006 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5007 | "2830 This device does not support " | |
5008 | "Advanced Error Reporting (AER)\n"); | |
5009 | phba->cfg_aer_support = 0; | |
5010 | } | |
5011 | } | |
5012 | ||
76a95d75 JS |
5013 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
5014 | /* | |
5015 | * The FC Port needs to register FCFI (index 0) | |
5016 | */ | |
5017 | lpfc_reg_fcfi(phba, mboxq); | |
5018 | mboxq->vport = phba->pport; | |
5019 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9589b062 | 5020 | if (rc != MBX_SUCCESS) |
76a95d75 | 5021 | goto out_unset_queue; |
9589b062 JS |
5022 | rc = 0; |
5023 | phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, | |
5024 | &mboxq->u.mqe.un.reg_fcfi); | |
76a95d75 | 5025 | } |
da0436e9 JS |
5026 | /* |
5027 | * The port is ready, set the host's link state to LINK_DOWN | |
5028 | * in preparation for link interrupts. | |
5029 | */ | |
da0436e9 JS |
5030 | spin_lock_irq(&phba->hbalock); |
5031 | phba->link_state = LPFC_LINK_DOWN; | |
5032 | spin_unlock_irq(&phba->hbalock); | |
fedd3b7b JS |
5033 | if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) |
5034 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
76a95d75 | 5035 | out_unset_queue: |
da0436e9 JS |
5036 | /* Unset all the queues set up in this routine when error out */ |
5037 | if (rc) | |
5038 | lpfc_sli4_queue_unset(phba); | |
da0436e9 JS |
5039 | out_stop_timers: |
5040 | if (rc) | |
5041 | lpfc_stop_hba_timers(phba); | |
da0436e9 JS |
5042 | out_free_mbox: |
5043 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5044 | return rc; | |
5045 | } | |
5046 | ||
5047 | /** | |
5048 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
5049 | * @ptr: context object - pointer to hba structure. | |
5050 | * | |
5051 | * This is the callback function for mailbox timer. The mailbox | |
5052 | * timer is armed when a new mailbox command is issued and the timer | |
5053 | * is deleted when the mailbox complete. The function is called by | |
5054 | * the kernel timer code when a mailbox does not complete within | |
5055 | * expected time. This function wakes up the worker thread to | |
5056 | * process the mailbox timeout and returns. All the processing is | |
5057 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
5058 | **/ | |
5059 | void | |
5060 | lpfc_mbox_timeout(unsigned long ptr) | |
5061 | { | |
5062 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
5063 | unsigned long iflag; | |
5064 | uint32_t tmo_posted; | |
5065 | ||
5066 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
5067 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
5068 | if (!tmo_posted) | |
5069 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
5070 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
5071 | ||
5072 | if (!tmo_posted) | |
5073 | lpfc_worker_wake_up(phba); | |
5074 | return; | |
5075 | } | |
5076 | ||
5077 | ||
5078 | /** | |
5079 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
5080 | * @phba: Pointer to HBA context object. | |
5081 | * | |
5082 | * This function is called from worker thread when a mailbox command times out. | |
5083 | * The caller is not required to hold any locks. This function will reset the | |
5084 | * HBA and recover all the pending commands. | |
5085 | **/ | |
5086 | void | |
5087 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
5088 | { | |
5089 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 5090 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
5091 | struct lpfc_sli *psli = &phba->sli; |
5092 | struct lpfc_sli_ring *pring; | |
5093 | ||
5094 | /* Check the pmbox pointer first. There is a race condition | |
5095 | * between the mbox timeout handler getting executed in the | |
5096 | * worklist and the mailbox actually completing. When this | |
5097 | * race condition occurs, the mbox_active will be NULL. | |
5098 | */ | |
5099 | spin_lock_irq(&phba->hbalock); | |
5100 | if (pmbox == NULL) { | |
5101 | lpfc_printf_log(phba, KERN_WARNING, | |
5102 | LOG_MBOX | LOG_SLI, | |
5103 | "0353 Active Mailbox cleared - mailbox timeout " | |
5104 | "exiting\n"); | |
5105 | spin_unlock_irq(&phba->hbalock); | |
5106 | return; | |
5107 | } | |
5108 | ||
5109 | /* Mbox cmd <mbxCommand> timeout */ | |
5110 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5111 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
5112 | mb->mbxCommand, | |
5113 | phba->pport->port_state, | |
5114 | phba->sli.sli_flag, | |
5115 | phba->sli.mbox_active); | |
5116 | spin_unlock_irq(&phba->hbalock); | |
5117 | ||
5118 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
5119 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
25985edc | 5120 | * it to fail all outstanding SCSI IO. |
da0436e9 JS |
5121 | */ |
5122 | spin_lock_irq(&phba->pport->work_port_lock); | |
5123 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
5124 | spin_unlock_irq(&phba->pport->work_port_lock); | |
5125 | spin_lock_irq(&phba->hbalock); | |
5126 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 5127 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
5128 | spin_unlock_irq(&phba->hbalock); |
5129 | ||
5130 | pring = &psli->ring[psli->fcp_ring]; | |
5131 | lpfc_sli_abort_iocb_ring(phba, pring); | |
5132 | ||
5133 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5134 | "0345 Resetting board due to mailbox timeout\n"); | |
5135 | ||
5136 | /* Reset the HBA device */ | |
5137 | lpfc_reset_hba(phba); | |
5138 | } | |
5139 | ||
5140 | /** | |
5141 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
5142 | * @phba: Pointer to HBA context object. | |
5143 | * @pmbox: Pointer to mailbox object. | |
5144 | * @flag: Flag indicating how the mailbox need to be processed. | |
5145 | * | |
5146 | * This function is called by discovery code and HBA management code | |
5147 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
5148 | * function gets the hbalock to protect the data structures. | |
5149 | * The mailbox command can be submitted in polling mode, in which case | |
5150 | * this function will wait in a polling loop for the completion of the | |
5151 | * mailbox. | |
5152 | * If the mailbox is submitted in no_wait mode (not polling) the | |
5153 | * function will submit the command and returns immediately without waiting | |
5154 | * for the mailbox completion. The no_wait is supported only when HBA | |
5155 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
5156 | * The SLI interface allows only one mailbox pending at a time. If the | |
5157 | * mailbox is issued in polling mode and there is already a mailbox | |
5158 | * pending, then the function will return an error. If the mailbox is issued | |
5159 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
5160 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
5161 | * The sli layer owns the mailbox object until the completion of mailbox | |
5162 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
5163 | * return codes the caller owns the mailbox command after the return of | |
5164 | * the function. | |
e59058c4 | 5165 | **/ |
3772a991 JS |
5166 | static int |
5167 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
5168 | uint32_t flag) | |
dea3101e | 5169 | { |
dea3101e | 5170 | MAILBOX_t *mb; |
2e0fef85 | 5171 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 5172 | uint32_t status, evtctr; |
9940b97b | 5173 | uint32_t ha_copy, hc_copy; |
dea3101e | 5174 | int i; |
09372820 | 5175 | unsigned long timeout; |
dea3101e | 5176 | unsigned long drvr_flag = 0; |
34b02dcd | 5177 | uint32_t word0, ldata; |
dea3101e | 5178 | void __iomem *to_slim; |
58da1ffb JS |
5179 | int processing_queue = 0; |
5180 | ||
5181 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5182 | if (!pmbox) { | |
8568a4d2 | 5183 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 5184 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
5185 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
5186 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5187 | return MBX_SUCCESS; | |
5188 | } | |
58da1ffb | 5189 | processing_queue = 1; |
58da1ffb JS |
5190 | pmbox = lpfc_mbox_get(phba); |
5191 | if (!pmbox) { | |
5192 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5193 | return MBX_SUCCESS; | |
5194 | } | |
5195 | } | |
dea3101e | 5196 | |
ed957684 | 5197 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 5198 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 5199 | if(!pmbox->vport) { |
58da1ffb | 5200 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 5201 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 5202 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 5203 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 5204 | pmbox->u.mb.mbxCommand); |
ed957684 | 5205 | dump_stack(); |
58da1ffb | 5206 | goto out_not_finished; |
ed957684 JS |
5207 | } |
5208 | } | |
5209 | ||
8d63f375 | 5210 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
5211 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
5212 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5213 | goto out_not_finished; | |
5214 | } | |
8d63f375 | 5215 | |
a257bf90 JS |
5216 | /* If HBA has a deferred error attention, fail the iocb. */ |
5217 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
5218 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5219 | goto out_not_finished; | |
5220 | } | |
5221 | ||
dea3101e | 5222 | psli = &phba->sli; |
92d7f7b0 | 5223 | |
3772a991 | 5224 | mb = &pmbox->u.mb; |
dea3101e JB |
5225 | status = MBX_SUCCESS; |
5226 | ||
2e0fef85 JS |
5227 | if (phba->link_state == LPFC_HBA_ERROR) { |
5228 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
5229 | |
5230 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
5231 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5232 | "(%d):0311 Mailbox command x%x cannot " | |
5233 | "issue Data: x%x x%x\n", | |
5234 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5235 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 5236 | goto out_not_finished; |
41415862 JW |
5237 | } |
5238 | ||
9940b97b JS |
5239 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) { |
5240 | if (lpfc_readl(phba->HCregaddr, &hc_copy) || | |
5241 | !(hc_copy & HC_MBINT_ENA)) { | |
5242 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5243 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
3772a991 JS |
5244 | "(%d):2528 Mailbox command x%x cannot " |
5245 | "issue Data: x%x x%x\n", | |
5246 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5247 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
9940b97b JS |
5248 | goto out_not_finished; |
5249 | } | |
9290831f JS |
5250 | } |
5251 | ||
dea3101e JB |
5252 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
5253 | /* Polling for a mbox command when another one is already active | |
5254 | * is not allowed in SLI. Also, the driver must have established | |
5255 | * SLI2 mode to queue and process multiple mbox commands. | |
5256 | */ | |
5257 | ||
5258 | if (flag & MBX_POLL) { | |
2e0fef85 | 5259 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
5260 | |
5261 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
5262 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5263 | "(%d):2529 Mailbox command x%x " | |
5264 | "cannot issue Data: x%x x%x\n", | |
5265 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5266 | pmbox->u.mb.mbxCommand, | |
5267 | psli->sli_flag, flag); | |
58da1ffb | 5268 | goto out_not_finished; |
dea3101e JB |
5269 | } |
5270 | ||
3772a991 | 5271 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 5272 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5273 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
5274 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5275 | "(%d):2530 Mailbox command x%x " | |
5276 | "cannot issue Data: x%x x%x\n", | |
5277 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5278 | pmbox->u.mb.mbxCommand, | |
5279 | psli->sli_flag, flag); | |
58da1ffb | 5280 | goto out_not_finished; |
dea3101e JB |
5281 | } |
5282 | ||
dea3101e JB |
5283 | /* Another mailbox command is still being processed, queue this |
5284 | * command to be processed later. | |
5285 | */ | |
5286 | lpfc_mbox_put(phba, pmbox); | |
5287 | ||
5288 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 5289 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 5290 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 5291 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
5292 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
5293 | mb->mbxCommand, phba->pport->port_state, | |
5294 | psli->sli_flag, flag); | |
dea3101e JB |
5295 | |
5296 | psli->slistat.mbox_busy++; | |
2e0fef85 | 5297 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5298 | |
858c9f6c JS |
5299 | if (pmbox->vport) { |
5300 | lpfc_debugfs_disc_trc(pmbox->vport, | |
5301 | LPFC_DISC_TRC_MBOX_VPORT, | |
5302 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
5303 | (uint32_t)mb->mbxCommand, | |
5304 | mb->un.varWords[0], mb->un.varWords[1]); | |
5305 | } | |
5306 | else { | |
5307 | lpfc_debugfs_disc_trc(phba->pport, | |
5308 | LPFC_DISC_TRC_MBOX, | |
5309 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
5310 | (uint32_t)mb->mbxCommand, | |
5311 | mb->un.varWords[0], mb->un.varWords[1]); | |
5312 | } | |
5313 | ||
2e0fef85 | 5314 | return MBX_BUSY; |
dea3101e JB |
5315 | } |
5316 | ||
dea3101e JB |
5317 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
5318 | ||
5319 | /* If we are not polling, we MUST be in SLI2 mode */ | |
5320 | if (flag != MBX_POLL) { | |
3772a991 | 5321 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 5322 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 5323 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5324 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5325 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
5326 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5327 | "(%d):2531 Mailbox command x%x " | |
5328 | "cannot issue Data: x%x x%x\n", | |
5329 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5330 | pmbox->u.mb.mbxCommand, | |
5331 | psli->sli_flag, flag); | |
58da1ffb | 5332 | goto out_not_finished; |
dea3101e JB |
5333 | } |
5334 | /* timeout active mbox command */ | |
a309a6b6 JS |
5335 | mod_timer(&psli->mbox_tmo, (jiffies + |
5336 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | |
dea3101e JB |
5337 | } |
5338 | ||
5339 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 5340 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 5341 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 5342 | "x%x\n", |
e8b62011 | 5343 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
5344 | mb->mbxCommand, phba->pport->port_state, |
5345 | psli->sli_flag, flag); | |
dea3101e | 5346 | |
858c9f6c JS |
5347 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
5348 | if (pmbox->vport) { | |
5349 | lpfc_debugfs_disc_trc(pmbox->vport, | |
5350 | LPFC_DISC_TRC_MBOX_VPORT, | |
5351 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5352 | (uint32_t)mb->mbxCommand, | |
5353 | mb->un.varWords[0], mb->un.varWords[1]); | |
5354 | } | |
5355 | else { | |
5356 | lpfc_debugfs_disc_trc(phba->pport, | |
5357 | LPFC_DISC_TRC_MBOX, | |
5358 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5359 | (uint32_t)mb->mbxCommand, | |
5360 | mb->un.varWords[0], mb->un.varWords[1]); | |
5361 | } | |
5362 | } | |
5363 | ||
dea3101e JB |
5364 | psli->slistat.mbox_cmd++; |
5365 | evtctr = psli->slistat.mbox_event; | |
5366 | ||
5367 | /* next set own bit for the adapter and copy over command word */ | |
5368 | mb->mbxOwner = OWN_CHIP; | |
5369 | ||
3772a991 | 5370 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
5371 | /* Populate mbox extension offset word. */ |
5372 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
5373 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
5374 | = (uint8_t *)phba->mbox_ext | |
5375 | - (uint8_t *)phba->mbox; | |
5376 | } | |
5377 | ||
5378 | /* Copy the mailbox extension data */ | |
5379 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
5380 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
5381 | (uint8_t *)phba->mbox_ext, | |
5382 | pmbox->in_ext_byte_len); | |
5383 | } | |
5384 | /* Copy command data to host SLIM area */ | |
34b02dcd | 5385 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 5386 | } else { |
7a470277 JS |
5387 | /* Populate mbox extension offset word. */ |
5388 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
5389 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
5390 | = MAILBOX_HBA_EXT_OFFSET; | |
5391 | ||
5392 | /* Copy the mailbox extension data */ | |
5393 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
5394 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
5395 | MAILBOX_HBA_EXT_OFFSET, | |
5396 | pmbox->context2, pmbox->in_ext_byte_len); | |
5397 | ||
5398 | } | |
9290831f | 5399 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 5400 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 5401 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e JB |
5402 | } |
5403 | ||
5404 | /* First copy mbox command data to HBA SLIM, skip past first | |
5405 | word */ | |
5406 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
5407 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
5408 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
5409 | ||
5410 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 5411 | ldata = *((uint32_t *)mb); |
dea3101e JB |
5412 | to_slim = phba->MBslimaddr; |
5413 | writel(ldata, to_slim); | |
5414 | readl(to_slim); /* flush */ | |
5415 | ||
5416 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5417 | /* switch over to host mailbox */ | |
3772a991 | 5418 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
5419 | } |
5420 | } | |
5421 | ||
5422 | wmb(); | |
dea3101e JB |
5423 | |
5424 | switch (flag) { | |
5425 | case MBX_NOWAIT: | |
09372820 | 5426 | /* Set up reference to mailbox command */ |
dea3101e | 5427 | psli->mbox_active = pmbox; |
09372820 JS |
5428 | /* Interrupt board to do it */ |
5429 | writel(CA_MBATT, phba->CAregaddr); | |
5430 | readl(phba->CAregaddr); /* flush */ | |
5431 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
5432 | break; |
5433 | ||
5434 | case MBX_POLL: | |
09372820 | 5435 | /* Set up null reference to mailbox command */ |
dea3101e | 5436 | psli->mbox_active = NULL; |
09372820 JS |
5437 | /* Interrupt board to do it */ |
5438 | writel(CA_MBATT, phba->CAregaddr); | |
5439 | readl(phba->CAregaddr); /* flush */ | |
5440 | ||
3772a991 | 5441 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5442 | /* First read mbox status word */ |
34b02dcd | 5443 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
5444 | word0 = le32_to_cpu(word0); |
5445 | } else { | |
5446 | /* First read mbox status word */ | |
9940b97b JS |
5447 | if (lpfc_readl(phba->MBslimaddr, &word0)) { |
5448 | spin_unlock_irqrestore(&phba->hbalock, | |
5449 | drvr_flag); | |
5450 | goto out_not_finished; | |
5451 | } | |
dea3101e JB |
5452 | } |
5453 | ||
5454 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
5455 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
5456 | spin_unlock_irqrestore(&phba->hbalock, | |
5457 | drvr_flag); | |
5458 | goto out_not_finished; | |
5459 | } | |
09372820 JS |
5460 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
5461 | mb->mbxCommand) * | |
5462 | 1000) + jiffies; | |
5463 | i = 0; | |
dea3101e | 5464 | /* Wait for command to complete */ |
41415862 JW |
5465 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
5466 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 5467 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 5468 | if (time_after(jiffies, timeout)) { |
dea3101e | 5469 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5470 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 5471 | drvr_flag); |
58da1ffb | 5472 | goto out_not_finished; |
dea3101e JB |
5473 | } |
5474 | ||
5475 | /* Check if we took a mbox interrupt while we were | |
5476 | polling */ | |
5477 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
5478 | && (evtctr != psli->slistat.mbox_event)) | |
5479 | break; | |
5480 | ||
09372820 JS |
5481 | if (i++ > 10) { |
5482 | spin_unlock_irqrestore(&phba->hbalock, | |
5483 | drvr_flag); | |
5484 | msleep(1); | |
5485 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5486 | } | |
dea3101e | 5487 | |
3772a991 | 5488 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5489 | /* First copy command data */ |
34b02dcd | 5490 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
5491 | word0 = le32_to_cpu(word0); |
5492 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5493 | MAILBOX_t *slimmb; | |
34b02dcd | 5494 | uint32_t slimword0; |
dea3101e JB |
5495 | /* Check real SLIM for any errors */ |
5496 | slimword0 = readl(phba->MBslimaddr); | |
5497 | slimmb = (MAILBOX_t *) & slimword0; | |
5498 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
5499 | && slimmb->mbxStatus) { | |
5500 | psli->sli_flag &= | |
3772a991 | 5501 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
5502 | word0 = slimword0; |
5503 | } | |
5504 | } | |
5505 | } else { | |
5506 | /* First copy command data */ | |
5507 | word0 = readl(phba->MBslimaddr); | |
5508 | } | |
5509 | /* Read the HBA Host Attention Register */ | |
9940b97b JS |
5510 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) { |
5511 | spin_unlock_irqrestore(&phba->hbalock, | |
5512 | drvr_flag); | |
5513 | goto out_not_finished; | |
5514 | } | |
dea3101e JB |
5515 | } |
5516 | ||
3772a991 | 5517 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5518 | /* copy results back to user */ |
34b02dcd | 5519 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
5520 | /* Copy the mailbox extension data */ |
5521 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5522 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
5523 | pmbox->context2, | |
5524 | pmbox->out_ext_byte_len); | |
5525 | } | |
dea3101e JB |
5526 | } else { |
5527 | /* First copy command data */ | |
5528 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
5529 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
5530 | /* Copy the mailbox extension data */ |
5531 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5532 | lpfc_memcpy_from_slim(pmbox->context2, | |
5533 | phba->MBslimaddr + | |
5534 | MAILBOX_HBA_EXT_OFFSET, | |
5535 | pmbox->out_ext_byte_len); | |
dea3101e JB |
5536 | } |
5537 | } | |
5538 | ||
5539 | writel(HA_MBATT, phba->HAregaddr); | |
5540 | readl(phba->HAregaddr); /* flush */ | |
5541 | ||
5542 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5543 | status = mb->mbxStatus; | |
5544 | } | |
5545 | ||
2e0fef85 JS |
5546 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
5547 | return status; | |
58da1ffb JS |
5548 | |
5549 | out_not_finished: | |
5550 | if (processing_queue) { | |
da0436e9 | 5551 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
5552 | lpfc_mbox_cmpl_put(phba, pmbox); |
5553 | } | |
5554 | return MBX_NOT_FINISHED; | |
dea3101e JB |
5555 | } |
5556 | ||
f1126688 JS |
5557 | /** |
5558 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
5559 | * @phba: Pointer to HBA context object. | |
5560 | * | |
5561 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
5562 | * the driver internal pending mailbox queue. It will then try to wait out the | |
5563 | * possible outstanding mailbox command before return. | |
5564 | * | |
5565 | * Returns: | |
5566 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
5567 | * the outstanding mailbox command timed out. | |
5568 | **/ | |
5569 | static int | |
5570 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
5571 | { | |
5572 | struct lpfc_sli *psli = &phba->sli; | |
5573 | uint8_t actcmd = MBX_HEARTBEAT; | |
5574 | int rc = 0; | |
5575 | unsigned long timeout; | |
5576 | ||
5577 | /* Mark the asynchronous mailbox command posting as blocked */ | |
5578 | spin_lock_irq(&phba->hbalock); | |
5579 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
5580 | if (phba->sli.mbox_active) | |
5581 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
5582 | spin_unlock_irq(&phba->hbalock); | |
5583 | /* Determine how long we might wait for the active mailbox | |
5584 | * command to be gracefully completed by firmware. | |
5585 | */ | |
5586 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
5587 | jiffies; | |
5588 | /* Wait for the outstnading mailbox command to complete */ | |
5589 | while (phba->sli.mbox_active) { | |
5590 | /* Check active mailbox complete status every 2ms */ | |
5591 | msleep(2); | |
5592 | if (time_after(jiffies, timeout)) { | |
5593 | /* Timeout, marked the outstanding cmd not complete */ | |
5594 | rc = 1; | |
5595 | break; | |
5596 | } | |
5597 | } | |
5598 | ||
5599 | /* Can not cleanly block async mailbox command, fails it */ | |
5600 | if (rc) { | |
5601 | spin_lock_irq(&phba->hbalock); | |
5602 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5603 | spin_unlock_irq(&phba->hbalock); | |
5604 | } | |
5605 | return rc; | |
5606 | } | |
5607 | ||
5608 | /** | |
5609 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
5610 | * @phba: Pointer to HBA context object. | |
5611 | * | |
5612 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
5613 | * commands from the driver internal pending mailbox queue. It makes sure | |
5614 | * that there is no outstanding mailbox command before resuming posting | |
5615 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
5616 | * mailbox command, it will try to wait it out before resuming asynchronous | |
5617 | * mailbox command posting. | |
5618 | **/ | |
5619 | static void | |
5620 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
5621 | { | |
5622 | struct lpfc_sli *psli = &phba->sli; | |
5623 | ||
5624 | spin_lock_irq(&phba->hbalock); | |
5625 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5626 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
5627 | spin_unlock_irq(&phba->hbalock); | |
5628 | return; | |
5629 | } | |
5630 | ||
5631 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
5632 | * successful or timeout, after timing-out the outstanding mailbox | |
5633 | * command shall always be removed, so just unblock posting async | |
5634 | * mailbox command and resume | |
5635 | */ | |
5636 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5637 | spin_unlock_irq(&phba->hbalock); | |
5638 | ||
5639 | /* wake up worker thread to post asynchronlous mailbox command */ | |
5640 | lpfc_worker_wake_up(phba); | |
5641 | } | |
5642 | ||
da0436e9 JS |
5643 | /** |
5644 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
5645 | * @phba: Pointer to HBA context object. | |
5646 | * @mboxq: Pointer to mailbox object. | |
5647 | * | |
5648 | * The function posts a mailbox to the port. The mailbox is expected | |
5649 | * to be comletely filled in and ready for the port to operate on it. | |
5650 | * This routine executes a synchronous completion operation on the | |
5651 | * mailbox by polling for its completion. | |
5652 | * | |
5653 | * The caller must not be holding any locks when calling this routine. | |
5654 | * | |
5655 | * Returns: | |
5656 | * MBX_SUCCESS - mailbox posted successfully | |
5657 | * Any of the MBX error values. | |
5658 | **/ | |
5659 | static int | |
5660 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
5661 | { | |
5662 | int rc = MBX_SUCCESS; | |
5663 | unsigned long iflag; | |
5664 | uint32_t db_ready; | |
5665 | uint32_t mcqe_status; | |
5666 | uint32_t mbx_cmnd; | |
5667 | unsigned long timeout; | |
5668 | struct lpfc_sli *psli = &phba->sli; | |
5669 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
5670 | struct lpfc_bmbx_create *mbox_rgn; | |
5671 | struct dma_address *dma_address; | |
5672 | struct lpfc_register bmbx_reg; | |
5673 | ||
5674 | /* | |
5675 | * Only one mailbox can be active to the bootstrap mailbox region | |
5676 | * at a time and there is no queueing provided. | |
5677 | */ | |
5678 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5679 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5680 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5681 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5682 | "(%d):2532 Mailbox command x%x (x%x) " | |
5683 | "cannot issue Data: x%x x%x\n", | |
5684 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5685 | mboxq->u.mb.mbxCommand, | |
5686 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5687 | psli->sli_flag, MBX_POLL); | |
5688 | return MBXERR_ERROR; | |
5689 | } | |
5690 | /* The server grabs the token and owns it until release */ | |
5691 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5692 | phba->sli.mbox_active = mboxq; | |
5693 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5694 | ||
5695 | /* | |
5696 | * Initialize the bootstrap memory region to avoid stale data areas | |
5697 | * in the mailbox post. Then copy the caller's mailbox contents to | |
5698 | * the bmbx mailbox region. | |
5699 | */ | |
5700 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
5701 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
5702 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
5703 | sizeof(struct lpfc_mqe)); | |
5704 | ||
5705 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
5706 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5707 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
5708 | ||
5709 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5710 | * 1000) + jiffies; | |
5711 | do { | |
5712 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5713 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5714 | if (!db_ready) | |
5715 | msleep(2); | |
5716 | ||
5717 | if (time_after(jiffies, timeout)) { | |
5718 | rc = MBXERR_ERROR; | |
5719 | goto exit; | |
5720 | } | |
5721 | } while (!db_ready); | |
5722 | ||
5723 | /* Post the low mailbox dma address to the port. */ | |
5724 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
5725 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5726 | * 1000) + jiffies; | |
5727 | do { | |
5728 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5729 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5730 | if (!db_ready) | |
5731 | msleep(2); | |
5732 | ||
5733 | if (time_after(jiffies, timeout)) { | |
5734 | rc = MBXERR_ERROR; | |
5735 | goto exit; | |
5736 | } | |
5737 | } while (!db_ready); | |
5738 | ||
5739 | /* | |
5740 | * Read the CQ to ensure the mailbox has completed. | |
5741 | * If so, update the mailbox status so that the upper layers | |
5742 | * can complete the request normally. | |
5743 | */ | |
5744 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
5745 | sizeof(struct lpfc_mqe)); | |
5746 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
5747 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
5748 | sizeof(struct lpfc_mcqe)); | |
5749 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
5750 | ||
5751 | /* Prefix the mailbox status with range x4000 to note SLI4 status. */ | |
5752 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
5753 | bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status); | |
5754 | rc = MBXERR_ERROR; | |
d7c47992 JS |
5755 | } else |
5756 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
5757 | |
5758 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5759 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " | |
5760 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" | |
5761 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
5762 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5763 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5764 | bf_get(lpfc_mqe_status, mb), | |
5765 | mb->un.mb_words[0], mb->un.mb_words[1], | |
5766 | mb->un.mb_words[2], mb->un.mb_words[3], | |
5767 | mb->un.mb_words[4], mb->un.mb_words[5], | |
5768 | mb->un.mb_words[6], mb->un.mb_words[7], | |
5769 | mb->un.mb_words[8], mb->un.mb_words[9], | |
5770 | mb->un.mb_words[10], mb->un.mb_words[11], | |
5771 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
5772 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
5773 | mboxq->mcqe.trailer); | |
5774 | exit: | |
5775 | /* We are holding the token, no needed for lock when release */ | |
5776 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5777 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5778 | phba->sli.mbox_active = NULL; | |
5779 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5780 | return rc; | |
5781 | } | |
5782 | ||
5783 | /** | |
5784 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
5785 | * @phba: Pointer to HBA context object. | |
5786 | * @pmbox: Pointer to mailbox object. | |
5787 | * @flag: Flag indicating how the mailbox need to be processed. | |
5788 | * | |
5789 | * This function is called by discovery code and HBA management code to submit | |
5790 | * a mailbox command to firmware with SLI-4 interface spec. | |
5791 | * | |
5792 | * Return codes the caller owns the mailbox command after the return of the | |
5793 | * function. | |
5794 | **/ | |
5795 | static int | |
5796 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
5797 | uint32_t flag) | |
5798 | { | |
5799 | struct lpfc_sli *psli = &phba->sli; | |
5800 | unsigned long iflags; | |
5801 | int rc; | |
5802 | ||
8fa38513 JS |
5803 | rc = lpfc_mbox_dev_check(phba); |
5804 | if (unlikely(rc)) { | |
5805 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5806 | "(%d):2544 Mailbox command x%x (x%x) " | |
5807 | "cannot issue Data: x%x x%x\n", | |
5808 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5809 | mboxq->u.mb.mbxCommand, | |
5810 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5811 | psli->sli_flag, flag); | |
5812 | goto out_not_finished; | |
5813 | } | |
5814 | ||
da0436e9 JS |
5815 | /* Detect polling mode and jump to a handler */ |
5816 | if (!phba->sli4_hba.intr_enable) { | |
5817 | if (flag == MBX_POLL) | |
5818 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5819 | else | |
5820 | rc = -EIO; | |
5821 | if (rc != MBX_SUCCESS) | |
5822 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5823 | "(%d):2541 Mailbox command x%x " | |
5824 | "(x%x) cannot issue Data: x%x x%x\n", | |
5825 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5826 | mboxq->u.mb.mbxCommand, | |
5827 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5828 | psli->sli_flag, flag); | |
5829 | return rc; | |
5830 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
5831 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
5832 | "(%d):2542 Try to issue mailbox command " | |
5833 | "x%x (x%x) synchronously ahead of async" | |
5834 | "mailbox command queue: x%x x%x\n", | |
da0436e9 JS |
5835 | mboxq->vport ? mboxq->vport->vpi : 0, |
5836 | mboxq->u.mb.mbxCommand, | |
5837 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5838 | psli->sli_flag, flag); | |
f1126688 JS |
5839 | /* Try to block the asynchronous mailbox posting */ |
5840 | rc = lpfc_sli4_async_mbox_block(phba); | |
5841 | if (!rc) { | |
5842 | /* Successfully blocked, now issue sync mbox cmd */ | |
5843 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5844 | if (rc != MBX_SUCCESS) | |
5845 | lpfc_printf_log(phba, KERN_ERR, | |
5846 | LOG_MBOX | LOG_SLI, | |
5847 | "(%d):2597 Mailbox command " | |
5848 | "x%x (x%x) cannot issue " | |
5849 | "Data: x%x x%x\n", | |
5850 | mboxq->vport ? | |
5851 | mboxq->vport->vpi : 0, | |
5852 | mboxq->u.mb.mbxCommand, | |
5853 | lpfc_sli4_mbox_opcode_get(phba, | |
5854 | mboxq), | |
5855 | psli->sli_flag, flag); | |
5856 | /* Unblock the async mailbox posting afterward */ | |
5857 | lpfc_sli4_async_mbox_unblock(phba); | |
5858 | } | |
5859 | return rc; | |
da0436e9 JS |
5860 | } |
5861 | ||
5862 | /* Now, interrupt mode asynchrous mailbox command */ | |
5863 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
5864 | if (rc) { | |
5865 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5866 | "(%d):2543 Mailbox command x%x (x%x) " | |
5867 | "cannot issue Data: x%x x%x\n", | |
5868 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5869 | mboxq->u.mb.mbxCommand, | |
5870 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5871 | psli->sli_flag, flag); | |
5872 | goto out_not_finished; | |
5873 | } | |
da0436e9 JS |
5874 | |
5875 | /* Put the mailbox command to the driver internal FIFO */ | |
5876 | psli->slistat.mbox_busy++; | |
5877 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5878 | lpfc_mbox_put(phba, mboxq); | |
5879 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5880 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5881 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
5882 | "x%x (x%x) x%x x%x x%x\n", | |
5883 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, | |
5884 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5885 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5886 | phba->pport->port_state, | |
5887 | psli->sli_flag, MBX_NOWAIT); | |
5888 | /* Wake up worker thread to transport mailbox command from head */ | |
5889 | lpfc_worker_wake_up(phba); | |
5890 | ||
5891 | return MBX_BUSY; | |
5892 | ||
5893 | out_not_finished: | |
5894 | return MBX_NOT_FINISHED; | |
5895 | } | |
5896 | ||
5897 | /** | |
5898 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
5899 | * @phba: Pointer to HBA context object. | |
5900 | * | |
5901 | * This function is called by worker thread to send a mailbox command to | |
5902 | * SLI4 HBA firmware. | |
5903 | * | |
5904 | **/ | |
5905 | int | |
5906 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
5907 | { | |
5908 | struct lpfc_sli *psli = &phba->sli; | |
5909 | LPFC_MBOXQ_t *mboxq; | |
5910 | int rc = MBX_SUCCESS; | |
5911 | unsigned long iflags; | |
5912 | struct lpfc_mqe *mqe; | |
5913 | uint32_t mbx_cmnd; | |
5914 | ||
5915 | /* Check interrupt mode before post async mailbox command */ | |
5916 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
5917 | return MBX_NOT_FINISHED; | |
5918 | ||
5919 | /* Check for mailbox command service token */ | |
5920 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5921 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5922 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5923 | return MBX_NOT_FINISHED; | |
5924 | } | |
5925 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5926 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5927 | return MBX_NOT_FINISHED; | |
5928 | } | |
5929 | if (unlikely(phba->sli.mbox_active)) { | |
5930 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5931 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5932 | "0384 There is pending active mailbox cmd\n"); | |
5933 | return MBX_NOT_FINISHED; | |
5934 | } | |
5935 | /* Take the mailbox command service token */ | |
5936 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5937 | ||
5938 | /* Get the next mailbox command from head of queue */ | |
5939 | mboxq = lpfc_mbox_get(phba); | |
5940 | ||
5941 | /* If no more mailbox command waiting for post, we're done */ | |
5942 | if (!mboxq) { | |
5943 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5944 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5945 | return MBX_SUCCESS; | |
5946 | } | |
5947 | phba->sli.mbox_active = mboxq; | |
5948 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5949 | ||
5950 | /* Check device readiness for posting mailbox command */ | |
5951 | rc = lpfc_mbox_dev_check(phba); | |
5952 | if (unlikely(rc)) | |
5953 | /* Driver clean routine will clean up pending mailbox */ | |
5954 | goto out_not_finished; | |
5955 | ||
5956 | /* Prepare the mbox command to be posted */ | |
5957 | mqe = &mboxq->u.mqe; | |
5958 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
5959 | ||
5960 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
5961 | mod_timer(&psli->mbox_tmo, (jiffies + | |
5962 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); | |
5963 | ||
5964 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5965 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " | |
5966 | "x%x x%x\n", | |
5967 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
5968 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5969 | phba->pport->port_state, psli->sli_flag); | |
5970 | ||
5971 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
5972 | if (mboxq->vport) { | |
5973 | lpfc_debugfs_disc_trc(mboxq->vport, | |
5974 | LPFC_DISC_TRC_MBOX_VPORT, | |
5975 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5976 | mbx_cmnd, mqe->un.mb_words[0], | |
5977 | mqe->un.mb_words[1]); | |
5978 | } else { | |
5979 | lpfc_debugfs_disc_trc(phba->pport, | |
5980 | LPFC_DISC_TRC_MBOX, | |
5981 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5982 | mbx_cmnd, mqe->un.mb_words[0], | |
5983 | mqe->un.mb_words[1]); | |
5984 | } | |
5985 | } | |
5986 | psli->slistat.mbox_cmd++; | |
5987 | ||
5988 | /* Post the mailbox command to the port */ | |
5989 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
5990 | if (rc != MBX_SUCCESS) { | |
5991 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5992 | "(%d):2533 Mailbox command x%x (x%x) " | |
5993 | "cannot issue Data: x%x x%x\n", | |
5994 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5995 | mboxq->u.mb.mbxCommand, | |
5996 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5997 | psli->sli_flag, MBX_NOWAIT); | |
5998 | goto out_not_finished; | |
5999 | } | |
6000 | ||
6001 | return rc; | |
6002 | ||
6003 | out_not_finished: | |
6004 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6005 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
6006 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
6007 | /* Release the token */ | |
6008 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6009 | phba->sli.mbox_active = NULL; | |
6010 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6011 | ||
6012 | return MBX_NOT_FINISHED; | |
6013 | } | |
6014 | ||
6015 | /** | |
6016 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
6017 | * @phba: Pointer to HBA context object. | |
6018 | * @pmbox: Pointer to mailbox object. | |
6019 | * @flag: Flag indicating how the mailbox need to be processed. | |
6020 | * | |
6021 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
6022 | * the API jump table function pointer from the lpfc_hba struct. | |
6023 | * | |
6024 | * Return codes the caller owns the mailbox command after the return of the | |
6025 | * function. | |
6026 | **/ | |
6027 | int | |
6028 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
6029 | { | |
6030 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
6031 | } | |
6032 | ||
6033 | /** | |
25985edc | 6034 | * lpfc_mbox_api_table_setup - Set up mbox api function jump table |
da0436e9 JS |
6035 | * @phba: The hba struct for which this call is being executed. |
6036 | * @dev_grp: The HBA PCI-Device group number. | |
6037 | * | |
6038 | * This routine sets up the mbox interface API function jump table in @phba | |
6039 | * struct. | |
6040 | * Returns: 0 - success, -ENODEV - failure. | |
6041 | **/ | |
6042 | int | |
6043 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6044 | { | |
6045 | ||
6046 | switch (dev_grp) { | |
6047 | case LPFC_PCI_DEV_LP: | |
6048 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
6049 | phba->lpfc_sli_handle_slow_ring_event = | |
6050 | lpfc_sli_handle_slow_ring_event_s3; | |
6051 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
6052 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
6053 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
6054 | break; | |
6055 | case LPFC_PCI_DEV_OC: | |
6056 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
6057 | phba->lpfc_sli_handle_slow_ring_event = | |
6058 | lpfc_sli_handle_slow_ring_event_s4; | |
6059 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
6060 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
6061 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
6062 | break; | |
6063 | default: | |
6064 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6065 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
6066 | dev_grp); | |
6067 | return -ENODEV; | |
6068 | break; | |
6069 | } | |
6070 | return 0; | |
6071 | } | |
6072 | ||
e59058c4 | 6073 | /** |
3621a710 | 6074 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
6075 | * @phba: Pointer to HBA context object. |
6076 | * @pring: Pointer to driver SLI ring object. | |
6077 | * @piocb: Pointer to address of newly added command iocb. | |
6078 | * | |
6079 | * This function is called with hbalock held to add a command | |
6080 | * iocb to the txq when SLI layer cannot submit the command iocb | |
6081 | * to the ring. | |
6082 | **/ | |
2a9bf3d0 | 6083 | void |
92d7f7b0 | 6084 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 6085 | struct lpfc_iocbq *piocb) |
dea3101e JB |
6086 | { |
6087 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
6088 | list_add_tail(&piocb->list, &pring->txq); | |
6089 | pring->txq_cnt++; | |
dea3101e JB |
6090 | } |
6091 | ||
e59058c4 | 6092 | /** |
3621a710 | 6093 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
6094 | * @phba: Pointer to HBA context object. |
6095 | * @pring: Pointer to driver SLI ring object. | |
6096 | * @piocb: Pointer to address of newly added command iocb. | |
6097 | * | |
6098 | * This function is called with hbalock held before a new | |
6099 | * iocb is submitted to the firmware. This function checks | |
6100 | * txq to flush the iocbs in txq to Firmware before | |
6101 | * submitting new iocbs to the Firmware. | |
6102 | * If there are iocbs in the txq which need to be submitted | |
6103 | * to firmware, lpfc_sli_next_iocb returns the first element | |
6104 | * of the txq after dequeuing it from txq. | |
6105 | * If there is no iocb in the txq then the function will return | |
6106 | * *piocb and *piocb is set to NULL. Caller needs to check | |
6107 | * *piocb to find if there are more commands in the txq. | |
6108 | **/ | |
dea3101e JB |
6109 | static struct lpfc_iocbq * |
6110 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 6111 | struct lpfc_iocbq **piocb) |
dea3101e JB |
6112 | { |
6113 | struct lpfc_iocbq * nextiocb; | |
6114 | ||
6115 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
6116 | if (!nextiocb) { | |
6117 | nextiocb = *piocb; | |
6118 | *piocb = NULL; | |
6119 | } | |
6120 | ||
6121 | return nextiocb; | |
6122 | } | |
6123 | ||
e59058c4 | 6124 | /** |
3772a991 | 6125 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 6126 | * @phba: Pointer to HBA context object. |
3772a991 | 6127 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
6128 | * @piocb: Pointer to command iocb. |
6129 | * @flag: Flag indicating if this command can be put into txq. | |
6130 | * | |
3772a991 JS |
6131 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
6132 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
6133 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
6134 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
6135 | * this function allows only iocbs for posting buffers. This function finds | |
6136 | * next available slot in the command ring and posts the command to the | |
6137 | * available slot and writes the port attention register to request HBA start | |
6138 | * processing new iocb. If there is no slot available in the ring and | |
6139 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
6140 | * the function returns IOCB_BUSY. | |
e59058c4 | 6141 | * |
3772a991 JS |
6142 | * This function is called with hbalock held. The function will return success |
6143 | * after it successfully submit the iocb to firmware or after adding to the | |
6144 | * txq. | |
e59058c4 | 6145 | **/ |
98c9ea5c | 6146 | static int |
3772a991 | 6147 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
6148 | struct lpfc_iocbq *piocb, uint32_t flag) |
6149 | { | |
6150 | struct lpfc_iocbq *nextiocb; | |
6151 | IOCB_t *iocb; | |
3772a991 | 6152 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 6153 | |
92d7f7b0 JS |
6154 | if (piocb->iocb_cmpl && (!piocb->vport) && |
6155 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
6156 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
6157 | lpfc_printf_log(phba, KERN_ERR, | |
6158 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 6159 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
6160 | piocb->iocb.ulpCommand); |
6161 | dump_stack(); | |
6162 | return IOCB_ERROR; | |
6163 | } | |
6164 | ||
6165 | ||
8d63f375 LV |
6166 | /* If the PCI channel is in offline state, do not post iocbs. */ |
6167 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
6168 | return IOCB_ERROR; | |
6169 | ||
a257bf90 JS |
6170 | /* If HBA has a deferred error attention, fail the iocb. */ |
6171 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
6172 | return IOCB_ERROR; | |
6173 | ||
dea3101e JB |
6174 | /* |
6175 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
6176 | */ | |
2e0fef85 | 6177 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
6178 | return IOCB_ERROR; |
6179 | ||
6180 | /* | |
6181 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 6182 | * outstanding event. |
dea3101e | 6183 | */ |
0b727fea | 6184 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
6185 | goto iocb_busy; |
6186 | ||
2e0fef85 | 6187 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 6188 | /* |
2680eeaa | 6189 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
6190 | * can be issued if the link is not up. |
6191 | */ | |
6192 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
6193 | case CMD_GEN_REQUEST64_CR: |
6194 | case CMD_GEN_REQUEST64_CX: | |
6195 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
6196 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 6197 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
6198 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
6199 | MENLO_TRANSPORT_TYPE)) | |
6200 | ||
6201 | goto iocb_busy; | |
6202 | break; | |
dea3101e JB |
6203 | case CMD_QUE_RING_BUF_CN: |
6204 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
6205 | /* |
6206 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
6207 | * completion, iocb_cmpl MUST be 0. | |
6208 | */ | |
6209 | if (piocb->iocb_cmpl) | |
6210 | piocb->iocb_cmpl = NULL; | |
6211 | /*FALLTHROUGH*/ | |
6212 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
6213 | case CMD_CLOSE_XRI_CN: |
6214 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
6215 | break; |
6216 | default: | |
6217 | goto iocb_busy; | |
6218 | } | |
6219 | ||
6220 | /* | |
6221 | * For FCP commands, we must be in a state where we can process link | |
6222 | * attention events. | |
6223 | */ | |
6224 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 6225 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 6226 | goto iocb_busy; |
92d7f7b0 | 6227 | } |
dea3101e | 6228 | |
dea3101e JB |
6229 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
6230 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
6231 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
6232 | ||
6233 | if (iocb) | |
6234 | lpfc_sli_update_ring(phba, pring); | |
6235 | else | |
6236 | lpfc_sli_update_full_ring(phba, pring); | |
6237 | ||
6238 | if (!piocb) | |
6239 | return IOCB_SUCCESS; | |
6240 | ||
6241 | goto out_busy; | |
6242 | ||
6243 | iocb_busy: | |
6244 | pring->stats.iocb_cmd_delay++; | |
6245 | ||
6246 | out_busy: | |
6247 | ||
6248 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 6249 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
6250 | return IOCB_SUCCESS; |
6251 | } | |
6252 | ||
6253 | return IOCB_BUSY; | |
6254 | } | |
6255 | ||
3772a991 | 6256 | /** |
4f774513 JS |
6257 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
6258 | * @phba: Pointer to HBA context object. | |
6259 | * @piocb: Pointer to command iocb. | |
6260 | * @sglq: Pointer to the scatter gather queue object. | |
6261 | * | |
6262 | * This routine converts the bpl or bde that is in the IOCB | |
6263 | * to a sgl list for the sli4 hardware. The physical address | |
6264 | * of the bpl/bde is converted back to a virtual address. | |
6265 | * If the IOCB contains a BPL then the list of BDE's is | |
6266 | * converted to sli4_sge's. If the IOCB contains a single | |
6267 | * BDE then it is converted to a single sli_sge. | |
6268 | * The IOCB is still in cpu endianess so the contents of | |
6269 | * the bpl can be used without byte swapping. | |
6270 | * | |
6271 | * Returns valid XRI = Success, NO_XRI = Failure. | |
6272 | **/ | |
6273 | static uint16_t | |
6274 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
6275 | struct lpfc_sglq *sglq) | |
3772a991 | 6276 | { |
4f774513 JS |
6277 | uint16_t xritag = NO_XRI; |
6278 | struct ulp_bde64 *bpl = NULL; | |
6279 | struct ulp_bde64 bde; | |
6280 | struct sli4_sge *sgl = NULL; | |
6281 | IOCB_t *icmd; | |
6282 | int numBdes = 0; | |
6283 | int i = 0; | |
63e801ce JS |
6284 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
6285 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 6286 | |
4f774513 JS |
6287 | if (!piocbq || !sglq) |
6288 | return xritag; | |
6289 | ||
6290 | sgl = (struct sli4_sge *)sglq->sgl; | |
6291 | icmd = &piocbq->iocb; | |
6292 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
6293 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
6294 | sizeof(struct ulp_bde64); | |
6295 | /* The addrHigh and addrLow fields within the IOCB | |
6296 | * have not been byteswapped yet so there is no | |
6297 | * need to swap them back. | |
6298 | */ | |
6299 | bpl = (struct ulp_bde64 *) | |
6300 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | |
6301 | ||
6302 | if (!bpl) | |
6303 | return xritag; | |
6304 | ||
6305 | for (i = 0; i < numBdes; i++) { | |
6306 | /* Should already be byte swapped. */ | |
28baac74 JS |
6307 | sgl->addr_hi = bpl->addrHigh; |
6308 | sgl->addr_lo = bpl->addrLow; | |
6309 | ||
4f774513 JS |
6310 | if ((i+1) == numBdes) |
6311 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
6312 | else | |
6313 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
28baac74 JS |
6314 | /* swap the size field back to the cpu so we |
6315 | * can assign it to the sgl. | |
6316 | */ | |
6317 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
6318 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
6319 | /* The offsets in the sgl need to be accumulated |
6320 | * separately for the request and reply lists. | |
6321 | * The request is always first, the reply follows. | |
6322 | */ | |
6323 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
6324 | /* add up the reply sg entries */ | |
6325 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
6326 | inbound++; | |
6327 | /* first inbound? reset the offset */ | |
6328 | if (inbound == 1) | |
6329 | offset = 0; | |
6330 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
6331 | offset += bde.tus.f.bdeSize; | |
6332 | } | |
546fc854 | 6333 | sgl->word2 = cpu_to_le32(sgl->word2); |
4f774513 JS |
6334 | bpl++; |
6335 | sgl++; | |
6336 | } | |
6337 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
6338 | /* The addrHigh and addrLow fields of the BDE have not | |
6339 | * been byteswapped yet so they need to be swapped | |
6340 | * before putting them in the sgl. | |
6341 | */ | |
6342 | sgl->addr_hi = | |
6343 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
6344 | sgl->addr_lo = | |
6345 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
4f774513 JS |
6346 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
6347 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
6348 | sgl->sge_len = |
6349 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
6350 | } |
6351 | return sglq->sli4_xritag; | |
3772a991 | 6352 | } |
92d7f7b0 | 6353 | |
e59058c4 | 6354 | /** |
4f774513 | 6355 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 6356 | * @phba: Pointer to HBA context object. |
e59058c4 | 6357 | * |
a93ff37a | 6358 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
6359 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
6360 | * held. | |
4f774513 JS |
6361 | * |
6362 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 6363 | **/ |
4f774513 | 6364 | static uint32_t |
8fa38513 | 6365 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 6366 | { |
8fa38513 JS |
6367 | ++phba->fcp_qidx; |
6368 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) | |
6369 | phba->fcp_qidx = 0; | |
92d7f7b0 | 6370 | |
8fa38513 | 6371 | return phba->fcp_qidx; |
92d7f7b0 JS |
6372 | } |
6373 | ||
e59058c4 | 6374 | /** |
4f774513 | 6375 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 6376 | * @phba: Pointer to HBA context object. |
4f774513 JS |
6377 | * @piocb: Pointer to command iocb. |
6378 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 6379 | * |
4f774513 JS |
6380 | * This routine converts the iocb command to its Work Queue Entry |
6381 | * equivalent. The wqe pointer should not have any fields set when | |
6382 | * this routine is called because it will memcpy over them. | |
6383 | * This routine does not set the CQ_ID or the WQEC bits in the | |
6384 | * wqe. | |
e59058c4 | 6385 | * |
4f774513 | 6386 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 6387 | **/ |
cf5bf97e | 6388 | static int |
4f774513 JS |
6389 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
6390 | union lpfc_wqe *wqe) | |
cf5bf97e | 6391 | { |
5ffc266e | 6392 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
6393 | uint8_t ct = 0; |
6394 | uint32_t fip; | |
6395 | uint32_t abort_tag; | |
6396 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
6397 | uint8_t cmnd; | |
6398 | uint16_t xritag; | |
dcf2a4e0 JS |
6399 | uint16_t abrt_iotag; |
6400 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 6401 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 6402 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
6403 | int numBdes, i; |
6404 | struct ulp_bde64 bde; | |
c31098ce | 6405 | struct lpfc_nodelist *ndlp; |
4f774513 | 6406 | |
45ed1190 | 6407 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 6408 | /* The fcp commands will set command type */ |
0c287589 | 6409 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 6410 | command_type = FCP_COMMAND; |
c868595d | 6411 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
6412 | command_type = ELS_COMMAND_FIP; |
6413 | else | |
6414 | command_type = ELS_COMMAND_NON_FIP; | |
6415 | ||
4f774513 JS |
6416 | /* Some of the fields are in the right position already */ |
6417 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
6418 | abort_tag = (uint32_t) iocbq->iotag; | |
6419 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 6420 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
6421 | /* words0-2 bpl convert bde */ |
6422 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
6423 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
6424 | sizeof(struct ulp_bde64); | |
4f774513 JS |
6425 | bpl = (struct ulp_bde64 *) |
6426 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
6427 | if (!bpl) | |
6428 | return IOCB_ERROR; | |
cf5bf97e | 6429 | |
4f774513 JS |
6430 | /* Should already be byte swapped. */ |
6431 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
6432 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
6433 | /* swap the size field back to the cpu so we | |
6434 | * can assign it to the sgl. | |
6435 | */ | |
6436 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
6437 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
6438 | total_len = 0; | |
6439 | for (i = 0; i < numBdes; i++) { | |
6440 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
6441 | total_len += bde.tus.f.bdeSize; | |
6442 | } | |
4f774513 | 6443 | } else |
5ffc266e | 6444 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 6445 | |
4f774513 JS |
6446 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
6447 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 6448 | |
4f774513 JS |
6449 | switch (iocbq->iocb.ulpCommand) { |
6450 | case CMD_ELS_REQUEST64_CR: | |
c31098ce | 6451 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 JS |
6452 | if (!iocbq->iocb.ulpLe) { |
6453 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6454 | "2007 Only Limited Edition cmd Format" | |
6455 | " supported 0x%x\n", | |
6456 | iocbq->iocb.ulpCommand); | |
6457 | return IOCB_ERROR; | |
6458 | } | |
5ffc266e | 6459 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
6460 | /* Els_reguest64 has a TMO */ |
6461 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
6462 | iocbq->iocb.ulpTimeout); | |
6463 | /* Need a VF for word 4 set the vf bit*/ | |
6464 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
6465 | /* And a VFID for word 12 */ | |
6466 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
4f774513 | 6467 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
6468 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
6469 | iocbq->iocb.ulpContext); | |
6470 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
6471 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 6472 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
c868595d JS |
6473 | if (command_type == ELS_COMMAND_FIP) { |
6474 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) | |
6475 | >> LPFC_FIP_ELS_ID_SHIFT); | |
6476 | } | |
c31098ce | 6477 | bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com, ndlp->nlp_rpi); |
f0d9bccc JS |
6478 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
6479 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
6480 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
6481 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
6482 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
6483 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
4f774513 | 6484 | break; |
5ffc266e | 6485 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
6486 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
6487 | iocbq->iocb.un.ulpWord[3]); | |
6488 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
6489 | iocbq->iocb.ulpContext); | |
5ffc266e JS |
6490 | /* The entire sequence is transmitted for this IOCB */ |
6491 | xmit_len = total_len; | |
6492 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
4f774513 | 6493 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
6494 | /* word3 iocb=io_tag32 wqe=reserved */ |
6495 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
6496 | /* word4 relative_offset memcpy */ |
6497 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
6498 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
6499 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
6500 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
6501 | LPFC_WQE_IOD_WRITE); | |
6502 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
6503 | LPFC_WQE_LENLOC_WORD12); | |
6504 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
6505 | wqe->xmit_sequence.xmit_len = xmit_len; |
6506 | command_type = OTHER_COMMAND; | |
4f774513 JS |
6507 | break; |
6508 | case CMD_XMIT_BCAST64_CN: | |
f0d9bccc JS |
6509 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
6510 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
6511 | /* word4 iocb=rsvd wqe=rsvd */ |
6512 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
6513 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 6514 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 6515 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
6516 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
6517 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
6518 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
6519 | LPFC_WQE_LENLOC_WORD3); | |
6520 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
4f774513 JS |
6521 | break; |
6522 | case CMD_FCP_IWRITE64_CR: | |
6523 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
6524 | /* word3 iocb=iotag wqe=payload_offset_len */ |
6525 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
6526 | wqe->fcp_iwrite.payload_offset_len = | |
6527 | xmit_len + sizeof(struct fcp_rsp); | |
6528 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
6529 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
6530 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
6531 | iocbq->iocb.ulpFCP2Rcvy); | |
6532 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
6533 | /* Always open the exchange */ | |
6534 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
6535 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
6536 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); | |
6537 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
6538 | LPFC_WQE_LENLOC_WORD4); | |
6539 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
6540 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
6541 | break; | |
4f774513 | 6542 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
6543 | /* word3 iocb=iotag wqe=payload_offset_len */ |
6544 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
6545 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 6546 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
6547 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
6548 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
6549 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
6550 | iocbq->iocb.ulpFCP2Rcvy); | |
6551 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
6552 | /* Always open the exchange */ |
6553 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
6554 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
6555 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); | |
6556 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
6557 | LPFC_WQE_LENLOC_WORD4); | |
6558 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
6559 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
6560 | break; | |
4f774513 | 6561 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
6562 | /* word3 iocb=IO_TAG wqe=reserved */ |
6563 | wqe->fcp_icmd.rsrvd3 = 0; | |
6564 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 6565 | /* Always open the exchange */ |
f0d9bccc JS |
6566 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
6567 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
6568 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
6569 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
6570 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
6571 | LPFC_WQE_LENLOC_NONE); | |
6572 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 JS |
6573 | break; |
6574 | case CMD_GEN_REQUEST64_CR: | |
63e801ce JS |
6575 | /* For this command calculate the xmit length of the |
6576 | * request bde. | |
6577 | */ | |
6578 | xmit_len = 0; | |
6579 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
6580 | sizeof(struct ulp_bde64); | |
6581 | for (i = 0; i < numBdes; i++) { | |
63e801ce | 6582 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); |
546fc854 JS |
6583 | if (bde.tus.f.bdeFlags != BUFF_TYPE_BDE_64) |
6584 | break; | |
63e801ce JS |
6585 | xmit_len += bde.tus.f.bdeSize; |
6586 | } | |
f0d9bccc JS |
6587 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
6588 | wqe->gen_req.request_payload_len = xmit_len; | |
6589 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
6590 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
6591 | /* word6 context tag copied in memcpy */ |
6592 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
6593 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
6594 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6595 | "2015 Invalid CT %x command 0x%x\n", | |
6596 | ct, iocbq->iocb.ulpCommand); | |
6597 | return IOCB_ERROR; | |
6598 | } | |
f0d9bccc JS |
6599 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
6600 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
6601 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
6602 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
6603 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
6604 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
6605 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
6606 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 JS |
6607 | command_type = OTHER_COMMAND; |
6608 | break; | |
6609 | case CMD_XMIT_ELS_RSP64_CX: | |
c31098ce | 6610 | ndlp = (struct lpfc_nodelist *)iocbq->context1; |
4f774513 | 6611 | /* words0-2 BDE memcpy */ |
f0d9bccc JS |
6612 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
6613 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
4f774513 | 6614 | /* word4 iocb=did wge=rsvd. */ |
f0d9bccc | 6615 | wqe->xmit_els_rsp.rsvd4 = 0; |
4f774513 JS |
6616 | /* word5 iocb=rsvd wge=did */ |
6617 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
6618 | iocbq->iocb.un.elsreq64.remoteID); | |
f0d9bccc JS |
6619 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
6620 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
6621 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
6622 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
6623 | iocbq->iocb.ulpContext); | |
4f774513 | 6624 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 6625 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
4f774513 | 6626 | iocbq->vport->vpi + phba->vpi_base); |
f0d9bccc JS |
6627 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
6628 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
6629 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
6630 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
6631 | LPFC_WQE_LENLOC_WORD3); | |
6632 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
c31098ce | 6633 | bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp, ndlp->nlp_rpi); |
4f774513 JS |
6634 | command_type = OTHER_COMMAND; |
6635 | break; | |
6636 | case CMD_CLOSE_XRI_CN: | |
6637 | case CMD_ABORT_XRI_CN: | |
6638 | case CMD_ABORT_XRI_CX: | |
6639 | /* words 0-2 memcpy should be 0 rserved */ | |
6640 | /* port will send abts */ | |
dcf2a4e0 JS |
6641 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
6642 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
6643 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
6644 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
6645 | } else | |
6646 | fip = 0; | |
6647 | ||
6648 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 6649 | /* |
dcf2a4e0 JS |
6650 | * The link is down, or the command was ELS_FIP |
6651 | * so the fw does not need to send abts | |
4f774513 JS |
6652 | * on the wire. |
6653 | */ | |
6654 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
6655 | else | |
6656 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
6657 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
6658 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
6659 | wqe->abort_cmd.rsrvd5 = 0; | |
6660 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
6661 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
6662 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
6663 | /* |
6664 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
6665 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
6666 | */ | |
f0d9bccc JS |
6667 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
6668 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
6669 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
6670 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
6671 | cmnd = CMD_ABORT_XRI_CX; |
6672 | command_type = OTHER_COMMAND; | |
6673 | xritag = 0; | |
6674 | break; | |
6669f9bb | 6675 | case CMD_XMIT_BLS_RSP64_CX: |
546fc854 | 6676 | /* As BLS ABTS RSP WQE is very different from other WQEs, |
6669f9bb JS |
6677 | * we re-construct this WQE here based on information in |
6678 | * iocbq from scratch. | |
6679 | */ | |
6680 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 6681 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 6682 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
546fc854 JS |
6683 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_rsp)); |
6684 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_rsp) == | |
5ffc266e JS |
6685 | LPFC_ABTS_UNSOL_INT) { |
6686 | /* ABTS sent by initiator to CT exchange, the | |
6687 | * RX_ID field will be filled with the newly | |
6688 | * allocated responder XRI. | |
6689 | */ | |
6690 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6691 | iocbq->sli4_xritag); | |
6692 | } else { | |
6693 | /* ABTS sent by responder to CT exchange, the | |
6694 | * RX_ID field will be filled with the responder | |
6695 | * RX_ID from ABTS. | |
6696 | */ | |
6697 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
546fc854 | 6698 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_rsp)); |
5ffc266e | 6699 | } |
6669f9bb JS |
6700 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
6701 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6702 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, | |
6703 | iocbq->iocb.ulpContext); | |
f0d9bccc JS |
6704 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
6705 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
6706 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
6707 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
6708 | command_type = OTHER_COMMAND; | |
546fc854 JS |
6709 | if (iocbq->iocb.un.xseq64.w5.hcsw.Rctl == FC_RCTL_BA_RJT) { |
6710 | bf_set(xmit_bls_rsp64_rjt_vspec, &wqe->xmit_bls_rsp, | |
6711 | bf_get(lpfc_vndr_code, &iocbq->iocb.un.bls_rsp)); | |
6712 | bf_set(xmit_bls_rsp64_rjt_expc, &wqe->xmit_bls_rsp, | |
6713 | bf_get(lpfc_rsn_expln, &iocbq->iocb.un.bls_rsp)); | |
6714 | bf_set(xmit_bls_rsp64_rjt_rsnc, &wqe->xmit_bls_rsp, | |
6715 | bf_get(lpfc_rsn_code, &iocbq->iocb.un.bls_rsp)); | |
6716 | } | |
6717 | ||
6669f9bb | 6718 | break; |
4f774513 JS |
6719 | case CMD_XRI_ABORTED_CX: |
6720 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
6721 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
6722 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
6723 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
6724 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
6725 | default: | |
6726 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6727 | "2014 Invalid command 0x%x\n", | |
6728 | iocbq->iocb.ulpCommand); | |
6729 | return IOCB_ERROR; | |
6730 | break; | |
4f774513 | 6731 | } |
f0d9bccc JS |
6732 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
6733 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
6734 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
6735 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
6736 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
6737 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
6738 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
6739 | return 0; |
6740 | } | |
6741 | ||
6742 | /** | |
6743 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
6744 | * @phba: Pointer to HBA context object. | |
6745 | * @ring_number: SLI ring number to issue iocb on. | |
6746 | * @piocb: Pointer to command iocb. | |
6747 | * @flag: Flag indicating if this command can be put into txq. | |
6748 | * | |
6749 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
6750 | * an iocb command to an HBA with SLI-4 interface spec. | |
6751 | * | |
6752 | * This function is called with hbalock held. The function will return success | |
6753 | * after it successfully submit the iocb to firmware or after adding to the | |
6754 | * txq. | |
6755 | **/ | |
6756 | static int | |
6757 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
6758 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6759 | { | |
6760 | struct lpfc_sglq *sglq; | |
4f774513 JS |
6761 | union lpfc_wqe wqe; |
6762 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
6763 | |
6764 | if (piocb->sli4_xritag == NO_XRI) { | |
6765 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
546fc854 JS |
6766 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN || |
6767 | piocb->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX) | |
4f774513 JS |
6768 | sglq = NULL; |
6769 | else { | |
2a9bf3d0 JS |
6770 | if (pring->txq_cnt) { |
6771 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6772 | __lpfc_sli_ringtx_put(phba, | |
6773 | pring, piocb); | |
6774 | return IOCB_SUCCESS; | |
6775 | } else { | |
6776 | return IOCB_BUSY; | |
6777 | } | |
6778 | } else { | |
19ca7609 | 6779 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
6780 | if (!sglq) { |
6781 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6782 | __lpfc_sli_ringtx_put(phba, | |
6783 | pring, | |
6784 | piocb); | |
6785 | return IOCB_SUCCESS; | |
6786 | } else | |
6787 | return IOCB_BUSY; | |
6788 | } | |
6789 | } | |
4f774513 JS |
6790 | } |
6791 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6792 | sglq = NULL; /* These IO's already have an XRI and | |
6793 | * a mapped sgl. | |
6794 | */ | |
6795 | } else { | |
6796 | /* This is a continuation of a commandi,(CX) so this | |
6797 | * sglq is on the active list | |
6798 | */ | |
6799 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
6800 | if (!sglq) | |
6801 | return IOCB_ERROR; | |
6802 | } | |
6803 | ||
6804 | if (sglq) { | |
2a9bf3d0 JS |
6805 | piocb->sli4_xritag = sglq->sli4_xritag; |
6806 | ||
6807 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) | |
4f774513 JS |
6808 | return IOCB_ERROR; |
6809 | } | |
6810 | ||
6811 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
6812 | return IOCB_ERROR; | |
6813 | ||
341af102 JS |
6814 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
6815 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
6816 | /* |
6817 | * For FCP command IOCB, get a new WQ index to distribute | |
6818 | * WQE across the WQsr. On the other hand, for abort IOCB, | |
6819 | * it carries the same WQ index to the original command | |
6820 | * IOCB. | |
6821 | */ | |
341af102 | 6822 | if (piocb->iocb_flag & LPFC_IO_FCP) |
5ffc266e JS |
6823 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
6824 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], | |
6825 | &wqe)) | |
4f774513 JS |
6826 | return IOCB_ERROR; |
6827 | } else { | |
6828 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
6829 | return IOCB_ERROR; | |
6830 | } | |
6831 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
6832 | ||
6833 | return 0; | |
6834 | } | |
6835 | ||
6836 | /** | |
6837 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
6838 | * | |
6839 | * This routine wraps the actual lockless version for issusing IOCB function | |
6840 | * pointer from the lpfc_hba struct. | |
6841 | * | |
6842 | * Return codes: | |
6843 | * IOCB_ERROR - Error | |
6844 | * IOCB_SUCCESS - Success | |
6845 | * IOCB_BUSY - Busy | |
6846 | **/ | |
2a9bf3d0 | 6847 | int |
4f774513 JS |
6848 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
6849 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6850 | { | |
6851 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6852 | } | |
6853 | ||
6854 | /** | |
25985edc | 6855 | * lpfc_sli_api_table_setup - Set up sli api function jump table |
4f774513 JS |
6856 | * @phba: The hba struct for which this call is being executed. |
6857 | * @dev_grp: The HBA PCI-Device group number. | |
6858 | * | |
6859 | * This routine sets up the SLI interface API function jump table in @phba | |
6860 | * struct. | |
6861 | * Returns: 0 - success, -ENODEV - failure. | |
6862 | **/ | |
6863 | int | |
6864 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6865 | { | |
6866 | ||
6867 | switch (dev_grp) { | |
6868 | case LPFC_PCI_DEV_LP: | |
6869 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
6870 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
6871 | break; | |
6872 | case LPFC_PCI_DEV_OC: | |
6873 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
6874 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
6875 | break; | |
6876 | default: | |
6877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6878 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
6879 | dev_grp); | |
6880 | return -ENODEV; | |
6881 | break; | |
6882 | } | |
6883 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
6884 | return 0; | |
6885 | } | |
6886 | ||
6887 | /** | |
6888 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
6889 | * @phba: Pointer to HBA context object. | |
6890 | * @pring: Pointer to driver SLI ring object. | |
6891 | * @piocb: Pointer to command iocb. | |
6892 | * @flag: Flag indicating if this command can be put into txq. | |
6893 | * | |
6894 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
6895 | * function. This function gets the hbalock and calls | |
6896 | * __lpfc_sli_issue_iocb function and will return the error returned | |
6897 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
6898 | * functions which do not hold hbalock. | |
6899 | **/ | |
6900 | int | |
6901 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
6902 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6903 | { | |
6904 | unsigned long iflags; | |
6905 | int rc; | |
6906 | ||
6907 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6908 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6909 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6910 | ||
6911 | return rc; | |
6912 | } | |
6913 | ||
6914 | /** | |
6915 | * lpfc_extra_ring_setup - Extra ring setup function | |
6916 | * @phba: Pointer to HBA context object. | |
6917 | * | |
6918 | * This function is called while driver attaches with the | |
6919 | * HBA to setup the extra ring. The extra ring is used | |
6920 | * only when driver needs to support target mode functionality | |
6921 | * or IP over FC functionalities. | |
6922 | * | |
6923 | * This function is called with no lock held. | |
6924 | **/ | |
6925 | static int | |
6926 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
6927 | { | |
6928 | struct lpfc_sli *psli; | |
6929 | struct lpfc_sli_ring *pring; | |
6930 | ||
6931 | psli = &phba->sli; | |
6932 | ||
6933 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
6934 | ||
6935 | /* Take some away from the FCP ring */ | |
6936 | pring = &psli->ring[psli->fcp_ring]; | |
6937 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
6938 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
cf5bf97e JW |
6939 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
6940 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6941 | ||
a4bc3379 JS |
6942 | /* and give them to the extra ring */ |
6943 | pring = &psli->ring[psli->extra_ring]; | |
6944 | ||
cf5bf97e JW |
6945 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
6946 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
6947 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
6948 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6949 | ||
6950 | /* Setup default profile for this ring */ | |
6951 | pring->iotag_max = 4096; | |
6952 | pring->num_mask = 1; | |
6953 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
6954 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
6955 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
6956 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
6957 | return 0; | |
6958 | } | |
6959 | ||
e59058c4 | 6960 | /** |
3621a710 | 6961 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
6962 | * @phba: Pointer to HBA context object. |
6963 | * @pring: Pointer to driver SLI ring object. | |
6964 | * @iocbq: Pointer to iocb object. | |
6965 | * | |
6966 | * This function is called by the slow ring event handler | |
6967 | * function when there is an ASYNC event iocb in the ring. | |
6968 | * This function is called with no lock held. | |
6969 | * Currently this function handles only temperature related | |
6970 | * ASYNC events. The function decodes the temperature sensor | |
6971 | * event message and posts events for the management applications. | |
6972 | **/ | |
98c9ea5c | 6973 | static void |
57127f15 JS |
6974 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
6975 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
6976 | { | |
6977 | IOCB_t *icmd; | |
6978 | uint16_t evt_code; | |
6979 | uint16_t temp; | |
6980 | struct temp_event temp_event_data; | |
6981 | struct Scsi_Host *shost; | |
a257bf90 | 6982 | uint32_t *iocb_w; |
57127f15 JS |
6983 | |
6984 | icmd = &iocbq->iocb; | |
6985 | evt_code = icmd->un.asyncstat.evt_code; | |
6986 | temp = icmd->ulpContext; | |
6987 | ||
6988 | if ((evt_code != ASYNC_TEMP_WARN) && | |
6989 | (evt_code != ASYNC_TEMP_SAFE)) { | |
a257bf90 | 6990 | iocb_w = (uint32_t *) icmd; |
57127f15 JS |
6991 | lpfc_printf_log(phba, |
6992 | KERN_ERR, | |
6993 | LOG_SLI, | |
76bb24ef | 6994 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 6995 | " evt_code 0x%x\n" |
a257bf90 JS |
6996 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
6997 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
6998 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
6999 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
57127f15 | 7000 | pring->ringno, |
a257bf90 JS |
7001 | icmd->un.asyncstat.evt_code, |
7002 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], | |
7003 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
7004 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
7005 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
7006 | ||
57127f15 JS |
7007 | return; |
7008 | } | |
7009 | temp_event_data.data = (uint32_t)temp; | |
7010 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
7011 | if (evt_code == ASYNC_TEMP_WARN) { | |
7012 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
7013 | lpfc_printf_log(phba, | |
09372820 | 7014 | KERN_ERR, |
57127f15 | 7015 | LOG_TEMP, |
76bb24ef | 7016 | "0347 Adapter is very hot, please take " |
57127f15 JS |
7017 | "corrective action. temperature : %d Celsius\n", |
7018 | temp); | |
7019 | } | |
7020 | if (evt_code == ASYNC_TEMP_SAFE) { | |
7021 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
7022 | lpfc_printf_log(phba, | |
09372820 | 7023 | KERN_ERR, |
57127f15 JS |
7024 | LOG_TEMP, |
7025 | "0340 Adapter temperature is OK now. " | |
7026 | "temperature : %d Celsius\n", | |
7027 | temp); | |
7028 | } | |
7029 | ||
7030 | /* Send temperature change event to applications */ | |
7031 | shost = lpfc_shost_from_vport(phba->pport); | |
7032 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
7033 | sizeof(temp_event_data), (char *) &temp_event_data, | |
ddcc50f0 | 7034 | LPFC_NL_VENDOR_ID); |
57127f15 JS |
7035 | |
7036 | } | |
7037 | ||
7038 | ||
e59058c4 | 7039 | /** |
3621a710 | 7040 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
7041 | * @phba: Pointer to HBA context object. |
7042 | * | |
7043 | * lpfc_sli_setup sets up rings of the SLI interface with | |
7044 | * number of iocbs per ring and iotags. This function is | |
7045 | * called while driver attach to the HBA and before the | |
7046 | * interrupts are enabled. So there is no need for locking. | |
7047 | * | |
7048 | * This function always returns 0. | |
7049 | **/ | |
dea3101e JB |
7050 | int |
7051 | lpfc_sli_setup(struct lpfc_hba *phba) | |
7052 | { | |
ed957684 | 7053 | int i, totiocbsize = 0; |
dea3101e JB |
7054 | struct lpfc_sli *psli = &phba->sli; |
7055 | struct lpfc_sli_ring *pring; | |
7056 | ||
7057 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
7058 | psli->sli_flag = 0; | |
7059 | psli->fcp_ring = LPFC_FCP_RING; | |
7060 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 7061 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 7062 | |
604a3e30 JB |
7063 | psli->iocbq_lookup = NULL; |
7064 | psli->iocbq_lookup_len = 0; | |
7065 | psli->last_iotag = 0; | |
7066 | ||
dea3101e JB |
7067 | for (i = 0; i < psli->num_rings; i++) { |
7068 | pring = &psli->ring[i]; | |
7069 | switch (i) { | |
7070 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
7071 | /* numCiocb and numRiocb are used in config_port */ | |
7072 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
7073 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
7074 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
7075 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
7076 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
7077 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 7078 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7079 | SLI3_IOCB_CMD_SIZE : |
7080 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7081 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7082 | SLI3_IOCB_RSP_SIZE : |
7083 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
7084 | pring->iotag_ctr = 0; |
7085 | pring->iotag_max = | |
92d7f7b0 | 7086 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
7087 | pring->fast_iotag = pring->iotag_max; |
7088 | pring->num_mask = 0; | |
7089 | break; | |
a4bc3379 | 7090 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e JB |
7091 | /* numCiocb and numRiocb are used in config_port */ |
7092 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
7093 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 7094 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7095 | SLI3_IOCB_CMD_SIZE : |
7096 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7097 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7098 | SLI3_IOCB_RSP_SIZE : |
7099 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 7100 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
7101 | pring->num_mask = 0; |
7102 | break; | |
7103 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
7104 | /* numCiocb and numRiocb are used in config_port */ | |
7105 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
7106 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 7107 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7108 | SLI3_IOCB_CMD_SIZE : |
7109 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7110 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7111 | SLI3_IOCB_RSP_SIZE : |
7112 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
7113 | pring->fast_iotag = 0; |
7114 | pring->iotag_ctr = 0; | |
7115 | pring->iotag_max = 4096; | |
57127f15 JS |
7116 | pring->lpfc_sli_rcv_async_status = |
7117 | lpfc_sli_async_event_handler; | |
6669f9bb | 7118 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 7119 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
7120 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
7121 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 7122 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7123 | lpfc_els_unsol_event; |
dea3101e | 7124 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
7125 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
7126 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 7127 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7128 | lpfc_els_unsol_event; |
dea3101e JB |
7129 | pring->prt[2].profile = 0; /* Mask 2 */ |
7130 | /* NameServer Inquiry */ | |
6a9c52cf | 7131 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 7132 | /* NameServer */ |
6a9c52cf | 7133 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 7134 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7135 | lpfc_ct_unsol_event; |
dea3101e JB |
7136 | pring->prt[3].profile = 0; /* Mask 3 */ |
7137 | /* NameServer response */ | |
6a9c52cf | 7138 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 7139 | /* NameServer */ |
6a9c52cf | 7140 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 7141 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7142 | lpfc_ct_unsol_event; |
6669f9bb JS |
7143 | /* abort unsolicited sequence */ |
7144 | pring->prt[4].profile = 0; /* Mask 4 */ | |
7145 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
7146 | pring->prt[4].type = FC_TYPE_BLS; | |
7147 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
7148 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e JB |
7149 | break; |
7150 | } | |
ed957684 | 7151 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 7152 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 7153 | } |
ed957684 | 7154 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 7155 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
7156 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
7157 | "SLI2 SLIM Data: x%x x%lx\n", | |
7158 | phba->brd_no, totiocbsize, | |
7159 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 7160 | } |
cf5bf97e JW |
7161 | if (phba->cfg_multi_ring_support == 2) |
7162 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
7163 | |
7164 | return 0; | |
7165 | } | |
7166 | ||
e59058c4 | 7167 | /** |
3621a710 | 7168 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
7169 | * @phba: Pointer to HBA context object. |
7170 | * | |
7171 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
7172 | * ring. This function also initializes ring indices of each ring. | |
7173 | * This function is called during the initialization of the SLI | |
7174 | * interface of an HBA. | |
7175 | * This function is called with no lock held and always returns | |
7176 | * 1. | |
7177 | **/ | |
dea3101e | 7178 | int |
2e0fef85 | 7179 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
7180 | { |
7181 | struct lpfc_sli *psli; | |
7182 | struct lpfc_sli_ring *pring; | |
604a3e30 | 7183 | int i; |
dea3101e JB |
7184 | |
7185 | psli = &phba->sli; | |
2e0fef85 | 7186 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7187 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 7188 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
7189 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
7190 | for (i = 0; i < psli->num_rings; i++) { | |
7191 | pring = &psli->ring[i]; | |
7192 | pring->ringno = i; | |
7193 | pring->next_cmdidx = 0; | |
7194 | pring->local_getidx = 0; | |
7195 | pring->cmdidx = 0; | |
7196 | INIT_LIST_HEAD(&pring->txq); | |
7197 | INIT_LIST_HEAD(&pring->txcmplq); | |
7198 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 7199 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 7200 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 7201 | } |
2e0fef85 JS |
7202 | spin_unlock_irq(&phba->hbalock); |
7203 | return 1; | |
dea3101e JB |
7204 | } |
7205 | ||
04c68496 JS |
7206 | /** |
7207 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
7208 | * @phba: Pointer to HBA context object. | |
7209 | * | |
7210 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
7211 | * flush all the mailbox commands in the three possible stages in the mailbox | |
7212 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
7213 | * command; and completed mailbox command queue. It is caller's responsibility | |
7214 | * to make sure that the driver is in the proper state to flush the mailbox | |
7215 | * command sub-system. Namely, the posting of mailbox commands into the | |
7216 | * pending mailbox command queue from the various clients must be stopped; | |
7217 | * either the HBA is in a state that it will never works on the outstanding | |
7218 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
7219 | * mailbox command has been completed. | |
7220 | **/ | |
7221 | static void | |
7222 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
7223 | { | |
7224 | LIST_HEAD(completions); | |
7225 | struct lpfc_sli *psli = &phba->sli; | |
7226 | LPFC_MBOXQ_t *pmb; | |
7227 | unsigned long iflag; | |
7228 | ||
7229 | /* Flush all the mailbox commands in the mbox system */ | |
7230 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7231 | /* The pending mailbox command queue */ | |
7232 | list_splice_init(&phba->sli.mboxq, &completions); | |
7233 | /* The outstanding active mailbox command */ | |
7234 | if (psli->mbox_active) { | |
7235 | list_add_tail(&psli->mbox_active->list, &completions); | |
7236 | psli->mbox_active = NULL; | |
7237 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7238 | } | |
7239 | /* The completed mailbox command queue */ | |
7240 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
7241 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7242 | ||
7243 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
7244 | while (!list_empty(&completions)) { | |
7245 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
7246 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7247 | if (pmb->mbox_cmpl) | |
7248 | pmb->mbox_cmpl(phba, pmb); | |
7249 | } | |
7250 | } | |
7251 | ||
e59058c4 | 7252 | /** |
3621a710 | 7253 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
7254 | * @vport: Pointer to virtual port object. |
7255 | * | |
7256 | * lpfc_sli_host_down is called to clean up the resources | |
7257 | * associated with a vport before destroying virtual | |
7258 | * port data structures. | |
7259 | * This function does following operations: | |
7260 | * - Free discovery resources associated with this virtual | |
7261 | * port. | |
7262 | * - Free iocbs associated with this virtual port in | |
7263 | * the txq. | |
7264 | * - Send abort for all iocb commands associated with this | |
7265 | * vport in txcmplq. | |
7266 | * | |
7267 | * This function is called with no lock held and always returns 1. | |
7268 | **/ | |
92d7f7b0 JS |
7269 | int |
7270 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
7271 | { | |
858c9f6c | 7272 | LIST_HEAD(completions); |
92d7f7b0 JS |
7273 | struct lpfc_hba *phba = vport->phba; |
7274 | struct lpfc_sli *psli = &phba->sli; | |
7275 | struct lpfc_sli_ring *pring; | |
7276 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
7277 | int i; |
7278 | unsigned long flags = 0; | |
7279 | uint16_t prev_pring_flag; | |
7280 | ||
7281 | lpfc_cleanup_discovery_resources(vport); | |
7282 | ||
7283 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
7284 | for (i = 0; i < psli->num_rings; i++) { |
7285 | pring = &psli->ring[i]; | |
7286 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
7287 | /* Only slow rings */ |
7288 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 7289 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
7290 | /* Set the lpfc data pending flag */ |
7291 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
7292 | } | |
92d7f7b0 JS |
7293 | /* |
7294 | * Error everything on the txq since these iocbs have not been | |
7295 | * given to the FW yet. | |
7296 | */ | |
92d7f7b0 JS |
7297 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
7298 | if (iocb->vport != vport) | |
7299 | continue; | |
858c9f6c | 7300 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 7301 | pring->txq_cnt--; |
92d7f7b0 JS |
7302 | } |
7303 | ||
7304 | /* Next issue ABTS for everything on the txcmplq */ | |
7305 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
7306 | list) { | |
7307 | if (iocb->vport != vport) | |
7308 | continue; | |
7309 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
7310 | } | |
7311 | ||
7312 | pring->flag = prev_pring_flag; | |
7313 | } | |
7314 | ||
7315 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
7316 | ||
a257bf90 JS |
7317 | /* Cancel all the IOCBs from the completions list */ |
7318 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7319 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
7320 | return 1; |
7321 | } | |
7322 | ||
e59058c4 | 7323 | /** |
3621a710 | 7324 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
7325 | * @phba: Pointer to HBA context object. |
7326 | * | |
7327 | * This function cleans up all iocb, buffers, mailbox commands | |
7328 | * while shutting down the HBA. This function is called with no | |
7329 | * lock held and always returns 1. | |
7330 | * This function does the following to cleanup driver resources: | |
7331 | * - Free discovery resources for each virtual port | |
7332 | * - Cleanup any pending fabric iocbs | |
7333 | * - Iterate through the iocb txq and free each entry | |
7334 | * in the list. | |
7335 | * - Free up any buffer posted to the HBA | |
7336 | * - Free mailbox commands in the mailbox queue. | |
7337 | **/ | |
dea3101e | 7338 | int |
2e0fef85 | 7339 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 7340 | { |
2534ba75 | 7341 | LIST_HEAD(completions); |
2e0fef85 | 7342 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 7343 | struct lpfc_sli_ring *pring; |
0ff10d46 | 7344 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 7345 | unsigned long flags = 0; |
04c68496 JS |
7346 | int i; |
7347 | ||
7348 | /* Shutdown the mailbox command sub-system */ | |
7349 | lpfc_sli_mbox_sys_shutdown(phba); | |
dea3101e | 7350 | |
dea3101e JB |
7351 | lpfc_hba_down_prep(phba); |
7352 | ||
92d7f7b0 JS |
7353 | lpfc_fabric_abort_hba(phba); |
7354 | ||
2e0fef85 | 7355 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
7356 | for (i = 0; i < psli->num_rings; i++) { |
7357 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
7358 | /* Only slow rings */ |
7359 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 7360 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
7361 | /* Set the lpfc data pending flag */ |
7362 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
7363 | } | |
dea3101e JB |
7364 | |
7365 | /* | |
7366 | * Error everything on the txq since these iocbs have not been | |
7367 | * given to the FW yet. | |
7368 | */ | |
2534ba75 | 7369 | list_splice_init(&pring->txq, &completions); |
dea3101e JB |
7370 | pring->txq_cnt = 0; |
7371 | ||
2534ba75 | 7372 | } |
2e0fef85 | 7373 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 7374 | |
a257bf90 JS |
7375 | /* Cancel all the IOCBs from the completions list */ |
7376 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7377 | IOERR_SLI_DOWN); | |
dea3101e | 7378 | |
0ff10d46 JS |
7379 | spin_lock_irqsave(&phba->hbalock, flags); |
7380 | list_splice_init(&phba->elsbuf, &completions); | |
7381 | phba->elsbuf_cnt = 0; | |
7382 | phba->elsbuf_prev_cnt = 0; | |
7383 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
7384 | ||
7385 | while (!list_empty(&completions)) { | |
7386 | list_remove_head(&completions, buf_ptr, | |
7387 | struct lpfc_dmabuf, list); | |
7388 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
7389 | kfree(buf_ptr); | |
7390 | } | |
7391 | ||
dea3101e JB |
7392 | /* Return any active mbox cmds */ |
7393 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 7394 | |
da0436e9 | 7395 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 7396 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 7397 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 7398 | |
da0436e9 JS |
7399 | return 1; |
7400 | } | |
7401 | ||
e59058c4 | 7402 | /** |
3621a710 | 7403 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
7404 | * @srcp: Source memory pointer. |
7405 | * @destp: Destination memory pointer. | |
7406 | * @cnt: Number of words required to be copied. | |
7407 | * | |
7408 | * This function is used for copying data between driver memory | |
7409 | * and the SLI memory. This function also changes the endianness | |
7410 | * of each word if native endianness is different from SLI | |
7411 | * endianness. This function can be called with or without | |
7412 | * lock. | |
7413 | **/ | |
dea3101e JB |
7414 | void |
7415 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
7416 | { | |
7417 | uint32_t *src = srcp; | |
7418 | uint32_t *dest = destp; | |
7419 | uint32_t ldata; | |
7420 | int i; | |
7421 | ||
7422 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
7423 | ldata = *src; | |
7424 | ldata = le32_to_cpu(ldata); | |
7425 | *dest = ldata; | |
7426 | src++; | |
7427 | dest++; | |
7428 | } | |
7429 | } | |
7430 | ||
e59058c4 | 7431 | |
a0c87cbd JS |
7432 | /** |
7433 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
7434 | * @srcp: Source memory pointer. | |
7435 | * @destp: Destination memory pointer. | |
7436 | * @cnt: Number of words required to be copied. | |
7437 | * | |
7438 | * This function is used for copying data between a data structure | |
7439 | * with big endian representation to local endianness. | |
7440 | * This function can be called with or without lock. | |
7441 | **/ | |
7442 | void | |
7443 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
7444 | { | |
7445 | uint32_t *src = srcp; | |
7446 | uint32_t *dest = destp; | |
7447 | uint32_t ldata; | |
7448 | int i; | |
7449 | ||
7450 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
7451 | ldata = *src; | |
7452 | ldata = be32_to_cpu(ldata); | |
7453 | *dest = ldata; | |
7454 | src++; | |
7455 | dest++; | |
7456 | } | |
7457 | } | |
7458 | ||
e59058c4 | 7459 | /** |
3621a710 | 7460 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
7461 | * @phba: Pointer to HBA context object. |
7462 | * @pring: Pointer to driver SLI ring object. | |
7463 | * @mp: Pointer to driver buffer object. | |
7464 | * | |
7465 | * This function is called with no lock held. | |
7466 | * It always return zero after adding the buffer to the postbufq | |
7467 | * buffer list. | |
7468 | **/ | |
dea3101e | 7469 | int |
2e0fef85 JS |
7470 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
7471 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
7472 | { |
7473 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
7474 | later */ | |
2e0fef85 | 7475 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7476 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 7477 | pring->postbufq_cnt++; |
2e0fef85 | 7478 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
7479 | return 0; |
7480 | } | |
7481 | ||
e59058c4 | 7482 | /** |
3621a710 | 7483 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
7484 | * @phba: Pointer to HBA context object. |
7485 | * | |
7486 | * When HBQ is enabled, buffers are searched based on tags. This function | |
7487 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
7488 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
7489 | * does not conflict with tags of buffer posted for unsolicited events. | |
7490 | * The function returns the allocated tag. The function is called with | |
7491 | * no locks held. | |
7492 | **/ | |
76bb24ef JS |
7493 | uint32_t |
7494 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
7495 | { | |
7496 | spin_lock_irq(&phba->hbalock); | |
7497 | phba->buffer_tag_count++; | |
7498 | /* | |
7499 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
7500 | * a tag assigned by HBQ. | |
7501 | */ | |
7502 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
7503 | spin_unlock_irq(&phba->hbalock); | |
7504 | return phba->buffer_tag_count; | |
7505 | } | |
7506 | ||
e59058c4 | 7507 | /** |
3621a710 | 7508 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
7509 | * @phba: Pointer to HBA context object. |
7510 | * @pring: Pointer to driver SLI ring object. | |
7511 | * @tag: Buffer tag. | |
7512 | * | |
7513 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
7514 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
7515 | * iocb is posted to the response ring with the tag of the buffer. | |
7516 | * This function searches the pring->postbufq list using the tag | |
7517 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
7518 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
7519 | * buffer is returned to the caller else NULL is returned. | |
7520 | * This function is called with no lock held. | |
7521 | **/ | |
76bb24ef JS |
7522 | struct lpfc_dmabuf * |
7523 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7524 | uint32_t tag) | |
7525 | { | |
7526 | struct lpfc_dmabuf *mp, *next_mp; | |
7527 | struct list_head *slp = &pring->postbufq; | |
7528 | ||
25985edc | 7529 | /* Search postbufq, from the beginning, looking for a match on tag */ |
76bb24ef JS |
7530 | spin_lock_irq(&phba->hbalock); |
7531 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
7532 | if (mp->buffer_tag == tag) { | |
7533 | list_del_init(&mp->list); | |
7534 | pring->postbufq_cnt--; | |
7535 | spin_unlock_irq(&phba->hbalock); | |
7536 | return mp; | |
7537 | } | |
7538 | } | |
7539 | ||
7540 | spin_unlock_irq(&phba->hbalock); | |
7541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 7542 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
7543 | "ring %d Data x%lx x%p x%p x%x\n", |
7544 | pring->ringno, (unsigned long) tag, | |
7545 | slp->next, slp->prev, pring->postbufq_cnt); | |
7546 | ||
7547 | return NULL; | |
7548 | } | |
dea3101e | 7549 | |
e59058c4 | 7550 | /** |
3621a710 | 7551 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
7552 | * @phba: Pointer to HBA context object. |
7553 | * @pring: Pointer to driver SLI ring object. | |
7554 | * @phys: DMA address of the buffer. | |
7555 | * | |
7556 | * This function searches the buffer list using the dma_address | |
7557 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
7558 | * corresponding to the dma_address. The function returns the | |
7559 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
7560 | * This function is called by the ct and els unsolicited event | |
7561 | * handlers to get the buffer associated with the unsolicited | |
7562 | * event. | |
7563 | * | |
7564 | * This function is called with no lock held. | |
7565 | **/ | |
dea3101e JB |
7566 | struct lpfc_dmabuf * |
7567 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7568 | dma_addr_t phys) | |
7569 | { | |
7570 | struct lpfc_dmabuf *mp, *next_mp; | |
7571 | struct list_head *slp = &pring->postbufq; | |
7572 | ||
25985edc | 7573 | /* Search postbufq, from the beginning, looking for a match on phys */ |
2e0fef85 | 7574 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
7575 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
7576 | if (mp->phys == phys) { | |
7577 | list_del_init(&mp->list); | |
7578 | pring->postbufq_cnt--; | |
2e0fef85 | 7579 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
7580 | return mp; |
7581 | } | |
7582 | } | |
7583 | ||
2e0fef85 | 7584 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7585 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 7586 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 7587 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 7588 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
7589 | slp->next, slp->prev, pring->postbufq_cnt); |
7590 | return NULL; | |
7591 | } | |
7592 | ||
e59058c4 | 7593 | /** |
3621a710 | 7594 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
7595 | * @phba: Pointer to HBA context object. |
7596 | * @cmdiocb: Pointer to driver command iocb object. | |
7597 | * @rspiocb: Pointer to driver response iocb object. | |
7598 | * | |
7599 | * This function is the completion handler for the abort iocbs for | |
7600 | * ELS commands. This function is called from the ELS ring event | |
7601 | * handler with no lock held. This function frees memory resources | |
7602 | * associated with the abort iocb. | |
7603 | **/ | |
dea3101e | 7604 | static void |
2e0fef85 JS |
7605 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7606 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 7607 | { |
2e0fef85 | 7608 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 7609 | uint16_t abort_iotag, abort_context; |
92d7f7b0 | 7610 | struct lpfc_iocbq *abort_iocb; |
2680eeaa JS |
7611 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
7612 | ||
7613 | abort_iocb = NULL; | |
2680eeaa JS |
7614 | |
7615 | if (irsp->ulpStatus) { | |
7616 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | |
7617 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
7618 | ||
2e0fef85 | 7619 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
7620 | if (phba->sli_rev < LPFC_SLI_REV4) { |
7621 | if (abort_iotag != 0 && | |
7622 | abort_iotag <= phba->sli.last_iotag) | |
7623 | abort_iocb = | |
7624 | phba->sli.iocbq_lookup[abort_iotag]; | |
7625 | } else | |
7626 | /* For sli4 the abort_tag is the XRI, | |
7627 | * so the abort routine puts the iotag of the iocb | |
7628 | * being aborted in the context field of the abort | |
7629 | * IOCB. | |
7630 | */ | |
7631 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 7632 | |
58da1ffb JS |
7633 | /* |
7634 | * If the iocb is not found in Firmware queue the iocb | |
7635 | * might have completed already. Do not free it again. | |
7636 | */ | |
9b379605 | 7637 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
45ed1190 JS |
7638 | if (irsp->un.ulpWord[4] != IOERR_NO_XRI) { |
7639 | spin_unlock_irq(&phba->hbalock); | |
7640 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
7641 | return; | |
7642 | } | |
7643 | /* For SLI4 the ulpContext field for abort IOCB | |
7644 | * holds the iotag of the IOCB being aborted so | |
7645 | * the local abort_context needs to be reset to | |
7646 | * match the aborted IOCBs ulpContext. | |
7647 | */ | |
7648 | if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4) | |
7649 | abort_context = abort_iocb->iocb.ulpContext; | |
58da1ffb | 7650 | } |
2a9bf3d0 JS |
7651 | |
7652 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, | |
7653 | "0327 Cannot abort els iocb %p " | |
7654 | "with tag %x context %x, abort status %x, " | |
7655 | "abort code %x\n", | |
7656 | abort_iocb, abort_iotag, abort_context, | |
7657 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
2680eeaa JS |
7658 | /* |
7659 | * make sure we have the right iocbq before taking it | |
7660 | * off the txcmplq and try to call completion routine. | |
7661 | */ | |
2e0fef85 JS |
7662 | if (!abort_iocb || |
7663 | abort_iocb->iocb.ulpContext != abort_context || | |
7664 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | |
7665 | spin_unlock_irq(&phba->hbalock); | |
341af102 JS |
7666 | else if (phba->sli_rev < LPFC_SLI_REV4) { |
7667 | /* | |
7668 | * leave the SLI4 aborted command on the txcmplq | |
7669 | * list and the command complete WCQE's XB bit | |
7670 | * will tell whether the SGL (XRI) can be released | |
7671 | * immediately or to the aborted SGL list for the | |
7672 | * following abort XRI from the HBA. | |
7673 | */ | |
92d7f7b0 | 7674 | list_del_init(&abort_iocb->list); |
2a9bf3d0 JS |
7675 | if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) { |
7676 | abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
7677 | pring->txcmplq_cnt--; | |
7678 | } | |
2680eeaa | 7679 | |
0ff10d46 JS |
7680 | /* Firmware could still be in progress of DMAing |
7681 | * payload, so don't free data buffer till after | |
7682 | * a hbeat. | |
7683 | */ | |
7684 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
92d7f7b0 | 7685 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
341af102 JS |
7686 | spin_unlock_irq(&phba->hbalock); |
7687 | ||
92d7f7b0 | 7688 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
341af102 | 7689 | abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED; |
92d7f7b0 | 7690 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
49198b37 JS |
7691 | } else |
7692 | spin_unlock_irq(&phba->hbalock); | |
2680eeaa JS |
7693 | } |
7694 | ||
604a3e30 | 7695 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
7696 | return; |
7697 | } | |
7698 | ||
e59058c4 | 7699 | /** |
3621a710 | 7700 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
7701 | * @phba: Pointer to HBA context object. |
7702 | * @cmdiocb: Pointer to driver command iocb object. | |
7703 | * @rspiocb: Pointer to driver response iocb object. | |
7704 | * | |
7705 | * The function is called from SLI ring event handler with no | |
7706 | * lock held. This function is the completion handler for ELS commands | |
7707 | * which are aborted. The function frees memory resources used for | |
7708 | * the aborted ELS commands. | |
7709 | **/ | |
92d7f7b0 JS |
7710 | static void |
7711 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
7712 | struct lpfc_iocbq *rspiocb) | |
7713 | { | |
7714 | IOCB_t *irsp = &rspiocb->iocb; | |
7715 | ||
7716 | /* ELS cmd tag <ulpIoTag> completes */ | |
7717 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 7718 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 7719 | "x%x x%x x%x\n", |
e8b62011 | 7720 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 7721 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
7722 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
7723 | lpfc_ct_free_iocb(phba, cmdiocb); | |
7724 | else | |
7725 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
7726 | return; |
7727 | } | |
7728 | ||
e59058c4 | 7729 | /** |
5af5eee7 | 7730 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
7731 | * @phba: Pointer to HBA context object. |
7732 | * @pring: Pointer to driver SLI ring object. | |
7733 | * @cmdiocb: Pointer to driver command iocb object. | |
7734 | * | |
5af5eee7 JS |
7735 | * This function issues an abort iocb for the provided command iocb down to |
7736 | * the port. Other than the case the outstanding command iocb is an abort | |
7737 | * request, this function issues abort out unconditionally. This function is | |
7738 | * called with hbalock held. The function returns 0 when it fails due to | |
7739 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 7740 | **/ |
5af5eee7 JS |
7741 | static int |
7742 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7743 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 7744 | { |
2e0fef85 | 7745 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 7746 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
7747 | IOCB_t *icmd = NULL; |
7748 | IOCB_t *iabt = NULL; | |
5af5eee7 | 7749 | int retval; |
07951076 | 7750 | |
92d7f7b0 JS |
7751 | /* |
7752 | * There are certain command types we don't want to abort. And we | |
7753 | * don't want to abort commands that are already in the process of | |
7754 | * being aborted. | |
07951076 JS |
7755 | */ |
7756 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 7757 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
7758 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
7759 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
7760 | return 0; |
7761 | ||
dea3101e | 7762 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 7763 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
7764 | if (abtsiocbp == NULL) |
7765 | return 0; | |
dea3101e | 7766 | |
07951076 | 7767 | /* This signals the response to set the correct status |
341af102 | 7768 | * before calling the completion handler |
07951076 JS |
7769 | */ |
7770 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
7771 | ||
dea3101e | 7772 | iabt = &abtsiocbp->iocb; |
07951076 JS |
7773 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
7774 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 7775 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 7776 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
7777 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
7778 | } | |
da0436e9 JS |
7779 | else |
7780 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
7781 | iabt->ulpLe = 1; |
7782 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 7783 | |
5ffc266e JS |
7784 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
7785 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
7786 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
7787 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 7788 | |
2e0fef85 | 7789 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
7790 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
7791 | else | |
7792 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 7793 | |
07951076 | 7794 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 7795 | |
e8b62011 JS |
7796 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
7797 | "0339 Abort xri x%x, original iotag x%x, " | |
7798 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 7799 | iabt->un.acxri.abortIoTag, |
e8b62011 | 7800 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 7801 | abtsiocbp->iotag); |
da0436e9 | 7802 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
dea3101e | 7803 | |
d7c255b2 JS |
7804 | if (retval) |
7805 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
7806 | |
7807 | /* | |
7808 | * Caller to this routine should check for IOCB_ERROR | |
7809 | * and handle it properly. This routine no longer removes | |
7810 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
7811 | */ | |
7812 | return retval; | |
7813 | } | |
7814 | ||
7815 | /** | |
7816 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
7817 | * @phba: Pointer to HBA context object. | |
7818 | * @pring: Pointer to driver SLI ring object. | |
7819 | * @cmdiocb: Pointer to driver command iocb object. | |
7820 | * | |
7821 | * This function issues an abort iocb for the provided command iocb. In case | |
7822 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
7823 | * ring. Instead, the callback function shall be changed to those commands | |
7824 | * so that nothing happens when them finishes. This function is called with | |
7825 | * hbalock held. The function returns 0 when the command iocb is an abort | |
7826 | * request. | |
7827 | **/ | |
7828 | int | |
7829 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7830 | struct lpfc_iocbq *cmdiocb) | |
7831 | { | |
7832 | struct lpfc_vport *vport = cmdiocb->vport; | |
7833 | int retval = IOCB_ERROR; | |
7834 | IOCB_t *icmd = NULL; | |
7835 | ||
7836 | /* | |
7837 | * There are certain command types we don't want to abort. And we | |
7838 | * don't want to abort commands that are already in the process of | |
7839 | * being aborted. | |
7840 | */ | |
7841 | icmd = &cmdiocb->iocb; | |
7842 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
7843 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
7844 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
7845 | return 0; | |
7846 | ||
7847 | /* | |
7848 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
7849 | * the callback so that nothing happens when it finishes. | |
7850 | */ | |
7851 | if ((vport->load_flag & FC_UNLOADING) && | |
7852 | (pring->ringno == LPFC_ELS_RING)) { | |
7853 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
7854 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
7855 | else | |
7856 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
7857 | goto abort_iotag_exit; | |
7858 | } | |
7859 | ||
7860 | /* Now, we try to issue the abort to the cmdiocb out */ | |
7861 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
7862 | ||
07951076 | 7863 | abort_iotag_exit: |
2e0fef85 JS |
7864 | /* |
7865 | * Caller to this routine should check for IOCB_ERROR | |
7866 | * and handle it properly. This routine no longer removes | |
7867 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 7868 | */ |
2e0fef85 | 7869 | return retval; |
dea3101e JB |
7870 | } |
7871 | ||
5af5eee7 JS |
7872 | /** |
7873 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
7874 | * @phba: Pointer to HBA context object. | |
7875 | * @pring: Pointer to driver SLI ring object. | |
7876 | * | |
7877 | * This function aborts all iocbs in the given ring and frees all the iocb | |
7878 | * objects in txq. This function issues abort iocbs unconditionally for all | |
7879 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
7880 | * to complete before the return of this function. The caller is not required | |
7881 | * to hold any locks. | |
7882 | **/ | |
7883 | static void | |
7884 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
7885 | { | |
7886 | LIST_HEAD(completions); | |
7887 | struct lpfc_iocbq *iocb, *next_iocb; | |
7888 | ||
7889 | if (pring->ringno == LPFC_ELS_RING) | |
7890 | lpfc_fabric_abort_hba(phba); | |
7891 | ||
7892 | spin_lock_irq(&phba->hbalock); | |
7893 | ||
7894 | /* Take off all the iocbs on txq for cancelling */ | |
7895 | list_splice_init(&pring->txq, &completions); | |
7896 | pring->txq_cnt = 0; | |
7897 | ||
7898 | /* Next issue ABTS for everything on the txcmplq */ | |
7899 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
7900 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
7901 | ||
7902 | spin_unlock_irq(&phba->hbalock); | |
7903 | ||
7904 | /* Cancel all the IOCBs from the completions list */ | |
7905 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7906 | IOERR_SLI_ABORTED); | |
7907 | } | |
7908 | ||
7909 | /** | |
7910 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
7911 | * @phba: pointer to lpfc HBA data structure. | |
7912 | * | |
7913 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
7914 | **/ | |
7915 | void | |
7916 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
7917 | { | |
7918 | struct lpfc_sli *psli = &phba->sli; | |
7919 | struct lpfc_sli_ring *pring; | |
7920 | int i; | |
7921 | ||
7922 | for (i = 0; i < psli->num_rings; i++) { | |
7923 | pring = &psli->ring[i]; | |
7924 | lpfc_sli_iocb_ring_abort(phba, pring); | |
7925 | } | |
7926 | } | |
7927 | ||
e59058c4 | 7928 | /** |
3621a710 | 7929 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
7930 | * @iocbq: Pointer to driver iocb object. |
7931 | * @vport: Pointer to driver virtual port object. | |
7932 | * @tgt_id: SCSI ID of the target. | |
7933 | * @lun_id: LUN ID of the scsi device. | |
7934 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
7935 | * | |
3621a710 | 7936 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
7937 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
7938 | * 0 if the filtering criteria is met for the given iocb and will return | |
7939 | * 1 if the filtering criteria is not met. | |
7940 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
7941 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
7942 | * lun_id parameter. | |
7943 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
7944 | * given iocb is for the SCSI target specified by vport and tgt_id | |
7945 | * parameters. | |
7946 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
7947 | * given iocb is for the SCSI host associated with the given vport. | |
7948 | * This function is called with no locks held. | |
7949 | **/ | |
dea3101e | 7950 | static int |
51ef4c26 JS |
7951 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
7952 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 7953 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 7954 | { |
0bd4ca25 | 7955 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
7956 | int rc = 1; |
7957 | ||
0bd4ca25 JSEC |
7958 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
7959 | return rc; | |
7960 | ||
51ef4c26 JS |
7961 | if (iocbq->vport != vport) |
7962 | return rc; | |
7963 | ||
0bd4ca25 | 7964 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 7965 | |
495a714c | 7966 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
7967 | return rc; |
7968 | ||
7969 | switch (ctx_cmd) { | |
7970 | case LPFC_CTX_LUN: | |
495a714c JS |
7971 | if ((lpfc_cmd->rdata->pnode) && |
7972 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
7973 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
7974 | rc = 0; |
7975 | break; | |
7976 | case LPFC_CTX_TGT: | |
495a714c JS |
7977 | if ((lpfc_cmd->rdata->pnode) && |
7978 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
7979 | rc = 0; |
7980 | break; | |
dea3101e JB |
7981 | case LPFC_CTX_HOST: |
7982 | rc = 0; | |
7983 | break; | |
7984 | default: | |
7985 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 7986 | __func__, ctx_cmd); |
dea3101e JB |
7987 | break; |
7988 | } | |
7989 | ||
7990 | return rc; | |
7991 | } | |
7992 | ||
e59058c4 | 7993 | /** |
3621a710 | 7994 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
7995 | * @vport: Pointer to virtual port. |
7996 | * @tgt_id: SCSI ID of the target. | |
7997 | * @lun_id: LUN ID of the scsi device. | |
7998 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
7999 | * | |
8000 | * This function returns number of FCP commands pending for the vport. | |
8001 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
8002 | * commands pending on the vport associated with SCSI device specified | |
8003 | * by tgt_id and lun_id parameters. | |
8004 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
8005 | * commands pending on the vport associated with SCSI target specified | |
8006 | * by tgt_id parameter. | |
8007 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
8008 | * commands pending on the vport. | |
8009 | * This function returns the number of iocbs which satisfy the filter. | |
8010 | * This function is called without any lock held. | |
8011 | **/ | |
dea3101e | 8012 | int |
51ef4c26 JS |
8013 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
8014 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 8015 | { |
51ef4c26 | 8016 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
8017 | struct lpfc_iocbq *iocbq; |
8018 | int sum, i; | |
dea3101e | 8019 | |
0bd4ca25 JSEC |
8020 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
8021 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 8022 | |
51ef4c26 JS |
8023 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
8024 | ctx_cmd) == 0) | |
0bd4ca25 | 8025 | sum++; |
dea3101e | 8026 | } |
0bd4ca25 | 8027 | |
dea3101e JB |
8028 | return sum; |
8029 | } | |
8030 | ||
e59058c4 | 8031 | /** |
3621a710 | 8032 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
8033 | * @phba: Pointer to HBA context object |
8034 | * @cmdiocb: Pointer to command iocb object. | |
8035 | * @rspiocb: Pointer to response iocb object. | |
8036 | * | |
8037 | * This function is called when an aborted FCP iocb completes. This | |
8038 | * function is called by the ring event handler with no lock held. | |
8039 | * This function frees the iocb. | |
8040 | **/ | |
5eb95af0 | 8041 | void |
2e0fef85 JS |
8042 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
8043 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 8044 | { |
604a3e30 | 8045 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
8046 | return; |
8047 | } | |
8048 | ||
e59058c4 | 8049 | /** |
3621a710 | 8050 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
8051 | * @vport: Pointer to virtual port. |
8052 | * @pring: Pointer to driver SLI ring object. | |
8053 | * @tgt_id: SCSI ID of the target. | |
8054 | * @lun_id: LUN ID of the scsi device. | |
8055 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
8056 | * | |
8057 | * This function sends an abort command for every SCSI command | |
8058 | * associated with the given virtual port pending on the ring | |
8059 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
8060 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
8061 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
8062 | * parameters | |
8063 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
8064 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
8065 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
8066 | * FCP iocbs associated with virtual port. | |
8067 | * This function returns number of iocbs it failed to abort. | |
8068 | * This function is called with no locks held. | |
8069 | **/ | |
dea3101e | 8070 | int |
51ef4c26 JS |
8071 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
8072 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 8073 | { |
51ef4c26 | 8074 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
8075 | struct lpfc_iocbq *iocbq; |
8076 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 8077 | IOCB_t *cmd = NULL; |
dea3101e | 8078 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 8079 | int i; |
dea3101e | 8080 | |
0bd4ca25 JSEC |
8081 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
8082 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 8083 | |
51ef4c26 | 8084 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 8085 | abort_cmd) != 0) |
dea3101e JB |
8086 | continue; |
8087 | ||
8088 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 8089 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
8090 | if (abtsiocb == NULL) { |
8091 | errcnt++; | |
8092 | continue; | |
8093 | } | |
dea3101e | 8094 | |
0bd4ca25 | 8095 | cmd = &iocbq->iocb; |
dea3101e JB |
8096 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
8097 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
8098 | if (phba->sli_rev == LPFC_SLI_REV4) |
8099 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
8100 | else | |
8101 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
8102 | abtsiocb->iocb.ulpLe = 1; |
8103 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 8104 | abtsiocb->vport = phba->pport; |
dea3101e | 8105 | |
5ffc266e JS |
8106 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
8107 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
8108 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
8109 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 8110 | |
2e0fef85 | 8111 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
8112 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
8113 | else | |
8114 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
8115 | ||
5eb95af0 JSEC |
8116 | /* Setup callback routine and issue the command. */ |
8117 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
8118 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
8119 | abtsiocb, 0); | |
dea3101e | 8120 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 8121 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
8122 | errcnt++; |
8123 | continue; | |
8124 | } | |
8125 | } | |
8126 | ||
8127 | return errcnt; | |
8128 | } | |
8129 | ||
e59058c4 | 8130 | /** |
3621a710 | 8131 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
8132 | * @phba: Pointer to HBA context object. |
8133 | * @cmdiocbq: Pointer to command iocb. | |
8134 | * @rspiocbq: Pointer to response iocb. | |
8135 | * | |
8136 | * This function is the completion handler for iocbs issued using | |
8137 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
8138 | * ring event handler function without any lock held. This function | |
8139 | * can be called from both worker thread context and interrupt | |
8140 | * context. This function also can be called from other thread which | |
8141 | * cleans up the SLI layer objects. | |
8142 | * This function copy the contents of the response iocb to the | |
8143 | * response iocb memory object provided by the caller of | |
8144 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
8145 | * sleeps for the iocb completion. | |
8146 | **/ | |
68876920 JSEC |
8147 | static void |
8148 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
8149 | struct lpfc_iocbq *cmdiocbq, | |
8150 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 8151 | { |
68876920 JSEC |
8152 | wait_queue_head_t *pdone_q; |
8153 | unsigned long iflags; | |
0f65ff68 | 8154 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 8155 | |
2e0fef85 | 8156 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
8157 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
8158 | if (cmdiocbq->context2 && rspiocbq) | |
8159 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
8160 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
8161 | ||
0f65ff68 JS |
8162 | /* Set the exchange busy flag for task management commands */ |
8163 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
8164 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
8165 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
8166 | cur_iocbq); | |
8167 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
8168 | } | |
8169 | ||
68876920 | 8170 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
8171 | if (pdone_q) |
8172 | wake_up(pdone_q); | |
858c9f6c | 8173 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
8174 | return; |
8175 | } | |
8176 | ||
d11e31dd JS |
8177 | /** |
8178 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
8179 | * @phba: Pointer to HBA context object.. | |
8180 | * @piocbq: Pointer to command iocb. | |
8181 | * @flag: Flag to test. | |
8182 | * | |
8183 | * This routine grabs the hbalock and then test the iocb_flag to | |
8184 | * see if the passed in flag is set. | |
8185 | * Returns: | |
8186 | * 1 if flag is set. | |
8187 | * 0 if flag is not set. | |
8188 | **/ | |
8189 | static int | |
8190 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
8191 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
8192 | { | |
8193 | unsigned long iflags; | |
8194 | int ret; | |
8195 | ||
8196 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8197 | ret = piocbq->iocb_flag & flag; | |
8198 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8199 | return ret; | |
8200 | ||
8201 | } | |
8202 | ||
e59058c4 | 8203 | /** |
3621a710 | 8204 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
8205 | * @phba: Pointer to HBA context object.. |
8206 | * @pring: Pointer to sli ring. | |
8207 | * @piocb: Pointer to command iocb. | |
8208 | * @prspiocbq: Pointer to response iocb. | |
8209 | * @timeout: Timeout in number of seconds. | |
8210 | * | |
8211 | * This function issues the iocb to firmware and waits for the | |
8212 | * iocb to complete. If the iocb command is not | |
8213 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
8214 | * Caller should not free the iocb resources if this function | |
8215 | * returns IOCB_TIMEDOUT. | |
8216 | * The function waits for the iocb completion using an | |
8217 | * non-interruptible wait. | |
8218 | * This function will sleep while waiting for iocb completion. | |
8219 | * So, this function should not be called from any context which | |
8220 | * does not allow sleeping. Due to the same reason, this function | |
8221 | * cannot be called with interrupt disabled. | |
8222 | * This function assumes that the iocb completions occur while | |
8223 | * this function sleep. So, this function cannot be called from | |
8224 | * the thread which process iocb completion for this ring. | |
8225 | * This function clears the iocb_flag of the iocb object before | |
8226 | * issuing the iocb and the iocb completion handler sets this | |
8227 | * flag and wakes this thread when the iocb completes. | |
8228 | * The contents of the response iocb will be copied to prspiocbq | |
8229 | * by the completion handler when the command completes. | |
8230 | * This function returns IOCB_SUCCESS when success. | |
8231 | * This function is called with no lock held. | |
8232 | **/ | |
dea3101e | 8233 | int |
2e0fef85 | 8234 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 8235 | uint32_t ring_number, |
2e0fef85 JS |
8236 | struct lpfc_iocbq *piocb, |
8237 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 8238 | uint32_t timeout) |
dea3101e | 8239 | { |
7259f0d0 | 8240 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
8241 | long timeleft, timeout_req = 0; |
8242 | int retval = IOCB_SUCCESS; | |
875fbdfe | 8243 | uint32_t creg_val; |
2a9bf3d0 | 8244 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 8245 | /* |
68876920 JSEC |
8246 | * If the caller has provided a response iocbq buffer, then context2 |
8247 | * is NULL or its an error. | |
dea3101e | 8248 | */ |
68876920 JSEC |
8249 | if (prspiocbq) { |
8250 | if (piocb->context2) | |
8251 | return IOCB_ERROR; | |
8252 | piocb->context2 = prspiocbq; | |
dea3101e JB |
8253 | } |
8254 | ||
68876920 JSEC |
8255 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
8256 | piocb->context_un.wait_queue = &done_q; | |
8257 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 8258 | |
875fbdfe | 8259 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
8260 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
8261 | return IOCB_ERROR; | |
875fbdfe JSEC |
8262 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
8263 | writel(creg_val, phba->HCregaddr); | |
8264 | readl(phba->HCregaddr); /* flush */ | |
8265 | } | |
8266 | ||
2a9bf3d0 JS |
8267 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
8268 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
8269 | if (retval == IOCB_SUCCESS) { |
8270 | timeout_req = timeout * HZ; | |
68876920 | 8271 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 8272 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 8273 | timeout_req); |
dea3101e | 8274 | |
7054a606 JS |
8275 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
8276 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 8277 | "0331 IOCB wake signaled\n"); |
7054a606 | 8278 | } else if (timeleft == 0) { |
68876920 | 8279 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
8280 | "0338 IOCB wait timeout error - no " |
8281 | "wake response Data x%x\n", timeout); | |
68876920 | 8282 | retval = IOCB_TIMEDOUT; |
7054a606 | 8283 | } else { |
68876920 | 8284 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
8285 | "0330 IOCB wake NOT set, " |
8286 | "Data x%x x%lx\n", | |
68876920 JSEC |
8287 | timeout, (timeleft / jiffies)); |
8288 | retval = IOCB_TIMEDOUT; | |
dea3101e | 8289 | } |
2a9bf3d0 JS |
8290 | } else if (retval == IOCB_BUSY) { |
8291 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8292 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
8293 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
8294 | return retval; | |
68876920 JSEC |
8295 | } else { |
8296 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 8297 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 8298 | retval); |
68876920 | 8299 | retval = IOCB_ERROR; |
dea3101e JB |
8300 | } |
8301 | ||
875fbdfe | 8302 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
9940b97b JS |
8303 | if (lpfc_readl(phba->HCregaddr, &creg_val)) |
8304 | return IOCB_ERROR; | |
875fbdfe JSEC |
8305 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
8306 | writel(creg_val, phba->HCregaddr); | |
8307 | readl(phba->HCregaddr); /* flush */ | |
8308 | } | |
8309 | ||
68876920 JSEC |
8310 | if (prspiocbq) |
8311 | piocb->context2 = NULL; | |
8312 | ||
8313 | piocb->context_un.wait_queue = NULL; | |
8314 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
8315 | return retval; |
8316 | } | |
68876920 | 8317 | |
e59058c4 | 8318 | /** |
3621a710 | 8319 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
8320 | * @phba: Pointer to HBA context object. |
8321 | * @pmboxq: Pointer to driver mailbox object. | |
8322 | * @timeout: Timeout in number of seconds. | |
8323 | * | |
8324 | * This function issues the mailbox to firmware and waits for the | |
8325 | * mailbox command to complete. If the mailbox command is not | |
8326 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
8327 | * The function waits for the mailbox completion using an | |
8328 | * interruptible wait. If the thread is woken up due to a | |
8329 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
8330 | * should not free the mailbox resources, if this function returns | |
8331 | * MBX_TIMEOUT. | |
8332 | * This function will sleep while waiting for mailbox completion. | |
8333 | * So, this function should not be called from any context which | |
8334 | * does not allow sleeping. Due to the same reason, this function | |
8335 | * cannot be called with interrupt disabled. | |
8336 | * This function assumes that the mailbox completion occurs while | |
8337 | * this function sleep. So, this function cannot be called from | |
8338 | * the worker thread which processes mailbox completion. | |
8339 | * This function is called in the context of HBA management | |
8340 | * applications. | |
8341 | * This function returns MBX_SUCCESS when successful. | |
8342 | * This function is called with no lock held. | |
8343 | **/ | |
dea3101e | 8344 | int |
2e0fef85 | 8345 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
8346 | uint32_t timeout) |
8347 | { | |
7259f0d0 | 8348 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 8349 | int retval; |
858c9f6c | 8350 | unsigned long flag; |
dea3101e JB |
8351 | |
8352 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 8353 | if (pmboxq->context1) |
2e0fef85 | 8354 | return MBX_NOT_FINISHED; |
dea3101e | 8355 | |
495a714c | 8356 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
8357 | /* setup wake call as IOCB callback */ |
8358 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
8359 | /* setup context field to pass wait_queue pointer to wake function */ | |
8360 | pmboxq->context1 = &done_q; | |
8361 | ||
dea3101e JB |
8362 | /* now issue the command */ |
8363 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
8364 | ||
8365 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | |
7054a606 JS |
8366 | wait_event_interruptible_timeout(done_q, |
8367 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
8368 | timeout * HZ); | |
8369 | ||
858c9f6c | 8370 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 8371 | pmboxq->context1 = NULL; |
7054a606 JS |
8372 | /* |
8373 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
8374 | * else do not free the resources. | |
8375 | */ | |
d7c47992 | 8376 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 8377 | retval = MBX_SUCCESS; |
d7c47992 JS |
8378 | lpfc_sli4_swap_str(phba, pmboxq); |
8379 | } else { | |
7054a606 | 8380 | retval = MBX_TIMEOUT; |
858c9f6c JS |
8381 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
8382 | } | |
8383 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e JB |
8384 | } |
8385 | ||
dea3101e JB |
8386 | return retval; |
8387 | } | |
8388 | ||
e59058c4 | 8389 | /** |
3772a991 | 8390 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
8391 | * @phba: Pointer to HBA context. |
8392 | * | |
3772a991 JS |
8393 | * This function is called to shutdown the driver's mailbox sub-system. |
8394 | * It first marks the mailbox sub-system is in a block state to prevent | |
8395 | * the asynchronous mailbox command from issued off the pending mailbox | |
8396 | * command queue. If the mailbox command sub-system shutdown is due to | |
8397 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
8398 | * the mailbox sub-system flush routine to forcefully bring down the | |
8399 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
8400 | * as with offline or HBA function reset), this routine will wait for the | |
8401 | * outstanding mailbox command to complete before invoking the mailbox | |
8402 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 8403 | **/ |
3772a991 JS |
8404 | void |
8405 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) | |
b4c02652 | 8406 | { |
3772a991 JS |
8407 | struct lpfc_sli *psli = &phba->sli; |
8408 | uint8_t actcmd = MBX_HEARTBEAT; | |
8409 | unsigned long timeout; | |
b4c02652 | 8410 | |
3772a991 JS |
8411 | spin_lock_irq(&phba->hbalock); |
8412 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
8413 | spin_unlock_irq(&phba->hbalock); | |
b4c02652 | 8414 | |
3772a991 | 8415 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
ed957684 | 8416 | spin_lock_irq(&phba->hbalock); |
3772a991 JS |
8417 | if (phba->sli.mbox_active) |
8418 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
ed957684 | 8419 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
8420 | /* Determine how long we might wait for the active mailbox |
8421 | * command to be gracefully completed by firmware. | |
8422 | */ | |
8423 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * | |
8424 | 1000) + jiffies; | |
8425 | while (phba->sli.mbox_active) { | |
8426 | /* Check active mailbox complete status every 2ms */ | |
8427 | msleep(2); | |
8428 | if (time_after(jiffies, timeout)) | |
8429 | /* Timeout, let the mailbox flush routine to | |
8430 | * forcefully release active mailbox command | |
8431 | */ | |
8432 | break; | |
8433 | } | |
8434 | } | |
8435 | lpfc_sli_mbox_sys_flush(phba); | |
8436 | } | |
ed957684 | 8437 | |
3772a991 JS |
8438 | /** |
8439 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
8440 | * @phba: Pointer to HBA context. | |
8441 | * | |
8442 | * This function is called to read the SLI3 device error attention registers | |
8443 | * for possible error attention events. The caller must hold the hostlock | |
8444 | * with spin_lock_irq(). | |
8445 | * | |
25985edc | 8446 | * This function returns 1 when there is Error Attention in the Host Attention |
3772a991 JS |
8447 | * Register and returns 0 otherwise. |
8448 | **/ | |
8449 | static int | |
8450 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
8451 | { | |
8452 | uint32_t ha_copy; | |
b4c02652 | 8453 | |
3772a991 | 8454 | /* Read chip Host Attention (HA) register */ |
9940b97b JS |
8455 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
8456 | goto unplug_err; | |
8457 | ||
3772a991 JS |
8458 | if (ha_copy & HA_ERATT) { |
8459 | /* Read host status register to retrieve error event */ | |
9940b97b JS |
8460 | if (lpfc_sli_read_hs(phba)) |
8461 | goto unplug_err; | |
b4c02652 | 8462 | |
3772a991 JS |
8463 | /* Check if there is a deferred error condition is active */ |
8464 | if ((HS_FFER1 & phba->work_hs) && | |
8465 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 8466 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 8467 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
8468 | /* Clear all interrupt enable conditions */ |
8469 | writel(0, phba->HCregaddr); | |
8470 | readl(phba->HCregaddr); | |
8471 | } | |
8472 | ||
8473 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
8474 | phba->work_ha |= HA_ERATT; |
8475 | /* Indicate polling handles this ERATT */ | |
8476 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
8477 | return 1; |
8478 | } | |
8479 | return 0; | |
9940b97b JS |
8480 | |
8481 | unplug_err: | |
8482 | /* Set the driver HS work bitmap */ | |
8483 | phba->work_hs |= UNPLUG_ERR; | |
8484 | /* Set the driver HA work bitmap */ | |
8485 | phba->work_ha |= HA_ERATT; | |
8486 | /* Indicate polling handles this ERATT */ | |
8487 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8488 | return 1; | |
b4c02652 JS |
8489 | } |
8490 | ||
da0436e9 JS |
8491 | /** |
8492 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
8493 | * @phba: Pointer to HBA context. | |
8494 | * | |
8495 | * This function is called to read the SLI4 device error attention registers | |
8496 | * for possible error attention events. The caller must hold the hostlock | |
8497 | * with spin_lock_irq(). | |
8498 | * | |
25985edc | 8499 | * This function returns 1 when there is Error Attention in the Host Attention |
da0436e9 JS |
8500 | * Register and returns 0 otherwise. |
8501 | **/ | |
8502 | static int | |
8503 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
8504 | { | |
8505 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
2fcee4bf JS |
8506 | uint32_t if_type, portsmphr; |
8507 | struct lpfc_register portstat_reg; | |
da0436e9 | 8508 | |
2fcee4bf JS |
8509 | /* |
8510 | * For now, use the SLI4 device internal unrecoverable error | |
da0436e9 JS |
8511 | * registers for error attention. This can be changed later. |
8512 | */ | |
2fcee4bf JS |
8513 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
8514 | switch (if_type) { | |
8515 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9940b97b JS |
8516 | if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr, |
8517 | &uerr_sta_lo) || | |
8518 | lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr, | |
8519 | &uerr_sta_hi)) { | |
8520 | phba->work_hs |= UNPLUG_ERR; | |
8521 | phba->work_ha |= HA_ERATT; | |
8522 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8523 | return 1; | |
8524 | } | |
2fcee4bf JS |
8525 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || |
8526 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
8527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8528 | "1423 HBA Unrecoverable error: " | |
8529 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
8530 | "ue_mask_lo_reg=0x%x, " | |
8531 | "ue_mask_hi_reg=0x%x\n", | |
8532 | uerr_sta_lo, uerr_sta_hi, | |
8533 | phba->sli4_hba.ue_mask_lo, | |
8534 | phba->sli4_hba.ue_mask_hi); | |
8535 | phba->work_status[0] = uerr_sta_lo; | |
8536 | phba->work_status[1] = uerr_sta_hi; | |
8537 | phba->work_ha |= HA_ERATT; | |
8538 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8539 | return 1; | |
8540 | } | |
8541 | break; | |
8542 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9940b97b JS |
8543 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
8544 | &portstat_reg.word0) || | |
8545 | lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
8546 | &portsmphr)){ | |
8547 | phba->work_hs |= UNPLUG_ERR; | |
8548 | phba->work_ha |= HA_ERATT; | |
8549 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8550 | return 1; | |
8551 | } | |
2fcee4bf JS |
8552 | if (bf_get(lpfc_sliport_status_err, &portstat_reg)) { |
8553 | phba->work_status[0] = | |
8554 | readl(phba->sli4_hba.u.if_type2.ERR1regaddr); | |
8555 | phba->work_status[1] = | |
8556 | readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
8557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8558 | "2885 Port Error Detected: " | |
8559 | "port status reg 0x%x, " | |
8560 | "port smphr reg 0x%x, " | |
8561 | "error 1=0x%x, error 2=0x%x\n", | |
8562 | portstat_reg.word0, | |
8563 | portsmphr, | |
8564 | phba->work_status[0], | |
8565 | phba->work_status[1]); | |
8566 | phba->work_ha |= HA_ERATT; | |
8567 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8568 | return 1; | |
8569 | } | |
8570 | break; | |
8571 | case LPFC_SLI_INTF_IF_TYPE_1: | |
8572 | default: | |
a747c9ce | 8573 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
8574 | "2886 HBA Error Attention on unsupported " |
8575 | "if type %d.", if_type); | |
a747c9ce | 8576 | return 1; |
da0436e9 | 8577 | } |
2fcee4bf | 8578 | |
da0436e9 JS |
8579 | return 0; |
8580 | } | |
8581 | ||
e59058c4 | 8582 | /** |
3621a710 | 8583 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
8584 | * @phba: Pointer to HBA context. |
8585 | * | |
3772a991 | 8586 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
8587 | * error attention register bit for error attention events. |
8588 | * | |
25985edc | 8589 | * This function returns 1 when there is Error Attention in the Host Attention |
9399627f JS |
8590 | * Register and returns 0 otherwise. |
8591 | **/ | |
8592 | int | |
8593 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
8594 | { | |
8595 | uint32_t ha_copy; | |
8596 | ||
8597 | /* If somebody is waiting to handle an eratt, don't process it | |
8598 | * here. The brdkill function will do this. | |
8599 | */ | |
8600 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8601 | return 0; | |
8602 | ||
8603 | /* Check if interrupt handler handles this ERATT */ | |
8604 | spin_lock_irq(&phba->hbalock); | |
8605 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
8606 | /* Interrupt handler has handled ERATT */ | |
8607 | spin_unlock_irq(&phba->hbalock); | |
8608 | return 0; | |
8609 | } | |
8610 | ||
a257bf90 JS |
8611 | /* |
8612 | * If there is deferred error attention, do not check for error | |
8613 | * attention | |
8614 | */ | |
8615 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
8616 | spin_unlock_irq(&phba->hbalock); | |
8617 | return 0; | |
8618 | } | |
8619 | ||
3772a991 JS |
8620 | /* If PCI channel is offline, don't process it */ |
8621 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 8622 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
8623 | return 0; |
8624 | } | |
8625 | ||
8626 | switch (phba->sli_rev) { | |
8627 | case LPFC_SLI_REV2: | |
8628 | case LPFC_SLI_REV3: | |
8629 | /* Read chip Host Attention (HA) register */ | |
8630 | ha_copy = lpfc_sli_eratt_read(phba); | |
8631 | break; | |
da0436e9 | 8632 | case LPFC_SLI_REV4: |
2fcee4bf | 8633 | /* Read device Uncoverable Error (UERR) registers */ |
da0436e9 JS |
8634 | ha_copy = lpfc_sli4_eratt_read(phba); |
8635 | break; | |
3772a991 JS |
8636 | default: |
8637 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8638 | "0299 Invalid SLI revision (%d)\n", | |
8639 | phba->sli_rev); | |
8640 | ha_copy = 0; | |
8641 | break; | |
9399627f JS |
8642 | } |
8643 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
8644 | |
8645 | return ha_copy; | |
8646 | } | |
8647 | ||
8648 | /** | |
8649 | * lpfc_intr_state_check - Check device state for interrupt handling | |
8650 | * @phba: Pointer to HBA context. | |
8651 | * | |
8652 | * This inline routine checks whether a device or its PCI slot is in a state | |
8653 | * that the interrupt should be handled. | |
8654 | * | |
8655 | * This function returns 0 if the device or the PCI slot is in a state that | |
8656 | * interrupt should be handled, otherwise -EIO. | |
8657 | */ | |
8658 | static inline int | |
8659 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
8660 | { | |
8661 | /* If the pci channel is offline, ignore all the interrupts */ | |
8662 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
8663 | return -EIO; | |
8664 | ||
8665 | /* Update device level interrupt statistics */ | |
8666 | phba->sli.slistat.sli_intr++; | |
8667 | ||
8668 | /* Ignore all interrupts during initialization. */ | |
8669 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
8670 | return -EIO; | |
8671 | ||
9399627f JS |
8672 | return 0; |
8673 | } | |
8674 | ||
8675 | /** | |
3772a991 | 8676 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
8677 | * @irq: Interrupt number. |
8678 | * @dev_id: The device context pointer. | |
8679 | * | |
9399627f | 8680 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
8681 | * service routine when device with SLI-3 interface spec is enabled with |
8682 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
8683 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
8684 | * interrupt mode, this function is called as part of the device-level | |
8685 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
8686 | * is undergoing initialization, the interrupt handler will not process | |
8687 | * the interrupt. The link attention and ELS ring attention events are | |
8688 | * handled by the worker thread. The interrupt handler signals the worker | |
8689 | * thread and returns for these events. This function is called without | |
8690 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
8691 | * structures. |
8692 | * | |
8693 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8694 | * returns IRQ_NONE. | |
e59058c4 | 8695 | **/ |
dea3101e | 8696 | irqreturn_t |
3772a991 | 8697 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 8698 | { |
2e0fef85 | 8699 | struct lpfc_hba *phba; |
a747c9ce | 8700 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
8701 | uint32_t work_ha_copy; |
8702 | unsigned long status; | |
5b75da2f | 8703 | unsigned long iflag; |
dea3101e JB |
8704 | uint32_t control; |
8705 | ||
92d7f7b0 | 8706 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
8707 | struct lpfc_vport *vport; |
8708 | struct lpfc_nodelist *ndlp; | |
8709 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
8710 | LPFC_MBOXQ_t *pmb; |
8711 | int rc; | |
8712 | ||
dea3101e JB |
8713 | /* |
8714 | * Get the driver's phba structure from the dev_id and | |
8715 | * assume the HBA is not interrupting. | |
8716 | */ | |
9399627f | 8717 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
8718 | |
8719 | if (unlikely(!phba)) | |
8720 | return IRQ_NONE; | |
8721 | ||
dea3101e | 8722 | /* |
9399627f JS |
8723 | * Stuff needs to be attented to when this function is invoked as an |
8724 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 8725 | */ |
9399627f | 8726 | if (phba->intr_type == MSIX) { |
3772a991 JS |
8727 | /* Check device state for handling interrupt */ |
8728 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8729 | return IRQ_NONE; |
8730 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 8731 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
8732 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
8733 | goto unplug_error; | |
9399627f JS |
8734 | /* If somebody is waiting to handle an eratt don't process it |
8735 | * here. The brdkill function will do this. | |
8736 | */ | |
8737 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8738 | ha_copy &= ~HA_ERATT; | |
8739 | /* Check the need for handling ERATT in interrupt handler */ | |
8740 | if (ha_copy & HA_ERATT) { | |
8741 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8742 | /* ERATT polling has handled ERATT */ | |
8743 | ha_copy &= ~HA_ERATT; | |
8744 | else | |
8745 | /* Indicate interrupt handler handles ERATT */ | |
8746 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8747 | } | |
a257bf90 JS |
8748 | |
8749 | /* | |
8750 | * If there is deferred error attention, do not check for any | |
8751 | * interrupt. | |
8752 | */ | |
8753 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8754 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8755 | return IRQ_NONE; |
8756 | } | |
8757 | ||
9399627f | 8758 | /* Clear up only attention source related to slow-path */ |
9940b97b JS |
8759 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) |
8760 | goto unplug_error; | |
8761 | ||
a747c9ce JS |
8762 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | |
8763 | HC_LAINT_ENA | HC_ERINT_ENA), | |
8764 | phba->HCregaddr); | |
9399627f JS |
8765 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
8766 | phba->HAregaddr); | |
a747c9ce | 8767 | writel(hc_copy, phba->HCregaddr); |
9399627f | 8768 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 8769 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8770 | } else |
8771 | ha_copy = phba->ha_copy; | |
dea3101e | 8772 | |
dea3101e JB |
8773 | work_ha_copy = ha_copy & phba->work_ha_mask; |
8774 | ||
9399627f | 8775 | if (work_ha_copy) { |
dea3101e JB |
8776 | if (work_ha_copy & HA_LATT) { |
8777 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
8778 | /* | |
8779 | * Turn off Link Attention interrupts | |
8780 | * until CLEAR_LA done | |
8781 | */ | |
5b75da2f | 8782 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 8783 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
9940b97b JS |
8784 | if (lpfc_readl(phba->HCregaddr, &control)) |
8785 | goto unplug_error; | |
dea3101e JB |
8786 | control &= ~HC_LAINT_ENA; |
8787 | writel(control, phba->HCregaddr); | |
8788 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 8789 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
8790 | } |
8791 | else | |
8792 | work_ha_copy &= ~HA_LATT; | |
8793 | } | |
8794 | ||
9399627f | 8795 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
8796 | /* |
8797 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
8798 | * the only slow ring. | |
8799 | */ | |
8800 | status = (work_ha_copy & | |
8801 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
8802 | status >>= (4*LPFC_ELS_RING); | |
8803 | if (status & HA_RXMASK) { | |
5b75da2f | 8804 | spin_lock_irqsave(&phba->hbalock, iflag); |
9940b97b JS |
8805 | if (lpfc_readl(phba->HCregaddr, &control)) |
8806 | goto unplug_error; | |
a58cbd52 JS |
8807 | |
8808 | lpfc_debugfs_slow_ring_trc(phba, | |
8809 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
8810 | control, status, | |
8811 | (uint32_t)phba->sli.slistat.sli_intr); | |
8812 | ||
858c9f6c | 8813 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
8814 | lpfc_debugfs_slow_ring_trc(phba, |
8815 | "ISR Disable ring:" | |
8816 | "pwork:x%x hawork:x%x wait:x%x", | |
8817 | phba->work_ha, work_ha_copy, | |
8818 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8819 | &phba->work_waitq)); |
a58cbd52 | 8820 | |
858c9f6c JS |
8821 | control &= |
8822 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
8823 | writel(control, phba->HCregaddr); |
8824 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 8825 | } |
a58cbd52 JS |
8826 | else { |
8827 | lpfc_debugfs_slow_ring_trc(phba, | |
8828 | "ISR slow ring: pwork:" | |
8829 | "x%x hawork:x%x wait:x%x", | |
8830 | phba->work_ha, work_ha_copy, | |
8831 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8832 | &phba->work_waitq)); |
a58cbd52 | 8833 | } |
5b75da2f | 8834 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
8835 | } |
8836 | } | |
5b75da2f | 8837 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 8838 | if (work_ha_copy & HA_ERATT) { |
9940b97b JS |
8839 | if (lpfc_sli_read_hs(phba)) |
8840 | goto unplug_error; | |
a257bf90 JS |
8841 | /* |
8842 | * Check if there is a deferred error condition | |
8843 | * is active | |
8844 | */ | |
8845 | if ((HS_FFER1 & phba->work_hs) && | |
8846 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
8847 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
8848 | phba->work_hs)) { | |
a257bf90 JS |
8849 | phba->hba_flag |= DEFER_ERATT; |
8850 | /* Clear all interrupt enable conditions */ | |
8851 | writel(0, phba->HCregaddr); | |
8852 | readl(phba->HCregaddr); | |
8853 | } | |
8854 | } | |
8855 | ||
9399627f | 8856 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 8857 | pmb = phba->sli.mbox_active; |
04c68496 | 8858 | pmbox = &pmb->u.mb; |
34b02dcd | 8859 | mbox = phba->mbox; |
858c9f6c | 8860 | vport = pmb->vport; |
92d7f7b0 JS |
8861 | |
8862 | /* First check out the status word */ | |
8863 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
8864 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 8865 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
8866 | /* |
8867 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
8868 | * mbxStatus <status> | |
8869 | */ | |
09372820 | 8870 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 8871 | LOG_SLI, |
e8b62011 | 8872 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
8873 | "Interrupt mbxCommand x%x " |
8874 | "mbxStatus x%x\n", | |
e8b62011 | 8875 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
8876 | pmbox->mbxCommand, |
8877 | pmbox->mbxStatus); | |
09372820 JS |
8878 | /* clear mailbox attention bit */ |
8879 | work_ha_copy &= ~HA_MBATT; | |
8880 | } else { | |
97eab634 | 8881 | phba->sli.mbox_active = NULL; |
5b75da2f | 8882 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
8883 | phba->last_completion_time = jiffies; |
8884 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
8885 | if (pmb->mbox_cmpl) { |
8886 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
8887 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
8888 | if (pmb->out_ext_byte_len && |
8889 | pmb->context2) | |
8890 | lpfc_sli_pcimem_bcopy( | |
8891 | phba->mbox_ext, | |
8892 | pmb->context2, | |
8893 | pmb->out_ext_byte_len); | |
09372820 JS |
8894 | } |
8895 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
8896 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
8897 | ||
8898 | lpfc_debugfs_disc_trc(vport, | |
8899 | LPFC_DISC_TRC_MBOX_VPORT, | |
8900 | "MBOX dflt rpi: : " | |
8901 | "status:x%x rpi:x%x", | |
8902 | (uint32_t)pmbox->mbxStatus, | |
8903 | pmbox->un.varWords[0], 0); | |
8904 | ||
8905 | if (!pmbox->mbxStatus) { | |
8906 | mp = (struct lpfc_dmabuf *) | |
8907 | (pmb->context1); | |
8908 | ndlp = (struct lpfc_nodelist *) | |
8909 | pmb->context2; | |
8910 | ||
8911 | /* Reg_LOGIN of dflt RPI was | |
8912 | * successful. new lets get | |
8913 | * rid of the RPI using the | |
8914 | * same mbox buffer. | |
8915 | */ | |
8916 | lpfc_unreg_login(phba, | |
8917 | vport->vpi, | |
8918 | pmbox->un.varWords[0], | |
8919 | pmb); | |
8920 | pmb->mbox_cmpl = | |
8921 | lpfc_mbx_cmpl_dflt_rpi; | |
8922 | pmb->context1 = mp; | |
8923 | pmb->context2 = ndlp; | |
8924 | pmb->vport = vport; | |
58da1ffb JS |
8925 | rc = lpfc_sli_issue_mbox(phba, |
8926 | pmb, | |
8927 | MBX_NOWAIT); | |
8928 | if (rc != MBX_BUSY) | |
8929 | lpfc_printf_log(phba, | |
8930 | KERN_ERR, | |
8931 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 8932 | "0350 rc should have" |
6a9c52cf | 8933 | "been MBX_BUSY\n"); |
3772a991 JS |
8934 | if (rc != MBX_NOT_FINISHED) |
8935 | goto send_current_mbox; | |
09372820 | 8936 | } |
858c9f6c | 8937 | } |
5b75da2f JS |
8938 | spin_lock_irqsave( |
8939 | &phba->pport->work_port_lock, | |
8940 | iflag); | |
09372820 JS |
8941 | phba->pport->work_port_events &= |
8942 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
8943 | spin_unlock_irqrestore( |
8944 | &phba->pport->work_port_lock, | |
8945 | iflag); | |
09372820 | 8946 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 8947 | } |
97eab634 | 8948 | } else |
5b75da2f | 8949 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 8950 | |
92d7f7b0 JS |
8951 | if ((work_ha_copy & HA_MBATT) && |
8952 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 8953 | send_current_mbox: |
92d7f7b0 | 8954 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
8955 | do { |
8956 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
8957 | MBX_NOWAIT); | |
8958 | } while (rc == MBX_NOT_FINISHED); | |
8959 | if (rc != MBX_SUCCESS) | |
8960 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
8961 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 8962 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
8963 | } |
8964 | ||
5b75da2f | 8965 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 8966 | phba->work_ha |= work_ha_copy; |
5b75da2f | 8967 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 8968 | lpfc_worker_wake_up(phba); |
dea3101e | 8969 | } |
9399627f | 8970 | return IRQ_HANDLED; |
9940b97b JS |
8971 | unplug_error: |
8972 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
8973 | return IRQ_HANDLED; | |
dea3101e | 8974 | |
3772a991 | 8975 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
8976 | |
8977 | /** | |
3772a991 | 8978 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
8979 | * @irq: Interrupt number. |
8980 | * @dev_id: The device context pointer. | |
8981 | * | |
8982 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
8983 | * service routine when device with SLI-3 interface spec is enabled with |
8984 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
8985 | * ring event in the HBA. However, when the device is enabled with either | |
8986 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
8987 | * device-level interrupt handler. When the PCI slot is in error recovery | |
8988 | * or the HBA is undergoing initialization, the interrupt handler will not | |
8989 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
8990 | * the intrrupt context. This function is called without any lock held. | |
8991 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
8992 | * |
8993 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8994 | * returns IRQ_NONE. | |
8995 | **/ | |
8996 | irqreturn_t | |
3772a991 | 8997 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
8998 | { |
8999 | struct lpfc_hba *phba; | |
9000 | uint32_t ha_copy; | |
9001 | unsigned long status; | |
5b75da2f | 9002 | unsigned long iflag; |
9399627f JS |
9003 | |
9004 | /* Get the driver's phba structure from the dev_id and | |
9005 | * assume the HBA is not interrupting. | |
9006 | */ | |
9007 | phba = (struct lpfc_hba *) dev_id; | |
9008 | ||
9009 | if (unlikely(!phba)) | |
9010 | return IRQ_NONE; | |
9011 | ||
9012 | /* | |
9013 | * Stuff needs to be attented to when this function is invoked as an | |
9014 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
9015 | */ | |
9016 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
9017 | /* Check device state for handling interrupt */ |
9018 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
9019 | return IRQ_NONE; |
9020 | /* Need to read HA REG for FCP ring and other ring events */ | |
9940b97b JS |
9021 | if (lpfc_readl(phba->HAregaddr, &ha_copy)) |
9022 | return IRQ_HANDLED; | |
9399627f | 9023 | /* Clear up only attention source related to fast-path */ |
5b75da2f | 9024 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
9025 | /* |
9026 | * If there is deferred error attention, do not check for | |
9027 | * any interrupt. | |
9028 | */ | |
9029 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 9030 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
9031 | return IRQ_NONE; |
9032 | } | |
9399627f JS |
9033 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
9034 | phba->HAregaddr); | |
9035 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 9036 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
9037 | } else |
9038 | ha_copy = phba->ha_copy; | |
dea3101e JB |
9039 | |
9040 | /* | |
9399627f | 9041 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 9042 | */ |
9399627f JS |
9043 | ha_copy &= ~(phba->work_ha_mask); |
9044 | ||
9045 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 9046 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 9047 | if (status & HA_RXMASK) |
dea3101e JB |
9048 | lpfc_sli_handle_fast_ring_event(phba, |
9049 | &phba->sli.ring[LPFC_FCP_RING], | |
9050 | status); | |
a4bc3379 JS |
9051 | |
9052 | if (phba->cfg_multi_ring_support == 2) { | |
9053 | /* | |
9399627f JS |
9054 | * Process all events on extra ring. Take the optimized path |
9055 | * for extra ring IO. | |
a4bc3379 | 9056 | */ |
9399627f | 9057 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 9058 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 9059 | if (status & HA_RXMASK) { |
a4bc3379 JS |
9060 | lpfc_sli_handle_fast_ring_event(phba, |
9061 | &phba->sli.ring[LPFC_EXTRA_RING], | |
9062 | status); | |
9063 | } | |
9064 | } | |
dea3101e | 9065 | return IRQ_HANDLED; |
3772a991 | 9066 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
9067 | |
9068 | /** | |
3772a991 | 9069 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
9070 | * @irq: Interrupt number. |
9071 | * @dev_id: The device context pointer. | |
9072 | * | |
3772a991 JS |
9073 | * This function is the HBA device-level interrupt handler to device with |
9074 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
9075 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
9076 | * requires driver attention. This function invokes the slow-path interrupt | |
9077 | * attention handling function and fast-path interrupt attention handling | |
9078 | * function in turn to process the relevant HBA attention events. This | |
9079 | * function is called without any lock held. It gets the hbalock to access | |
9080 | * and update SLI data structures. | |
9399627f JS |
9081 | * |
9082 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
9083 | * returns IRQ_NONE. | |
9084 | **/ | |
9085 | irqreturn_t | |
3772a991 | 9086 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
9087 | { |
9088 | struct lpfc_hba *phba; | |
9089 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
9090 | unsigned long status1, status2; | |
a747c9ce | 9091 | uint32_t hc_copy; |
9399627f JS |
9092 | |
9093 | /* | |
9094 | * Get the driver's phba structure from the dev_id and | |
9095 | * assume the HBA is not interrupting. | |
9096 | */ | |
9097 | phba = (struct lpfc_hba *) dev_id; | |
9098 | ||
9099 | if (unlikely(!phba)) | |
9100 | return IRQ_NONE; | |
9101 | ||
3772a991 JS |
9102 | /* Check device state for handling interrupt */ |
9103 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
9104 | return IRQ_NONE; |
9105 | ||
9106 | spin_lock(&phba->hbalock); | |
9940b97b JS |
9107 | if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) { |
9108 | spin_unlock(&phba->hbalock); | |
9109 | return IRQ_HANDLED; | |
9110 | } | |
9111 | ||
9399627f JS |
9112 | if (unlikely(!phba->ha_copy)) { |
9113 | spin_unlock(&phba->hbalock); | |
9114 | return IRQ_NONE; | |
9115 | } else if (phba->ha_copy & HA_ERATT) { | |
9116 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
9117 | /* ERATT polling has handled ERATT */ | |
9118 | phba->ha_copy &= ~HA_ERATT; | |
9119 | else | |
9120 | /* Indicate interrupt handler handles ERATT */ | |
9121 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
9122 | } | |
9123 | ||
a257bf90 JS |
9124 | /* |
9125 | * If there is deferred error attention, do not check for any interrupt. | |
9126 | */ | |
9127 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 9128 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
9129 | return IRQ_NONE; |
9130 | } | |
9131 | ||
9399627f | 9132 | /* Clear attention sources except link and error attentions */ |
9940b97b JS |
9133 | if (lpfc_readl(phba->HCregaddr, &hc_copy)) { |
9134 | spin_unlock(&phba->hbalock); | |
9135 | return IRQ_HANDLED; | |
9136 | } | |
a747c9ce JS |
9137 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA |
9138 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
9139 | phba->HCregaddr); | |
9399627f | 9140 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 9141 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
9142 | readl(phba->HAregaddr); /* flush */ |
9143 | spin_unlock(&phba->hbalock); | |
9144 | ||
9145 | /* | |
9146 | * Invokes slow-path host attention interrupt handling as appropriate. | |
9147 | */ | |
9148 | ||
9149 | /* status of events with mailbox and link attention */ | |
9150 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
9151 | ||
9152 | /* status of events with ELS ring */ | |
9153 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
9154 | status2 >>= (4*LPFC_ELS_RING); | |
9155 | ||
9156 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 9157 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
9158 | else |
9159 | sp_irq_rc = IRQ_NONE; | |
9160 | ||
9161 | /* | |
9162 | * Invoke fast-path host attention interrupt handling as appropriate. | |
9163 | */ | |
9164 | ||
9165 | /* status of events with FCP ring */ | |
9166 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
9167 | status1 >>= (4*LPFC_FCP_RING); | |
9168 | ||
9169 | /* status of events with extra ring */ | |
9170 | if (phba->cfg_multi_ring_support == 2) { | |
9171 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
9172 | status2 >>= (4*LPFC_EXTRA_RING); | |
9173 | } else | |
9174 | status2 = 0; | |
9175 | ||
9176 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 9177 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
9178 | else |
9179 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 9180 | |
9399627f JS |
9181 | /* Return device-level interrupt handling status */ |
9182 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 9183 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
9184 | |
9185 | /** | |
9186 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
9187 | * @phba: pointer to lpfc hba data structure. | |
9188 | * | |
9189 | * This routine is invoked by the worker thread to process all the pending | |
9190 | * SLI4 FCP abort XRI events. | |
9191 | **/ | |
9192 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
9193 | { | |
9194 | struct lpfc_cq_event *cq_event; | |
9195 | ||
9196 | /* First, declare the fcp xri abort event has been handled */ | |
9197 | spin_lock_irq(&phba->hbalock); | |
9198 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
9199 | spin_unlock_irq(&phba->hbalock); | |
9200 | /* Now, handle all the fcp xri abort events */ | |
9201 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
9202 | /* Get the first event from the head of the event queue */ | |
9203 | spin_lock_irq(&phba->hbalock); | |
9204 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
9205 | cq_event, struct lpfc_cq_event, list); | |
9206 | spin_unlock_irq(&phba->hbalock); | |
9207 | /* Notify aborted XRI for FCP work queue */ | |
9208 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
9209 | /* Free the event processed back to the free pool */ | |
9210 | lpfc_sli4_cq_event_release(phba, cq_event); | |
9211 | } | |
9212 | } | |
9213 | ||
9214 | /** | |
9215 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
9216 | * @phba: pointer to lpfc hba data structure. | |
9217 | * | |
9218 | * This routine is invoked by the worker thread to process all the pending | |
9219 | * SLI4 els abort xri events. | |
9220 | **/ | |
9221 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
9222 | { | |
9223 | struct lpfc_cq_event *cq_event; | |
9224 | ||
9225 | /* First, declare the els xri abort event has been handled */ | |
9226 | spin_lock_irq(&phba->hbalock); | |
9227 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
9228 | spin_unlock_irq(&phba->hbalock); | |
9229 | /* Now, handle all the els xri abort events */ | |
9230 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
9231 | /* Get the first event from the head of the event queue */ | |
9232 | spin_lock_irq(&phba->hbalock); | |
9233 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
9234 | cq_event, struct lpfc_cq_event, list); | |
9235 | spin_unlock_irq(&phba->hbalock); | |
9236 | /* Notify aborted XRI for ELS work queue */ | |
9237 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
9238 | /* Free the event processed back to the free pool */ | |
9239 | lpfc_sli4_cq_event_release(phba, cq_event); | |
9240 | } | |
9241 | } | |
9242 | ||
341af102 JS |
9243 | /** |
9244 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
9245 | * @phba: pointer to lpfc hba data structure | |
9246 | * @pIocbIn: pointer to the rspiocbq | |
9247 | * @pIocbOut: pointer to the cmdiocbq | |
9248 | * @wcqe: pointer to the complete wcqe | |
9249 | * | |
9250 | * This routine transfers the fields of a command iocbq to a response iocbq | |
9251 | * by copying all the IOCB fields from command iocbq and transferring the | |
9252 | * completion status information from the complete wcqe. | |
9253 | **/ | |
4f774513 | 9254 | static void |
341af102 JS |
9255 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
9256 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
9257 | struct lpfc_iocbq *pIocbOut, |
9258 | struct lpfc_wcqe_complete *wcqe) | |
9259 | { | |
341af102 | 9260 | unsigned long iflags; |
4f774513 JS |
9261 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
9262 | ||
9263 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
9264 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 JS |
9265 | /* Map WCQE parameters into irspiocb parameters */ |
9266 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | |
9267 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | |
9268 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
9269 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
9270 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
9271 | wcqe->total_data_placed; | |
9272 | else | |
9273 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 9274 | else { |
4f774513 | 9275 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
9276 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
9277 | } | |
341af102 JS |
9278 | |
9279 | /* Pick up HBA exchange busy condition */ | |
9280 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
9281 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9282 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
9283 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9284 | } | |
4f774513 JS |
9285 | } |
9286 | ||
45ed1190 JS |
9287 | /** |
9288 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
9289 | * @phba: Pointer to HBA context object. | |
9290 | * @wcqe: Pointer to work-queue completion queue entry. | |
9291 | * | |
9292 | * This routine handles an ELS work-queue completion event and construct | |
9293 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
9294 | * discovery engine to handle. | |
9295 | * | |
9296 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
9297 | **/ | |
9298 | static struct lpfc_iocbq * | |
9299 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
9300 | struct lpfc_iocbq *irspiocbq) | |
9301 | { | |
9302 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
9303 | struct lpfc_iocbq *cmdiocbq; | |
9304 | struct lpfc_wcqe_complete *wcqe; | |
9305 | unsigned long iflags; | |
9306 | ||
9307 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
9308 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9309 | pring->stats.iocb_event++; | |
9310 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
9311 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9312 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9313 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9314 | ||
9315 | if (unlikely(!cmdiocbq)) { | |
9316 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9317 | "0386 ELS complete with no corresponding " | |
9318 | "cmdiocb: iotag (%d)\n", | |
9319 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9320 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
9321 | return NULL; | |
9322 | } | |
9323 | ||
9324 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 9325 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
9326 | |
9327 | return irspiocbq; | |
9328 | } | |
9329 | ||
04c68496 JS |
9330 | /** |
9331 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
9332 | * @phba: Pointer to HBA context object. | |
9333 | * @cqe: Pointer to mailbox completion queue entry. | |
9334 | * | |
9335 | * This routine process a mailbox completion queue entry with asynchrous | |
9336 | * event. | |
9337 | * | |
9338 | * Return: true if work posted to worker thread, otherwise false. | |
9339 | **/ | |
9340 | static bool | |
9341 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
9342 | { | |
9343 | struct lpfc_cq_event *cq_event; | |
9344 | unsigned long iflags; | |
9345 | ||
9346 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9347 | "0392 Async Event: word0:x%x, word1:x%x, " | |
9348 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
9349 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
9350 | ||
9351 | /* Allocate a new internal CQ_EVENT entry */ | |
9352 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
9353 | if (!cq_event) { | |
9354 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9355 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
9356 | return false; | |
9357 | } | |
9358 | ||
9359 | /* Move the CQE into an asynchronous event entry */ | |
9360 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
9361 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9362 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
9363 | /* Set the async event flag */ | |
9364 | phba->hba_flag |= ASYNC_EVENT; | |
9365 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9366 | ||
9367 | return true; | |
9368 | } | |
9369 | ||
9370 | /** | |
9371 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
9372 | * @phba: Pointer to HBA context object. | |
9373 | * @cqe: Pointer to mailbox completion queue entry. | |
9374 | * | |
9375 | * This routine process a mailbox completion queue entry with mailbox | |
9376 | * completion event. | |
9377 | * | |
9378 | * Return: true if work posted to worker thread, otherwise false. | |
9379 | **/ | |
9380 | static bool | |
9381 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
9382 | { | |
9383 | uint32_t mcqe_status; | |
9384 | MAILBOX_t *mbox, *pmbox; | |
9385 | struct lpfc_mqe *mqe; | |
9386 | struct lpfc_vport *vport; | |
9387 | struct lpfc_nodelist *ndlp; | |
9388 | struct lpfc_dmabuf *mp; | |
9389 | unsigned long iflags; | |
9390 | LPFC_MBOXQ_t *pmb; | |
9391 | bool workposted = false; | |
9392 | int rc; | |
9393 | ||
9394 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
9395 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
9396 | goto out_no_mqe_complete; | |
9397 | ||
9398 | /* Get the reference to the active mbox command */ | |
9399 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9400 | pmb = phba->sli.mbox_active; | |
9401 | if (unlikely(!pmb)) { | |
9402 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
9403 | "1832 No pending MBOX command to handle\n"); | |
9404 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9405 | goto out_no_mqe_complete; | |
9406 | } | |
9407 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9408 | mqe = &pmb->u.mqe; | |
9409 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
9410 | mbox = phba->mbox; | |
9411 | vport = pmb->vport; | |
9412 | ||
9413 | /* Reset heartbeat timer */ | |
9414 | phba->last_completion_time = jiffies; | |
9415 | del_timer(&phba->sli.mbox_tmo); | |
9416 | ||
9417 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
9418 | if (pmb->mbox_cmpl && mbox) | |
9419 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
9420 | /* Set the mailbox status with SLI4 range 0x4000 */ | |
9421 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
9422 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) | |
9423 | bf_set(lpfc_mqe_status, mqe, | |
9424 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
9425 | ||
9426 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
9427 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
9428 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
9429 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
9430 | mcqe_status, | |
9431 | pmbox->un.varWords[0], 0); | |
9432 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
9433 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
9434 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
9435 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
9436 | * RID of the PPI using the same mbox buffer. | |
9437 | */ | |
9438 | lpfc_unreg_login(phba, vport->vpi, | |
9439 | pmbox->un.varWords[0], pmb); | |
9440 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
9441 | pmb->context1 = mp; | |
9442 | pmb->context2 = ndlp; | |
9443 | pmb->vport = vport; | |
9444 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
9445 | if (rc != MBX_BUSY) | |
9446 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
9447 | LOG_SLI, "0385 rc should " | |
9448 | "have been MBX_BUSY\n"); | |
9449 | if (rc != MBX_NOT_FINISHED) | |
9450 | goto send_current_mbox; | |
9451 | } | |
9452 | } | |
9453 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
9454 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
9455 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
9456 | ||
9457 | /* There is mailbox completion work to do */ | |
9458 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9459 | __lpfc_mbox_cmpl_put(phba, pmb); | |
9460 | phba->work_ha |= HA_MBATT; | |
9461 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9462 | workposted = true; | |
9463 | ||
9464 | send_current_mbox: | |
9465 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9466 | /* Release the mailbox command posting token */ | |
9467 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9468 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
9469 | phba->sli.mbox_active = NULL; | |
9470 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9471 | /* Wake up worker thread to post the next pending mailbox command */ | |
9472 | lpfc_worker_wake_up(phba); | |
9473 | out_no_mqe_complete: | |
9474 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
9475 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
9476 | return workposted; | |
9477 | } | |
9478 | ||
9479 | /** | |
9480 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
9481 | * @phba: Pointer to HBA context object. | |
9482 | * @cqe: Pointer to mailbox completion queue entry. | |
9483 | * | |
9484 | * This routine process a mailbox completion queue entry, it invokes the | |
9485 | * proper mailbox complete handling or asynchrous event handling routine | |
9486 | * according to the MCQE's async bit. | |
9487 | * | |
9488 | * Return: true if work posted to worker thread, otherwise false. | |
9489 | **/ | |
9490 | static bool | |
9491 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
9492 | { | |
9493 | struct lpfc_mcqe mcqe; | |
9494 | bool workposted; | |
9495 | ||
9496 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
9497 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
9498 | ||
9499 | /* Invoke the proper event handling routine */ | |
9500 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
9501 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
9502 | else | |
9503 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
9504 | return workposted; | |
9505 | } | |
9506 | ||
4f774513 JS |
9507 | /** |
9508 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
9509 | * @phba: Pointer to HBA context object. | |
9510 | * @wcqe: Pointer to work-queue completion queue entry. | |
9511 | * | |
9512 | * This routine handles an ELS work-queue completion event. | |
9513 | * | |
9514 | * Return: true if work posted to worker thread, otherwise false. | |
9515 | **/ | |
9516 | static bool | |
9517 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | |
9518 | struct lpfc_wcqe_complete *wcqe) | |
9519 | { | |
4f774513 JS |
9520 | struct lpfc_iocbq *irspiocbq; |
9521 | unsigned long iflags; | |
2a9bf3d0 | 9522 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
4f774513 | 9523 | |
45ed1190 | 9524 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
9525 | irspiocbq = lpfc_sli_get_iocbq(phba); |
9526 | if (!irspiocbq) { | |
9527 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
9528 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
9529 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
9530 | pring->txq_cnt, phba->iocb_cnt, | |
9531 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
9532 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 9533 | return false; |
4f774513 | 9534 | } |
4f774513 | 9535 | |
45ed1190 JS |
9536 | /* Save off the slow-path queue event for work thread to process */ |
9537 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 9538 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 9539 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
9540 | &phba->sli4_hba.sp_queue_event); |
9541 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 9542 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 9543 | |
45ed1190 | 9544 | return true; |
4f774513 JS |
9545 | } |
9546 | ||
9547 | /** | |
9548 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
9549 | * @phba: Pointer to HBA context object. | |
9550 | * @wcqe: Pointer to work-queue completion queue entry. | |
9551 | * | |
9552 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
9553 | * proper WQ release routine to the slow-path WQ. | |
9554 | **/ | |
9555 | static void | |
9556 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
9557 | struct lpfc_wcqe_release *wcqe) | |
9558 | { | |
9559 | /* Check for the slow-path ELS work queue */ | |
9560 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
9561 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
9562 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9563 | else | |
9564 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9565 | "2579 Slow-path wqe consume event carries " | |
9566 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
9567 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
9568 | phba->sli4_hba.els_wq->queue_id); | |
9569 | } | |
9570 | ||
9571 | /** | |
9572 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
9573 | * @phba: Pointer to HBA context object. | |
9574 | * @cq: Pointer to a WQ completion queue. | |
9575 | * @wcqe: Pointer to work-queue completion queue entry. | |
9576 | * | |
9577 | * This routine handles an XRI abort event. | |
9578 | * | |
9579 | * Return: true if work posted to worker thread, otherwise false. | |
9580 | **/ | |
9581 | static bool | |
9582 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
9583 | struct lpfc_queue *cq, | |
9584 | struct sli4_wcqe_xri_aborted *wcqe) | |
9585 | { | |
9586 | bool workposted = false; | |
9587 | struct lpfc_cq_event *cq_event; | |
9588 | unsigned long iflags; | |
9589 | ||
9590 | /* Allocate a new internal CQ_EVENT entry */ | |
9591 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
9592 | if (!cq_event) { | |
9593 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9594 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
9595 | return false; | |
9596 | } | |
9597 | ||
9598 | /* Move the CQE into the proper xri abort event list */ | |
9599 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
9600 | switch (cq->subtype) { | |
9601 | case LPFC_FCP: | |
9602 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9603 | list_add_tail(&cq_event->list, | |
9604 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
9605 | /* Set the fcp xri abort event flag */ | |
9606 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
9607 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9608 | workposted = true; | |
9609 | break; | |
9610 | case LPFC_ELS: | |
9611 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9612 | list_add_tail(&cq_event->list, | |
9613 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
9614 | /* Set the els xri abort event flag */ | |
9615 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
9616 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9617 | workposted = true; | |
9618 | break; | |
9619 | default: | |
9620 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9621 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
9622 | cq->subtype); | |
9623 | workposted = false; | |
9624 | break; | |
9625 | } | |
9626 | return workposted; | |
9627 | } | |
9628 | ||
4f774513 JS |
9629 | /** |
9630 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
9631 | * @phba: Pointer to HBA context object. | |
9632 | * @rcqe: Pointer to receive-queue completion queue entry. | |
9633 | * | |
9634 | * This routine process a receive-queue completion queue entry. | |
9635 | * | |
9636 | * Return: true if work posted to worker thread, otherwise false. | |
9637 | **/ | |
9638 | static bool | |
4d9ab994 | 9639 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 9640 | { |
4f774513 JS |
9641 | bool workposted = false; |
9642 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
9643 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
9644 | struct hbq_dmabuf *dma_buf; | |
9645 | uint32_t status; | |
9646 | unsigned long iflags; | |
9647 | ||
4d9ab994 | 9648 | if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id) |
4f774513 JS |
9649 | goto out; |
9650 | ||
4d9ab994 | 9651 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
9652 | switch (status) { |
9653 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
9654 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9655 | "2537 Receive Frame Truncated!!\n"); | |
9656 | case FC_STATUS_RQ_SUCCESS: | |
5ffc266e | 9657 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
9658 | spin_lock_irqsave(&phba->hbalock, iflags); |
9659 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
9660 | if (!dma_buf) { | |
9661 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9662 | goto out; | |
9663 | } | |
4d9ab994 | 9664 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 9665 | /* save off the frame for the word thread to process */ |
4d9ab994 | 9666 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 9667 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 9668 | /* Frame received */ |
45ed1190 | 9669 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
9670 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
9671 | workposted = true; | |
9672 | break; | |
9673 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
9674 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
9675 | /* Post more buffers if possible */ | |
9676 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9677 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
9678 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9679 | workposted = true; | |
9680 | break; | |
9681 | } | |
9682 | out: | |
9683 | return workposted; | |
4f774513 JS |
9684 | } |
9685 | ||
4d9ab994 JS |
9686 | /** |
9687 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
9688 | * @phba: Pointer to HBA context object. | |
9689 | * @cq: Pointer to the completion queue. | |
9690 | * @wcqe: Pointer to a completion queue entry. | |
9691 | * | |
25985edc | 9692 | * This routine process a slow-path work-queue or receive queue completion queue |
4d9ab994 JS |
9693 | * entry. |
9694 | * | |
9695 | * Return: true if work posted to worker thread, otherwise false. | |
9696 | **/ | |
9697 | static bool | |
9698 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9699 | struct lpfc_cqe *cqe) | |
9700 | { | |
45ed1190 | 9701 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
9702 | bool workposted = false; |
9703 | ||
9704 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 9705 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
9706 | |
9707 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 9708 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 9709 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 9710 | /* Process the WQ/RQ complete event */ |
bc73905a | 9711 | phba->last_completion_time = jiffies; |
4d9ab994 | 9712 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
45ed1190 | 9713 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
9714 | break; |
9715 | case CQE_CODE_RELEASE_WQE: | |
9716 | /* Process the WQ release event */ | |
9717 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 9718 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
9719 | break; |
9720 | case CQE_CODE_XRI_ABORTED: | |
9721 | /* Process the WQ XRI abort event */ | |
bc73905a | 9722 | phba->last_completion_time = jiffies; |
4d9ab994 | 9723 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 9724 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
9725 | break; |
9726 | case CQE_CODE_RECEIVE: | |
9727 | /* Process the RQ event */ | |
bc73905a | 9728 | phba->last_completion_time = jiffies; |
4d9ab994 | 9729 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 9730 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
9731 | break; |
9732 | default: | |
9733 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9734 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 9735 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
9736 | break; |
9737 | } | |
9738 | return workposted; | |
9739 | } | |
9740 | ||
4f774513 JS |
9741 | /** |
9742 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
9743 | * @phba: Pointer to HBA context object. | |
9744 | * @eqe: Pointer to fast-path event queue entry. | |
9745 | * | |
9746 | * This routine process a event queue entry from the slow-path event queue. | |
9747 | * It will check the MajorCode and MinorCode to determine this is for a | |
9748 | * completion event on a completion queue, if not, an error shall be logged | |
9749 | * and just return. Otherwise, it will get to the corresponding completion | |
9750 | * queue and process all the entries on that completion queue, rearm the | |
9751 | * completion queue, and then return. | |
9752 | * | |
9753 | **/ | |
9754 | static void | |
9755 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
9756 | { | |
9757 | struct lpfc_queue *cq = NULL, *childq, *speq; | |
9758 | struct lpfc_cqe *cqe; | |
9759 | bool workposted = false; | |
9760 | int ecount = 0; | |
9761 | uint16_t cqid; | |
9762 | ||
cb5172ea | 9763 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
4f774513 JS |
9764 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9765 | "0359 Not a valid slow-path completion " | |
9766 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9767 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9768 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9769 | return; |
9770 | } | |
9771 | ||
9772 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9773 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9774 | |
9775 | /* Search for completion queue pointer matching this cqid */ | |
9776 | speq = phba->sli4_hba.sp_eq; | |
9777 | list_for_each_entry(childq, &speq->child_list, list) { | |
9778 | if (childq->queue_id == cqid) { | |
9779 | cq = childq; | |
9780 | break; | |
9781 | } | |
9782 | } | |
9783 | if (unlikely(!cq)) { | |
75baf696 JS |
9784 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
9785 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9786 | "0365 Slow-path CQ identifier " | |
9787 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
9788 | return; |
9789 | } | |
9790 | ||
9791 | /* Process all the entries to the CQ */ | |
9792 | switch (cq->type) { | |
9793 | case LPFC_MCQ: | |
9794 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9795 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
9796 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9797 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9798 | } | |
9799 | break; | |
9800 | case LPFC_WCQ: | |
9801 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
4d9ab994 | 9802 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe); |
4f774513 JS |
9803 | if (!(++ecount % LPFC_GET_QE_REL_INT)) |
9804 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9805 | } | |
9806 | break; | |
9807 | default: | |
9808 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9809 | "0370 Invalid completion queue type (%d)\n", | |
9810 | cq->type); | |
9811 | return; | |
9812 | } | |
9813 | ||
9814 | /* Catch the no cq entry condition, log an error */ | |
9815 | if (unlikely(ecount == 0)) | |
9816 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9817 | "0371 No entry from the CQ: identifier " | |
9818 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
9819 | ||
9820 | /* In any case, flash and re-arm the RCQ */ | |
9821 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9822 | ||
9823 | /* wake up worker thread if there are works to be done */ | |
9824 | if (workposted) | |
9825 | lpfc_worker_wake_up(phba); | |
9826 | } | |
9827 | ||
9828 | /** | |
9829 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
9830 | * @eqe: Pointer to fast-path completion queue entry. | |
9831 | * | |
9832 | * This routine process a fast-path work queue completion entry from fast-path | |
9833 | * event queue for FCP command response completion. | |
9834 | **/ | |
9835 | static void | |
9836 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | |
9837 | struct lpfc_wcqe_complete *wcqe) | |
9838 | { | |
9839 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | |
9840 | struct lpfc_iocbq *cmdiocbq; | |
9841 | struct lpfc_iocbq irspiocbq; | |
9842 | unsigned long iflags; | |
9843 | ||
9844 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9845 | pring->stats.iocb_event++; | |
9846 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9847 | ||
9848 | /* Check for response status */ | |
9849 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
9850 | /* If resource errors reported from HBA, reduce queue | |
9851 | * depth of the SCSI device. | |
9852 | */ | |
9853 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
9854 | IOSTAT_LOCAL_REJECT) && | |
9855 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
9856 | phba->lpfc_rampdown_queue_depth(phba); | |
9857 | } | |
9858 | /* Log the error status */ | |
9859 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9860 | "0373 FCP complete error: status=x%x, " | |
9861 | "hw_status=x%x, total_data_specified=%d, " | |
9862 | "parameter=x%x, word3=x%x\n", | |
9863 | bf_get(lpfc_wcqe_c_status, wcqe), | |
9864 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
9865 | wcqe->total_data_placed, wcqe->parameter, | |
9866 | wcqe->word3); | |
9867 | } | |
9868 | ||
9869 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
9870 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9871 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9872 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9873 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9874 | if (unlikely(!cmdiocbq)) { | |
9875 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9876 | "0374 FCP complete with no corresponding " | |
9877 | "cmdiocb: iotag (%d)\n", | |
9878 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9879 | return; | |
9880 | } | |
9881 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
9882 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9883 | "0375 FCP cmdiocb not callback function " | |
9884 | "iotag: (%d)\n", | |
9885 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9886 | return; | |
9887 | } | |
9888 | ||
9889 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 9890 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 9891 | |
0f65ff68 JS |
9892 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
9893 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9894 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
9895 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9896 | } | |
9897 | ||
4f774513 JS |
9898 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
9899 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
9900 | } | |
9901 | ||
9902 | /** | |
9903 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
9904 | * @phba: Pointer to HBA context object. | |
9905 | * @cq: Pointer to completion queue. | |
9906 | * @wcqe: Pointer to work-queue completion queue entry. | |
9907 | * | |
9908 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
9909 | * proper WQ release routine to the slow-path WQ. | |
9910 | **/ | |
9911 | static void | |
9912 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9913 | struct lpfc_wcqe_release *wcqe) | |
9914 | { | |
9915 | struct lpfc_queue *childwq; | |
9916 | bool wqid_matched = false; | |
9917 | uint16_t fcp_wqid; | |
9918 | ||
9919 | /* Check for fast-path FCP work queue release */ | |
9920 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
9921 | list_for_each_entry(childwq, &cq->child_list, list) { | |
9922 | if (childwq->queue_id == fcp_wqid) { | |
9923 | lpfc_sli4_wq_release(childwq, | |
9924 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9925 | wqid_matched = true; | |
9926 | break; | |
9927 | } | |
9928 | } | |
9929 | /* Report warning log message if no match found */ | |
9930 | if (wqid_matched != true) | |
9931 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9932 | "2580 Fast-path wqe consume event carries " | |
9933 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
9934 | } | |
9935 | ||
9936 | /** | |
9937 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
9938 | * @cq: Pointer to the completion queue. | |
9939 | * @eqe: Pointer to fast-path completion queue entry. | |
9940 | * | |
9941 | * This routine process a fast-path work queue completion entry from fast-path | |
9942 | * event queue for FCP command response completion. | |
9943 | **/ | |
9944 | static int | |
9945 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9946 | struct lpfc_cqe *cqe) | |
9947 | { | |
9948 | struct lpfc_wcqe_release wcqe; | |
9949 | bool workposted = false; | |
9950 | ||
9951 | /* Copy the work queue CQE and convert endian order if needed */ | |
9952 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
9953 | ||
9954 | /* Check and process for different type of WCQE and dispatch */ | |
9955 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
9956 | case CQE_CODE_COMPL_WQE: | |
9957 | /* Process the WQ complete event */ | |
98fc5dd9 | 9958 | phba->last_completion_time = jiffies; |
4f774513 JS |
9959 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
9960 | (struct lpfc_wcqe_complete *)&wcqe); | |
9961 | break; | |
9962 | case CQE_CODE_RELEASE_WQE: | |
9963 | /* Process the WQ release event */ | |
9964 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
9965 | (struct lpfc_wcqe_release *)&wcqe); | |
9966 | break; | |
9967 | case CQE_CODE_XRI_ABORTED: | |
9968 | /* Process the WQ XRI abort event */ | |
bc73905a | 9969 | phba->last_completion_time = jiffies; |
4f774513 JS |
9970 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
9971 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
9972 | break; | |
9973 | default: | |
9974 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9975 | "0144 Not a valid WCQE code: x%x\n", | |
9976 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
9977 | break; | |
9978 | } | |
9979 | return workposted; | |
9980 | } | |
9981 | ||
9982 | /** | |
9983 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | |
9984 | * @phba: Pointer to HBA context object. | |
9985 | * @eqe: Pointer to fast-path event queue entry. | |
9986 | * | |
9987 | * This routine process a event queue entry from the fast-path event queue. | |
9988 | * It will check the MajorCode and MinorCode to determine this is for a | |
9989 | * completion event on a completion queue, if not, an error shall be logged | |
9990 | * and just return. Otherwise, it will get to the corresponding completion | |
9991 | * queue and process all the entries on the completion queue, rearm the | |
9992 | * completion queue, and then return. | |
9993 | **/ | |
9994 | static void | |
9995 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | |
9996 | uint32_t fcp_cqidx) | |
9997 | { | |
9998 | struct lpfc_queue *cq; | |
9999 | struct lpfc_cqe *cqe; | |
10000 | bool workposted = false; | |
10001 | uint16_t cqid; | |
10002 | int ecount = 0; | |
10003 | ||
cb5172ea | 10004 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 JS |
10005 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
10006 | "0366 Not a valid fast-path completion " | |
10007 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
10008 | bf_get_le32(lpfc_eqe_major_code, eqe), |
10009 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
10010 | return; |
10011 | } | |
10012 | ||
10013 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | |
10014 | if (unlikely(!cq)) { | |
75baf696 JS |
10015 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
10016 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10017 | "0367 Fast-path completion queue " | |
10018 | "does not exist\n"); | |
4f774513 JS |
10019 | return; |
10020 | } | |
10021 | ||
10022 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 10023 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
10024 | if (unlikely(cqid != cq->queue_id)) { |
10025 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10026 | "0368 Miss-matched fast-path completion " | |
10027 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
10028 | cqid, cq->queue_id); | |
10029 | return; | |
10030 | } | |
10031 | ||
10032 | /* Process all the entries to the CQ */ | |
10033 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
10034 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
10035 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10036 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
10037 | } | |
10038 | ||
10039 | /* Catch the no cq entry condition */ | |
10040 | if (unlikely(ecount == 0)) | |
10041 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10042 | "0369 No entry from fast-path completion " | |
10043 | "queue fcpcqid=%d\n", cq->queue_id); | |
10044 | ||
10045 | /* In any case, flash and re-arm the CQ */ | |
10046 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
10047 | ||
10048 | /* wake up worker thread if there are works to be done */ | |
10049 | if (workposted) | |
10050 | lpfc_worker_wake_up(phba); | |
10051 | } | |
10052 | ||
10053 | static void | |
10054 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
10055 | { | |
10056 | struct lpfc_eqe *eqe; | |
10057 | ||
10058 | /* walk all the EQ entries and drop on the floor */ | |
10059 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
10060 | ; | |
10061 | ||
10062 | /* Clear and re-arm the EQ */ | |
10063 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
10064 | } | |
10065 | ||
10066 | /** | |
10067 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | |
10068 | * @irq: Interrupt number. | |
10069 | * @dev_id: The device context pointer. | |
10070 | * | |
10071 | * This function is directly called from the PCI layer as an interrupt | |
10072 | * service routine when device with SLI-4 interface spec is enabled with | |
10073 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
10074 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
10075 | * interrupt mode, this function is called as part of the device-level | |
10076 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | |
10077 | * undergoing initialization, the interrupt handler will not process the | |
10078 | * interrupt. The link attention and ELS ring attention events are handled | |
10079 | * by the worker thread. The interrupt handler signals the worker thread | |
10080 | * and returns for these events. This function is called without any lock | |
10081 | * held. It gets the hbalock to access and update SLI data structures. | |
10082 | * | |
10083 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10084 | * returns IRQ_NONE. | |
10085 | **/ | |
10086 | irqreturn_t | |
10087 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | |
10088 | { | |
10089 | struct lpfc_hba *phba; | |
10090 | struct lpfc_queue *speq; | |
10091 | struct lpfc_eqe *eqe; | |
10092 | unsigned long iflag; | |
10093 | int ecount = 0; | |
10094 | ||
10095 | /* | |
10096 | * Get the driver's phba structure from the dev_id | |
10097 | */ | |
10098 | phba = (struct lpfc_hba *)dev_id; | |
10099 | ||
10100 | if (unlikely(!phba)) | |
10101 | return IRQ_NONE; | |
10102 | ||
10103 | /* Get to the EQ struct associated with this vector */ | |
10104 | speq = phba->sli4_hba.sp_eq; | |
10105 | ||
10106 | /* Check device state for handling interrupt */ | |
10107 | if (unlikely(lpfc_intr_state_check(phba))) { | |
10108 | /* Check again for link_state with lock held */ | |
10109 | spin_lock_irqsave(&phba->hbalock, iflag); | |
10110 | if (phba->link_state < LPFC_LINK_DOWN) | |
10111 | /* Flush, clear interrupt, and rearm the EQ */ | |
10112 | lpfc_sli4_eq_flush(phba, speq); | |
10113 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10114 | return IRQ_NONE; | |
10115 | } | |
10116 | ||
10117 | /* | |
10118 | * Process all the event on FCP slow-path EQ | |
10119 | */ | |
10120 | while ((eqe = lpfc_sli4_eq_get(speq))) { | |
10121 | lpfc_sli4_sp_handle_eqe(phba, eqe); | |
10122 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10123 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); | |
10124 | } | |
10125 | ||
10126 | /* Always clear and re-arm the slow-path EQ */ | |
10127 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | |
10128 | ||
10129 | /* Catch the no cq entry condition */ | |
10130 | if (unlikely(ecount == 0)) { | |
10131 | if (phba->intr_type == MSIX) | |
10132 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10133 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10134 | "0357 MSI-X interrupt with no EQE\n"); | |
10135 | else | |
10136 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10137 | return IRQ_NONE; | |
10138 | } | |
10139 | ||
10140 | return IRQ_HANDLED; | |
10141 | } /* lpfc_sli4_sp_intr_handler */ | |
10142 | ||
10143 | /** | |
10144 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | |
10145 | * @irq: Interrupt number. | |
10146 | * @dev_id: The device context pointer. | |
10147 | * | |
10148 | * This function is directly called from the PCI layer as an interrupt | |
10149 | * service routine when device with SLI-4 interface spec is enabled with | |
10150 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10151 | * ring event in the HBA. However, when the device is enabled with either | |
10152 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10153 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10154 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10155 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
10156 | * the intrrupt context. This function is called without any lock held. | |
10157 | * It gets the hbalock to access and update SLI data structures. Note that, | |
10158 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
10159 | * equal to that of FCP CQ index. | |
10160 | * | |
10161 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10162 | * returns IRQ_NONE. | |
10163 | **/ | |
10164 | irqreturn_t | |
10165 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | |
10166 | { | |
10167 | struct lpfc_hba *phba; | |
10168 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
10169 | struct lpfc_queue *fpeq; | |
10170 | struct lpfc_eqe *eqe; | |
10171 | unsigned long iflag; | |
10172 | int ecount = 0; | |
10173 | uint32_t fcp_eqidx; | |
10174 | ||
10175 | /* Get the driver's phba structure from the dev_id */ | |
10176 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
10177 | phba = fcp_eq_hdl->phba; | |
10178 | fcp_eqidx = fcp_eq_hdl->idx; | |
10179 | ||
10180 | if (unlikely(!phba)) | |
10181 | return IRQ_NONE; | |
10182 | ||
10183 | /* Get to the EQ struct associated with this vector */ | |
10184 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | |
10185 | ||
10186 | /* Check device state for handling interrupt */ | |
10187 | if (unlikely(lpfc_intr_state_check(phba))) { | |
10188 | /* Check again for link_state with lock held */ | |
10189 | spin_lock_irqsave(&phba->hbalock, iflag); | |
10190 | if (phba->link_state < LPFC_LINK_DOWN) | |
10191 | /* Flush, clear interrupt, and rearm the EQ */ | |
10192 | lpfc_sli4_eq_flush(phba, fpeq); | |
10193 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10194 | return IRQ_NONE; | |
10195 | } | |
10196 | ||
10197 | /* | |
10198 | * Process all the event on FCP fast-path EQ | |
10199 | */ | |
10200 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
10201 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | |
10202 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10203 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); | |
10204 | } | |
10205 | ||
10206 | /* Always clear and re-arm the fast-path EQ */ | |
10207 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
10208 | ||
10209 | if (unlikely(ecount == 0)) { | |
10210 | if (phba->intr_type == MSIX) | |
10211 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10212 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10213 | "0358 MSI-X interrupt with no EQE\n"); | |
10214 | else | |
10215 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10216 | return IRQ_NONE; | |
10217 | } | |
10218 | ||
10219 | return IRQ_HANDLED; | |
10220 | } /* lpfc_sli4_fp_intr_handler */ | |
10221 | ||
10222 | /** | |
10223 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
10224 | * @irq: Interrupt number. | |
10225 | * @dev_id: The device context pointer. | |
10226 | * | |
10227 | * This function is the device-level interrupt handler to device with SLI-4 | |
10228 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
10229 | * interrupt mode is enabled and there is an event in the HBA which requires | |
10230 | * driver attention. This function invokes the slow-path interrupt attention | |
10231 | * handling function and fast-path interrupt attention handling function in | |
10232 | * turn to process the relevant HBA attention events. This function is called | |
10233 | * without any lock held. It gets the hbalock to access and update SLI data | |
10234 | * structures. | |
10235 | * | |
10236 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
10237 | * returns IRQ_NONE. | |
10238 | **/ | |
10239 | irqreturn_t | |
10240 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
10241 | { | |
10242 | struct lpfc_hba *phba; | |
10243 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
10244 | bool fp_handled = false; | |
10245 | uint32_t fcp_eqidx; | |
10246 | ||
10247 | /* Get the driver's phba structure from the dev_id */ | |
10248 | phba = (struct lpfc_hba *)dev_id; | |
10249 | ||
10250 | if (unlikely(!phba)) | |
10251 | return IRQ_NONE; | |
10252 | ||
10253 | /* | |
10254 | * Invokes slow-path host attention interrupt handling as appropriate. | |
10255 | */ | |
10256 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | |
10257 | ||
10258 | /* | |
10259 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10260 | */ | |
10261 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
10262 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | |
10263 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | |
10264 | if (fp_irq_rc == IRQ_HANDLED) | |
10265 | fp_handled |= true; | |
10266 | } | |
10267 | ||
10268 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | |
10269 | } /* lpfc_sli4_intr_handler */ | |
10270 | ||
10271 | /** | |
10272 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
10273 | * @queue: The queue structure to free. | |
10274 | * | |
b595076a | 10275 | * This function frees a queue structure and the DMAable memory used for |
4f774513 JS |
10276 | * the host resident queue. This function must be called after destroying the |
10277 | * queue on the HBA. | |
10278 | **/ | |
10279 | void | |
10280 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
10281 | { | |
10282 | struct lpfc_dmabuf *dmabuf; | |
10283 | ||
10284 | if (!queue) | |
10285 | return; | |
10286 | ||
10287 | while (!list_empty(&queue->page_list)) { | |
10288 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
10289 | list); | |
49198b37 | 10290 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
10291 | dmabuf->virt, dmabuf->phys); |
10292 | kfree(dmabuf); | |
10293 | } | |
10294 | kfree(queue); | |
10295 | return; | |
10296 | } | |
10297 | ||
10298 | /** | |
10299 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
10300 | * @phba: The HBA that this queue is being created on. | |
10301 | * @entry_size: The size of each queue entry for this queue. | |
10302 | * @entry count: The number of entries that this queue will handle. | |
10303 | * | |
10304 | * This function allocates a queue structure and the DMAable memory used for | |
10305 | * the host resident queue. This function must be called before creating the | |
10306 | * queue on the HBA. | |
10307 | **/ | |
10308 | struct lpfc_queue * | |
10309 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
10310 | uint32_t entry_count) | |
10311 | { | |
10312 | struct lpfc_queue *queue; | |
10313 | struct lpfc_dmabuf *dmabuf; | |
10314 | int x, total_qe_count; | |
10315 | void *dma_pointer; | |
cb5172ea | 10316 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 10317 | |
cb5172ea JS |
10318 | if (!phba->sli4_hba.pc_sli4_params.supported) |
10319 | hw_page_size = SLI4_PAGE_SIZE; | |
10320 | ||
4f774513 JS |
10321 | queue = kzalloc(sizeof(struct lpfc_queue) + |
10322 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
10323 | if (!queue) | |
10324 | return NULL; | |
cb5172ea JS |
10325 | queue->page_count = (ALIGN(entry_size * entry_count, |
10326 | hw_page_size))/hw_page_size; | |
4f774513 JS |
10327 | INIT_LIST_HEAD(&queue->list); |
10328 | INIT_LIST_HEAD(&queue->page_list); | |
10329 | INIT_LIST_HEAD(&queue->child_list); | |
10330 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
10331 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
10332 | if (!dmabuf) | |
10333 | goto out_fail; | |
10334 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 10335 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
10336 | GFP_KERNEL); |
10337 | if (!dmabuf->virt) { | |
10338 | kfree(dmabuf); | |
10339 | goto out_fail; | |
10340 | } | |
cb5172ea | 10341 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10342 | dmabuf->buffer_tag = x; |
10343 | list_add_tail(&dmabuf->list, &queue->page_list); | |
10344 | /* initialize queue's entry array */ | |
10345 | dma_pointer = dmabuf->virt; | |
10346 | for (; total_qe_count < entry_count && | |
cb5172ea | 10347 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
10348 | total_qe_count++, dma_pointer += entry_size) { |
10349 | queue->qe[total_qe_count].address = dma_pointer; | |
10350 | } | |
10351 | } | |
10352 | queue->entry_size = entry_size; | |
10353 | queue->entry_count = entry_count; | |
10354 | queue->phba = phba; | |
10355 | ||
10356 | return queue; | |
10357 | out_fail: | |
10358 | lpfc_sli4_queue_free(queue); | |
10359 | return NULL; | |
10360 | } | |
10361 | ||
10362 | /** | |
10363 | * lpfc_eq_create - Create an Event Queue on the HBA | |
10364 | * @phba: HBA structure that indicates port to create a queue on. | |
10365 | * @eq: The queue structure to use to create the event queue. | |
10366 | * @imax: The maximum interrupt per second limit. | |
10367 | * | |
10368 | * This function creates an event queue, as detailed in @eq, on a port, | |
10369 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
10370 | * | |
10371 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
10372 | * is used to get the entry count and entry size that are necessary to | |
10373 | * determine the number of pages to allocate and use for this queue. This | |
10374 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
10375 | * event queue. This function is asynchronous and will wait for the mailbox | |
10376 | * command to finish before continuing. | |
10377 | * | |
10378 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10379 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10380 | * fails this function will return -ENXIO. | |
4f774513 JS |
10381 | **/ |
10382 | uint32_t | |
10383 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
10384 | { | |
10385 | struct lpfc_mbx_eq_create *eq_create; | |
10386 | LPFC_MBOXQ_t *mbox; | |
10387 | int rc, length, status = 0; | |
10388 | struct lpfc_dmabuf *dmabuf; | |
10389 | uint32_t shdr_status, shdr_add_status; | |
10390 | union lpfc_sli4_cfg_shdr *shdr; | |
10391 | uint16_t dmult; | |
49198b37 JS |
10392 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10393 | ||
10394 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10395 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10396 | |
10397 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10398 | if (!mbox) | |
10399 | return -ENOMEM; | |
10400 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
10401 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10402 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10403 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
10404 | length, LPFC_SLI4_MBX_EMBED); | |
10405 | eq_create = &mbox->u.mqe.un.eq_create; | |
10406 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
10407 | eq->page_count); | |
10408 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
10409 | LPFC_EQE_SIZE); | |
10410 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
10411 | /* Calculate delay multiper from maximum interrupt per second */ | |
10412 | dmult = LPFC_DMULT_CONST/imax - 1; | |
10413 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
10414 | dmult); | |
10415 | switch (eq->entry_count) { | |
10416 | default: | |
10417 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10418 | "0360 Unsupported EQ count. (%d)\n", | |
10419 | eq->entry_count); | |
10420 | if (eq->entry_count < 256) | |
10421 | return -EINVAL; | |
10422 | /* otherwise default to smallest count (drop through) */ | |
10423 | case 256: | |
10424 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10425 | LPFC_EQ_CNT_256); | |
10426 | break; | |
10427 | case 512: | |
10428 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10429 | LPFC_EQ_CNT_512); | |
10430 | break; | |
10431 | case 1024: | |
10432 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10433 | LPFC_EQ_CNT_1024); | |
10434 | break; | |
10435 | case 2048: | |
10436 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10437 | LPFC_EQ_CNT_2048); | |
10438 | break; | |
10439 | case 4096: | |
10440 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10441 | LPFC_EQ_CNT_4096); | |
10442 | break; | |
10443 | } | |
10444 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 10445 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10446 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10447 | putPaddrLow(dmabuf->phys); | |
10448 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10449 | putPaddrHigh(dmabuf->phys); | |
10450 | } | |
10451 | mbox->vport = phba->pport; | |
10452 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10453 | mbox->context1 = NULL; | |
10454 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10455 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
10456 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10457 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10458 | if (shdr_status || shdr_add_status || rc) { | |
10459 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10460 | "2500 EQ_CREATE mailbox failed with " | |
10461 | "status x%x add_status x%x, mbx status x%x\n", | |
10462 | shdr_status, shdr_add_status, rc); | |
10463 | status = -ENXIO; | |
10464 | } | |
10465 | eq->type = LPFC_EQ; | |
10466 | eq->subtype = LPFC_NONE; | |
10467 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
10468 | if (eq->queue_id == 0xFFFF) | |
10469 | status = -ENXIO; | |
10470 | eq->host_index = 0; | |
10471 | eq->hba_index = 0; | |
10472 | ||
8fa38513 | 10473 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10474 | return status; |
10475 | } | |
10476 | ||
10477 | /** | |
10478 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
10479 | * @phba: HBA structure that indicates port to create a queue on. | |
10480 | * @cq: The queue structure to use to create the completion queue. | |
10481 | * @eq: The event queue to bind this completion queue to. | |
10482 | * | |
10483 | * This function creates a completion queue, as detailed in @wq, on a port, | |
10484 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
10485 | * | |
10486 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
10487 | * is used to get the entry count and entry size that are necessary to | |
10488 | * determine the number of pages to allocate and use for this queue. The @eq | |
10489 | * is used to indicate which event queue to bind this completion queue to. This | |
10490 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
10491 | * completion queue. This function is asynchronous and will wait for the mailbox | |
10492 | * command to finish before continuing. | |
10493 | * | |
10494 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10495 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10496 | * fails this function will return -ENXIO. | |
4f774513 JS |
10497 | **/ |
10498 | uint32_t | |
10499 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
10500 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
10501 | { | |
10502 | struct lpfc_mbx_cq_create *cq_create; | |
10503 | struct lpfc_dmabuf *dmabuf; | |
10504 | LPFC_MBOXQ_t *mbox; | |
10505 | int rc, length, status = 0; | |
10506 | uint32_t shdr_status, shdr_add_status; | |
10507 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10508 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10509 | ||
10510 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10511 | hw_page_size = SLI4_PAGE_SIZE; | |
10512 | ||
4f774513 JS |
10513 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
10514 | if (!mbox) | |
10515 | return -ENOMEM; | |
10516 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
10517 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10518 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10519 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
10520 | length, LPFC_SLI4_MBX_EMBED); | |
10521 | cq_create = &mbox->u.mqe.un.cq_create; | |
5a6f133e | 10522 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; |
4f774513 JS |
10523 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, |
10524 | cq->page_count); | |
10525 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
10526 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
5a6f133e JS |
10527 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
10528 | phba->sli4_hba.pc_sli4_params.cqv); | |
10529 | if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) { | |
c31098ce JS |
10530 | /* FW only supports 1. Should be PAGE_SIZE/SLI4_PAGE_SIZE */ |
10531 | bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request, 1); | |
5a6f133e JS |
10532 | bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context, |
10533 | eq->queue_id); | |
10534 | } else { | |
10535 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, | |
10536 | eq->queue_id); | |
10537 | } | |
4f774513 JS |
10538 | switch (cq->entry_count) { |
10539 | default: | |
10540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10541 | "0361 Unsupported CQ count. (%d)\n", | |
10542 | cq->entry_count); | |
10543 | if (cq->entry_count < 256) | |
10544 | return -EINVAL; | |
10545 | /* otherwise default to smallest count (drop through) */ | |
10546 | case 256: | |
10547 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10548 | LPFC_CQ_CNT_256); | |
10549 | break; | |
10550 | case 512: | |
10551 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10552 | LPFC_CQ_CNT_512); | |
10553 | break; | |
10554 | case 1024: | |
10555 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10556 | LPFC_CQ_CNT_1024); | |
10557 | break; | |
10558 | } | |
10559 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 10560 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10561 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10562 | putPaddrLow(dmabuf->phys); | |
10563 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10564 | putPaddrHigh(dmabuf->phys); | |
10565 | } | |
10566 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10567 | ||
10568 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
10569 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
10570 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10571 | if (shdr_status || shdr_add_status || rc) { | |
10572 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10573 | "2501 CQ_CREATE mailbox failed with " | |
10574 | "status x%x add_status x%x, mbx status x%x\n", | |
10575 | shdr_status, shdr_add_status, rc); | |
10576 | status = -ENXIO; | |
10577 | goto out; | |
10578 | } | |
10579 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
10580 | if (cq->queue_id == 0xFFFF) { | |
10581 | status = -ENXIO; | |
10582 | goto out; | |
10583 | } | |
10584 | /* link the cq onto the parent eq child list */ | |
10585 | list_add_tail(&cq->list, &eq->child_list); | |
10586 | /* Set up completion queue's type and subtype */ | |
10587 | cq->type = type; | |
10588 | cq->subtype = subtype; | |
10589 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
2a622bfb | 10590 | cq->assoc_qid = eq->queue_id; |
4f774513 JS |
10591 | cq->host_index = 0; |
10592 | cq->hba_index = 0; | |
4f774513 | 10593 | |
8fa38513 JS |
10594 | out: |
10595 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
10596 | return status; |
10597 | } | |
10598 | ||
b19a061a JS |
10599 | /** |
10600 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
10601 | * @phba: HBA structure that indicates port to create a queue on. | |
10602 | * @mq: The queue structure to use to create the mailbox queue. | |
10603 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
10604 | * @cq: The completion queue to associate with this cq. | |
10605 | * | |
10606 | * This function provides failback (fb) functionality when the | |
10607 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
10608 | * to mq_create_ext otherwise. | |
10609 | * | |
10610 | * This routine cannot fail as all attributes were previously accessed and | |
10611 | * initialized in mq_create_ext. | |
10612 | **/ | |
10613 | static void | |
10614 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
10615 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
10616 | { | |
10617 | struct lpfc_mbx_mq_create *mq_create; | |
10618 | struct lpfc_dmabuf *dmabuf; | |
10619 | int length; | |
10620 | ||
10621 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
10622 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10623 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10624 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
10625 | length, LPFC_SLI4_MBX_EMBED); | |
10626 | mq_create = &mbox->u.mqe.un.mq_create; | |
10627 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
10628 | mq->page_count); | |
10629 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
10630 | cq->queue_id); | |
10631 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
10632 | switch (mq->entry_count) { | |
10633 | case 16: | |
5a6f133e JS |
10634 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
10635 | LPFC_MQ_RING_SIZE_16); | |
b19a061a JS |
10636 | break; |
10637 | case 32: | |
5a6f133e JS |
10638 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
10639 | LPFC_MQ_RING_SIZE_32); | |
b19a061a JS |
10640 | break; |
10641 | case 64: | |
5a6f133e JS |
10642 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
10643 | LPFC_MQ_RING_SIZE_64); | |
b19a061a JS |
10644 | break; |
10645 | case 128: | |
5a6f133e JS |
10646 | bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context, |
10647 | LPFC_MQ_RING_SIZE_128); | |
b19a061a JS |
10648 | break; |
10649 | } | |
10650 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
10651 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
10652 | putPaddrLow(dmabuf->phys); | |
10653 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10654 | putPaddrHigh(dmabuf->phys); | |
10655 | } | |
10656 | } | |
10657 | ||
04c68496 JS |
10658 | /** |
10659 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
10660 | * @phba: HBA structure that indicates port to create a queue on. | |
10661 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
10662 | * @cq: The completion queue to associate with this cq. |
10663 | * @subtype: The queue's subtype. | |
04c68496 JS |
10664 | * |
10665 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
10666 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
10667 | * | |
10668 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
10669 | * is used to get the entry count and entry size that are necessary to | |
10670 | * determine the number of pages to allocate and use for this queue. This | |
10671 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
10672 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
10673 | * command to finish before continuing. | |
10674 | * | |
10675 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10676 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10677 | * fails this function will return -ENXIO. | |
04c68496 | 10678 | **/ |
b19a061a | 10679 | int32_t |
04c68496 JS |
10680 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
10681 | struct lpfc_queue *cq, uint32_t subtype) | |
10682 | { | |
10683 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 10684 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
10685 | struct lpfc_dmabuf *dmabuf; |
10686 | LPFC_MBOXQ_t *mbox; | |
10687 | int rc, length, status = 0; | |
10688 | uint32_t shdr_status, shdr_add_status; | |
10689 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 10690 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 10691 | |
49198b37 JS |
10692 | if (!phba->sli4_hba.pc_sli4_params.supported) |
10693 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 10694 | |
04c68496 JS |
10695 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
10696 | if (!mbox) | |
10697 | return -ENOMEM; | |
b19a061a | 10698 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
10699 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
10700 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 10701 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 10702 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
10703 | |
10704 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
5a6f133e | 10705 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
70f3c073 JS |
10706 | bf_set(lpfc_mbx_mq_create_ext_num_pages, |
10707 | &mq_create_ext->u.request, mq->page_count); | |
10708 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, | |
10709 | &mq_create_ext->u.request, 1); | |
10710 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fip, | |
b19a061a JS |
10711 | &mq_create_ext->u.request, 1); |
10712 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
10713 | &mq_create_ext->u.request, 1); | |
70f3c073 JS |
10714 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fc, |
10715 | &mq_create_ext->u.request, 1); | |
10716 | bf_set(lpfc_mbx_mq_create_ext_async_evt_sli, | |
10717 | &mq_create_ext->u.request, 1); | |
b19a061a | 10718 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); |
5a6f133e JS |
10719 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
10720 | phba->sli4_hba.pc_sli4_params.mqv); | |
10721 | if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1) | |
10722 | bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request, | |
10723 | cq->queue_id); | |
10724 | else | |
10725 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
10726 | cq->queue_id); | |
04c68496 JS |
10727 | switch (mq->entry_count) { |
10728 | default: | |
10729 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10730 | "0362 Unsupported MQ count. (%d)\n", | |
10731 | mq->entry_count); | |
10732 | if (mq->entry_count < 16) | |
10733 | return -EINVAL; | |
10734 | /* otherwise default to smallest count (drop through) */ | |
10735 | case 16: | |
5a6f133e JS |
10736 | bf_set(lpfc_mq_context_ring_size, |
10737 | &mq_create_ext->u.request.context, | |
10738 | LPFC_MQ_RING_SIZE_16); | |
04c68496 JS |
10739 | break; |
10740 | case 32: | |
5a6f133e JS |
10741 | bf_set(lpfc_mq_context_ring_size, |
10742 | &mq_create_ext->u.request.context, | |
10743 | LPFC_MQ_RING_SIZE_32); | |
04c68496 JS |
10744 | break; |
10745 | case 64: | |
5a6f133e JS |
10746 | bf_set(lpfc_mq_context_ring_size, |
10747 | &mq_create_ext->u.request.context, | |
10748 | LPFC_MQ_RING_SIZE_64); | |
04c68496 JS |
10749 | break; |
10750 | case 128: | |
5a6f133e JS |
10751 | bf_set(lpfc_mq_context_ring_size, |
10752 | &mq_create_ext->u.request.context, | |
10753 | LPFC_MQ_RING_SIZE_128); | |
04c68496 JS |
10754 | break; |
10755 | } | |
10756 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 10757 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 10758 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 10759 | putPaddrLow(dmabuf->phys); |
b19a061a | 10760 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
10761 | putPaddrHigh(dmabuf->phys); |
10762 | } | |
10763 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
10764 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, |
10765 | &mq_create_ext->u.response); | |
10766 | if (rc != MBX_SUCCESS) { | |
10767 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10768 | "2795 MQ_CREATE_EXT failed with " | |
10769 | "status x%x. Failback to MQ_CREATE.\n", | |
10770 | rc); | |
10771 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
10772 | mq_create = &mbox->u.mqe.un.mq_create; | |
10773 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10774 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
10775 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10776 | &mq_create->u.response); | |
10777 | } | |
10778 | ||
04c68496 | 10779 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
10780 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
10781 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10782 | if (shdr_status || shdr_add_status || rc) { | |
10783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10784 | "2502 MQ_CREATE mailbox failed with " | |
10785 | "status x%x add_status x%x, mbx status x%x\n", | |
10786 | shdr_status, shdr_add_status, rc); | |
10787 | status = -ENXIO; | |
10788 | goto out; | |
10789 | } | |
04c68496 JS |
10790 | if (mq->queue_id == 0xFFFF) { |
10791 | status = -ENXIO; | |
10792 | goto out; | |
10793 | } | |
10794 | mq->type = LPFC_MQ; | |
2a622bfb | 10795 | mq->assoc_qid = cq->queue_id; |
04c68496 JS |
10796 | mq->subtype = subtype; |
10797 | mq->host_index = 0; | |
10798 | mq->hba_index = 0; | |
10799 | ||
10800 | /* link the mq onto the parent cq child list */ | |
10801 | list_add_tail(&mq->list, &cq->child_list); | |
10802 | out: | |
8fa38513 | 10803 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
10804 | return status; |
10805 | } | |
10806 | ||
4f774513 JS |
10807 | /** |
10808 | * lpfc_wq_create - Create a Work Queue on the HBA | |
10809 | * @phba: HBA structure that indicates port to create a queue on. | |
10810 | * @wq: The queue structure to use to create the work queue. | |
10811 | * @cq: The completion queue to bind this work queue to. | |
10812 | * @subtype: The subtype of the work queue indicating its functionality. | |
10813 | * | |
10814 | * This function creates a work queue, as detailed in @wq, on a port, described | |
10815 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
10816 | * | |
10817 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
10818 | * is used to get the entry count and entry size that are necessary to | |
10819 | * determine the number of pages to allocate and use for this queue. The @cq | |
10820 | * is used to indicate which completion queue to bind this work queue to. This | |
10821 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
10822 | * work queue. This function is asynchronous and will wait for the mailbox | |
10823 | * command to finish before continuing. | |
10824 | * | |
10825 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10826 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10827 | * fails this function will return -ENXIO. | |
4f774513 JS |
10828 | **/ |
10829 | uint32_t | |
10830 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
10831 | struct lpfc_queue *cq, uint32_t subtype) | |
10832 | { | |
10833 | struct lpfc_mbx_wq_create *wq_create; | |
10834 | struct lpfc_dmabuf *dmabuf; | |
10835 | LPFC_MBOXQ_t *mbox; | |
10836 | int rc, length, status = 0; | |
10837 | uint32_t shdr_status, shdr_add_status; | |
10838 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 10839 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
5a6f133e | 10840 | struct dma_address *page; |
49198b37 JS |
10841 | |
10842 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10843 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10844 | |
10845 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10846 | if (!mbox) | |
10847 | return -ENOMEM; | |
10848 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
10849 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10850 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10851 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
10852 | length, LPFC_SLI4_MBX_EMBED); | |
10853 | wq_create = &mbox->u.mqe.un.wq_create; | |
5a6f133e | 10854 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; |
4f774513 JS |
10855 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, |
10856 | wq->page_count); | |
10857 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
10858 | cq->queue_id); | |
5a6f133e JS |
10859 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
10860 | phba->sli4_hba.pc_sli4_params.wqv); | |
10861 | if (phba->sli4_hba.pc_sli4_params.wqv == LPFC_Q_CREATE_VERSION_1) { | |
10862 | bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1, | |
10863 | wq->entry_count); | |
10864 | switch (wq->entry_size) { | |
10865 | default: | |
10866 | case 64: | |
10867 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
10868 | &wq_create->u.request_1, | |
10869 | LPFC_WQ_WQE_SIZE_64); | |
10870 | break; | |
10871 | case 128: | |
10872 | bf_set(lpfc_mbx_wq_create_wqe_size, | |
10873 | &wq_create->u.request_1, | |
10874 | LPFC_WQ_WQE_SIZE_128); | |
10875 | break; | |
10876 | } | |
10877 | bf_set(lpfc_mbx_wq_create_page_size, &wq_create->u.request_1, | |
10878 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
10879 | page = wq_create->u.request_1.page; | |
10880 | } else { | |
10881 | page = wq_create->u.request.page; | |
10882 | } | |
4f774513 | 10883 | list_for_each_entry(dmabuf, &wq->page_list, list) { |
49198b37 | 10884 | memset(dmabuf->virt, 0, hw_page_size); |
5a6f133e JS |
10885 | page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys); |
10886 | page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys); | |
4f774513 JS |
10887 | } |
10888 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10889 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
10890 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
10891 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10892 | if (shdr_status || shdr_add_status || rc) { | |
10893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10894 | "2503 WQ_CREATE mailbox failed with " | |
10895 | "status x%x add_status x%x, mbx status x%x\n", | |
10896 | shdr_status, shdr_add_status, rc); | |
10897 | status = -ENXIO; | |
10898 | goto out; | |
10899 | } | |
10900 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
10901 | if (wq->queue_id == 0xFFFF) { | |
10902 | status = -ENXIO; | |
10903 | goto out; | |
10904 | } | |
10905 | wq->type = LPFC_WQ; | |
2a622bfb | 10906 | wq->assoc_qid = cq->queue_id; |
4f774513 JS |
10907 | wq->subtype = subtype; |
10908 | wq->host_index = 0; | |
10909 | wq->hba_index = 0; | |
10910 | ||
10911 | /* link the wq onto the parent cq child list */ | |
10912 | list_add_tail(&wq->list, &cq->child_list); | |
10913 | out: | |
8fa38513 | 10914 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10915 | return status; |
10916 | } | |
10917 | ||
10918 | /** | |
10919 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
10920 | * @phba: HBA structure that indicates port to create a queue on. | |
10921 | * @hrq: The queue structure to use to create the header receive queue. | |
10922 | * @drq: The queue structure to use to create the data receive queue. | |
10923 | * @cq: The completion queue to bind this work queue to. | |
10924 | * | |
10925 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
10926 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
10927 | * to the HBA. | |
10928 | * | |
10929 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
10930 | * struct is used to get the entry count that is necessary to determine the | |
10931 | * number of pages to use for this queue. The @cq is used to indicate which | |
10932 | * completion queue to bind received buffers that are posted to these queues to. | |
10933 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
10934 | * receive queue pair. This function is asynchronous and will wait for the | |
10935 | * mailbox command to finish before continuing. | |
10936 | * | |
10937 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10938 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10939 | * fails this function will return -ENXIO. | |
4f774513 JS |
10940 | **/ |
10941 | uint32_t | |
10942 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
10943 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
10944 | { | |
10945 | struct lpfc_mbx_rq_create *rq_create; | |
10946 | struct lpfc_dmabuf *dmabuf; | |
10947 | LPFC_MBOXQ_t *mbox; | |
10948 | int rc, length, status = 0; | |
10949 | uint32_t shdr_status, shdr_add_status; | |
10950 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10951 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10952 | ||
10953 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10954 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10955 | |
10956 | if (hrq->entry_count != drq->entry_count) | |
10957 | return -EINVAL; | |
10958 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10959 | if (!mbox) | |
10960 | return -ENOMEM; | |
10961 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
10962 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10963 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10964 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10965 | length, LPFC_SLI4_MBX_EMBED); | |
10966 | rq_create = &mbox->u.mqe.un.rq_create; | |
5a6f133e JS |
10967 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; |
10968 | bf_set(lpfc_mbox_hdr_version, &shdr->request, | |
10969 | phba->sli4_hba.pc_sli4_params.rqv); | |
10970 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
10971 | bf_set(lpfc_rq_context_rqe_count_1, | |
10972 | &rq_create->u.request.context, | |
10973 | hrq->entry_count); | |
10974 | rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE; | |
c31098ce JS |
10975 | bf_set(lpfc_rq_context_rqe_size, |
10976 | &rq_create->u.request.context, | |
10977 | LPFC_RQE_SIZE_8); | |
10978 | bf_set(lpfc_rq_context_page_size, | |
10979 | &rq_create->u.request.context, | |
10980 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
10981 | } else { |
10982 | switch (hrq->entry_count) { | |
10983 | default: | |
10984 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10985 | "2535 Unsupported RQ count. (%d)\n", | |
10986 | hrq->entry_count); | |
10987 | if (hrq->entry_count < 512) | |
10988 | return -EINVAL; | |
10989 | /* otherwise default to smallest count (drop through) */ | |
10990 | case 512: | |
10991 | bf_set(lpfc_rq_context_rqe_count, | |
10992 | &rq_create->u.request.context, | |
10993 | LPFC_RQ_RING_SIZE_512); | |
10994 | break; | |
10995 | case 1024: | |
10996 | bf_set(lpfc_rq_context_rqe_count, | |
10997 | &rq_create->u.request.context, | |
10998 | LPFC_RQ_RING_SIZE_1024); | |
10999 | break; | |
11000 | case 2048: | |
11001 | bf_set(lpfc_rq_context_rqe_count, | |
11002 | &rq_create->u.request.context, | |
11003 | LPFC_RQ_RING_SIZE_2048); | |
11004 | break; | |
11005 | case 4096: | |
11006 | bf_set(lpfc_rq_context_rqe_count, | |
11007 | &rq_create->u.request.context, | |
11008 | LPFC_RQ_RING_SIZE_4096); | |
11009 | break; | |
11010 | } | |
11011 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
11012 | LPFC_HDR_BUF_SIZE); | |
4f774513 JS |
11013 | } |
11014 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
11015 | cq->queue_id); | |
11016 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
11017 | hrq->page_count); | |
4f774513 | 11018 | list_for_each_entry(dmabuf, &hrq->page_list, list) { |
49198b37 | 11019 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
11020 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
11021 | putPaddrLow(dmabuf->phys); | |
11022 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11023 | putPaddrHigh(dmabuf->phys); | |
11024 | } | |
11025 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11026 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
4f774513 JS |
11027 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
11028 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11029 | if (shdr_status || shdr_add_status || rc) { | |
11030 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11031 | "2504 RQ_CREATE mailbox failed with " | |
11032 | "status x%x add_status x%x, mbx status x%x\n", | |
11033 | shdr_status, shdr_add_status, rc); | |
11034 | status = -ENXIO; | |
11035 | goto out; | |
11036 | } | |
11037 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
11038 | if (hrq->queue_id == 0xFFFF) { | |
11039 | status = -ENXIO; | |
11040 | goto out; | |
11041 | } | |
11042 | hrq->type = LPFC_HRQ; | |
2a622bfb | 11043 | hrq->assoc_qid = cq->queue_id; |
4f774513 JS |
11044 | hrq->subtype = subtype; |
11045 | hrq->host_index = 0; | |
11046 | hrq->hba_index = 0; | |
11047 | ||
11048 | /* now create the data queue */ | |
11049 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11050 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
11051 | length, LPFC_SLI4_MBX_EMBED); | |
5a6f133e JS |
11052 | bf_set(lpfc_mbox_hdr_version, &shdr->request, |
11053 | phba->sli4_hba.pc_sli4_params.rqv); | |
11054 | if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) { | |
11055 | bf_set(lpfc_rq_context_rqe_count_1, | |
c31098ce | 11056 | &rq_create->u.request.context, hrq->entry_count); |
5a6f133e | 11057 | rq_create->u.request.context.buffer_size = LPFC_DATA_BUF_SIZE; |
c31098ce JS |
11058 | bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context, |
11059 | LPFC_RQE_SIZE_8); | |
11060 | bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context, | |
11061 | (PAGE_SIZE/SLI4_PAGE_SIZE)); | |
5a6f133e JS |
11062 | } else { |
11063 | switch (drq->entry_count) { | |
11064 | default: | |
11065 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11066 | "2536 Unsupported RQ count. (%d)\n", | |
11067 | drq->entry_count); | |
11068 | if (drq->entry_count < 512) | |
11069 | return -EINVAL; | |
11070 | /* otherwise default to smallest count (drop through) */ | |
11071 | case 512: | |
11072 | bf_set(lpfc_rq_context_rqe_count, | |
11073 | &rq_create->u.request.context, | |
11074 | LPFC_RQ_RING_SIZE_512); | |
11075 | break; | |
11076 | case 1024: | |
11077 | bf_set(lpfc_rq_context_rqe_count, | |
11078 | &rq_create->u.request.context, | |
11079 | LPFC_RQ_RING_SIZE_1024); | |
11080 | break; | |
11081 | case 2048: | |
11082 | bf_set(lpfc_rq_context_rqe_count, | |
11083 | &rq_create->u.request.context, | |
11084 | LPFC_RQ_RING_SIZE_2048); | |
11085 | break; | |
11086 | case 4096: | |
11087 | bf_set(lpfc_rq_context_rqe_count, | |
11088 | &rq_create->u.request.context, | |
11089 | LPFC_RQ_RING_SIZE_4096); | |
11090 | break; | |
11091 | } | |
11092 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
11093 | LPFC_DATA_BUF_SIZE); | |
4f774513 JS |
11094 | } |
11095 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
11096 | cq->queue_id); | |
11097 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
11098 | drq->page_count); | |
4f774513 JS |
11099 | list_for_each_entry(dmabuf, &drq->page_list, list) { |
11100 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
11101 | putPaddrLow(dmabuf->phys); | |
11102 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
11103 | putPaddrHigh(dmabuf->phys); | |
11104 | } | |
11105 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11106 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11107 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
11108 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11109 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11110 | if (shdr_status || shdr_add_status || rc) { | |
11111 | status = -ENXIO; | |
11112 | goto out; | |
11113 | } | |
11114 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
11115 | if (drq->queue_id == 0xFFFF) { | |
11116 | status = -ENXIO; | |
11117 | goto out; | |
11118 | } | |
11119 | drq->type = LPFC_DRQ; | |
2a622bfb | 11120 | drq->assoc_qid = cq->queue_id; |
4f774513 JS |
11121 | drq->subtype = subtype; |
11122 | drq->host_index = 0; | |
11123 | drq->hba_index = 0; | |
11124 | ||
11125 | /* link the header and data RQs onto the parent cq child list */ | |
11126 | list_add_tail(&hrq->list, &cq->child_list); | |
11127 | list_add_tail(&drq->list, &cq->child_list); | |
11128 | ||
11129 | out: | |
8fa38513 | 11130 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
11131 | return status; |
11132 | } | |
11133 | ||
11134 | /** | |
11135 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
11136 | * @eq: The queue structure associated with the queue to destroy. | |
11137 | * | |
11138 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
11139 | * command, specific to the type of queue, to the HBA. | |
11140 | * | |
11141 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
11142 | * | |
11143 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11144 | * command fails this function will return -ENXIO. |
4f774513 JS |
11145 | **/ |
11146 | uint32_t | |
11147 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
11148 | { | |
11149 | LPFC_MBOXQ_t *mbox; | |
11150 | int rc, length, status = 0; | |
11151 | uint32_t shdr_status, shdr_add_status; | |
11152 | union lpfc_sli4_cfg_shdr *shdr; | |
11153 | ||
11154 | if (!eq) | |
11155 | return -ENODEV; | |
11156 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
11157 | if (!mbox) | |
11158 | return -ENOMEM; | |
11159 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
11160 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11161 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11162 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
11163 | length, LPFC_SLI4_MBX_EMBED); | |
11164 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
11165 | eq->queue_id); | |
11166 | mbox->vport = eq->phba->pport; | |
11167 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11168 | ||
11169 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
11170 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11171 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11172 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
11173 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11174 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11175 | if (shdr_status || shdr_add_status || rc) { | |
11176 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11177 | "2505 EQ_DESTROY mailbox failed with " | |
11178 | "status x%x add_status x%x, mbx status x%x\n", | |
11179 | shdr_status, shdr_add_status, rc); | |
11180 | status = -ENXIO; | |
11181 | } | |
11182 | ||
11183 | /* Remove eq from any list */ | |
11184 | list_del_init(&eq->list); | |
8fa38513 | 11185 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
11186 | return status; |
11187 | } | |
11188 | ||
11189 | /** | |
11190 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
11191 | * @cq: The queue structure associated with the queue to destroy. | |
11192 | * | |
11193 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
11194 | * command, specific to the type of queue, to the HBA. | |
11195 | * | |
11196 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
11197 | * | |
11198 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11199 | * command fails this function will return -ENXIO. |
4f774513 JS |
11200 | **/ |
11201 | uint32_t | |
11202 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
11203 | { | |
11204 | LPFC_MBOXQ_t *mbox; | |
11205 | int rc, length, status = 0; | |
11206 | uint32_t shdr_status, shdr_add_status; | |
11207 | union lpfc_sli4_cfg_shdr *shdr; | |
11208 | ||
11209 | if (!cq) | |
11210 | return -ENODEV; | |
11211 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
11212 | if (!mbox) | |
11213 | return -ENOMEM; | |
11214 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
11215 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11216 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11217 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
11218 | length, LPFC_SLI4_MBX_EMBED); | |
11219 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
11220 | cq->queue_id); | |
11221 | mbox->vport = cq->phba->pport; | |
11222 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11223 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
11224 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11225 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11226 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
11227 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11228 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11229 | if (shdr_status || shdr_add_status || rc) { | |
11230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11231 | "2506 CQ_DESTROY mailbox failed with " | |
11232 | "status x%x add_status x%x, mbx status x%x\n", | |
11233 | shdr_status, shdr_add_status, rc); | |
11234 | status = -ENXIO; | |
11235 | } | |
11236 | /* Remove cq from any list */ | |
11237 | list_del_init(&cq->list); | |
8fa38513 | 11238 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
11239 | return status; |
11240 | } | |
11241 | ||
04c68496 JS |
11242 | /** |
11243 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
11244 | * @qm: The queue structure associated with the queue to destroy. | |
11245 | * | |
11246 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
11247 | * command, specific to the type of queue, to the HBA. | |
11248 | * | |
11249 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
11250 | * | |
11251 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11252 | * command fails this function will return -ENXIO. |
04c68496 JS |
11253 | **/ |
11254 | uint32_t | |
11255 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
11256 | { | |
11257 | LPFC_MBOXQ_t *mbox; | |
11258 | int rc, length, status = 0; | |
11259 | uint32_t shdr_status, shdr_add_status; | |
11260 | union lpfc_sli4_cfg_shdr *shdr; | |
11261 | ||
11262 | if (!mq) | |
11263 | return -ENODEV; | |
11264 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
11265 | if (!mbox) | |
11266 | return -ENOMEM; | |
11267 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
11268 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11269 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11270 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
11271 | length, LPFC_SLI4_MBX_EMBED); | |
11272 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
11273 | mq->queue_id); | |
11274 | mbox->vport = mq->phba->pport; | |
11275 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11276 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
11277 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11278 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11279 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
11280 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11281 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11282 | if (shdr_status || shdr_add_status || rc) { | |
11283 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11284 | "2507 MQ_DESTROY mailbox failed with " | |
11285 | "status x%x add_status x%x, mbx status x%x\n", | |
11286 | shdr_status, shdr_add_status, rc); | |
11287 | status = -ENXIO; | |
11288 | } | |
11289 | /* Remove mq from any list */ | |
11290 | list_del_init(&mq->list); | |
8fa38513 | 11291 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
11292 | return status; |
11293 | } | |
11294 | ||
4f774513 JS |
11295 | /** |
11296 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
11297 | * @wq: The queue structure associated with the queue to destroy. | |
11298 | * | |
11299 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
11300 | * command, specific to the type of queue, to the HBA. | |
11301 | * | |
11302 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
11303 | * | |
11304 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11305 | * command fails this function will return -ENXIO. |
4f774513 JS |
11306 | **/ |
11307 | uint32_t | |
11308 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
11309 | { | |
11310 | LPFC_MBOXQ_t *mbox; | |
11311 | int rc, length, status = 0; | |
11312 | uint32_t shdr_status, shdr_add_status; | |
11313 | union lpfc_sli4_cfg_shdr *shdr; | |
11314 | ||
11315 | if (!wq) | |
11316 | return -ENODEV; | |
11317 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
11318 | if (!mbox) | |
11319 | return -ENOMEM; | |
11320 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
11321 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11322 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11323 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
11324 | length, LPFC_SLI4_MBX_EMBED); | |
11325 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
11326 | wq->queue_id); | |
11327 | mbox->vport = wq->phba->pport; | |
11328 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11329 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
11330 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11331 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
11332 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11333 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11334 | if (shdr_status || shdr_add_status || rc) { | |
11335 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11336 | "2508 WQ_DESTROY mailbox failed with " | |
11337 | "status x%x add_status x%x, mbx status x%x\n", | |
11338 | shdr_status, shdr_add_status, rc); | |
11339 | status = -ENXIO; | |
11340 | } | |
11341 | /* Remove wq from any list */ | |
11342 | list_del_init(&wq->list); | |
8fa38513 | 11343 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
11344 | return status; |
11345 | } | |
11346 | ||
11347 | /** | |
11348 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
11349 | * @rq: The queue structure associated with the queue to destroy. | |
11350 | * | |
11351 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
11352 | * command, specific to the type of queue, to the HBA. | |
11353 | * | |
11354 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
11355 | * | |
11356 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11357 | * command fails this function will return -ENXIO. |
4f774513 JS |
11358 | **/ |
11359 | uint32_t | |
11360 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
11361 | struct lpfc_queue *drq) | |
11362 | { | |
11363 | LPFC_MBOXQ_t *mbox; | |
11364 | int rc, length, status = 0; | |
11365 | uint32_t shdr_status, shdr_add_status; | |
11366 | union lpfc_sli4_cfg_shdr *shdr; | |
11367 | ||
11368 | if (!hrq || !drq) | |
11369 | return -ENODEV; | |
11370 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
11371 | if (!mbox) | |
11372 | return -ENOMEM; | |
11373 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
fedd3b7b | 11374 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
4f774513 JS |
11375 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, |
11376 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
11377 | length, LPFC_SLI4_MBX_EMBED); | |
11378 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
11379 | hrq->queue_id); | |
11380 | mbox->vport = hrq->phba->pport; | |
11381 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11382 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
11383 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11384 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11385 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
11386 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11387 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11388 | if (shdr_status || shdr_add_status || rc) { | |
11389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11390 | "2509 RQ_DESTROY mailbox failed with " | |
11391 | "status x%x add_status x%x, mbx status x%x\n", | |
11392 | shdr_status, shdr_add_status, rc); | |
11393 | if (rc != MBX_TIMEOUT) | |
11394 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
11395 | return -ENXIO; | |
11396 | } | |
11397 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
11398 | drq->queue_id); | |
11399 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
11400 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11401 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
11402 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11403 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11404 | if (shdr_status || shdr_add_status || rc) { | |
11405 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11406 | "2510 RQ_DESTROY mailbox failed with " | |
11407 | "status x%x add_status x%x, mbx status x%x\n", | |
11408 | shdr_status, shdr_add_status, rc); | |
11409 | status = -ENXIO; | |
11410 | } | |
11411 | list_del_init(&hrq->list); | |
11412 | list_del_init(&drq->list); | |
8fa38513 | 11413 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
11414 | return status; |
11415 | } | |
11416 | ||
11417 | /** | |
11418 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
11419 | * @phba: The virtual port for which this call being executed. | |
11420 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
11421 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
11422 | * @xritag: the xritag that ties this io to the SGL pages. | |
11423 | * | |
11424 | * This routine will post the sgl pages for the IO that has the xritag | |
11425 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
11426 | * creation and persists for as long as the driver is loaded. | |
11427 | * if the caller has fewer than 256 scatter gather segments to map then | |
11428 | * pdma_phys_addr1 should be 0. | |
11429 | * If the caller needs to map more than 256 scatter gather segment then | |
11430 | * pdma_phys_addr1 should be a valid physical address. | |
11431 | * physical address for SGLs must be 64 byte aligned. | |
11432 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
11433 | * the second sgl can have between 1 and 256 entries. | |
11434 | * | |
11435 | * Return codes: | |
11436 | * 0 - Success | |
11437 | * -ENXIO, -ENOMEM - Failure | |
11438 | **/ | |
11439 | int | |
11440 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
11441 | dma_addr_t pdma_phys_addr0, | |
11442 | dma_addr_t pdma_phys_addr1, | |
11443 | uint16_t xritag) | |
11444 | { | |
11445 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
11446 | LPFC_MBOXQ_t *mbox; | |
11447 | int rc; | |
11448 | uint32_t shdr_status, shdr_add_status; | |
11449 | union lpfc_sli4_cfg_shdr *shdr; | |
11450 | ||
11451 | if (xritag == NO_XRI) { | |
11452 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11453 | "0364 Invalid param:\n"); | |
11454 | return -EINVAL; | |
11455 | } | |
11456 | ||
11457 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11458 | if (!mbox) | |
11459 | return -ENOMEM; | |
11460 | ||
11461 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11462 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
11463 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
fedd3b7b | 11464 | sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED); |
4f774513 JS |
11465 | |
11466 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
11467 | &mbox->u.mqe.un.post_sgl_pages; | |
11468 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
11469 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
11470 | ||
11471 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
11472 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
11473 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
11474 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
11475 | ||
11476 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
11477 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
11478 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
11479 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
11480 | if (!phba->sli4_hba.intr_enable) | |
11481 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11482 | else | |
11483 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
11484 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11485 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
11486 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11487 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11488 | if (rc != MBX_TIMEOUT) | |
11489 | mempool_free(mbox, phba->mbox_mem_pool); | |
11490 | if (shdr_status || shdr_add_status || rc) { | |
11491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11492 | "2511 POST_SGL mailbox failed with " | |
11493 | "status x%x add_status x%x, mbx status x%x\n", | |
11494 | shdr_status, shdr_add_status, rc); | |
11495 | rc = -ENXIO; | |
11496 | } | |
11497 | return 0; | |
11498 | } | |
4f774513 JS |
11499 | |
11500 | /** | |
11501 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
11502 | * @phba: Pointer to HBA context object. | |
11503 | * | |
11504 | * This function gets an xritag for the iocb. If there is no unused xritag | |
11505 | * it will return 0xffff. | |
11506 | * The function returns the allocated xritag if successful, else returns zero. | |
11507 | * Zero is not a valid xritag. | |
11508 | * The caller is not required to hold any lock. | |
11509 | **/ | |
11510 | uint16_t | |
11511 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
11512 | { | |
11513 | uint16_t xritag; | |
11514 | ||
11515 | spin_lock_irq(&phba->hbalock); | |
11516 | xritag = phba->sli4_hba.next_xri; | |
11517 | if ((xritag != (uint16_t) -1) && xritag < | |
11518 | (phba->sli4_hba.max_cfg_param.max_xri | |
11519 | + phba->sli4_hba.max_cfg_param.xri_base)) { | |
11520 | phba->sli4_hba.next_xri++; | |
11521 | phba->sli4_hba.max_cfg_param.xri_used++; | |
11522 | spin_unlock_irq(&phba->hbalock); | |
11523 | return xritag; | |
11524 | } | |
11525 | spin_unlock_irq(&phba->hbalock); | |
6a9c52cf | 11526 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
4f774513 JS |
11527 | "2004 Failed to allocate XRI.last XRITAG is %d" |
11528 | " Max XRI is %d, Used XRI is %d\n", | |
11529 | phba->sli4_hba.next_xri, | |
11530 | phba->sli4_hba.max_cfg_param.max_xri, | |
11531 | phba->sli4_hba.max_cfg_param.xri_used); | |
11532 | return -1; | |
11533 | } | |
11534 | ||
11535 | /** | |
11536 | * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware. | |
11537 | * @phba: pointer to lpfc hba data structure. | |
11538 | * | |
11539 | * This routine is invoked to post a block of driver's sgl pages to the | |
11540 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
11541 | * is only called when the driver is loading and after all IO has been | |
11542 | * stopped. | |
11543 | **/ | |
11544 | int | |
11545 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba) | |
11546 | { | |
11547 | struct lpfc_sglq *sglq_entry; | |
11548 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
11549 | struct sgl_page_pairs *sgl_pg_pairs; | |
11550 | void *viraddr; | |
11551 | LPFC_MBOXQ_t *mbox; | |
11552 | uint32_t reqlen, alloclen, pg_pairs; | |
11553 | uint32_t mbox_tmo; | |
11554 | uint16_t xritag_start = 0; | |
11555 | int els_xri_cnt, rc = 0; | |
11556 | uint32_t shdr_status, shdr_add_status; | |
11557 | union lpfc_sli4_cfg_shdr *shdr; | |
11558 | ||
11559 | /* The number of sgls to be posted */ | |
11560 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
11561 | ||
11562 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
11563 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 11564 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
11565 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
11566 | "2559 Block sgl registration required DMA " | |
11567 | "size (%d) great than a page\n", reqlen); | |
11568 | return -ENOMEM; | |
11569 | } | |
11570 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11571 | if (!mbox) { | |
11572 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11573 | "2560 Failed to allocate mbox cmd memory\n"); | |
11574 | return -ENOMEM; | |
11575 | } | |
11576 | ||
11577 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
11578 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11579 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
11580 | LPFC_SLI4_MBX_NEMBED); | |
11581 | ||
11582 | if (alloclen < reqlen) { | |
11583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11584 | "0285 Allocated DMA memory size (%d) is " | |
11585 | "less than the requested DMA memory " | |
11586 | "size (%d)\n", alloclen, reqlen); | |
11587 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11588 | return -ENOMEM; | |
11589 | } | |
4f774513 | 11590 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
11591 | viraddr = mbox->sge_array->addr[0]; |
11592 | ||
11593 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
11594 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
11595 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
11596 | ||
11597 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | |
11598 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | |
11599 | /* Set up the sge entry */ | |
11600 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
11601 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
11602 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
11603 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
11604 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
11605 | cpu_to_le32(putPaddrLow(0)); | |
11606 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
11607 | cpu_to_le32(putPaddrHigh(0)); | |
11608 | /* Keep the first xritag on the list */ | |
11609 | if (pg_pairs == 0) | |
11610 | xritag_start = sglq_entry->sli4_xritag; | |
11611 | sgl_pg_pairs++; | |
11612 | } | |
11613 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
6a9c52cf | 11614 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
4f774513 JS |
11615 | /* Perform endian conversion if necessary */ |
11616 | sgl->word0 = cpu_to_le32(sgl->word0); | |
11617 | ||
11618 | if (!phba->sli4_hba.intr_enable) | |
11619 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11620 | else { | |
11621 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11622 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11623 | } | |
11624 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11625 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11626 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11627 | if (rc != MBX_TIMEOUT) | |
11628 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11629 | if (shdr_status || shdr_add_status || rc) { | |
11630 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11631 | "2513 POST_SGL_BLOCK mailbox command failed " | |
11632 | "status x%x add_status x%x mbx status x%x\n", | |
11633 | shdr_status, shdr_add_status, rc); | |
11634 | rc = -ENXIO; | |
11635 | } | |
11636 | return rc; | |
11637 | } | |
11638 | ||
11639 | /** | |
11640 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
11641 | * @phba: pointer to lpfc hba data structure. | |
11642 | * @sblist: pointer to scsi buffer list. | |
11643 | * @count: number of scsi buffers on the list. | |
11644 | * | |
11645 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
11646 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
11647 | * No Lock is held. | |
11648 | * | |
11649 | **/ | |
11650 | int | |
11651 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | |
11652 | int cnt) | |
11653 | { | |
11654 | struct lpfc_scsi_buf *psb; | |
11655 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
11656 | struct sgl_page_pairs *sgl_pg_pairs; | |
11657 | void *viraddr; | |
11658 | LPFC_MBOXQ_t *mbox; | |
11659 | uint32_t reqlen, alloclen, pg_pairs; | |
11660 | uint32_t mbox_tmo; | |
11661 | uint16_t xritag_start = 0; | |
11662 | int rc = 0; | |
11663 | uint32_t shdr_status, shdr_add_status; | |
11664 | dma_addr_t pdma_phys_bpl1; | |
11665 | union lpfc_sli4_cfg_shdr *shdr; | |
11666 | ||
11667 | /* Calculate the requested length of the dma memory */ | |
11668 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
11669 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 11670 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
11671 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
11672 | "0217 Block sgl registration required DMA " | |
11673 | "size (%d) great than a page\n", reqlen); | |
11674 | return -ENOMEM; | |
11675 | } | |
11676 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11677 | if (!mbox) { | |
11678 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11679 | "0283 Failed to allocate mbox cmd memory\n"); | |
11680 | return -ENOMEM; | |
11681 | } | |
11682 | ||
11683 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
11684 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11685 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
11686 | LPFC_SLI4_MBX_NEMBED); | |
11687 | ||
11688 | if (alloclen < reqlen) { | |
11689 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11690 | "2561 Allocated DMA memory size (%d) is " | |
11691 | "less than the requested DMA memory " | |
11692 | "size (%d)\n", alloclen, reqlen); | |
11693 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11694 | return -ENOMEM; | |
11695 | } | |
4f774513 | 11696 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
11697 | viraddr = mbox->sge_array->addr[0]; |
11698 | ||
11699 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
11700 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
11701 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
11702 | ||
11703 | pg_pairs = 0; | |
11704 | list_for_each_entry(psb, sblist, list) { | |
11705 | /* Set up the sge entry */ | |
11706 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
11707 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
11708 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
11709 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
11710 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
11711 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
11712 | else | |
11713 | pdma_phys_bpl1 = 0; | |
11714 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
11715 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
11716 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
11717 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
11718 | /* Keep the first xritag on the list */ | |
11719 | if (pg_pairs == 0) | |
11720 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
11721 | sgl_pg_pairs++; | |
11722 | pg_pairs++; | |
11723 | } | |
11724 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
11725 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
11726 | /* Perform endian conversion if necessary */ | |
11727 | sgl->word0 = cpu_to_le32(sgl->word0); | |
11728 | ||
11729 | if (!phba->sli4_hba.intr_enable) | |
11730 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11731 | else { | |
11732 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11733 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11734 | } | |
11735 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11736 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11737 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11738 | if (rc != MBX_TIMEOUT) | |
11739 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11740 | if (shdr_status || shdr_add_status || rc) { | |
11741 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11742 | "2564 POST_SGL_BLOCK mailbox command failed " | |
11743 | "status x%x add_status x%x mbx status x%x\n", | |
11744 | shdr_status, shdr_add_status, rc); | |
11745 | rc = -ENXIO; | |
11746 | } | |
11747 | return rc; | |
11748 | } | |
11749 | ||
11750 | /** | |
11751 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
11752 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
11753 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11754 | * | |
11755 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
11756 | * valid type of frame that the LPFC driver will handle. This function will | |
11757 | * return a zero if the frame is a valid frame or a non zero value when the | |
11758 | * frame does not pass the check. | |
11759 | **/ | |
11760 | static int | |
11761 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
11762 | { | |
474ffb74 TH |
11763 | /* make rctl_names static to save stack space */ |
11764 | static char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
4f774513 JS |
11765 | char *type_names[] = FC_TYPE_NAMES_INIT; |
11766 | struct fc_vft_header *fc_vft_hdr; | |
546fc854 | 11767 | uint32_t *header = (uint32_t *) fc_hdr; |
4f774513 JS |
11768 | |
11769 | switch (fc_hdr->fh_r_ctl) { | |
11770 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
11771 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
11772 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
11773 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
11774 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
11775 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
11776 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
11777 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
11778 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
11779 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
11780 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
11781 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
11782 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
11783 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
11784 | case FC_RCTL_BA_RMC: /* remove connection */ | |
11785 | case FC_RCTL_BA_ACC: /* basic accept */ | |
11786 | case FC_RCTL_BA_RJT: /* basic reject */ | |
11787 | case FC_RCTL_BA_PRMT: | |
11788 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
11789 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
11790 | case FC_RCTL_P_RJT: /* port reject */ | |
11791 | case FC_RCTL_F_RJT: /* fabric reject */ | |
11792 | case FC_RCTL_P_BSY: /* port busy */ | |
11793 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
11794 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
11795 | case FC_RCTL_LCR: /* link credit reset */ | |
11796 | case FC_RCTL_END: /* end */ | |
11797 | break; | |
11798 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
11799 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11800 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
11801 | return lpfc_fc_frame_check(phba, fc_hdr); | |
11802 | default: | |
11803 | goto drop; | |
11804 | } | |
11805 | switch (fc_hdr->fh_type) { | |
11806 | case FC_TYPE_BLS: | |
11807 | case FC_TYPE_ELS: | |
11808 | case FC_TYPE_FCP: | |
11809 | case FC_TYPE_CT: | |
11810 | break; | |
11811 | case FC_TYPE_IP: | |
11812 | case FC_TYPE_ILS: | |
11813 | default: | |
11814 | goto drop; | |
11815 | } | |
546fc854 | 11816 | |
4f774513 | 11817 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
11818 | "2538 Received frame rctl:%s type:%s " |
11819 | "Frame Data:%08x %08x %08x %08x %08x %08x\n", | |
4f774513 | 11820 | rctl_names[fc_hdr->fh_r_ctl], |
546fc854 JS |
11821 | type_names[fc_hdr->fh_type], |
11822 | be32_to_cpu(header[0]), be32_to_cpu(header[1]), | |
11823 | be32_to_cpu(header[2]), be32_to_cpu(header[3]), | |
11824 | be32_to_cpu(header[4]), be32_to_cpu(header[5])); | |
4f774513 JS |
11825 | return 0; |
11826 | drop: | |
11827 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11828 | "2539 Dropped frame rctl:%s type:%s\n", | |
11829 | rctl_names[fc_hdr->fh_r_ctl], | |
11830 | type_names[fc_hdr->fh_type]); | |
11831 | return 1; | |
11832 | } | |
11833 | ||
11834 | /** | |
11835 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
11836 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11837 | * | |
11838 | * This function processes the FC header to retrieve the VFI from the VF | |
11839 | * header, if one exists. This function will return the VFI if one exists | |
11840 | * or 0 if no VSAN Header exists. | |
11841 | **/ | |
11842 | static uint32_t | |
11843 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
11844 | { | |
11845 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11846 | ||
11847 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
11848 | return 0; | |
11849 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
11850 | } | |
11851 | ||
11852 | /** | |
11853 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
11854 | * @phba: Pointer to the HBA structure to search for the vport on | |
11855 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11856 | * @fcfi: The FC Fabric ID that the frame came from | |
11857 | * | |
11858 | * This function searches the @phba for a vport that matches the content of the | |
11859 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
11860 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
11861 | * returns the matching vport pointer or NULL if unable to match frame to a | |
11862 | * vport. | |
11863 | **/ | |
11864 | static struct lpfc_vport * | |
11865 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
11866 | uint16_t fcfi) | |
11867 | { | |
11868 | struct lpfc_vport **vports; | |
11869 | struct lpfc_vport *vport = NULL; | |
11870 | int i; | |
11871 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
11872 | fc_hdr->fh_d_id[1] << 8 | | |
11873 | fc_hdr->fh_d_id[2]); | |
11874 | ||
11875 | vports = lpfc_create_vport_work_array(phba); | |
11876 | if (vports != NULL) | |
11877 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
11878 | if (phba->fcf.fcfi == fcfi && | |
11879 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
11880 | vports[i]->fc_myDID == did) { | |
11881 | vport = vports[i]; | |
11882 | break; | |
11883 | } | |
11884 | } | |
11885 | lpfc_destroy_vport_work_array(phba, vports); | |
11886 | return vport; | |
11887 | } | |
11888 | ||
45ed1190 JS |
11889 | /** |
11890 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
11891 | * @vport: The vport to work on. | |
11892 | * | |
11893 | * This function updates the receive sequence time stamp for this vport. The | |
11894 | * receive sequence time stamp indicates the time that the last frame of the | |
11895 | * the sequence that has been idle for the longest amount of time was received. | |
11896 | * the driver uses this time stamp to indicate if any received sequences have | |
11897 | * timed out. | |
11898 | **/ | |
11899 | void | |
11900 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
11901 | { | |
11902 | struct lpfc_dmabuf *h_buf; | |
11903 | struct hbq_dmabuf *dmabuf = NULL; | |
11904 | ||
11905 | /* get the oldest sequence on the rcv list */ | |
11906 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
11907 | struct lpfc_dmabuf, list); | |
11908 | if (!h_buf) | |
11909 | return; | |
11910 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11911 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
11912 | } | |
11913 | ||
11914 | /** | |
11915 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
11916 | * @vport: The vport that the received sequences were sent to. | |
11917 | * | |
11918 | * This function cleans up all outstanding received sequences. This is called | |
11919 | * by the driver when a link event or user action invalidates all the received | |
11920 | * sequences. | |
11921 | **/ | |
11922 | void | |
11923 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
11924 | { | |
11925 | struct lpfc_dmabuf *h_buf, *hnext; | |
11926 | struct lpfc_dmabuf *d_buf, *dnext; | |
11927 | struct hbq_dmabuf *dmabuf = NULL; | |
11928 | ||
11929 | /* start with the oldest sequence on the rcv list */ | |
11930 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11931 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11932 | list_del_init(&dmabuf->hbuf.list); | |
11933 | list_for_each_entry_safe(d_buf, dnext, | |
11934 | &dmabuf->dbuf.list, list) { | |
11935 | list_del_init(&d_buf->list); | |
11936 | lpfc_in_buf_free(vport->phba, d_buf); | |
11937 | } | |
11938 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11939 | } | |
11940 | } | |
11941 | ||
11942 | /** | |
11943 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
11944 | * @vport: The vport that the received sequences were sent to. | |
11945 | * | |
11946 | * This function determines whether any received sequences have timed out by | |
11947 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
11948 | * indicates that there is at least one timed out sequence this routine will | |
11949 | * go through the received sequences one at a time from most inactive to most | |
11950 | * active to determine which ones need to be cleaned up. Once it has determined | |
11951 | * that a sequence needs to be cleaned up it will simply free up the resources | |
11952 | * without sending an abort. | |
11953 | **/ | |
11954 | void | |
11955 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
11956 | { | |
11957 | struct lpfc_dmabuf *h_buf, *hnext; | |
11958 | struct lpfc_dmabuf *d_buf, *dnext; | |
11959 | struct hbq_dmabuf *dmabuf = NULL; | |
11960 | unsigned long timeout; | |
11961 | int abort_count = 0; | |
11962 | ||
11963 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11964 | vport->rcv_buffer_time_stamp); | |
11965 | if (list_empty(&vport->rcv_buffer_list) || | |
11966 | time_before(jiffies, timeout)) | |
11967 | return; | |
11968 | /* start with the oldest sequence on the rcv list */ | |
11969 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11970 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11971 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11972 | dmabuf->time_stamp); | |
11973 | if (time_before(jiffies, timeout)) | |
11974 | break; | |
11975 | abort_count++; | |
11976 | list_del_init(&dmabuf->hbuf.list); | |
11977 | list_for_each_entry_safe(d_buf, dnext, | |
11978 | &dmabuf->dbuf.list, list) { | |
11979 | list_del_init(&d_buf->list); | |
11980 | lpfc_in_buf_free(vport->phba, d_buf); | |
11981 | } | |
11982 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11983 | } | |
11984 | if (abort_count) | |
11985 | lpfc_update_rcv_time_stamp(vport); | |
11986 | } | |
11987 | ||
4f774513 JS |
11988 | /** |
11989 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
11990 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
11991 | * | |
11992 | * This function searches through the existing incomplete sequences that have | |
11993 | * been sent to this @vport. If the frame matches one of the incomplete | |
11994 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
11995 | * make up that sequence. If no sequence is found that matches this frame then | |
11996 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
11997 | * This function returns a pointer to the first dmabuf in the sequence list that | |
11998 | * the frame was linked to. | |
11999 | **/ | |
12000 | static struct hbq_dmabuf * | |
12001 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
12002 | { | |
12003 | struct fc_frame_header *new_hdr; | |
12004 | struct fc_frame_header *temp_hdr; | |
12005 | struct lpfc_dmabuf *d_buf; | |
12006 | struct lpfc_dmabuf *h_buf; | |
12007 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
12008 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
12009 | ||
4d9ab994 | 12010 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 12011 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
12012 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
12013 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
12014 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
12015 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
12016 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
12017 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
12018 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
12019 | continue; | |
12020 | /* found a pending sequence that matches this frame */ | |
12021 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
12022 | break; | |
12023 | } | |
12024 | if (!seq_dmabuf) { | |
12025 | /* | |
12026 | * This indicates first frame received for this sequence. | |
12027 | * Queue the buffer on the vport's rcv_buffer_list. | |
12028 | */ | |
12029 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 12030 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
12031 | return dmabuf; |
12032 | } | |
12033 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
12034 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
12035 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
12036 | list_del_init(&seq_dmabuf->hbuf.list); |
12037 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
12038 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 12039 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
12040 | return dmabuf; |
12041 | } | |
45ed1190 JS |
12042 | /* move this sequence to the tail to indicate a young sequence */ |
12043 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
12044 | seq_dmabuf->time_stamp = jiffies; | |
12045 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
12046 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
12047 | temp_hdr = dmabuf->hbuf.virt; | |
12048 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
12049 | return seq_dmabuf; | |
12050 | } | |
4f774513 JS |
12051 | /* find the correct place in the sequence to insert this frame */ |
12052 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
12053 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
12054 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
12055 | /* | |
12056 | * If the frame's sequence count is greater than the frame on | |
12057 | * the list then insert the frame right after this frame | |
12058 | */ | |
eeead811 JS |
12059 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
12060 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
12061 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
12062 | return seq_dmabuf; | |
12063 | } | |
12064 | } | |
12065 | return NULL; | |
12066 | } | |
12067 | ||
6669f9bb JS |
12068 | /** |
12069 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
12070 | * @vport: pointer to a vitural port | |
12071 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12072 | * | |
12073 | * This function tries to abort from the partially assembed sequence, described | |
12074 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
12075 | * partially assembled sequence held by the driver. If so, it shall free up all | |
12076 | * the frames from the partially assembled sequence. | |
12077 | * | |
12078 | * Return | |
12079 | * true -- if there is matching partially assembled sequence present and all | |
12080 | * the frames freed with the sequence; | |
12081 | * false -- if there is no matching partially assembled sequence present so | |
12082 | * nothing got aborted in the lower layer driver | |
12083 | **/ | |
12084 | static bool | |
12085 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
12086 | struct hbq_dmabuf *dmabuf) | |
12087 | { | |
12088 | struct fc_frame_header *new_hdr; | |
12089 | struct fc_frame_header *temp_hdr; | |
12090 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
12091 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
12092 | ||
12093 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
12094 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
12095 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
12096 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
12097 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
12098 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
12099 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
12100 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
12101 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
12102 | continue; | |
12103 | /* found a pending sequence that matches this frame */ | |
12104 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
12105 | break; | |
12106 | } | |
12107 | ||
12108 | /* Free up all the frames from the partially assembled sequence */ | |
12109 | if (seq_dmabuf) { | |
12110 | list_for_each_entry_safe(d_buf, n_buf, | |
12111 | &seq_dmabuf->dbuf.list, list) { | |
12112 | list_del_init(&d_buf->list); | |
12113 | lpfc_in_buf_free(vport->phba, d_buf); | |
12114 | } | |
12115 | return true; | |
12116 | } | |
12117 | return false; | |
12118 | } | |
12119 | ||
12120 | /** | |
546fc854 | 12121 | * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler |
6669f9bb JS |
12122 | * @phba: Pointer to HBA context object. |
12123 | * @cmd_iocbq: pointer to the command iocbq structure. | |
12124 | * @rsp_iocbq: pointer to the response iocbq structure. | |
12125 | * | |
546fc854 | 12126 | * This function handles the sequence abort response iocb command complete |
6669f9bb JS |
12127 | * event. It properly releases the memory allocated to the sequence abort |
12128 | * accept iocb. | |
12129 | **/ | |
12130 | static void | |
546fc854 | 12131 | lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba, |
6669f9bb JS |
12132 | struct lpfc_iocbq *cmd_iocbq, |
12133 | struct lpfc_iocbq *rsp_iocbq) | |
12134 | { | |
12135 | if (cmd_iocbq) | |
12136 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
12137 | } | |
12138 | ||
12139 | /** | |
546fc854 | 12140 | * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort |
6669f9bb JS |
12141 | * @phba: Pointer to HBA context object. |
12142 | * @fc_hdr: pointer to a FC frame header. | |
12143 | * | |
546fc854 | 12144 | * This function sends a basic response to a previous unsol sequence abort |
6669f9bb JS |
12145 | * event after aborting the sequence handling. |
12146 | **/ | |
12147 | static void | |
546fc854 | 12148 | lpfc_sli4_seq_abort_rsp(struct lpfc_hba *phba, |
6669f9bb JS |
12149 | struct fc_frame_header *fc_hdr) |
12150 | { | |
12151 | struct lpfc_iocbq *ctiocb = NULL; | |
12152 | struct lpfc_nodelist *ndlp; | |
5ffc266e JS |
12153 | uint16_t oxid, rxid; |
12154 | uint32_t sid, fctl; | |
6669f9bb | 12155 | IOCB_t *icmd; |
546fc854 | 12156 | int rc; |
6669f9bb JS |
12157 | |
12158 | if (!lpfc_is_link_up(phba)) | |
12159 | return; | |
12160 | ||
12161 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
12162 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 12163 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
12164 | |
12165 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
12166 | if (!ndlp) { | |
12167 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
12168 | "1268 Find ndlp returned NULL for oxid:x%x " | |
12169 | "SID:x%x\n", oxid, sid); | |
12170 | return; | |
12171 | } | |
19ca7609 JS |
12172 | if (rxid >= phba->sli4_hba.max_cfg_param.xri_base |
12173 | && rxid <= (phba->sli4_hba.max_cfg_param.max_xri | |
12174 | + phba->sli4_hba.max_cfg_param.xri_base)) | |
12175 | lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); | |
6669f9bb | 12176 | |
546fc854 | 12177 | /* Allocate buffer for rsp iocb */ |
6669f9bb JS |
12178 | ctiocb = lpfc_sli_get_iocbq(phba); |
12179 | if (!ctiocb) | |
12180 | return; | |
12181 | ||
5ffc266e JS |
12182 | /* Extract the F_CTL field from FC_HDR */ |
12183 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
12184 | ||
6669f9bb | 12185 | icmd = &ctiocb->iocb; |
6669f9bb | 12186 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 12187 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
12188 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
12189 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
12190 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
12191 | ||
12192 | /* Fill in the rest of iocb fields */ | |
12193 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
12194 | icmd->ulpBdeCount = 0; | |
12195 | icmd->ulpLe = 1; | |
12196 | icmd->ulpClass = CLASS3; | |
12197 | icmd->ulpContext = ndlp->nlp_rpi; | |
be858b65 | 12198 | ctiocb->context1 = ndlp; |
6669f9bb | 12199 | |
6669f9bb JS |
12200 | ctiocb->iocb_cmpl = NULL; |
12201 | ctiocb->vport = phba->pport; | |
546fc854 JS |
12202 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_rsp_cmpl; |
12203 | ctiocb->sli4_xritag = NO_XRI; | |
12204 | ||
12205 | /* If the oxid maps to the FCP XRI range or if it is out of range, | |
12206 | * send a BLS_RJT. The driver no longer has that exchange. | |
12207 | * Override the IOCB for a BA_RJT. | |
12208 | */ | |
12209 | if (oxid > (phba->sli4_hba.max_cfg_param.max_xri + | |
12210 | phba->sli4_hba.max_cfg_param.xri_base) || | |
12211 | oxid > (lpfc_sli4_get_els_iocb_cnt(phba) + | |
12212 | phba->sli4_hba.max_cfg_param.xri_base)) { | |
12213 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_RJT; | |
12214 | bf_set(lpfc_vndr_code, &icmd->un.bls_rsp, 0); | |
12215 | bf_set(lpfc_rsn_expln, &icmd->un.bls_rsp, FC_BA_RJT_INV_XID); | |
12216 | bf_set(lpfc_rsn_code, &icmd->un.bls_rsp, FC_BA_RJT_UNABLE); | |
12217 | } | |
6669f9bb | 12218 | |
5ffc266e JS |
12219 | if (fctl & FC_FC_EX_CTX) { |
12220 | /* ABTS sent by responder to CT exchange, construction | |
12221 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
12222 | * field and RX_ID from ABTS for RX_ID field. | |
12223 | */ | |
546fc854 JS |
12224 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_RSP); |
12225 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, rxid); | |
5ffc266e JS |
12226 | } else { |
12227 | /* ABTS sent by initiator to CT exchange, construction | |
12228 | * of BA_ACC will need to allocate a new XRI as for the | |
12229 | * XRI_TAG and RX_ID fields. | |
12230 | */ | |
546fc854 JS |
12231 | bf_set(lpfc_abts_orig, &icmd->un.bls_rsp, LPFC_ABTS_UNSOL_INT); |
12232 | bf_set(lpfc_abts_rxid, &icmd->un.bls_rsp, NO_XRI); | |
5ffc266e | 12233 | } |
546fc854 | 12234 | bf_set(lpfc_abts_oxid, &icmd->un.bls_rsp, oxid); |
5ffc266e | 12235 | |
546fc854 | 12236 | /* Xmit CT abts response on exchange <xid> */ |
6669f9bb | 12237 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, |
546fc854 JS |
12238 | "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n", |
12239 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, phba->link_state); | |
12240 | ||
12241 | rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
12242 | if (rc == IOCB_ERROR) { | |
12243 | lpfc_printf_log(phba, KERN_ERR, LOG_ELS, | |
12244 | "2925 Failed to issue CT ABTS RSP x%x on " | |
12245 | "xri x%x, Data x%x\n", | |
12246 | icmd->un.xseq64.w5.hcsw.Rctl, oxid, | |
12247 | phba->link_state); | |
12248 | lpfc_sli_release_iocbq(phba, ctiocb); | |
12249 | } | |
6669f9bb JS |
12250 | } |
12251 | ||
12252 | /** | |
12253 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
12254 | * @vport: Pointer to the vport on which this sequence was received | |
12255 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12256 | * | |
12257 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
12258 | * receive sequence is only partially assembed by the driver, it shall abort | |
12259 | * the partially assembled frames for the sequence. Otherwise, if the | |
12260 | * unsolicited receive sequence has been completely assembled and passed to | |
12261 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
12262 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
12263 | * accept to accept the abort. | |
12264 | **/ | |
12265 | void | |
12266 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
12267 | struct hbq_dmabuf *dmabuf) | |
12268 | { | |
12269 | struct lpfc_hba *phba = vport->phba; | |
12270 | struct fc_frame_header fc_hdr; | |
5ffc266e | 12271 | uint32_t fctl; |
6669f9bb JS |
12272 | bool abts_par; |
12273 | ||
6669f9bb JS |
12274 | /* Make a copy of fc_hdr before the dmabuf being released */ |
12275 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 12276 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 12277 | |
5ffc266e JS |
12278 | if (fctl & FC_FC_EX_CTX) { |
12279 | /* | |
12280 | * ABTS sent by responder to exchange, just free the buffer | |
12281 | */ | |
6669f9bb | 12282 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
12283 | } else { |
12284 | /* | |
12285 | * ABTS sent by initiator to exchange, need to do cleanup | |
12286 | */ | |
12287 | /* Try to abort partially assembled seq */ | |
12288 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
12289 | ||
12290 | /* Send abort to ULP if partially seq abort failed */ | |
12291 | if (abts_par == false) | |
12292 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
12293 | else | |
12294 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12295 | } | |
6669f9bb | 12296 | /* Send basic accept (BA_ACC) to the abort requester */ |
546fc854 | 12297 | lpfc_sli4_seq_abort_rsp(phba, &fc_hdr); |
6669f9bb JS |
12298 | } |
12299 | ||
4f774513 JS |
12300 | /** |
12301 | * lpfc_seq_complete - Indicates if a sequence is complete | |
12302 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12303 | * | |
12304 | * This function checks the sequence, starting with the frame described by | |
12305 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
12306 | * the frames associated with this sequence are linked to the @dmabuf using the | |
12307 | * dbuf list. This function looks for two major things. 1) That the first frame | |
12308 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
12309 | * set. 3) That there are no holes in the sequence count. The function will | |
12310 | * return 1 when the sequence is complete, otherwise it will return 0. | |
12311 | **/ | |
12312 | static int | |
12313 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
12314 | { | |
12315 | struct fc_frame_header *hdr; | |
12316 | struct lpfc_dmabuf *d_buf; | |
12317 | struct hbq_dmabuf *seq_dmabuf; | |
12318 | uint32_t fctl; | |
12319 | int seq_count = 0; | |
12320 | ||
12321 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
12322 | /* make sure first fame of sequence has a sequence count of zero */ | |
12323 | if (hdr->fh_seq_cnt != seq_count) | |
12324 | return 0; | |
12325 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
12326 | hdr->fh_f_ctl[1] << 8 | | |
12327 | hdr->fh_f_ctl[2]); | |
12328 | /* If last frame of sequence we can return success. */ | |
12329 | if (fctl & FC_FC_END_SEQ) | |
12330 | return 1; | |
12331 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
12332 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
12333 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12334 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 12335 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
12336 | return 0; |
12337 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
12338 | hdr->fh_f_ctl[1] << 8 | | |
12339 | hdr->fh_f_ctl[2]); | |
12340 | /* If last frame of sequence we can return success. */ | |
12341 | if (fctl & FC_FC_END_SEQ) | |
12342 | return 1; | |
12343 | } | |
12344 | return 0; | |
12345 | } | |
12346 | ||
12347 | /** | |
12348 | * lpfc_prep_seq - Prep sequence for ULP processing | |
12349 | * @vport: Pointer to the vport on which this sequence was received | |
12350 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12351 | * | |
12352 | * This function takes a sequence, described by a list of frames, and creates | |
12353 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
12354 | * used to issue to the generic unsolicited sequence handler. This routine | |
12355 | * returns a pointer to the first iocbq in the list. If the function is unable | |
12356 | * to allocate an iocbq then it throw out the received frames that were not | |
12357 | * able to be described and return a pointer to the first iocbq. If unable to | |
12358 | * allocate any iocbqs (including the first) this function will return NULL. | |
12359 | **/ | |
12360 | static struct lpfc_iocbq * | |
12361 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
12362 | { | |
12363 | struct lpfc_dmabuf *d_buf, *n_buf; | |
12364 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
12365 | struct fc_frame_header *fc_hdr; | |
12366 | uint32_t sid; | |
eeead811 | 12367 | struct ulp_bde64 *pbde; |
4f774513 JS |
12368 | |
12369 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12370 | /* remove from receive buffer list */ | |
12371 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 12372 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 12373 | /* get the Remote Port's SID */ |
6669f9bb | 12374 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
4f774513 JS |
12375 | /* Get an iocbq struct to fill in. */ |
12376 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
12377 | if (first_iocbq) { | |
12378 | /* Initialize the first IOCB. */ | |
8fa38513 | 12379 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 JS |
12380 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
12381 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
12382 | first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id); | |
12383 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
12384 | vport->vpi + vport->phba->vpi_base; | |
12385 | /* put the first buffer into the first IOCBq */ | |
12386 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
12387 | first_iocbq->context3 = NULL; | |
12388 | first_iocbq->iocb.ulpBdeCount = 1; | |
12389 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
12390 | LPFC_DATA_BUF_SIZE; | |
12391 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
8fa38513 | 12392 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12393 | bf_get(lpfc_rcqe_length, |
12394 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12395 | } |
12396 | iocbq = first_iocbq; | |
12397 | /* | |
12398 | * Each IOCBq can have two Buffers assigned, so go through the list | |
12399 | * of buffers for this sequence and save two buffers in each IOCBq | |
12400 | */ | |
12401 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
12402 | if (!iocbq) { | |
12403 | lpfc_in_buf_free(vport->phba, d_buf); | |
12404 | continue; | |
12405 | } | |
12406 | if (!iocbq->context3) { | |
12407 | iocbq->context3 = d_buf; | |
12408 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
12409 | pbde = (struct ulp_bde64 *) |
12410 | &iocbq->iocb.unsli3.sli3Words[4]; | |
12411 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
8fa38513 | 12412 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12413 | bf_get(lpfc_rcqe_length, |
12414 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12415 | } else { |
12416 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
12417 | if (!iocbq) { | |
12418 | if (first_iocbq) { | |
12419 | first_iocbq->iocb.ulpStatus = | |
12420 | IOSTAT_FCP_RSP_ERROR; | |
12421 | first_iocbq->iocb.un.ulpWord[4] = | |
12422 | IOERR_NO_RESOURCES; | |
12423 | } | |
12424 | lpfc_in_buf_free(vport->phba, d_buf); | |
12425 | continue; | |
12426 | } | |
12427 | iocbq->context2 = d_buf; | |
12428 | iocbq->context3 = NULL; | |
12429 | iocbq->iocb.ulpBdeCount = 1; | |
12430 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
12431 | LPFC_DATA_BUF_SIZE; | |
8fa38513 | 12432 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12433 | bf_get(lpfc_rcqe_length, |
12434 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12435 | iocbq->iocb.un.rcvels.remoteID = sid; |
12436 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
12437 | } | |
12438 | } | |
12439 | return first_iocbq; | |
12440 | } | |
12441 | ||
6669f9bb JS |
12442 | static void |
12443 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
12444 | struct hbq_dmabuf *seq_dmabuf) | |
12445 | { | |
12446 | struct fc_frame_header *fc_hdr; | |
12447 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
12448 | struct lpfc_hba *phba = vport->phba; | |
12449 | ||
12450 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12451 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
12452 | if (!iocbq) { | |
12453 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12454 | "2707 Ring %d handler: Failed to allocate " | |
12455 | "iocb Rctl x%x Type x%x received\n", | |
12456 | LPFC_ELS_RING, | |
12457 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
12458 | return; | |
12459 | } | |
12460 | if (!lpfc_complete_unsol_iocb(phba, | |
12461 | &phba->sli.ring[LPFC_ELS_RING], | |
12462 | iocbq, fc_hdr->fh_r_ctl, | |
12463 | fc_hdr->fh_type)) | |
12464 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12465 | "2540 Ring %d handler: unexpected Rctl " | |
12466 | "x%x Type x%x received\n", | |
12467 | LPFC_ELS_RING, | |
12468 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
12469 | ||
12470 | /* Free iocb created in lpfc_prep_seq */ | |
12471 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
12472 | &iocbq->list, list) { | |
12473 | list_del_init(&curr_iocb->list); | |
12474 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
12475 | } | |
12476 | lpfc_sli_release_iocbq(phba, iocbq); | |
12477 | } | |
12478 | ||
4f774513 JS |
12479 | /** |
12480 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
12481 | * @phba: Pointer to HBA context object. | |
12482 | * | |
12483 | * This function is called with no lock held. This function processes all | |
12484 | * the received buffers and gives it to upper layers when a received buffer | |
12485 | * indicates that it is the final frame in the sequence. The interrupt | |
12486 | * service routine processes received buffers at interrupt contexts and adds | |
12487 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
12488 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
12489 | * appropriate receive function when the final frame in a sequence is received. | |
12490 | **/ | |
4d9ab994 JS |
12491 | void |
12492 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
12493 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 12494 | { |
4d9ab994 | 12495 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
12496 | struct fc_frame_header *fc_hdr; |
12497 | struct lpfc_vport *vport; | |
12498 | uint32_t fcfi; | |
4f774513 | 12499 | |
4f774513 | 12500 | /* Process each received buffer */ |
4d9ab994 JS |
12501 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
12502 | /* check to see if this a valid type of frame */ | |
12503 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
12504 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12505 | return; | |
12506 | } | |
12507 | fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl); | |
12508 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); | |
c868595d | 12509 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
4d9ab994 JS |
12510 | /* throw out the frame */ |
12511 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12512 | return; | |
12513 | } | |
6669f9bb JS |
12514 | /* Handle the basic abort sequence (BA_ABTS) event */ |
12515 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
12516 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
12517 | return; | |
12518 | } | |
12519 | ||
4d9ab994 JS |
12520 | /* Link this frame */ |
12521 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
12522 | if (!seq_dmabuf) { | |
12523 | /* unable to add frame to vport - throw it out */ | |
12524 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12525 | return; | |
12526 | } | |
12527 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 12528 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 12529 | return; |
def9c7a9 | 12530 | |
6669f9bb JS |
12531 | /* Send the complete sequence to the upper layer protocol */ |
12532 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 12533 | } |
6fb120a7 JS |
12534 | |
12535 | /** | |
12536 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
12537 | * @phba: pointer to lpfc hba data structure. | |
12538 | * | |
12539 | * This routine is invoked to post rpi header templates to the | |
12540 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
12541 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
12542 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
12543 | * |
12544 | * This routine does not require any locks. It's usage is expected | |
12545 | * to be driver load or reset recovery when the driver is | |
12546 | * sequential. | |
12547 | * | |
12548 | * Return codes | |
af901ca1 | 12549 | * 0 - successful |
d439d286 | 12550 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
12551 | * When this error occurs, the driver is not guaranteed |
12552 | * to have any rpi regions posted to the device and | |
12553 | * must either attempt to repost the regions or take a | |
12554 | * fatal error. | |
12555 | **/ | |
12556 | int | |
12557 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
12558 | { | |
12559 | struct lpfc_rpi_hdr *rpi_page; | |
12560 | uint32_t rc = 0; | |
12561 | ||
12562 | /* Post all rpi memory regions to the port. */ | |
12563 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
12564 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); | |
12565 | if (rc != MBX_SUCCESS) { | |
12566 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12567 | "2008 Error %d posting all rpi " | |
12568 | "headers\n", rc); | |
12569 | rc = -EIO; | |
12570 | break; | |
12571 | } | |
12572 | } | |
12573 | ||
12574 | return rc; | |
12575 | } | |
12576 | ||
12577 | /** | |
12578 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
12579 | * @phba: pointer to lpfc hba data structure. | |
12580 | * @rpi_page: pointer to the rpi memory region. | |
12581 | * | |
12582 | * This routine is invoked to post a single rpi header to the | |
12583 | * HBA consistent with the SLI-4 interface spec. This memory region | |
12584 | * maps up to 64 rpi context regions. | |
12585 | * | |
12586 | * Return codes | |
af901ca1 | 12587 | * 0 - successful |
d439d286 JS |
12588 | * -ENOMEM - No available memory |
12589 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
12590 | **/ |
12591 | int | |
12592 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
12593 | { | |
12594 | LPFC_MBOXQ_t *mboxq; | |
12595 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
12596 | uint32_t rc = 0; | |
12597 | uint32_t mbox_tmo; | |
12598 | uint32_t shdr_status, shdr_add_status; | |
12599 | union lpfc_sli4_cfg_shdr *shdr; | |
12600 | ||
12601 | /* The port is notified of the header region via a mailbox command. */ | |
12602 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12603 | if (!mboxq) { | |
12604 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12605 | "2001 Unable to allocate memory for issuing " | |
12606 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
12607 | return -ENOMEM; | |
12608 | } | |
12609 | ||
12610 | /* Post all rpi memory regions to the port. */ | |
12611 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
12612 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12613 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12614 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
12615 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
fedd3b7b JS |
12616 | sizeof(struct lpfc_sli4_cfg_mhdr), |
12617 | LPFC_SLI4_MBX_EMBED); | |
6fb120a7 JS |
12618 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, |
12619 | hdr_tmpl, rpi_page->page_count); | |
12620 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, | |
12621 | rpi_page->start_rpi); | |
12622 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); | |
12623 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 12624 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
12625 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->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 (rc != MBX_TIMEOUT) | |
12629 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12630 | if (shdr_status || shdr_add_status || rc) { | |
12631 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12632 | "2514 POST_RPI_HDR mailbox failed with " | |
12633 | "status x%x add_status x%x, mbx status x%x\n", | |
12634 | shdr_status, shdr_add_status, rc); | |
12635 | rc = -ENXIO; | |
12636 | } | |
12637 | return rc; | |
12638 | } | |
12639 | ||
12640 | /** | |
12641 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
12642 | * @phba: pointer to lpfc hba data structure. | |
12643 | * | |
12644 | * This routine is invoked to post rpi header templates to the | |
12645 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
12646 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
12647 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
12648 | * |
12649 | * Returns | |
af901ca1 | 12650 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
12651 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
12652 | **/ | |
12653 | int | |
12654 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
12655 | { | |
12656 | int rpi; | |
12657 | uint16_t max_rpi, rpi_base, rpi_limit; | |
12658 | uint16_t rpi_remaining; | |
12659 | struct lpfc_rpi_hdr *rpi_hdr; | |
12660 | ||
12661 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
12662 | rpi_base = phba->sli4_hba.max_cfg_param.rpi_base; | |
12663 | rpi_limit = phba->sli4_hba.next_rpi; | |
12664 | ||
12665 | /* | |
12666 | * The valid rpi range is not guaranteed to be zero-based. Start | |
12667 | * the search at the rpi_base as reported by the port. | |
12668 | */ | |
12669 | spin_lock_irq(&phba->hbalock); | |
12670 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base); | |
12671 | if (rpi >= rpi_limit || rpi < rpi_base) | |
12672 | rpi = LPFC_RPI_ALLOC_ERROR; | |
12673 | else { | |
12674 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
12675 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
12676 | phba->sli4_hba.rpi_count++; | |
12677 | } | |
12678 | ||
12679 | /* | |
12680 | * Don't try to allocate more rpi header regions if the device limit | |
12681 | * on available rpis max has been exhausted. | |
12682 | */ | |
12683 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
12684 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
12685 | spin_unlock_irq(&phba->hbalock); | |
12686 | return rpi; | |
12687 | } | |
12688 | ||
12689 | /* | |
12690 | * If the driver is running low on rpi resources, allocate another | |
12691 | * page now. Note that the next_rpi value is used because | |
12692 | * it represents how many are actually in use whereas max_rpi notes | |
12693 | * how many are supported max by the device. | |
12694 | */ | |
12695 | rpi_remaining = phba->sli4_hba.next_rpi - rpi_base - | |
12696 | phba->sli4_hba.rpi_count; | |
12697 | spin_unlock_irq(&phba->hbalock); | |
12698 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
12699 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
12700 | if (!rpi_hdr) { | |
12701 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12702 | "2002 Error Could not grow rpi " | |
12703 | "count\n"); | |
12704 | } else { | |
12705 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); | |
12706 | } | |
12707 | } | |
12708 | ||
12709 | return rpi; | |
12710 | } | |
12711 | ||
d7c47992 JS |
12712 | /** |
12713 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
12714 | * @phba: pointer to lpfc hba data structure. | |
12715 | * | |
12716 | * This routine is invoked to release an rpi to the pool of | |
12717 | * available rpis maintained by the driver. | |
12718 | **/ | |
12719 | void | |
12720 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
12721 | { | |
12722 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
12723 | phba->sli4_hba.rpi_count--; | |
12724 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
12725 | } | |
12726 | } | |
12727 | ||
6fb120a7 JS |
12728 | /** |
12729 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
12730 | * @phba: pointer to lpfc hba data structure. | |
12731 | * | |
12732 | * This routine is invoked to release an rpi to the pool of | |
12733 | * available rpis maintained by the driver. | |
12734 | **/ | |
12735 | void | |
12736 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
12737 | { | |
12738 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 12739 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
12740 | spin_unlock_irq(&phba->hbalock); |
12741 | } | |
12742 | ||
12743 | /** | |
12744 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
12745 | * @phba: pointer to lpfc hba data structure. | |
12746 | * | |
12747 | * This routine is invoked to remove the memory region that | |
12748 | * provided rpi via a bitmask. | |
12749 | **/ | |
12750 | void | |
12751 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
12752 | { | |
12753 | kfree(phba->sli4_hba.rpi_bmask); | |
12754 | } | |
12755 | ||
12756 | /** | |
12757 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
12758 | * @phba: pointer to lpfc hba data structure. | |
12759 | * | |
12760 | * This routine is invoked to remove the memory region that | |
12761 | * provided rpi via a bitmask. | |
12762 | **/ | |
12763 | int | |
12764 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | |
12765 | { | |
12766 | LPFC_MBOXQ_t *mboxq; | |
12767 | struct lpfc_hba *phba = ndlp->phba; | |
12768 | int rc; | |
12769 | ||
12770 | /* The port is notified of the header region via a mailbox command. */ | |
12771 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12772 | if (!mboxq) | |
12773 | return -ENOMEM; | |
12774 | ||
12775 | /* Post all rpi memory regions to the port. */ | |
12776 | lpfc_resume_rpi(mboxq, ndlp); | |
12777 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12778 | if (rc == MBX_NOT_FINISHED) { | |
12779 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12780 | "2010 Resume RPI Mailbox failed " | |
12781 | "status %d, mbxStatus x%x\n", rc, | |
12782 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
12783 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12784 | return -EIO; | |
12785 | } | |
12786 | return 0; | |
12787 | } | |
12788 | ||
12789 | /** | |
12790 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 12791 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 12792 | * |
76a95d75 | 12793 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
12794 | * |
12795 | * Returns: | |
12796 | * 0 success | |
12797 | * -Evalue otherwise | |
12798 | **/ | |
12799 | int | |
76a95d75 | 12800 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
12801 | { |
12802 | LPFC_MBOXQ_t *mboxq; | |
12803 | int rc = 0; | |
6a9c52cf | 12804 | int retval = MBX_SUCCESS; |
6fb120a7 | 12805 | uint32_t mbox_tmo; |
76a95d75 | 12806 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
12807 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12808 | if (!mboxq) | |
12809 | return -ENOMEM; | |
76a95d75 | 12810 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
6fb120a7 JS |
12811 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI); |
12812 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6fb120a7 | 12813 | if (rc != MBX_SUCCESS) { |
76a95d75 | 12814 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
12815 | "2022 INIT VPI Mailbox failed " |
12816 | "status %d, mbxStatus x%x\n", rc, | |
12817 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 12818 | retval = -EIO; |
6fb120a7 | 12819 | } |
6a9c52cf | 12820 | if (rc != MBX_TIMEOUT) |
76a95d75 | 12821 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
12822 | |
12823 | return retval; | |
6fb120a7 JS |
12824 | } |
12825 | ||
12826 | /** | |
12827 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
12828 | * @phba: pointer to lpfc hba data structure. | |
12829 | * @mboxq: Pointer to mailbox object. | |
12830 | * | |
12831 | * This routine is invoked to manually add a single FCF record. The caller | |
12832 | * must pass a completely initialized FCF_Record. This routine takes | |
12833 | * care of the nonembedded mailbox operations. | |
12834 | **/ | |
12835 | static void | |
12836 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
12837 | { | |
12838 | void *virt_addr; | |
12839 | union lpfc_sli4_cfg_shdr *shdr; | |
12840 | uint32_t shdr_status, shdr_add_status; | |
12841 | ||
12842 | virt_addr = mboxq->sge_array->addr[0]; | |
12843 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12844 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
12845 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12846 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12847 | ||
12848 | if ((shdr_status || shdr_add_status) && | |
12849 | (shdr_status != STATUS_FCF_IN_USE)) | |
12850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12851 | "2558 ADD_FCF_RECORD mailbox failed with " | |
12852 | "status x%x add_status x%x\n", | |
12853 | shdr_status, shdr_add_status); | |
12854 | ||
12855 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12856 | } | |
12857 | ||
12858 | /** | |
12859 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
12860 | * @phba: pointer to lpfc hba data structure. | |
12861 | * @fcf_record: pointer to the initialized fcf record to add. | |
12862 | * | |
12863 | * This routine is invoked to manually add a single FCF record. The caller | |
12864 | * must pass a completely initialized FCF_Record. This routine takes | |
12865 | * care of the nonembedded mailbox operations. | |
12866 | **/ | |
12867 | int | |
12868 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
12869 | { | |
12870 | int rc = 0; | |
12871 | LPFC_MBOXQ_t *mboxq; | |
12872 | uint8_t *bytep; | |
12873 | void *virt_addr; | |
12874 | dma_addr_t phys_addr; | |
12875 | struct lpfc_mbx_sge sge; | |
12876 | uint32_t alloc_len, req_len; | |
12877 | uint32_t fcfindex; | |
12878 | ||
12879 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12880 | if (!mboxq) { | |
12881 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12882 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
12883 | return -ENOMEM; | |
12884 | } | |
12885 | ||
12886 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
12887 | sizeof(uint32_t); | |
12888 | ||
12889 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
12890 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12891 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
12892 | req_len, LPFC_SLI4_MBX_NEMBED); | |
12893 | if (alloc_len < req_len) { | |
12894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12895 | "2523 Allocated DMA memory size (x%x) is " | |
12896 | "less than the requested DMA memory " | |
12897 | "size (x%x)\n", alloc_len, req_len); | |
12898 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12899 | return -ENOMEM; | |
12900 | } | |
12901 | ||
12902 | /* | |
12903 | * Get the first SGE entry from the non-embedded DMA memory. This | |
12904 | * routine only uses a single SGE. | |
12905 | */ | |
12906 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
12907 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
12908 | virt_addr = mboxq->sge_array->addr[0]; |
12909 | /* | |
12910 | * Configure the FCF record for FCFI 0. This is the driver's | |
12911 | * hardcoded default and gets used in nonFIP mode. | |
12912 | */ | |
12913 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
12914 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
12915 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
12916 | ||
12917 | /* | |
12918 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
12919 | * the FCoE header plus word10. The data copy needs to be endian | |
12920 | * correct. | |
12921 | */ | |
12922 | bytep += sizeof(uint32_t); | |
12923 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
12924 | mboxq->vport = phba->pport; | |
12925 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
12926 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12927 | if (rc == MBX_NOT_FINISHED) { | |
12928 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12929 | "2515 ADD_FCF_RECORD mailbox failed with " | |
12930 | "status 0x%x\n", rc); | |
12931 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12932 | rc = -EIO; | |
12933 | } else | |
12934 | rc = 0; | |
12935 | ||
12936 | return rc; | |
12937 | } | |
12938 | ||
12939 | /** | |
12940 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
12941 | * @phba: pointer to lpfc hba data structure. | |
12942 | * @fcf_record: pointer to the fcf record to write the default data. | |
12943 | * @fcf_index: FCF table entry index. | |
12944 | * | |
12945 | * This routine is invoked to build the driver's default FCF record. The | |
12946 | * values used are hardcoded. This routine handles memory initialization. | |
12947 | * | |
12948 | **/ | |
12949 | void | |
12950 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
12951 | struct fcf_record *fcf_record, | |
12952 | uint16_t fcf_index) | |
12953 | { | |
12954 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
12955 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
12956 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
12957 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
12958 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
12959 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
12960 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
12961 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
12962 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
12963 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
12964 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
12965 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
12966 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
12967 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 12968 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
12969 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
12970 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
12971 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
12972 | /* Set the VLAN bit map */ | |
12973 | if (phba->valid_vlan) { | |
12974 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
12975 | = 1 << (phba->vlan_id % 8); | |
12976 | } | |
12977 | } | |
12978 | ||
12979 | /** | |
0c9ab6f5 | 12980 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
12981 | * @phba: pointer to lpfc hba data structure. |
12982 | * @fcf_index: FCF table entry offset. | |
12983 | * | |
0c9ab6f5 JS |
12984 | * This routine is invoked to scan the entire FCF table by reading FCF |
12985 | * record and processing it one at a time starting from the @fcf_index | |
12986 | * for initial FCF discovery or fast FCF failover rediscovery. | |
12987 | * | |
25985edc | 12988 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 | 12989 | * otherwise. |
6fb120a7 JS |
12990 | **/ |
12991 | int | |
0c9ab6f5 | 12992 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
12993 | { |
12994 | int rc = 0, error; | |
12995 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 12996 | |
32b9793f | 12997 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
6fb120a7 JS |
12998 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12999 | if (!mboxq) { | |
13000 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13001 | "2000 Failed to allocate mbox for " | |
13002 | "READ_FCF cmd\n"); | |
4d9ab994 | 13003 | error = -ENOMEM; |
0c9ab6f5 | 13004 | goto fail_fcf_scan; |
6fb120a7 | 13005 | } |
ecfd03c6 | 13006 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 13007 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
13008 | if (rc) { |
13009 | error = -EINVAL; | |
0c9ab6f5 | 13010 | goto fail_fcf_scan; |
6fb120a7 | 13011 | } |
ecfd03c6 | 13012 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 13013 | mboxq->vport = phba->pport; |
0c9ab6f5 | 13014 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
13015 | |
13016 | spin_lock_irq(&phba->hbalock); | |
13017 | phba->hba_flag |= FCF_TS_INPROG; | |
13018 | spin_unlock_irq(&phba->hbalock); | |
13019 | ||
6fb120a7 | 13020 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 13021 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 13022 | error = -EIO; |
ecfd03c6 | 13023 | else { |
38b92ef8 JS |
13024 | /* Reset eligible FCF count for new scan */ |
13025 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 13026 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 13027 | error = 0; |
32b9793f | 13028 | } |
0c9ab6f5 | 13029 | fail_fcf_scan: |
4d9ab994 JS |
13030 | if (error) { |
13031 | if (mboxq) | |
13032 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 13033 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 13034 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 13035 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
13036 | spin_unlock_irq(&phba->hbalock); |
13037 | } | |
6fb120a7 JS |
13038 | return error; |
13039 | } | |
a0c87cbd | 13040 | |
0c9ab6f5 | 13041 | /** |
a93ff37a | 13042 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
13043 | * @phba: pointer to lpfc hba data structure. |
13044 | * @fcf_index: FCF table entry offset. | |
13045 | * | |
13046 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 13047 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 | 13048 | * |
25985edc | 13049 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
13050 | * otherwise. |
13051 | **/ | |
13052 | int | |
13053 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
13054 | { | |
13055 | int rc = 0, error; | |
13056 | LPFC_MBOXQ_t *mboxq; | |
13057 | ||
13058 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13059 | if (!mboxq) { | |
13060 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
13061 | "2763 Failed to allocate mbox for " | |
13062 | "READ_FCF cmd\n"); | |
13063 | error = -ENOMEM; | |
13064 | goto fail_fcf_read; | |
13065 | } | |
13066 | /* Construct the read FCF record mailbox command */ | |
13067 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
13068 | if (rc) { | |
13069 | error = -EINVAL; | |
13070 | goto fail_fcf_read; | |
13071 | } | |
13072 | /* Issue the mailbox command asynchronously */ | |
13073 | mboxq->vport = phba->pport; | |
13074 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
13075 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
13076 | if (rc == MBX_NOT_FINISHED) | |
13077 | error = -EIO; | |
13078 | else | |
13079 | error = 0; | |
13080 | ||
13081 | fail_fcf_read: | |
13082 | if (error && mboxq) | |
13083 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
13084 | return error; | |
13085 | } | |
13086 | ||
13087 | /** | |
13088 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
13089 | * @phba: pointer to lpfc hba data structure. | |
13090 | * @fcf_index: FCF table entry offset. | |
13091 | * | |
13092 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 13093 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 | 13094 | * |
25985edc | 13095 | * Return 0 if the mailbox command is submitted successfully, none 0 |
0c9ab6f5 JS |
13096 | * otherwise. |
13097 | **/ | |
13098 | int | |
13099 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
13100 | { | |
13101 | int rc = 0, error; | |
13102 | LPFC_MBOXQ_t *mboxq; | |
13103 | ||
13104 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13105 | if (!mboxq) { | |
13106 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
13107 | "2758 Failed to allocate mbox for " | |
13108 | "READ_FCF cmd\n"); | |
13109 | error = -ENOMEM; | |
13110 | goto fail_fcf_read; | |
13111 | } | |
13112 | /* Construct the read FCF record mailbox command */ | |
13113 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
13114 | if (rc) { | |
13115 | error = -EINVAL; | |
13116 | goto fail_fcf_read; | |
13117 | } | |
13118 | /* Issue the mailbox command asynchronously */ | |
13119 | mboxq->vport = phba->pport; | |
13120 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
13121 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
13122 | if (rc == MBX_NOT_FINISHED) | |
13123 | error = -EIO; | |
13124 | else | |
13125 | error = 0; | |
13126 | ||
13127 | fail_fcf_read: | |
13128 | if (error && mboxq) | |
13129 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
13130 | return error; | |
13131 | } | |
13132 | ||
13133 | /** | |
13134 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
13135 | * @phba: pointer to lpfc hba data structure. | |
13136 | * | |
13137 | * This routine is to get the next eligible FCF record index in a round | |
13138 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 13139 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
13140 | * shall be returned, otherwise, the next eligible FCF record's index |
13141 | * shall be returned. | |
13142 | **/ | |
13143 | uint16_t | |
13144 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
13145 | { | |
13146 | uint16_t next_fcf_index; | |
13147 | ||
3804dc84 JS |
13148 | /* Search start from next bit of currently registered FCF index */ |
13149 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % | |
13150 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
13151 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
13152 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
13153 | next_fcf_index); |
13154 | ||
0c9ab6f5 JS |
13155 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
13156 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) | |
13157 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, | |
13158 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
3804dc84 JS |
13159 | |
13160 | /* Check roundrobin failover list empty condition */ | |
13161 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
13162 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
13163 | "2844 No roundrobin failover FCF available\n"); | |
0c9ab6f5 | 13164 | return LPFC_FCOE_FCF_NEXT_NONE; |
3804dc84 JS |
13165 | } |
13166 | ||
3804dc84 | 13167 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
13168 | "2845 Get next roundrobin failover FCF (x%x)\n", |
13169 | next_fcf_index); | |
13170 | ||
0c9ab6f5 JS |
13171 | return next_fcf_index; |
13172 | } | |
13173 | ||
13174 | /** | |
13175 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
13176 | * @phba: pointer to lpfc hba data structure. | |
13177 | * | |
13178 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 13179 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
13180 | * does not go beyond the range of the driver allocated bmask dimension |
13181 | * before setting the bit. | |
13182 | * | |
13183 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
13184 | * -EINVAL. | |
13185 | **/ | |
13186 | int | |
13187 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
13188 | { | |
13189 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
13190 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
13191 | "2610 FCF (x%x) reached driver's book " |
13192 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
13193 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
13194 | return -EINVAL; | |
13195 | } | |
13196 | /* Set the eligible FCF record index bmask */ | |
13197 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
13198 | ||
3804dc84 | 13199 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 13200 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
13201 | "bmask\n", fcf_index); |
13202 | ||
0c9ab6f5 JS |
13203 | return 0; |
13204 | } | |
13205 | ||
13206 | /** | |
3804dc84 | 13207 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
13208 | * @phba: pointer to lpfc hba data structure. |
13209 | * | |
13210 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 13211 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
13212 | * does not go beyond the range of the driver allocated bmask dimension |
13213 | * before clearing the bit. | |
13214 | **/ | |
13215 | void | |
13216 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
13217 | { | |
13218 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
13219 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
13220 | "2762 FCF (x%x) reached driver's book " |
13221 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
13222 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
13223 | return; | |
13224 | } | |
13225 | /* Clear the eligible FCF record index bmask */ | |
13226 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
3804dc84 JS |
13227 | |
13228 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 13229 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 13230 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
13231 | } |
13232 | ||
ecfd03c6 JS |
13233 | /** |
13234 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
13235 | * @phba: pointer to lpfc hba data structure. | |
13236 | * | |
13237 | * This routine is the completion routine for the rediscover FCF table mailbox | |
13238 | * command. If the mailbox command returned failure, it will try to stop the | |
13239 | * FCF rediscover wait timer. | |
13240 | **/ | |
13241 | void | |
13242 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
13243 | { | |
13244 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
13245 | uint32_t shdr_status, shdr_add_status; | |
13246 | ||
13247 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
13248 | ||
13249 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
13250 | &redisc_fcf->header.cfg_shdr.response); | |
13251 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
13252 | &redisc_fcf->header.cfg_shdr.response); | |
13253 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 13254 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
13255 | "2746 Requesting for FCF rediscovery failed " |
13256 | "status x%x add_status x%x\n", | |
13257 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 13258 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 13259 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 13260 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
13261 | spin_unlock_irq(&phba->hbalock); |
13262 | /* | |
13263 | * CVL event triggered FCF rediscover request failed, | |
13264 | * last resort to re-try current registered FCF entry. | |
13265 | */ | |
13266 | lpfc_retry_pport_discovery(phba); | |
13267 | } else { | |
13268 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 13269 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
13270 | spin_unlock_irq(&phba->hbalock); |
13271 | /* | |
13272 | * DEAD FCF event triggered FCF rediscover request | |
13273 | * failed, last resort to fail over as a link down | |
13274 | * to FCF registration. | |
13275 | */ | |
13276 | lpfc_sli4_fcf_dead_failthrough(phba); | |
13277 | } | |
0c9ab6f5 JS |
13278 | } else { |
13279 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 13280 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
13281 | /* |
13282 | * Start FCF rediscovery wait timer for pending FCF | |
13283 | * before rescan FCF record table. | |
13284 | */ | |
13285 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 13286 | } |
ecfd03c6 JS |
13287 | |
13288 | mempool_free(mbox, phba->mbox_mem_pool); | |
13289 | } | |
13290 | ||
13291 | /** | |
3804dc84 | 13292 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
13293 | * @phba: pointer to lpfc hba data structure. |
13294 | * | |
13295 | * This routine is invoked to request for rediscovery of the entire FCF table | |
13296 | * by the port. | |
13297 | **/ | |
13298 | int | |
13299 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
13300 | { | |
13301 | LPFC_MBOXQ_t *mbox; | |
13302 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
13303 | int rc, length; | |
13304 | ||
0c9ab6f5 JS |
13305 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
13306 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
13307 | ||
ecfd03c6 JS |
13308 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13309 | if (!mbox) { | |
13310 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13311 | "2745 Failed to allocate mbox for " | |
13312 | "requesting FCF rediscover.\n"); | |
13313 | return -ENOMEM; | |
13314 | } | |
13315 | ||
13316 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
13317 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13318 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13319 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
13320 | length, LPFC_SLI4_MBX_EMBED); | |
13321 | ||
13322 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
13323 | /* Set count to 0 for invalidating the entire FCF database */ | |
13324 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
13325 | ||
13326 | /* Issue the mailbox command asynchronously */ | |
13327 | mbox->vport = phba->pport; | |
13328 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
13329 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
13330 | ||
13331 | if (rc == MBX_NOT_FINISHED) { | |
13332 | mempool_free(mbox, phba->mbox_mem_pool); | |
13333 | return -EIO; | |
13334 | } | |
13335 | return 0; | |
13336 | } | |
13337 | ||
fc2b989b JS |
13338 | /** |
13339 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
13340 | * @phba: pointer to lpfc hba data structure. | |
13341 | * | |
13342 | * This function is the failover routine as a last resort to the FCF DEAD | |
13343 | * event when driver failed to perform fast FCF failover. | |
13344 | **/ | |
13345 | void | |
13346 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
13347 | { | |
13348 | uint32_t link_state; | |
13349 | ||
13350 | /* | |
13351 | * Last resort as FCF DEAD event failover will treat this as | |
13352 | * a link down, but save the link state because we don't want | |
13353 | * it to be changed to Link Down unless it is already down. | |
13354 | */ | |
13355 | link_state = phba->link_state; | |
13356 | lpfc_linkdown(phba); | |
13357 | phba->link_state = link_state; | |
13358 | ||
13359 | /* Unregister FCF if no devices connected to it */ | |
13360 | lpfc_unregister_unused_fcf(phba); | |
13361 | } | |
13362 | ||
a0c87cbd JS |
13363 | /** |
13364 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
13365 | * @phba: pointer to lpfc hba data structure. | |
13366 | * | |
13367 | * This function read region 23 and parse TLV for port status to | |
13368 | * decide if the user disaled the port. If the TLV indicates the | |
13369 | * port is disabled, the hba_flag is set accordingly. | |
13370 | **/ | |
13371 | void | |
13372 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
13373 | { | |
13374 | LPFC_MBOXQ_t *pmb = NULL; | |
13375 | MAILBOX_t *mb; | |
13376 | uint8_t *rgn23_data = NULL; | |
13377 | uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset; | |
13378 | int rc; | |
13379 | ||
13380 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13381 | if (!pmb) { | |
13382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13383 | "2600 lpfc_sli_read_serdes_param failed to" | |
13384 | " allocate mailbox memory\n"); | |
13385 | goto out; | |
13386 | } | |
13387 | mb = &pmb->u.mb; | |
13388 | ||
13389 | /* Get adapter Region 23 data */ | |
13390 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
13391 | if (!rgn23_data) | |
13392 | goto out; | |
13393 | ||
13394 | do { | |
13395 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
13396 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
13397 | ||
13398 | if (rc != MBX_SUCCESS) { | |
13399 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13400 | "2601 lpfc_sli_read_link_ste failed to" | |
13401 | " read config region 23 rc 0x%x Status 0x%x\n", | |
13402 | rc, mb->mbxStatus); | |
13403 | mb->un.varDmp.word_cnt = 0; | |
13404 | } | |
13405 | /* | |
13406 | * dump mem may return a zero when finished or we got a | |
13407 | * mailbox error, either way we are done. | |
13408 | */ | |
13409 | if (mb->un.varDmp.word_cnt == 0) | |
13410 | break; | |
13411 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
13412 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
13413 | ||
13414 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
13415 | rgn23_data + offset, | |
13416 | mb->un.varDmp.word_cnt); | |
13417 | offset += mb->un.varDmp.word_cnt; | |
13418 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
13419 | ||
13420 | data_size = offset; | |
13421 | offset = 0; | |
13422 | ||
13423 | if (!data_size) | |
13424 | goto out; | |
13425 | ||
13426 | /* Check the region signature first */ | |
13427 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
13428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13429 | "2619 Config region 23 has bad signature\n"); | |
13430 | goto out; | |
13431 | } | |
13432 | offset += 4; | |
13433 | ||
13434 | /* Check the data structure version */ | |
13435 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
13436 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13437 | "2620 Config region 23 has bad version\n"); | |
13438 | goto out; | |
13439 | } | |
13440 | offset += 4; | |
13441 | ||
13442 | /* Parse TLV entries in the region */ | |
13443 | while (offset < data_size) { | |
13444 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
13445 | break; | |
13446 | /* | |
13447 | * If the TLV is not driver specific TLV or driver id is | |
13448 | * not linux driver id, skip the record. | |
13449 | */ | |
13450 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
13451 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
13452 | (rgn23_data[offset + 3] != 0)) { | |
13453 | offset += rgn23_data[offset + 1] * 4 + 4; | |
13454 | continue; | |
13455 | } | |
13456 | ||
13457 | /* Driver found a driver specific TLV in the config region */ | |
13458 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
13459 | offset += 4; | |
13460 | tlv_offset = 0; | |
13461 | ||
13462 | /* | |
13463 | * Search for configured port state sub-TLV. | |
13464 | */ | |
13465 | while ((offset < data_size) && | |
13466 | (tlv_offset < sub_tlv_len)) { | |
13467 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
13468 | offset += 4; | |
13469 | tlv_offset += 4; | |
13470 | break; | |
13471 | } | |
13472 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
13473 | offset += rgn23_data[offset + 1] * 4 + 4; | |
13474 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
13475 | continue; | |
13476 | } | |
13477 | ||
13478 | /* This HBA contains PORT_STE configured */ | |
13479 | if (!rgn23_data[offset + 2]) | |
13480 | phba->hba_flag |= LINK_DISABLED; | |
13481 | ||
13482 | goto out; | |
13483 | } | |
13484 | } | |
13485 | out: | |
13486 | if (pmb) | |
13487 | mempool_free(pmb, phba->mbox_mem_pool); | |
13488 | kfree(rgn23_data); | |
13489 | return; | |
13490 | } | |
695a814e JS |
13491 | |
13492 | /** | |
13493 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
13494 | * @vport: pointer to vport data structure. | |
13495 | * | |
13496 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
13497 | * and REG_VPI mailbox commands associated with the vport. This function | |
13498 | * is called when driver want to restart discovery of the vport due to | |
13499 | * a Clear Virtual Link event. | |
13500 | **/ | |
13501 | void | |
13502 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
13503 | { | |
13504 | struct lpfc_hba *phba = vport->phba; | |
13505 | LPFC_MBOXQ_t *mb, *nextmb; | |
13506 | struct lpfc_dmabuf *mp; | |
78730cfe | 13507 | struct lpfc_nodelist *ndlp; |
d439d286 | 13508 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 13509 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 13510 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 13511 | uint8_t restart_loop; |
695a814e | 13512 | |
d439d286 | 13513 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
13514 | spin_lock_irq(&phba->hbalock); |
13515 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
13516 | if (mb->vport != vport) | |
13517 | continue; | |
13518 | ||
13519 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
13520 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
13521 | continue; | |
13522 | ||
d439d286 JS |
13523 | list_del(&mb->list); |
13524 | list_add_tail(&mb->list, &mbox_cmd_list); | |
13525 | } | |
13526 | /* Clean up active mailbox command with the vport */ | |
13527 | mb = phba->sli.mbox_active; | |
13528 | if (mb && (mb->vport == vport)) { | |
13529 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
13530 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
13531 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13532 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
13533 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
13534 | /* Put reference count for delayed processing */ | |
13535 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
13536 | /* Unregister the RPI when mailbox complete */ | |
13537 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
13538 | } | |
13539 | } | |
63e801ce JS |
13540 | /* Cleanup any mailbox completions which are not yet processed */ |
13541 | do { | |
13542 | restart_loop = 0; | |
13543 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
13544 | /* | |
13545 | * If this mailox is already processed or it is | |
13546 | * for another vport ignore it. | |
13547 | */ | |
13548 | if ((mb->vport != vport) || | |
13549 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
13550 | continue; | |
13551 | ||
13552 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
13553 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
13554 | continue; | |
13555 | ||
13556 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13557 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
13558 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
13559 | /* Unregister the RPI when mailbox complete */ | |
13560 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
13561 | restart_loop = 1; | |
13562 | spin_unlock_irq(&phba->hbalock); | |
13563 | spin_lock(shost->host_lock); | |
13564 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
13565 | spin_unlock(shost->host_lock); | |
13566 | spin_lock_irq(&phba->hbalock); | |
13567 | break; | |
13568 | } | |
13569 | } | |
13570 | } while (restart_loop); | |
13571 | ||
d439d286 JS |
13572 | spin_unlock_irq(&phba->hbalock); |
13573 | ||
13574 | /* Release the cleaned-up mailbox commands */ | |
13575 | while (!list_empty(&mbox_cmd_list)) { | |
13576 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e JS |
13577 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
13578 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
13579 | if (mp) { | |
13580 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
13581 | kfree(mp); | |
13582 | } | |
78730cfe | 13583 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 13584 | mb->context2 = NULL; |
78730cfe | 13585 | if (ndlp) { |
ec21b3b0 | 13586 | spin_lock(shost->host_lock); |
589a52d6 | 13587 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 13588 | spin_unlock(shost->host_lock); |
78730cfe | 13589 | lpfc_nlp_put(ndlp); |
78730cfe | 13590 | } |
695a814e | 13591 | } |
695a814e JS |
13592 | mempool_free(mb, phba->mbox_mem_pool); |
13593 | } | |
d439d286 JS |
13594 | |
13595 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
13596 | if (act_mbx_ndlp) { | |
13597 | spin_lock(shost->host_lock); | |
13598 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
13599 | spin_unlock(shost->host_lock); | |
13600 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 13601 | } |
695a814e JS |
13602 | } |
13603 | ||
2a9bf3d0 JS |
13604 | /** |
13605 | * lpfc_drain_txq - Drain the txq | |
13606 | * @phba: Pointer to HBA context object. | |
13607 | * | |
13608 | * This function attempt to submit IOCBs on the txq | |
13609 | * to the adapter. For SLI4 adapters, the txq contains | |
13610 | * ELS IOCBs that have been deferred because the there | |
13611 | * are no SGLs. This congestion can occur with large | |
13612 | * vport counts during node discovery. | |
13613 | **/ | |
13614 | ||
13615 | uint32_t | |
13616 | lpfc_drain_txq(struct lpfc_hba *phba) | |
13617 | { | |
13618 | LIST_HEAD(completions); | |
13619 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
13620 | struct lpfc_iocbq *piocbq = 0; | |
13621 | unsigned long iflags = 0; | |
13622 | char *fail_msg = NULL; | |
13623 | struct lpfc_sglq *sglq; | |
13624 | union lpfc_wqe wqe; | |
13625 | ||
13626 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13627 | if (pring->txq_cnt > pring->txq_max) | |
13628 | pring->txq_max = pring->txq_cnt; | |
13629 | ||
13630 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13631 | ||
13632 | while (pring->txq_cnt) { | |
13633 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13634 | ||
19ca7609 JS |
13635 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
13636 | sglq = __lpfc_sli_get_sglq(phba, piocbq); | |
2a9bf3d0 | 13637 | if (!sglq) { |
19ca7609 | 13638 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
13639 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
13640 | break; | |
13641 | } else { | |
2a9bf3d0 JS |
13642 | if (!piocbq) { |
13643 | /* The txq_cnt out of sync. This should | |
13644 | * never happen | |
13645 | */ | |
13646 | sglq = __lpfc_clear_active_sglq(phba, | |
13647 | sglq->sli4_xritag); | |
13648 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13649 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13650 | "2823 txq empty and txq_cnt is %d\n ", | |
13651 | pring->txq_cnt); | |
13652 | break; | |
13653 | } | |
13654 | } | |
13655 | ||
13656 | /* The xri and iocb resources secured, | |
13657 | * attempt to issue request | |
13658 | */ | |
13659 | piocbq->sli4_xritag = sglq->sli4_xritag; | |
13660 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
13661 | fail_msg = "to convert bpl to sgl"; | |
13662 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
13663 | fail_msg = "to convert iocb to wqe"; | |
13664 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
13665 | fail_msg = " - Wq is full"; | |
13666 | else | |
13667 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
13668 | ||
13669 | if (fail_msg) { | |
13670 | /* Failed means we can't issue and need to cancel */ | |
13671 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13672 | "2822 IOCB failed %s iotag 0x%x " | |
13673 | "xri 0x%x\n", | |
13674 | fail_msg, | |
13675 | piocbq->iotag, piocbq->sli4_xritag); | |
13676 | list_add_tail(&piocbq->list, &completions); | |
13677 | } | |
13678 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13679 | } | |
13680 | ||
2a9bf3d0 JS |
13681 | /* Cancel all the IOCBs that cannot be issued */ |
13682 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
13683 | IOERR_SLI_ABORTED); | |
13684 | ||
13685 | return pring->txq_cnt; | |
13686 | } |