Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
d8e93df1 | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | |
91886523 | 28 | #include <scsi/scsi.h> |
dea3101e | 29 | #include <scsi/scsi_cmnd.h> |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_host.h> | |
f888ba3c | 32 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 33 | #include <scsi/fc/fc_fs.h> |
0d878419 | 34 | #include <linux/aer.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e | 37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e | 41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_crtn.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_compat.h" | |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
04c68496 | 48 | #include "lpfc_vport.h" |
dea3101e | 49 | |
50 | /* There are only four IOCB completion types. */ | |
51 | typedef enum _lpfc_iocb_type { | |
52 | LPFC_UNKNOWN_IOCB, | |
53 | LPFC_UNSOL_IOCB, | |
54 | LPFC_SOL_IOCB, | |
55 | LPFC_ABORT_IOCB | |
56 | } lpfc_iocb_type; | |
57 | ||
4f774513 JS |
58 | |
59 | /* Provide function prototypes local to this module. */ | |
60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
61 | uint32_t); | |
62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
63 | uint8_t *, uint32_t *); |
64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
65 | struct lpfc_iocbq *); | |
6669f9bb JS |
66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
67 | struct hbq_dmabuf *); | |
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); |
4f774513 JS |
99 | |
100 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); | |
101 | ||
102 | /* Update the host index before invoking device */ | |
103 | host_index = q->host_index; | |
104 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
105 | ||
106 | /* Ring Doorbell */ | |
107 | doorbell.word0 = 0; | |
108 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); | |
109 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); | |
110 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); | |
111 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); | |
112 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ | |
113 | ||
114 | return 0; | |
115 | } | |
116 | ||
117 | /** | |
118 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | |
119 | * @q: The Work Queue to operate on. | |
120 | * @index: The index to advance the hba index to. | |
121 | * | |
122 | * This routine will update the HBA index of a queue to reflect consumption of | |
123 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | |
124 | * an entry the host calls this function to update the queue's internal | |
125 | * pointers. This routine returns the number of entries that were consumed by | |
126 | * the HBA. | |
127 | **/ | |
128 | static uint32_t | |
129 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | |
130 | { | |
131 | uint32_t released = 0; | |
132 | ||
133 | if (q->hba_index == index) | |
134 | return 0; | |
135 | do { | |
136 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
137 | released++; | |
138 | } while (q->hba_index != index); | |
139 | return released; | |
140 | } | |
141 | ||
142 | /** | |
143 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | |
144 | * @q: The Mailbox Queue to operate on. | |
145 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | |
146 | * | |
147 | * This routine will copy the contents of @mqe to the next available entry on | |
148 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
149 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
150 | * successful. If no entries are available on @q then this function will return | |
151 | * -ENOMEM. | |
152 | * The caller is expected to hold the hbalock when calling this routine. | |
153 | **/ | |
154 | static uint32_t | |
155 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | |
156 | { | |
157 | struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe; | |
158 | struct lpfc_register doorbell; | |
159 | uint32_t host_index; | |
160 | ||
161 | /* If the host has not yet processed the next entry then we are done */ | |
162 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
163 | return -ENOMEM; | |
164 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | |
165 | /* Save off the mailbox pointer for completion */ | |
166 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | |
167 | ||
168 | /* Update the host index before invoking device */ | |
169 | host_index = q->host_index; | |
170 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
171 | ||
172 | /* Ring Doorbell */ | |
173 | doorbell.word0 = 0; | |
174 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | |
175 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | |
176 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | |
177 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ | |
178 | return 0; | |
179 | } | |
180 | ||
181 | /** | |
182 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | |
183 | * @q: The Mailbox Queue to operate on. | |
184 | * | |
185 | * This routine will update the HBA index of a queue to reflect consumption of | |
186 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | |
187 | * an entry the host calls this function to update the queue's internal | |
188 | * pointers. This routine returns the number of entries that were consumed by | |
189 | * the HBA. | |
190 | **/ | |
191 | static uint32_t | |
192 | lpfc_sli4_mq_release(struct lpfc_queue *q) | |
193 | { | |
194 | /* Clear the mailbox pointer for completion */ | |
195 | q->phba->mbox = NULL; | |
196 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
197 | return 1; | |
198 | } | |
199 | ||
200 | /** | |
201 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | |
202 | * @q: The Event Queue to get the first valid EQE from | |
203 | * | |
204 | * This routine will get the first valid Event Queue Entry from @q, update | |
205 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | |
206 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | |
207 | * processed, but not popped back to the HBA then this routine will return NULL. | |
208 | **/ | |
209 | static struct lpfc_eqe * | |
210 | lpfc_sli4_eq_get(struct lpfc_queue *q) | |
211 | { | |
212 | struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe; | |
213 | ||
214 | /* If the next EQE is not valid then we are done */ | |
cb5172ea | 215 | if (!bf_get_le32(lpfc_eqe_valid, eqe)) |
4f774513 JS |
216 | return NULL; |
217 | /* If the host has not yet processed the next entry then we are done */ | |
218 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | |
219 | return NULL; | |
220 | ||
221 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
222 | return eqe; | |
223 | } | |
224 | ||
225 | /** | |
226 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | |
227 | * @q: The Event Queue that the host has completed processing for. | |
228 | * @arm: Indicates whether the host wants to arms this CQ. | |
229 | * | |
230 | * This routine will mark all Event Queue Entries on @q, from the last | |
231 | * known completed entry to the last entry that was processed, as completed | |
232 | * by clearing the valid bit for each completion queue entry. Then it will | |
233 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | |
234 | * The internal host index in the @q will be updated by this routine to indicate | |
235 | * that the host has finished processing the entries. The @arm parameter | |
236 | * indicates that the queue should be rearmed when ringing the doorbell. | |
237 | * | |
238 | * This function will return the number of EQEs that were popped. | |
239 | **/ | |
240 | uint32_t | |
241 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | |
242 | { | |
243 | uint32_t released = 0; | |
244 | struct lpfc_eqe *temp_eqe; | |
245 | struct lpfc_register doorbell; | |
246 | ||
247 | /* while there are valid entries */ | |
248 | while (q->hba_index != q->host_index) { | |
249 | temp_eqe = q->qe[q->host_index].eqe; | |
cb5172ea | 250 | bf_set_le32(lpfc_eqe_valid, temp_eqe, 0); |
4f774513 JS |
251 | released++; |
252 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
253 | } | |
254 | if (unlikely(released == 0 && !arm)) | |
255 | return 0; | |
256 | ||
257 | /* ring doorbell for number popped */ | |
258 | doorbell.word0 = 0; | |
259 | if (arm) { | |
260 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
261 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | |
262 | } | |
263 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
264 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | |
265 | bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id); | |
266 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
a747c9ce JS |
267 | /* PCI read to flush PCI pipeline on re-arming for INTx mode */ |
268 | if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM)) | |
269 | readl(q->phba->sli4_hba.EQCQDBregaddr); | |
4f774513 JS |
270 | return released; |
271 | } | |
272 | ||
273 | /** | |
274 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | |
275 | * @q: The Completion Queue to get the first valid CQE from | |
276 | * | |
277 | * This routine will get the first valid Completion Queue Entry from @q, update | |
278 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | |
279 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | |
280 | * processed, but not popped back to the HBA then this routine will return NULL. | |
281 | **/ | |
282 | static struct lpfc_cqe * | |
283 | lpfc_sli4_cq_get(struct lpfc_queue *q) | |
284 | { | |
285 | struct lpfc_cqe *cqe; | |
286 | ||
287 | /* If the next CQE is not valid then we are done */ | |
cb5172ea | 288 | if (!bf_get_le32(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) |
4f774513 JS |
289 | return NULL; |
290 | /* If the host has not yet processed the next entry then we are done */ | |
291 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | |
292 | return NULL; | |
293 | ||
294 | cqe = q->qe[q->hba_index].cqe; | |
295 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | |
296 | return cqe; | |
297 | } | |
298 | ||
299 | /** | |
300 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | |
301 | * @q: The Completion Queue that the host has completed processing for. | |
302 | * @arm: Indicates whether the host wants to arms this CQ. | |
303 | * | |
304 | * This routine will mark all Completion queue entries on @q, from the last | |
305 | * known completed entry to the last entry that was processed, as completed | |
306 | * by clearing the valid bit for each completion queue entry. Then it will | |
307 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | |
308 | * The internal host index in the @q will be updated by this routine to indicate | |
309 | * that the host has finished processing the entries. The @arm parameter | |
310 | * indicates that the queue should be rearmed when ringing the doorbell. | |
311 | * | |
312 | * This function will return the number of CQEs that were released. | |
313 | **/ | |
314 | uint32_t | |
315 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | |
316 | { | |
317 | uint32_t released = 0; | |
318 | struct lpfc_cqe *temp_qe; | |
319 | struct lpfc_register doorbell; | |
320 | ||
321 | /* while there are valid entries */ | |
322 | while (q->hba_index != q->host_index) { | |
323 | temp_qe = q->qe[q->host_index].cqe; | |
cb5172ea | 324 | bf_set_le32(lpfc_cqe_valid, temp_qe, 0); |
4f774513 JS |
325 | released++; |
326 | q->host_index = ((q->host_index + 1) % q->entry_count); | |
327 | } | |
328 | if (unlikely(released == 0 && !arm)) | |
329 | return 0; | |
330 | ||
331 | /* ring doorbell for number popped */ | |
332 | doorbell.word0 = 0; | |
333 | if (arm) | |
334 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | |
335 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | |
336 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | |
337 | bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id); | |
338 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | |
339 | return released; | |
340 | } | |
341 | ||
342 | /** | |
343 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | |
344 | * @q: The Header Receive Queue to operate on. | |
345 | * @wqe: The Receive Queue Entry to put on the Receive queue. | |
346 | * | |
347 | * This routine will copy the contents of @wqe to the next available entry on | |
348 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | |
349 | * HBA to start processing the Receive Queue Entry. This function returns the | |
350 | * index that the rqe was copied to if successful. If no entries are available | |
351 | * on @q then this function will return -ENOMEM. | |
352 | * The caller is expected to hold the hbalock when calling this routine. | |
353 | **/ | |
354 | static int | |
355 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | |
356 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | |
357 | { | |
358 | struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe; | |
359 | struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe; | |
360 | struct lpfc_register doorbell; | |
361 | int put_index = hq->host_index; | |
362 | ||
363 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) | |
364 | return -EINVAL; | |
365 | if (hq->host_index != dq->host_index) | |
366 | return -EINVAL; | |
367 | /* If the host has not yet processed the next entry then we are done */ | |
368 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | |
369 | return -EBUSY; | |
370 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | |
371 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | |
372 | ||
373 | /* Update the host index to point to the next slot */ | |
374 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | |
375 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | |
376 | ||
377 | /* Ring The Header Receive Queue Doorbell */ | |
378 | if (!(hq->host_index % LPFC_RQ_POST_BATCH)) { | |
379 | doorbell.word0 = 0; | |
380 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | |
381 | LPFC_RQ_POST_BATCH); | |
382 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); | |
383 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); | |
384 | } | |
385 | return put_index; | |
386 | } | |
387 | ||
388 | /** | |
389 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | |
390 | * @q: The Header Receive Queue to operate on. | |
391 | * | |
392 | * This routine will update the HBA index of a queue to reflect consumption of | |
393 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | |
394 | * consumed an entry the host calls this function to update the queue's | |
395 | * internal pointers. This routine returns the number of entries that were | |
396 | * consumed by the HBA. | |
397 | **/ | |
398 | static uint32_t | |
399 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | |
400 | { | |
401 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) | |
402 | return 0; | |
403 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | |
404 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | |
405 | return 1; | |
406 | } | |
407 | ||
e59058c4 | 408 | /** |
3621a710 | 409 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
e59058c4 JS |
410 | * @phba: Pointer to HBA context object. |
411 | * @pring: Pointer to driver SLI ring object. | |
412 | * | |
413 | * This function returns pointer to next command iocb entry | |
414 | * in the command ring. The caller must hold hbalock to prevent | |
415 | * other threads consume the next command iocb. | |
416 | * SLI-2/SLI-3 provide different sized iocbs. | |
417 | **/ | |
ed957684 JS |
418 | static inline IOCB_t * |
419 | lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
420 | { | |
421 | return (IOCB_t *) (((char *) pring->cmdringaddr) + | |
422 | pring->cmdidx * phba->iocb_cmd_size); | |
423 | } | |
424 | ||
e59058c4 | 425 | /** |
3621a710 | 426 | * lpfc_resp_iocb - Get next response iocb entry in the ring |
e59058c4 JS |
427 | * @phba: Pointer to HBA context object. |
428 | * @pring: Pointer to driver SLI ring object. | |
429 | * | |
430 | * This function returns pointer to next response iocb entry | |
431 | * in the response ring. The caller must hold hbalock to make sure | |
432 | * that no other thread consume the next response iocb. | |
433 | * SLI-2/SLI-3 provide different sized iocbs. | |
434 | **/ | |
ed957684 JS |
435 | static inline IOCB_t * |
436 | lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
437 | { | |
438 | return (IOCB_t *) (((char *) pring->rspringaddr) + | |
439 | pring->rspidx * phba->iocb_rsp_size); | |
440 | } | |
441 | ||
e59058c4 | 442 | /** |
3621a710 | 443 | * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
444 | * @phba: Pointer to HBA context object. |
445 | * | |
446 | * This function is called with hbalock held. This function | |
447 | * allocates a new driver iocb object from the iocb pool. If the | |
448 | * allocation is successful, it returns pointer to the newly | |
449 | * allocated iocb object else it returns NULL. | |
450 | **/ | |
2e0fef85 JS |
451 | static struct lpfc_iocbq * |
452 | __lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
0bd4ca25 JSEC |
453 | { |
454 | struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; | |
455 | struct lpfc_iocbq * iocbq = NULL; | |
456 | ||
457 | list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list); | |
2a9bf3d0 JS |
458 | |
459 | if (iocbq) | |
460 | phba->iocb_cnt++; | |
461 | if (phba->iocb_cnt > phba->iocb_max) | |
462 | phba->iocb_max = phba->iocb_cnt; | |
0bd4ca25 JSEC |
463 | return iocbq; |
464 | } | |
465 | ||
da0436e9 JS |
466 | /** |
467 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | |
468 | * @phba: Pointer to HBA context object. | |
469 | * @xritag: XRI value. | |
470 | * | |
471 | * This function clears the sglq pointer from the array of acive | |
472 | * sglq's. The xritag that is passed in is used to index into the | |
473 | * array. Before the xritag can be used it needs to be adjusted | |
474 | * by subtracting the xribase. | |
475 | * | |
476 | * Returns sglq ponter = success, NULL = Failure. | |
477 | **/ | |
478 | static struct lpfc_sglq * | |
479 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | |
480 | { | |
481 | uint16_t adj_xri; | |
482 | struct lpfc_sglq *sglq; | |
483 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
484 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) | |
485 | return NULL; | |
486 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; | |
487 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL; | |
488 | return sglq; | |
489 | } | |
490 | ||
491 | /** | |
492 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | |
493 | * @phba: Pointer to HBA context object. | |
494 | * @xritag: XRI value. | |
495 | * | |
496 | * This function returns the sglq pointer from the array of acive | |
497 | * sglq's. The xritag that is passed in is used to index into the | |
498 | * array. Before the xritag can be used it needs to be adjusted | |
499 | * by subtracting the xribase. | |
500 | * | |
501 | * Returns sglq ponter = success, NULL = Failure. | |
502 | **/ | |
0f65ff68 | 503 | struct lpfc_sglq * |
da0436e9 JS |
504 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) |
505 | { | |
506 | uint16_t adj_xri; | |
507 | struct lpfc_sglq *sglq; | |
508 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
509 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) | |
510 | return NULL; | |
511 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; | |
512 | return sglq; | |
513 | } | |
514 | ||
19ca7609 JS |
515 | /** |
516 | * __lpfc_set_rrq_active - set RRQ active bit in the ndlp's xri_bitmap. | |
517 | * @phba: Pointer to HBA context object. | |
518 | * @ndlp: nodelist pointer for this target. | |
519 | * @xritag: xri used in this exchange. | |
520 | * @rxid: Remote Exchange ID. | |
521 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
522 | * | |
523 | * This function is called with hbalock held. | |
524 | * The active bit is set in the ndlp's active rrq xri_bitmap. Allocates an | |
525 | * rrq struct and adds it to the active_rrq_list. | |
526 | * | |
527 | * returns 0 for rrq slot for this xri | |
528 | * < 0 Were not able to get rrq mem or invalid parameter. | |
529 | **/ | |
530 | static int | |
531 | __lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
532 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) | |
533 | { | |
534 | uint16_t adj_xri; | |
535 | struct lpfc_node_rrq *rrq; | |
536 | int empty; | |
537 | ||
538 | /* | |
539 | * set the active bit even if there is no mem available. | |
540 | */ | |
541 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
542 | if (!ndlp) | |
543 | return -EINVAL; | |
544 | if (test_and_set_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) | |
545 | return -EINVAL; | |
546 | rrq = mempool_alloc(phba->rrq_pool, GFP_KERNEL); | |
547 | if (rrq) { | |
548 | rrq->send_rrq = send_rrq; | |
549 | rrq->xritag = xritag; | |
550 | rrq->rrq_stop_time = jiffies + HZ * (phba->fc_ratov + 1); | |
551 | rrq->ndlp = ndlp; | |
552 | rrq->nlp_DID = ndlp->nlp_DID; | |
553 | rrq->vport = ndlp->vport; | |
554 | rrq->rxid = rxid; | |
555 | empty = list_empty(&phba->active_rrq_list); | |
556 | if (phba->cfg_enable_rrq && send_rrq) | |
557 | /* | |
558 | * We need the xri before we can add this to the | |
559 | * phba active rrq list. | |
560 | */ | |
561 | rrq->send_rrq = send_rrq; | |
562 | else | |
563 | rrq->send_rrq = 0; | |
564 | list_add_tail(&rrq->list, &phba->active_rrq_list); | |
565 | if (!(phba->hba_flag & HBA_RRQ_ACTIVE)) { | |
566 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
567 | if (empty) | |
568 | lpfc_worker_wake_up(phba); | |
569 | } | |
570 | return 0; | |
571 | } | |
572 | return -ENOMEM; | |
573 | } | |
574 | ||
575 | /** | |
576 | * __lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. | |
577 | * @phba: Pointer to HBA context object. | |
578 | * @xritag: xri used in this exchange. | |
579 | * @rrq: The RRQ to be cleared. | |
580 | * | |
581 | * This function is called with hbalock held. This function | |
582 | **/ | |
583 | static void | |
584 | __lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
585 | uint16_t xritag, | |
586 | struct lpfc_node_rrq *rrq) | |
587 | { | |
588 | uint16_t adj_xri; | |
589 | struct lpfc_nodelist *ndlp; | |
590 | ||
591 | ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID); | |
592 | ||
593 | /* The target DID could have been swapped (cable swap) | |
594 | * we should use the ndlp from the findnode if it is | |
595 | * available. | |
596 | */ | |
597 | if (!ndlp) | |
598 | ndlp = rrq->ndlp; | |
599 | ||
600 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
601 | if (test_and_clear_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) { | |
602 | rrq->send_rrq = 0; | |
603 | rrq->xritag = 0; | |
604 | rrq->rrq_stop_time = 0; | |
605 | } | |
606 | mempool_free(rrq, phba->rrq_pool); | |
607 | } | |
608 | ||
609 | /** | |
610 | * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV. | |
611 | * @phba: Pointer to HBA context object. | |
612 | * | |
613 | * This function is called with hbalock held. This function | |
614 | * Checks if stop_time (ratov from setting rrq active) has | |
615 | * been reached, if it has and the send_rrq flag is set then | |
616 | * it will call lpfc_send_rrq. If the send_rrq flag is not set | |
617 | * then it will just call the routine to clear the rrq and | |
618 | * free the rrq resource. | |
619 | * The timer is set to the next rrq that is going to expire before | |
620 | * leaving the routine. | |
621 | * | |
622 | **/ | |
623 | void | |
624 | lpfc_handle_rrq_active(struct lpfc_hba *phba) | |
625 | { | |
626 | struct lpfc_node_rrq *rrq; | |
627 | struct lpfc_node_rrq *nextrrq; | |
628 | unsigned long next_time; | |
629 | unsigned long iflags; | |
630 | ||
631 | spin_lock_irqsave(&phba->hbalock, iflags); | |
632 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
633 | next_time = jiffies + HZ * (phba->fc_ratov + 1); | |
634 | list_for_each_entry_safe(rrq, nextrrq, | |
635 | &phba->active_rrq_list, list) { | |
636 | if (time_after(jiffies, rrq->rrq_stop_time)) { | |
637 | list_del(&rrq->list); | |
638 | if (!rrq->send_rrq) | |
639 | /* this call will free the rrq */ | |
640 | __lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
641 | else { | |
642 | /* if we send the rrq then the completion handler | |
643 | * will clear the bit in the xribitmap. | |
644 | */ | |
645 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
646 | if (lpfc_send_rrq(phba, rrq)) { | |
647 | lpfc_clr_rrq_active(phba, rrq->xritag, | |
648 | rrq); | |
649 | } | |
650 | spin_lock_irqsave(&phba->hbalock, iflags); | |
651 | } | |
652 | } else if (time_before(rrq->rrq_stop_time, next_time)) | |
653 | next_time = rrq->rrq_stop_time; | |
654 | } | |
655 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
656 | if (!list_empty(&phba->active_rrq_list)) | |
657 | mod_timer(&phba->rrq_tmr, next_time); | |
658 | } | |
659 | ||
660 | /** | |
661 | * lpfc_get_active_rrq - Get the active RRQ for this exchange. | |
662 | * @vport: Pointer to vport context object. | |
663 | * @xri: The xri used in the exchange. | |
664 | * @did: The targets DID for this exchange. | |
665 | * | |
666 | * returns NULL = rrq not found in the phba->active_rrq_list. | |
667 | * rrq = rrq for this xri and target. | |
668 | **/ | |
669 | struct lpfc_node_rrq * | |
670 | lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did) | |
671 | { | |
672 | struct lpfc_hba *phba = vport->phba; | |
673 | struct lpfc_node_rrq *rrq; | |
674 | struct lpfc_node_rrq *nextrrq; | |
675 | unsigned long iflags; | |
676 | ||
677 | if (phba->sli_rev != LPFC_SLI_REV4) | |
678 | return NULL; | |
679 | spin_lock_irqsave(&phba->hbalock, iflags); | |
680 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
681 | if (rrq->vport == vport && rrq->xritag == xri && | |
682 | rrq->nlp_DID == did){ | |
683 | list_del(&rrq->list); | |
684 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
685 | return rrq; | |
686 | } | |
687 | } | |
688 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
689 | return NULL; | |
690 | } | |
691 | ||
692 | /** | |
693 | * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport. | |
694 | * @vport: Pointer to vport context object. | |
695 | * | |
696 | * Remove all active RRQs for this vport from the phba->active_rrq_list and | |
697 | * clear the rrq. | |
698 | **/ | |
699 | void | |
700 | lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport) | |
701 | ||
702 | { | |
703 | struct lpfc_hba *phba = vport->phba; | |
704 | struct lpfc_node_rrq *rrq; | |
705 | struct lpfc_node_rrq *nextrrq; | |
706 | unsigned long iflags; | |
707 | ||
708 | if (phba->sli_rev != LPFC_SLI_REV4) | |
709 | return; | |
710 | spin_lock_irqsave(&phba->hbalock, iflags); | |
711 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
712 | if (rrq->vport == vport) { | |
713 | list_del(&rrq->list); | |
714 | __lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
715 | } | |
716 | } | |
717 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
718 | } | |
719 | ||
720 | /** | |
721 | * lpfc_cleanup_wt_rrqs - Remove all rrq's from the active list. | |
722 | * @phba: Pointer to HBA context object. | |
723 | * | |
724 | * Remove all rrqs from the phba->active_rrq_list and free them by | |
725 | * calling __lpfc_clr_active_rrq | |
726 | * | |
727 | **/ | |
728 | void | |
729 | lpfc_cleanup_wt_rrqs(struct lpfc_hba *phba) | |
730 | { | |
731 | struct lpfc_node_rrq *rrq; | |
732 | struct lpfc_node_rrq *nextrrq; | |
733 | unsigned long next_time; | |
734 | unsigned long iflags; | |
735 | ||
736 | if (phba->sli_rev != LPFC_SLI_REV4) | |
737 | return; | |
738 | spin_lock_irqsave(&phba->hbalock, iflags); | |
739 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
740 | next_time = jiffies + HZ * (phba->fc_ratov * 2); | |
741 | list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) { | |
742 | list_del(&rrq->list); | |
743 | __lpfc_clr_rrq_active(phba, rrq->xritag, rrq); | |
744 | } | |
745 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
746 | if (!list_empty(&phba->active_rrq_list)) | |
747 | mod_timer(&phba->rrq_tmr, next_time); | |
748 | } | |
749 | ||
750 | ||
751 | /** | |
752 | * __lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. | |
753 | * @phba: Pointer to HBA context object. | |
754 | * @ndlp: Targets nodelist pointer for this exchange. | |
755 | * @xritag the xri in the bitmap to test. | |
756 | * | |
757 | * This function is called with hbalock held. This function | |
758 | * returns 0 = rrq not active for this xri | |
759 | * 1 = rrq is valid for this xri. | |
760 | **/ | |
761 | static int | |
762 | __lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
763 | uint16_t xritag) | |
764 | { | |
765 | uint16_t adj_xri; | |
766 | ||
767 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | |
768 | if (!ndlp) | |
769 | return 0; | |
770 | if (test_bit(adj_xri, ndlp->active_rrqs.xri_bitmap)) | |
771 | return 1; | |
772 | else | |
773 | return 0; | |
774 | } | |
775 | ||
776 | /** | |
777 | * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap. | |
778 | * @phba: Pointer to HBA context object. | |
779 | * @ndlp: nodelist pointer for this target. | |
780 | * @xritag: xri used in this exchange. | |
781 | * @rxid: Remote Exchange ID. | |
782 | * @send_rrq: Flag used to determine if we should send rrq els cmd. | |
783 | * | |
784 | * This function takes the hbalock. | |
785 | * The active bit is always set in the active rrq xri_bitmap even | |
786 | * if there is no slot avaiable for the other rrq information. | |
787 | * | |
788 | * returns 0 rrq actived for this xri | |
789 | * < 0 No memory or invalid ndlp. | |
790 | **/ | |
791 | int | |
792 | lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
793 | uint16_t xritag, uint16_t rxid, uint16_t send_rrq) | |
794 | { | |
795 | int ret; | |
796 | unsigned long iflags; | |
797 | ||
798 | spin_lock_irqsave(&phba->hbalock, iflags); | |
799 | ret = __lpfc_set_rrq_active(phba, ndlp, xritag, rxid, send_rrq); | |
800 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
801 | return ret; | |
802 | } | |
803 | ||
804 | /** | |
805 | * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap. | |
806 | * @phba: Pointer to HBA context object. | |
807 | * @xritag: xri used in this exchange. | |
808 | * @rrq: The RRQ to be cleared. | |
809 | * | |
810 | * This function is takes the hbalock. | |
811 | **/ | |
812 | void | |
813 | lpfc_clr_rrq_active(struct lpfc_hba *phba, | |
814 | uint16_t xritag, | |
815 | struct lpfc_node_rrq *rrq) | |
816 | { | |
817 | unsigned long iflags; | |
818 | ||
819 | spin_lock_irqsave(&phba->hbalock, iflags); | |
820 | __lpfc_clr_rrq_active(phba, xritag, rrq); | |
821 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
822 | return; | |
823 | } | |
824 | ||
825 | ||
826 | ||
827 | /** | |
828 | * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap. | |
829 | * @phba: Pointer to HBA context object. | |
830 | * @ndlp: Targets nodelist pointer for this exchange. | |
831 | * @xritag the xri in the bitmap to test. | |
832 | * | |
833 | * This function takes the hbalock. | |
834 | * returns 0 = rrq not active for this xri | |
835 | * 1 = rrq is valid for this xri. | |
836 | **/ | |
837 | int | |
838 | lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, | |
839 | uint16_t xritag) | |
840 | { | |
841 | int ret; | |
842 | unsigned long iflags; | |
843 | ||
844 | spin_lock_irqsave(&phba->hbalock, iflags); | |
845 | ret = __lpfc_test_rrq_active(phba, ndlp, xritag); | |
846 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
847 | return ret; | |
848 | } | |
849 | ||
da0436e9 JS |
850 | /** |
851 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
852 | * @phba: Pointer to HBA context object. | |
19ca7609 | 853 | * @piocb: Pointer to the iocbq. |
da0436e9 JS |
854 | * |
855 | * This function is called with hbalock held. This function | |
856 | * Gets a new driver sglq object from the sglq list. If the | |
857 | * list is not empty then it is successful, it returns pointer to the newly | |
858 | * allocated sglq object else it returns NULL. | |
859 | **/ | |
860 | static struct lpfc_sglq * | |
19ca7609 | 861 | __lpfc_sli_get_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq) |
da0436e9 JS |
862 | { |
863 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
864 | struct lpfc_sglq *sglq = NULL; | |
19ca7609 | 865 | struct lpfc_sglq *start_sglq = NULL; |
da0436e9 | 866 | uint16_t adj_xri; |
19ca7609 JS |
867 | struct lpfc_scsi_buf *lpfc_cmd; |
868 | struct lpfc_nodelist *ndlp; | |
869 | int found = 0; | |
870 | ||
871 | if (piocbq->iocb_flag & LPFC_IO_FCP) { | |
872 | lpfc_cmd = (struct lpfc_scsi_buf *) piocbq->context1; | |
873 | ndlp = lpfc_cmd->rdata->pnode; | |
be858b65 JS |
874 | } else if ((piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) && |
875 | !(piocbq->iocb_flag & LPFC_IO_LIBDFC)) | |
19ca7609 | 876 | ndlp = piocbq->context_un.ndlp; |
19ca7609 JS |
877 | else |
878 | ndlp = piocbq->context1; | |
879 | ||
da0436e9 | 880 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
881 | start_sglq = sglq; |
882 | while (!found) { | |
883 | if (!sglq) | |
884 | return NULL; | |
885 | adj_xri = sglq->sli4_xritag - | |
886 | phba->sli4_hba.max_cfg_param.xri_base; | |
887 | if (__lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { | |
888 | /* This xri has an rrq outstanding for this DID. | |
889 | * put it back in the list and get another xri. | |
890 | */ | |
891 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
892 | sglq = NULL; | |
893 | list_remove_head(lpfc_sgl_list, sglq, | |
894 | struct lpfc_sglq, list); | |
895 | if (sglq == start_sglq) { | |
896 | sglq = NULL; | |
897 | break; | |
898 | } else | |
899 | continue; | |
900 | } | |
901 | sglq->ndlp = ndlp; | |
902 | found = 1; | |
903 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq; | |
904 | sglq->state = SGL_ALLOCATED; | |
905 | } | |
da0436e9 JS |
906 | return sglq; |
907 | } | |
908 | ||
e59058c4 | 909 | /** |
3621a710 | 910 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
911 | * @phba: Pointer to HBA context object. |
912 | * | |
913 | * This function is called with no lock held. This function | |
914 | * allocates a new driver iocb object from the iocb pool. If the | |
915 | * allocation is successful, it returns pointer to the newly | |
916 | * allocated iocb object else it returns NULL. | |
917 | **/ | |
2e0fef85 JS |
918 | struct lpfc_iocbq * |
919 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
920 | { | |
921 | struct lpfc_iocbq * iocbq = NULL; | |
922 | unsigned long iflags; | |
923 | ||
924 | spin_lock_irqsave(&phba->hbalock, iflags); | |
925 | iocbq = __lpfc_sli_get_iocbq(phba); | |
926 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
927 | return iocbq; | |
928 | } | |
929 | ||
4f774513 JS |
930 | /** |
931 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
932 | * @phba: Pointer to HBA context object. | |
933 | * @iocbq: Pointer to driver iocb object. | |
934 | * | |
935 | * This function is called with hbalock held to release driver | |
936 | * iocb object to the iocb pool. The iotag in the iocb object | |
937 | * does not change for each use of the iocb object. This function | |
938 | * clears all other fields of the iocb object when it is freed. | |
939 | * The sqlq structure that holds the xritag and phys and virtual | |
940 | * mappings for the scatter gather list is retrieved from the | |
941 | * active array of sglq. The get of the sglq pointer also clears | |
942 | * the entry in the array. If the status of the IO indiactes that | |
943 | * this IO was aborted then the sglq entry it put on the | |
944 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
945 | * IO has good status or fails for any other reason then the sglq | |
946 | * entry is added to the free list (lpfc_sgl_list). | |
947 | **/ | |
948 | static void | |
949 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
950 | { | |
951 | struct lpfc_sglq *sglq; | |
952 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
953 | unsigned long iflag = 0; |
954 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
955 | |
956 | if (iocbq->sli4_xritag == NO_XRI) | |
957 | sglq = NULL; | |
958 | else | |
959 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag); | |
960 | if (sglq) { | |
0f65ff68 JS |
961 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
962 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
963 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
964 | iflag); | |
965 | list_add(&sglq->list, | |
966 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
967 | spin_unlock_irqrestore( | |
968 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
969 | } else { |
970 | sglq->state = SGL_FREED; | |
19ca7609 | 971 | sglq->ndlp = NULL; |
4f774513 | 972 | list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list); |
2a9bf3d0 JS |
973 | |
974 | /* Check if TXQ queue needs to be serviced */ | |
589a52d6 | 975 | if (pring->txq_cnt) |
2a9bf3d0 | 976 | lpfc_worker_wake_up(phba); |
0f65ff68 | 977 | } |
4f774513 JS |
978 | } |
979 | ||
980 | ||
981 | /* | |
982 | * Clean all volatile data fields, preserve iotag and node struct. | |
983 | */ | |
984 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
985 | iocbq->sli4_xritag = NO_XRI; | |
986 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
987 | } | |
988 | ||
2a9bf3d0 | 989 | |
e59058c4 | 990 | /** |
3772a991 | 991 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
992 | * @phba: Pointer to HBA context object. |
993 | * @iocbq: Pointer to driver iocb object. | |
994 | * | |
995 | * This function is called with hbalock held to release driver | |
996 | * iocb object to the iocb pool. The iotag in the iocb object | |
997 | * does not change for each use of the iocb object. This function | |
998 | * clears all other fields of the iocb object when it is freed. | |
999 | **/ | |
a6ababd2 | 1000 | static void |
3772a991 | 1001 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1002 | { |
2e0fef85 | 1003 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
1004 | |
1005 | /* | |
1006 | * Clean all volatile data fields, preserve iotag and node struct. | |
1007 | */ | |
1008 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1009 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1010 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1011 | } | |
1012 | ||
3772a991 JS |
1013 | /** |
1014 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1015 | * @phba: Pointer to HBA context object. | |
1016 | * @iocbq: Pointer to driver iocb object. | |
1017 | * | |
1018 | * This function is called with hbalock held to release driver | |
1019 | * iocb object to the iocb pool. The iotag in the iocb object | |
1020 | * does not change for each use of the iocb object. This function | |
1021 | * clears all other fields of the iocb object when it is freed. | |
1022 | **/ | |
1023 | static void | |
1024 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1025 | { | |
1026 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1027 | phba->iocb_cnt--; |
3772a991 JS |
1028 | } |
1029 | ||
e59058c4 | 1030 | /** |
3621a710 | 1031 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1032 | * @phba: Pointer to HBA context object. |
1033 | * @iocbq: Pointer to driver iocb object. | |
1034 | * | |
1035 | * This function is called with no lock held to release the iocb to | |
1036 | * iocb pool. | |
1037 | **/ | |
2e0fef85 JS |
1038 | void |
1039 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1040 | { | |
1041 | unsigned long iflags; | |
1042 | ||
1043 | /* | |
1044 | * Clean all volatile data fields, preserve iotag and node struct. | |
1045 | */ | |
1046 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1047 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1048 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1049 | } | |
1050 | ||
a257bf90 JS |
1051 | /** |
1052 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1053 | * @phba: Pointer to HBA context object. | |
1054 | * @iocblist: List of IOCBs. | |
1055 | * @ulpstatus: ULP status in IOCB command field. | |
1056 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1057 | * | |
1058 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1059 | * on the list by invoking the complete callback function associated with the | |
1060 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1061 | * fields. | |
1062 | **/ | |
1063 | void | |
1064 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1065 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1066 | { | |
1067 | struct lpfc_iocbq *piocb; | |
1068 | ||
1069 | while (!list_empty(iocblist)) { | |
1070 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
1071 | ||
1072 | if (!piocb->iocb_cmpl) | |
1073 | lpfc_sli_release_iocbq(phba, piocb); | |
1074 | else { | |
1075 | piocb->iocb.ulpStatus = ulpstatus; | |
1076 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1077 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1078 | } | |
1079 | } | |
1080 | return; | |
1081 | } | |
1082 | ||
e59058c4 | 1083 | /** |
3621a710 JS |
1084 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1085 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1086 | * |
1087 | * This function is called by ring event handler function to get the iocb type. | |
1088 | * This function translates the iocb command to an iocb command type used to | |
1089 | * decide the final disposition of each completed IOCB. | |
1090 | * The function returns | |
1091 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1092 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1093 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1094 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1095 | * | |
1096 | * The caller is not required to hold any lock. | |
1097 | **/ | |
dea3101e | 1098 | static lpfc_iocb_type |
1099 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1100 | { | |
1101 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1102 | ||
1103 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1104 | return 0; | |
1105 | ||
1106 | switch (iocb_cmnd) { | |
1107 | case CMD_XMIT_SEQUENCE_CR: | |
1108 | case CMD_XMIT_SEQUENCE_CX: | |
1109 | case CMD_XMIT_BCAST_CN: | |
1110 | case CMD_XMIT_BCAST_CX: | |
1111 | case CMD_ELS_REQUEST_CR: | |
1112 | case CMD_ELS_REQUEST_CX: | |
1113 | case CMD_CREATE_XRI_CR: | |
1114 | case CMD_CREATE_XRI_CX: | |
1115 | case CMD_GET_RPI_CN: | |
1116 | case CMD_XMIT_ELS_RSP_CX: | |
1117 | case CMD_GET_RPI_CR: | |
1118 | case CMD_FCP_IWRITE_CR: | |
1119 | case CMD_FCP_IWRITE_CX: | |
1120 | case CMD_FCP_IREAD_CR: | |
1121 | case CMD_FCP_IREAD_CX: | |
1122 | case CMD_FCP_ICMND_CR: | |
1123 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1124 | case CMD_FCP_TSEND_CX: |
1125 | case CMD_FCP_TRSP_CX: | |
1126 | case CMD_FCP_TRECEIVE_CX: | |
1127 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e | 1128 | case CMD_ADAPTER_MSG: |
1129 | case CMD_ADAPTER_DUMP: | |
1130 | case CMD_XMIT_SEQUENCE64_CR: | |
1131 | case CMD_XMIT_SEQUENCE64_CX: | |
1132 | case CMD_XMIT_BCAST64_CN: | |
1133 | case CMD_XMIT_BCAST64_CX: | |
1134 | case CMD_ELS_REQUEST64_CR: | |
1135 | case CMD_ELS_REQUEST64_CX: | |
1136 | case CMD_FCP_IWRITE64_CR: | |
1137 | case CMD_FCP_IWRITE64_CX: | |
1138 | case CMD_FCP_IREAD64_CR: | |
1139 | case CMD_FCP_IREAD64_CX: | |
1140 | case CMD_FCP_ICMND64_CR: | |
1141 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1142 | case CMD_FCP_TSEND64_CX: |
1143 | case CMD_FCP_TRSP64_CX: | |
1144 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e | 1145 | case CMD_GEN_REQUEST64_CR: |
1146 | case CMD_GEN_REQUEST64_CX: | |
1147 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1148 | case DSSCMD_IWRITE64_CR: |
1149 | case DSSCMD_IWRITE64_CX: | |
1150 | case DSSCMD_IREAD64_CR: | |
1151 | case DSSCMD_IREAD64_CX: | |
dea3101e | 1152 | type = LPFC_SOL_IOCB; |
1153 | break; | |
1154 | case CMD_ABORT_XRI_CN: | |
1155 | case CMD_ABORT_XRI_CX: | |
1156 | case CMD_CLOSE_XRI_CN: | |
1157 | case CMD_CLOSE_XRI_CX: | |
1158 | case CMD_XRI_ABORTED_CX: | |
1159 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1160 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e | 1161 | type = LPFC_ABORT_IOCB; |
1162 | break; | |
1163 | case CMD_RCV_SEQUENCE_CX: | |
1164 | case CMD_RCV_ELS_REQ_CX: | |
1165 | case CMD_RCV_SEQUENCE64_CX: | |
1166 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1167 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1168 | case CMD_IOCB_RCV_SEQ64_CX: |
1169 | case CMD_IOCB_RCV_ELS64_CX: | |
1170 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1171 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e | 1172 | type = LPFC_UNSOL_IOCB; |
1173 | break; | |
3163f725 JS |
1174 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1175 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1176 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1177 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1178 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1179 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1180 | case CMD_IOCB_RET_HBQE64_CN: | |
1181 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1182 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1183 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1184 | case CMD_IOCB_LOGENTRY_CN: | |
1185 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1186 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1187 | __func__, iocb_cmnd); |
3163f725 JS |
1188 | type = LPFC_UNKNOWN_IOCB; |
1189 | break; | |
dea3101e | 1190 | default: |
1191 | type = LPFC_UNKNOWN_IOCB; | |
1192 | break; | |
1193 | } | |
1194 | ||
1195 | return type; | |
1196 | } | |
1197 | ||
e59058c4 | 1198 | /** |
3621a710 | 1199 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1200 | * @phba: Pointer to HBA context object. |
1201 | * | |
1202 | * This function is called from SLI initialization code | |
1203 | * to configure every ring of the HBA's SLI interface. The | |
1204 | * caller is not required to hold any lock. This function issues | |
1205 | * a config_ring mailbox command for each ring. | |
1206 | * This function returns zero if successful else returns a negative | |
1207 | * error code. | |
1208 | **/ | |
dea3101e | 1209 | static int |
ed957684 | 1210 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e | 1211 | { |
1212 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1213 | LPFC_MBOXQ_t *pmb; |
1214 | MAILBOX_t *pmbox; | |
1215 | int i, rc, ret = 0; | |
dea3101e | 1216 | |
ed957684 JS |
1217 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1218 | if (!pmb) | |
1219 | return -ENOMEM; | |
04c68496 | 1220 | pmbox = &pmb->u.mb; |
ed957684 | 1221 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1222 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e | 1223 | lpfc_config_ring(phba, i, pmb); |
1224 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1225 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1226 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1227 | "0446 Adapter failed to init (%d), " |
dea3101e | 1228 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1229 | "ring %d\n", | |
e8b62011 JS |
1230 | rc, pmbox->mbxCommand, |
1231 | pmbox->mbxStatus, i); | |
2e0fef85 | 1232 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1233 | ret = -ENXIO; |
1234 | break; | |
dea3101e | 1235 | } |
1236 | } | |
ed957684 JS |
1237 | mempool_free(pmb, phba->mbox_mem_pool); |
1238 | return ret; | |
dea3101e | 1239 | } |
1240 | ||
e59058c4 | 1241 | /** |
3621a710 | 1242 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1243 | * @phba: Pointer to HBA context object. |
1244 | * @pring: Pointer to driver SLI ring object. | |
1245 | * @piocb: Pointer to the driver iocb object. | |
1246 | * | |
1247 | * This function is called with hbalock held. The function adds the | |
1248 | * new iocb to txcmplq of the given ring. This function always returns | |
1249 | * 0. If this function is called for ELS ring, this function checks if | |
1250 | * there is a vport associated with the ELS command. This function also | |
1251 | * starts els_tmofunc timer if this is an ELS command. | |
1252 | **/ | |
dea3101e | 1253 | static int |
2e0fef85 JS |
1254 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1255 | struct lpfc_iocbq *piocb) | |
dea3101e | 1256 | { |
dea3101e | 1257 | list_add_tail(&piocb->list, &pring->txcmplq); |
2a9bf3d0 | 1258 | piocb->iocb_flag |= LPFC_IO_ON_Q; |
dea3101e | 1259 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
1260 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
1261 | pring->txcmplq_max = pring->txcmplq_cnt; | |
1262 | ||
92d7f7b0 JS |
1263 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1264 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
1265 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
1266 | if (!piocb->vport) | |
1267 | BUG(); | |
1268 | else | |
1269 | mod_timer(&piocb->vport->els_tmofunc, | |
1270 | jiffies + HZ * (phba->fc_ratov << 1)); | |
1271 | } | |
1272 | ||
dea3101e | 1273 | |
2e0fef85 | 1274 | return 0; |
dea3101e | 1275 | } |
1276 | ||
e59058c4 | 1277 | /** |
3621a710 | 1278 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1279 | * @phba: Pointer to HBA context object. |
1280 | * @pring: Pointer to driver SLI ring object. | |
1281 | * | |
1282 | * This function is called with hbalock held to get next | |
1283 | * iocb in txq of the given ring. If there is any iocb in | |
1284 | * the txq, the function returns first iocb in the list after | |
1285 | * removing the iocb from the list, else it returns NULL. | |
1286 | **/ | |
2a9bf3d0 | 1287 | struct lpfc_iocbq * |
2e0fef85 | 1288 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1289 | { |
dea3101e | 1290 | struct lpfc_iocbq *cmd_iocb; |
1291 | ||
858c9f6c JS |
1292 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
1293 | if (cmd_iocb != NULL) | |
dea3101e | 1294 | pring->txq_cnt--; |
2e0fef85 | 1295 | return cmd_iocb; |
dea3101e | 1296 | } |
1297 | ||
e59058c4 | 1298 | /** |
3621a710 | 1299 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1300 | * @phba: Pointer to HBA context object. |
1301 | * @pring: Pointer to driver SLI ring object. | |
1302 | * | |
1303 | * This function is called with hbalock held and the caller must post the | |
1304 | * iocb without releasing the lock. If the caller releases the lock, | |
1305 | * iocb slot returned by the function is not guaranteed to be available. | |
1306 | * The function returns pointer to the next available iocb slot if there | |
1307 | * is available slot in the ring, else it returns NULL. | |
1308 | * If the get index of the ring is ahead of the put index, the function | |
1309 | * will post an error attention event to the worker thread to take the | |
1310 | * HBA to offline state. | |
1311 | **/ | |
dea3101e | 1312 | static IOCB_t * |
1313 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1314 | { | |
34b02dcd | 1315 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 1316 | uint32_t max_cmd_idx = pring->numCiocb; |
dea3101e | 1317 | if ((pring->next_cmdidx == pring->cmdidx) && |
1318 | (++pring->next_cmdidx >= max_cmd_idx)) | |
1319 | pring->next_cmdidx = 0; | |
1320 | ||
1321 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { | |
1322 | ||
1323 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
1324 | ||
1325 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { | |
1326 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 1327 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1328 | "is bigger than cmd ring %d\n", |
e8b62011 | 1329 | pring->ringno, |
dea3101e | 1330 | pring->local_getidx, max_cmd_idx); |
1331 | ||
2e0fef85 | 1332 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1333 | /* |
1334 | * All error attention handlers are posted to | |
1335 | * worker thread | |
1336 | */ | |
1337 | phba->work_ha |= HA_ERATT; | |
1338 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1339 | |
5e9d9b82 | 1340 | lpfc_worker_wake_up(phba); |
dea3101e | 1341 | |
1342 | return NULL; | |
1343 | } | |
1344 | ||
1345 | if (pring->local_getidx == pring->next_cmdidx) | |
1346 | return NULL; | |
1347 | } | |
1348 | ||
ed957684 | 1349 | return lpfc_cmd_iocb(phba, pring); |
dea3101e | 1350 | } |
1351 | ||
e59058c4 | 1352 | /** |
3621a710 | 1353 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1354 | * @phba: Pointer to HBA context object. |
1355 | * @iocbq: Pointer to driver iocb object. | |
1356 | * | |
1357 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1358 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1359 | * array and assigns a new iotag. | |
1360 | * The function returns the allocated iotag if successful, else returns zero. | |
1361 | * Zero is not a valid iotag. | |
1362 | * The caller is not required to hold any lock. | |
1363 | **/ | |
604a3e30 | 1364 | uint16_t |
2e0fef85 | 1365 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1366 | { |
2e0fef85 JS |
1367 | struct lpfc_iocbq **new_arr; |
1368 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1369 | size_t new_len; |
1370 | struct lpfc_sli *psli = &phba->sli; | |
1371 | uint16_t iotag; | |
dea3101e | 1372 | |
2e0fef85 | 1373 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1374 | iotag = psli->last_iotag; |
1375 | if(++iotag < psli->iocbq_lookup_len) { | |
1376 | psli->last_iotag = iotag; | |
1377 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1378 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1379 | iocbq->iotag = iotag; |
1380 | return iotag; | |
2e0fef85 | 1381 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1382 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1383 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1384 | spin_unlock_irq(&phba->hbalock); |
1385 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1386 | GFP_KERNEL); |
1387 | if (new_arr) { | |
2e0fef85 | 1388 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1389 | old_arr = psli->iocbq_lookup; |
1390 | if (new_len <= psli->iocbq_lookup_len) { | |
1391 | /* highly unprobable case */ | |
1392 | kfree(new_arr); | |
1393 | iotag = psli->last_iotag; | |
1394 | if(++iotag < psli->iocbq_lookup_len) { | |
1395 | psli->last_iotag = iotag; | |
1396 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1397 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1398 | iocbq->iotag = iotag; |
1399 | return iotag; | |
1400 | } | |
2e0fef85 | 1401 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1402 | return 0; |
1403 | } | |
1404 | if (psli->iocbq_lookup) | |
1405 | memcpy(new_arr, old_arr, | |
1406 | ((psli->last_iotag + 1) * | |
311464ec | 1407 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1408 | psli->iocbq_lookup = new_arr; |
1409 | psli->iocbq_lookup_len = new_len; | |
1410 | psli->last_iotag = iotag; | |
1411 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1412 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1413 | iocbq->iotag = iotag; |
1414 | kfree(old_arr); | |
1415 | return iotag; | |
1416 | } | |
8f6d98d2 | 1417 | } else |
2e0fef85 | 1418 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1419 | |
bc73905a | 1420 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1421 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1422 | psli->last_iotag); | |
dea3101e | 1423 | |
604a3e30 | 1424 | return 0; |
dea3101e | 1425 | } |
1426 | ||
e59058c4 | 1427 | /** |
3621a710 | 1428 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1429 | * @phba: Pointer to HBA context object. |
1430 | * @pring: Pointer to driver SLI ring object. | |
1431 | * @iocb: Pointer to iocb slot in the ring. | |
1432 | * @nextiocb: Pointer to driver iocb object which need to be | |
1433 | * posted to firmware. | |
1434 | * | |
1435 | * This function is called with hbalock held to post a new iocb to | |
1436 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1437 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1438 | * a completion call back for this iocb else the function will free the | |
1439 | * iocb object. | |
1440 | **/ | |
dea3101e | 1441 | static void |
1442 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1443 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1444 | { | |
1445 | /* | |
604a3e30 | 1446 | * Set up an iotag |
dea3101e | 1447 | */ |
604a3e30 | 1448 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1449 | |
e2a0a9d6 | 1450 | |
a58cbd52 JS |
1451 | if (pring->ringno == LPFC_ELS_RING) { |
1452 | lpfc_debugfs_slow_ring_trc(phba, | |
1453 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1454 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1455 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1456 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1457 | } | |
1458 | ||
dea3101e | 1459 | /* |
1460 | * Issue iocb command to adapter | |
1461 | */ | |
92d7f7b0 | 1462 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e | 1463 | wmb(); |
1464 | pring->stats.iocb_cmd++; | |
1465 | ||
1466 | /* | |
1467 | * If there is no completion routine to call, we can release the | |
1468 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1469 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1470 | */ | |
1471 | if (nextiocb->iocb_cmpl) | |
1472 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1473 | else |
2e0fef85 | 1474 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e | 1475 | |
1476 | /* | |
1477 | * Let the HBA know what IOCB slot will be the next one the | |
1478 | * driver will put a command into. | |
1479 | */ | |
1480 | pring->cmdidx = pring->next_cmdidx; | |
ed957684 | 1481 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
dea3101e | 1482 | } |
1483 | ||
e59058c4 | 1484 | /** |
3621a710 | 1485 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1486 | * @phba: Pointer to HBA context object. |
1487 | * @pring: Pointer to driver SLI ring object. | |
1488 | * | |
1489 | * The caller is not required to hold any lock for calling this function. | |
1490 | * This function updates the chip attention bits for the ring to inform firmware | |
1491 | * that there are pending work to be done for this ring and requests an | |
1492 | * interrupt when there is space available in the ring. This function is | |
1493 | * called when the driver is unable to post more iocbs to the ring due | |
1494 | * to unavailability of space in the ring. | |
1495 | **/ | |
dea3101e | 1496 | static void |
2e0fef85 | 1497 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1498 | { |
1499 | int ringno = pring->ringno; | |
1500 | ||
1501 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1502 | ||
1503 | wmb(); | |
1504 | ||
1505 | /* | |
1506 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1507 | * The HBA will tell us when an IOCB entry is available. | |
1508 | */ | |
1509 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1510 | readl(phba->CAregaddr); /* flush */ | |
1511 | ||
1512 | pring->stats.iocb_cmd_full++; | |
1513 | } | |
1514 | ||
e59058c4 | 1515 | /** |
3621a710 | 1516 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1517 | * @phba: Pointer to HBA context object. |
1518 | * @pring: Pointer to driver SLI ring object. | |
1519 | * | |
1520 | * This function updates the chip attention register bit for the | |
1521 | * given ring to inform HBA that there is more work to be done | |
1522 | * in this ring. The caller is not required to hold any lock. | |
1523 | **/ | |
dea3101e | 1524 | static void |
2e0fef85 | 1525 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1526 | { |
1527 | int ringno = pring->ringno; | |
1528 | ||
1529 | /* | |
1530 | * Tell the HBA that there is work to do in this ring. | |
1531 | */ | |
34b02dcd JS |
1532 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1533 | wmb(); | |
1534 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1535 | readl(phba->CAregaddr); /* flush */ | |
1536 | } | |
dea3101e | 1537 | } |
1538 | ||
e59058c4 | 1539 | /** |
3621a710 | 1540 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1541 | * @phba: Pointer to HBA context object. |
1542 | * @pring: Pointer to driver SLI ring object. | |
1543 | * | |
1544 | * This function is called with hbalock held to post pending iocbs | |
1545 | * in the txq to the firmware. This function is called when driver | |
1546 | * detects space available in the ring. | |
1547 | **/ | |
dea3101e | 1548 | static void |
2e0fef85 | 1549 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1550 | { |
1551 | IOCB_t *iocb; | |
1552 | struct lpfc_iocbq *nextiocb; | |
1553 | ||
1554 | /* | |
1555 | * Check to see if: | |
1556 | * (a) there is anything on the txq to send | |
1557 | * (b) link is up | |
1558 | * (c) link attention events can be processed (fcp ring only) | |
1559 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1560 | */ | |
1561 | if (pring->txq_cnt && | |
2e0fef85 | 1562 | lpfc_is_link_up(phba) && |
dea3101e | 1563 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1564 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e | 1565 | |
1566 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1567 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1568 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1569 | ||
1570 | if (iocb) | |
1571 | lpfc_sli_update_ring(phba, pring); | |
1572 | else | |
1573 | lpfc_sli_update_full_ring(phba, pring); | |
1574 | } | |
1575 | ||
1576 | return; | |
1577 | } | |
1578 | ||
e59058c4 | 1579 | /** |
3621a710 | 1580 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1581 | * @phba: Pointer to HBA context object. |
1582 | * @hbqno: HBQ number. | |
1583 | * | |
1584 | * This function is called with hbalock held to get the next | |
1585 | * available slot for the given HBQ. If there is free slot | |
1586 | * available for the HBQ it will return pointer to the next available | |
1587 | * HBQ entry else it will return NULL. | |
1588 | **/ | |
a6ababd2 | 1589 | static struct lpfc_hbq_entry * |
ed957684 JS |
1590 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1591 | { | |
1592 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1593 | ||
1594 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1595 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1596 | hbqp->next_hbqPutIdx = 0; | |
1597 | ||
1598 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1599 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1600 | uint32_t getidx = le32_to_cpu(raw_index); |
1601 | ||
1602 | hbqp->local_hbqGetIdx = getidx; | |
1603 | ||
1604 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1605 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1606 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1607 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1608 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1609 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1610 | hbqp->entry_count); |
1611 | ||
1612 | phba->link_state = LPFC_HBA_ERROR; | |
1613 | return NULL; | |
1614 | } | |
1615 | ||
1616 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1617 | return NULL; | |
1618 | } | |
1619 | ||
51ef4c26 JS |
1620 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1621 | hbqp->hbqPutIdx; | |
ed957684 JS |
1622 | } |
1623 | ||
e59058c4 | 1624 | /** |
3621a710 | 1625 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1626 | * @phba: Pointer to HBA context object. |
1627 | * | |
1628 | * This function is called with no lock held to free all the | |
1629 | * hbq buffers while uninitializing the SLI interface. It also | |
1630 | * frees the HBQ buffers returned by the firmware but not yet | |
1631 | * processed by the upper layers. | |
1632 | **/ | |
ed957684 JS |
1633 | void |
1634 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1635 | { | |
92d7f7b0 JS |
1636 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1637 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1638 | unsigned long flags; |
51ef4c26 | 1639 | int i, hbq_count; |
3163f725 | 1640 | uint32_t hbqno; |
ed957684 | 1641 | |
51ef4c26 | 1642 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1643 | /* Return all memory used by all HBQs */ |
3163f725 | 1644 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1645 | for (i = 0; i < hbq_count; ++i) { |
1646 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1647 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1648 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1649 | list_del(&hbq_buf->dbuf.list); | |
1650 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1651 | } | |
a8adb832 | 1652 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1653 | } |
3163f725 | 1654 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1655 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1656 | list) { | |
3163f725 JS |
1657 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1658 | list_del(&hbq_buf->dbuf.list); | |
1659 | if (hbq_buf->tag == -1) { | |
1660 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1661 | (phba, hbq_buf); | |
1662 | } else { | |
1663 | hbqno = hbq_buf->tag >> 16; | |
1664 | if (hbqno >= LPFC_MAX_HBQS) | |
1665 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1666 | (phba, hbq_buf); | |
1667 | else | |
1668 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1669 | hbq_buf); | |
1670 | } | |
1671 | } | |
1672 | ||
1673 | /* Mark the HBQs not in use */ | |
1674 | phba->hbq_in_use = 0; | |
1675 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1676 | } |
1677 | ||
e59058c4 | 1678 | /** |
3621a710 | 1679 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1680 | * @phba: Pointer to HBA context object. |
1681 | * @hbqno: HBQ number. | |
1682 | * @hbq_buf: Pointer to HBQ buffer. | |
1683 | * | |
1684 | * This function is called with the hbalock held to post a | |
1685 | * hbq buffer to the firmware. If the function finds an empty | |
1686 | * slot in the HBQ, it will post the buffer. The function will return | |
1687 | * pointer to the hbq entry if it successfully post the buffer | |
1688 | * else it will return NULL. | |
1689 | **/ | |
3772a991 | 1690 | static int |
ed957684 | 1691 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1692 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1693 | { |
1694 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1695 | } | |
1696 | ||
1697 | /** | |
1698 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1699 | * @phba: Pointer to HBA context object. | |
1700 | * @hbqno: HBQ number. | |
1701 | * @hbq_buf: Pointer to HBQ buffer. | |
1702 | * | |
1703 | * This function is called with the hbalock held to post a hbq buffer to the | |
1704 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1705 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1706 | * it successfully post the buffer else it will return an error. | |
1707 | **/ | |
1708 | static int | |
1709 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1710 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1711 | { |
1712 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1713 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1714 | |
1715 | /* Get next HBQ entry slot to use */ | |
1716 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1717 | if (hbqe) { | |
1718 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1719 | ||
92d7f7b0 JS |
1720 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1721 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1722 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1723 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1724 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1725 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1726 | /* Sync SLIM */ | |
ed957684 JS |
1727 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1728 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1729 | /* flush */ |
ed957684 | 1730 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1731 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1732 | return 0; |
1733 | } else | |
1734 | return -ENOMEM; | |
ed957684 JS |
1735 | } |
1736 | ||
4f774513 JS |
1737 | /** |
1738 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1739 | * @phba: Pointer to HBA context object. | |
1740 | * @hbqno: HBQ number. | |
1741 | * @hbq_buf: Pointer to HBQ buffer. | |
1742 | * | |
1743 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1744 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1745 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1746 | **/ | |
1747 | static int | |
1748 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1749 | struct hbq_dmabuf *hbq_buf) | |
1750 | { | |
1751 | int rc; | |
1752 | struct lpfc_rqe hrqe; | |
1753 | struct lpfc_rqe drqe; | |
1754 | ||
1755 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1756 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1757 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1758 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1759 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1760 | &hrqe, &drqe); | |
1761 | if (rc < 0) | |
1762 | return rc; | |
1763 | hbq_buf->tag = rc; | |
1764 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1765 | return 0; | |
1766 | } | |
1767 | ||
e59058c4 | 1768 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1769 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1770 | .rn = 1, | |
def9c7a9 | 1771 | .entry_count = 256, |
92d7f7b0 JS |
1772 | .mask_count = 0, |
1773 | .profile = 0, | |
51ef4c26 | 1774 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1775 | .buffer_count = 0, |
a257bf90 JS |
1776 | .init_count = 40, |
1777 | .add_count = 40, | |
92d7f7b0 | 1778 | }; |
ed957684 | 1779 | |
e59058c4 | 1780 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1781 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1782 | .rn = 1, | |
1783 | .entry_count = 200, | |
1784 | .mask_count = 0, | |
1785 | .profile = 0, | |
1786 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1787 | .buffer_count = 0, | |
1788 | .init_count = 0, | |
1789 | .add_count = 5, | |
1790 | }; | |
1791 | ||
e59058c4 | 1792 | /* Array of HBQs */ |
78b2d852 | 1793 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1794 | &lpfc_els_hbq, |
51ef4c26 | 1795 | &lpfc_extra_hbq, |
92d7f7b0 | 1796 | }; |
ed957684 | 1797 | |
e59058c4 | 1798 | /** |
3621a710 | 1799 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1800 | * @phba: Pointer to HBA context object. |
1801 | * @hbqno: HBQ number. | |
1802 | * @count: Number of HBQ buffers to be posted. | |
1803 | * | |
d7c255b2 JS |
1804 | * This function is called with no lock held to post more hbq buffers to the |
1805 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1806 | * posted. | |
e59058c4 | 1807 | **/ |
311464ec | 1808 | static int |
92d7f7b0 | 1809 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1810 | { |
d7c255b2 | 1811 | uint32_t i, posted = 0; |
3163f725 | 1812 | unsigned long flags; |
92d7f7b0 | 1813 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1814 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1815 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1816 | return 0; |
51ef4c26 | 1817 | |
d7c255b2 JS |
1818 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1819 | lpfc_hbq_defs[hbqno]->entry_count) | |
1820 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1821 | phba->hbqs[hbqno].buffer_count; | |
1822 | if (!count) | |
1823 | return 0; | |
1824 | /* Allocate HBQ entries */ | |
1825 | for (i = 0; i < count; i++) { | |
1826 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1827 | if (!hbq_buffer) | |
1828 | break; | |
1829 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1830 | } | |
3163f725 JS |
1831 | /* Check whether HBQ is still in use */ |
1832 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1833 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1834 | goto err; |
1835 | while (!list_empty(&hbq_buf_list)) { | |
1836 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1837 | dbuf.list); | |
1838 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1839 | (hbqno << 16)); | |
3772a991 | 1840 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1841 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1842 | posted++; |
1843 | } else | |
51ef4c26 | 1844 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1845 | } |
3163f725 | 1846 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1847 | return posted; |
1848 | err: | |
eafe1df9 | 1849 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1850 | while (!list_empty(&hbq_buf_list)) { |
1851 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1852 | dbuf.list); | |
1853 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1854 | } | |
1855 | return 0; | |
ed957684 JS |
1856 | } |
1857 | ||
e59058c4 | 1858 | /** |
3621a710 | 1859 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1860 | * @phba: Pointer to HBA context object. |
1861 | * @qno: HBQ number. | |
1862 | * | |
1863 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1864 | * is called with no lock held. The function returns the number of HBQ entries |
1865 | * successfully allocated. | |
e59058c4 | 1866 | **/ |
92d7f7b0 JS |
1867 | int |
1868 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1869 | { |
def9c7a9 JS |
1870 | if (phba->sli_rev == LPFC_SLI_REV4) |
1871 | return 0; | |
1872 | else | |
1873 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1874 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1875 | } |
ed957684 | 1876 | |
e59058c4 | 1877 | /** |
3621a710 | 1878 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1879 | * @phba: Pointer to HBA context object. |
1880 | * @qno: HBQ queue number. | |
1881 | * | |
1882 | * This function is called from SLI initialization code path with | |
1883 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1884 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1885 | **/ |
a6ababd2 | 1886 | static int |
92d7f7b0 JS |
1887 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1888 | { | |
def9c7a9 JS |
1889 | if (phba->sli_rev == LPFC_SLI_REV4) |
1890 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1891 | lpfc_hbq_defs[qno]->entry_count); | |
1892 | else | |
1893 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1894 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1895 | } |
1896 | ||
3772a991 JS |
1897 | /** |
1898 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1899 | * @phba: Pointer to HBA context object. | |
1900 | * @hbqno: HBQ number. | |
1901 | * | |
1902 | * This function removes the first hbq buffer on an hbq list and returns a | |
1903 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1904 | **/ | |
1905 | static struct hbq_dmabuf * | |
1906 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1907 | { | |
1908 | struct lpfc_dmabuf *d_buf; | |
1909 | ||
1910 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1911 | if (!d_buf) | |
1912 | return NULL; | |
1913 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1914 | } | |
1915 | ||
e59058c4 | 1916 | /** |
3621a710 | 1917 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1918 | * @phba: Pointer to HBA context object. |
1919 | * @tag: Tag of the hbq buffer. | |
1920 | * | |
1921 | * This function is called with hbalock held. This function searches | |
1922 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1923 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1924 | * it returns NULL. | |
1925 | **/ | |
a6ababd2 | 1926 | static struct hbq_dmabuf * |
92d7f7b0 | 1927 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1928 | { |
92d7f7b0 JS |
1929 | struct lpfc_dmabuf *d_buf; |
1930 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1931 | uint32_t hbqno; |
1932 | ||
1933 | hbqno = tag >> 16; | |
a0a74e45 | 1934 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1935 | return NULL; |
ed957684 | 1936 | |
3772a991 | 1937 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1938 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1939 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1940 | if (hbq_buf->tag == tag) { |
3772a991 | 1941 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1942 | return hbq_buf; |
ed957684 JS |
1943 | } |
1944 | } | |
3772a991 | 1945 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1946 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1947 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1948 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1949 | return NULL; |
ed957684 JS |
1950 | } |
1951 | ||
e59058c4 | 1952 | /** |
3621a710 | 1953 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1954 | * @phba: Pointer to HBA context object. |
1955 | * @hbq_buffer: Pointer to HBQ buffer. | |
1956 | * | |
1957 | * This function is called with hbalock. This function gives back | |
1958 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1959 | * post the buffer, it will free the buffer. | |
1960 | **/ | |
ed957684 | 1961 | void |
51ef4c26 | 1962 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
1963 | { |
1964 | uint32_t hbqno; | |
1965 | ||
51ef4c26 JS |
1966 | if (hbq_buffer) { |
1967 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 1968 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 1969 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
1970 | } |
1971 | } | |
1972 | ||
e59058c4 | 1973 | /** |
3621a710 | 1974 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
1975 | * @mbxCommand: mailbox command code. |
1976 | * | |
1977 | * This function is called by the mailbox event handler function to verify | |
1978 | * that the completed mailbox command is a legitimate mailbox command. If the | |
1979 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
1980 | * and the mailbox event handler will take the HBA offline. | |
1981 | **/ | |
dea3101e | 1982 | static int |
1983 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
1984 | { | |
1985 | uint8_t ret; | |
1986 | ||
1987 | switch (mbxCommand) { | |
1988 | case MBX_LOAD_SM: | |
1989 | case MBX_READ_NV: | |
1990 | case MBX_WRITE_NV: | |
a8adb832 | 1991 | case MBX_WRITE_VPARMS: |
dea3101e | 1992 | case MBX_RUN_BIU_DIAG: |
1993 | case MBX_INIT_LINK: | |
1994 | case MBX_DOWN_LINK: | |
1995 | case MBX_CONFIG_LINK: | |
1996 | case MBX_CONFIG_RING: | |
1997 | case MBX_RESET_RING: | |
1998 | case MBX_READ_CONFIG: | |
1999 | case MBX_READ_RCONFIG: | |
2000 | case MBX_READ_SPARM: | |
2001 | case MBX_READ_STATUS: | |
2002 | case MBX_READ_RPI: | |
2003 | case MBX_READ_XRI: | |
2004 | case MBX_READ_REV: | |
2005 | case MBX_READ_LNK_STAT: | |
2006 | case MBX_REG_LOGIN: | |
2007 | case MBX_UNREG_LOGIN: | |
dea3101e | 2008 | case MBX_CLEAR_LA: |
2009 | case MBX_DUMP_MEMORY: | |
2010 | case MBX_DUMP_CONTEXT: | |
2011 | case MBX_RUN_DIAGS: | |
2012 | case MBX_RESTART: | |
2013 | case MBX_UPDATE_CFG: | |
2014 | case MBX_DOWN_LOAD: | |
2015 | case MBX_DEL_LD_ENTRY: | |
2016 | case MBX_RUN_PROGRAM: | |
2017 | case MBX_SET_MASK: | |
09372820 | 2018 | case MBX_SET_VARIABLE: |
dea3101e | 2019 | case MBX_UNREG_D_ID: |
41415862 | 2020 | case MBX_KILL_BOARD: |
dea3101e | 2021 | case MBX_CONFIG_FARP: |
41415862 | 2022 | case MBX_BEACON: |
dea3101e | 2023 | case MBX_LOAD_AREA: |
2024 | case MBX_RUN_BIU_DIAG64: | |
2025 | case MBX_CONFIG_PORT: | |
2026 | case MBX_READ_SPARM64: | |
2027 | case MBX_READ_RPI64: | |
2028 | case MBX_REG_LOGIN64: | |
76a95d75 | 2029 | case MBX_READ_TOPOLOGY: |
09372820 | 2030 | case MBX_WRITE_WWN: |
dea3101e | 2031 | case MBX_SET_DEBUG: |
2032 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2033 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2034 | case MBX_REG_VPI: |
2035 | case MBX_UNREG_VPI: | |
858c9f6c | 2036 | case MBX_HEARTBEAT: |
84774a4d JS |
2037 | case MBX_PORT_CAPABILITIES: |
2038 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2039 | case MBX_SLI4_CONFIG: |
2040 | case MBX_SLI4_REQ_FTRS: | |
2041 | case MBX_REG_FCFI: | |
2042 | case MBX_UNREG_FCFI: | |
2043 | case MBX_REG_VFI: | |
2044 | case MBX_UNREG_VFI: | |
2045 | case MBX_INIT_VPI: | |
2046 | case MBX_INIT_VFI: | |
2047 | case MBX_RESUME_RPI: | |
c7495937 JS |
2048 | case MBX_READ_EVENT_LOG_STATUS: |
2049 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2050 | case MBX_SECURITY_MGMT: |
2051 | case MBX_AUTH_PORT: | |
dea3101e | 2052 | ret = mbxCommand; |
2053 | break; | |
2054 | default: | |
2055 | ret = MBX_SHUTDOWN; | |
2056 | break; | |
2057 | } | |
2e0fef85 | 2058 | return ret; |
dea3101e | 2059 | } |
e59058c4 JS |
2060 | |
2061 | /** | |
3621a710 | 2062 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2063 | * @phba: Pointer to HBA context object. |
2064 | * @pmboxq: Pointer to mailbox command. | |
2065 | * | |
2066 | * This is completion handler function for mailbox commands issued from | |
2067 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2068 | * mailbox event handler function with no lock held. This function | |
2069 | * will wake up thread waiting on the wait queue pointed by context1 | |
2070 | * of the mailbox. | |
2071 | **/ | |
04c68496 | 2072 | void |
2e0fef85 | 2073 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e | 2074 | { |
2075 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2076 | unsigned long drvr_flag; |
dea3101e | 2077 | |
2078 | /* | |
2079 | * If pdone_q is empty, the driver thread gave up waiting and | |
2080 | * continued running. | |
2081 | */ | |
7054a606 | 2082 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2083 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e | 2084 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2085 | if (pdone_q) | |
2086 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2087 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 2088 | return; |
2089 | } | |
2090 | ||
e59058c4 JS |
2091 | |
2092 | /** | |
3621a710 | 2093 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2094 | * @phba: Pointer to HBA context object. |
2095 | * @pmb: Pointer to mailbox object. | |
2096 | * | |
2097 | * This function is the default mailbox completion handler. It | |
2098 | * frees the memory resources associated with the completed mailbox | |
2099 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2100 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2101 | **/ | |
dea3101e | 2102 | void |
2e0fef85 | 2103 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2104 | { |
d439d286 | 2105 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2106 | struct lpfc_dmabuf *mp; |
d439d286 | 2107 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2108 | struct Scsi_Host *shost; |
04c68496 | 2109 | uint16_t rpi, vpi; |
7054a606 JS |
2110 | int rc; |
2111 | ||
dea3101e | 2112 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2113 | |
dea3101e | 2114 | if (mp) { |
2115 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2116 | kfree(mp); | |
2117 | } | |
7054a606 | 2118 | |
04c68496 | 2119 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
5af5eee7 JS |
2120 | (phba->sli_rev == LPFC_SLI_REV4) && |
2121 | (pmb->u.mb.un.varUnregLogin.rsvd1 == 0x0)) | |
04c68496 JS |
2122 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
2123 | ||
7054a606 JS |
2124 | /* |
2125 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2126 | * is in re-discovery driver need to cleanup the RPI. | |
2127 | */ | |
2e0fef85 | 2128 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2129 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2130 | !pmb->u.mb.mbxStatus) { | |
2131 | rpi = pmb->u.mb.un.varWords[0]; | |
2132 | vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base; | |
2133 | lpfc_unreg_login(phba, vpi, rpi, pmb); | |
92d7f7b0 | 2134 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2135 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2136 | if (rc != MBX_NOT_FINISHED) | |
2137 | return; | |
2138 | } | |
2139 | ||
695a814e JS |
2140 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2141 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2142 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2143 | shost = lpfc_shost_from_vport(vport); |
2144 | spin_lock_irq(shost->host_lock); | |
2145 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2146 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2147 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2148 | } |
2149 | ||
d439d286 JS |
2150 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2151 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2152 | lpfc_nlp_put(ndlp); | |
2153 | pmb->context2 = NULL; | |
2154 | } | |
2155 | ||
dcf2a4e0 JS |
2156 | /* Check security permission status on INIT_LINK mailbox command */ |
2157 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2158 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2159 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2160 | "2860 SLI authentication is required " | |
2161 | "for INIT_LINK but has not done yet\n"); | |
2162 | ||
04c68496 JS |
2163 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2164 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2165 | else | |
2166 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e | 2167 | } |
2168 | ||
e59058c4 | 2169 | /** |
3621a710 | 2170 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2171 | * @phba: Pointer to HBA context object. |
2172 | * | |
2173 | * This function is called with no lock held. This function processes all | |
2174 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2175 | * service routine processes mailbox completion interrupt and adds completed | |
2176 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2177 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2178 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2179 | * function returns the mailbox commands to the upper layer by calling the | |
2180 | * completion handler function of each mailbox. | |
2181 | **/ | |
dea3101e | 2182 | int |
2e0fef85 | 2183 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2184 | { |
92d7f7b0 | 2185 | MAILBOX_t *pmbox; |
dea3101e | 2186 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2187 | int rc; |
2188 | LIST_HEAD(cmplq); | |
dea3101e | 2189 | |
2190 | phba->sli.slistat.mbox_event++; | |
2191 | ||
92d7f7b0 JS |
2192 | /* Get all completed mailboxe buffers into the cmplq */ |
2193 | spin_lock_irq(&phba->hbalock); | |
2194 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2195 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2196 | |
92d7f7b0 JS |
2197 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2198 | do { | |
2199 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2200 | if (pmb == NULL) | |
2201 | break; | |
2e0fef85 | 2202 | |
04c68496 | 2203 | pmbox = &pmb->u.mb; |
dea3101e | 2204 | |
858c9f6c JS |
2205 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2206 | if (pmb->vport) { | |
2207 | lpfc_debugfs_disc_trc(pmb->vport, | |
2208 | LPFC_DISC_TRC_MBOX_VPORT, | |
2209 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2210 | (uint32_t)pmbox->mbxCommand, | |
2211 | pmbox->un.varWords[0], | |
2212 | pmbox->un.varWords[1]); | |
2213 | } | |
2214 | else { | |
2215 | lpfc_debugfs_disc_trc(phba->pport, | |
2216 | LPFC_DISC_TRC_MBOX, | |
2217 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2218 | (uint32_t)pmbox->mbxCommand, | |
2219 | pmbox->un.varWords[0], | |
2220 | pmbox->un.varWords[1]); | |
2221 | } | |
2222 | } | |
2223 | ||
dea3101e | 2224 | /* |
2225 | * It is a fatal error if unknown mbox command completion. | |
2226 | */ | |
2227 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2228 | MBX_SHUTDOWN) { | |
af901ca1 | 2229 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2230 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2231 | "(%d):0323 Unknown Mailbox command " |
04c68496 | 2232 | "x%x (x%x) Cmpl\n", |
92d7f7b0 | 2233 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 JS |
2234 | pmbox->mbxCommand, |
2235 | lpfc_sli4_mbox_opcode_get(phba, pmb)); | |
2e0fef85 | 2236 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 2237 | phba->work_hs = HS_FFER3; |
2238 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2239 | continue; |
dea3101e | 2240 | } |
2241 | ||
dea3101e | 2242 | if (pmbox->mbxStatus) { |
2243 | phba->sli.slistat.mbox_stat_err++; | |
2244 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2245 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 JS |
2246 | lpfc_printf_log(phba, KERN_INFO, |
2247 | LOG_MBOX | LOG_SLI, | |
e8b62011 | 2248 | "(%d):0305 Mbox cmd cmpl " |
92d7f7b0 | 2249 | "error - RETRYing Data: x%x " |
04c68496 | 2250 | "(x%x) x%x x%x x%x\n", |
92d7f7b0 JS |
2251 | pmb->vport ? pmb->vport->vpi :0, |
2252 | pmbox->mbxCommand, | |
04c68496 JS |
2253 | lpfc_sli4_mbox_opcode_get(phba, |
2254 | pmb), | |
92d7f7b0 JS |
2255 | pmbox->mbxStatus, |
2256 | pmbox->un.varWords[0], | |
2257 | pmb->vport->port_state); | |
dea3101e | 2258 | pmbox->mbxStatus = 0; |
2259 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2260 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2261 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2262 | continue; |
dea3101e | 2263 | } |
2264 | } | |
2265 | ||
2266 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2267 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
04c68496 | 2268 | "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p " |
dea3101e | 2269 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2270 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2271 | pmbox->mbxCommand, |
04c68496 | 2272 | lpfc_sli4_mbox_opcode_get(phba, pmb), |
dea3101e | 2273 | pmb->mbox_cmpl, |
2274 | *((uint32_t *) pmbox), | |
2275 | pmbox->un.varWords[0], | |
2276 | pmbox->un.varWords[1], | |
2277 | pmbox->un.varWords[2], | |
2278 | pmbox->un.varWords[3], | |
2279 | pmbox->un.varWords[4], | |
2280 | pmbox->un.varWords[5], | |
2281 | pmbox->un.varWords[6], | |
2282 | pmbox->un.varWords[7]); | |
2283 | ||
92d7f7b0 | 2284 | if (pmb->mbox_cmpl) |
dea3101e | 2285 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2286 | } while (1); |
2287 | return 0; | |
2288 | } | |
dea3101e | 2289 | |
e59058c4 | 2290 | /** |
3621a710 | 2291 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2292 | * @phba: Pointer to HBA context object. |
2293 | * @pring: Pointer to driver SLI ring object. | |
2294 | * @tag: buffer tag. | |
2295 | * | |
2296 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2297 | * is set in the tag the buffer is posted for a particular exchange, | |
2298 | * the function will return the buffer without replacing the buffer. | |
2299 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2300 | * returns the buffer and also posts another buffer to the firmware. | |
2301 | **/ | |
76bb24ef JS |
2302 | static struct lpfc_dmabuf * |
2303 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2304 | struct lpfc_sli_ring *pring, |
2305 | uint32_t tag) | |
76bb24ef | 2306 | { |
9f1e1b50 JS |
2307 | struct hbq_dmabuf *hbq_entry; |
2308 | ||
76bb24ef JS |
2309 | if (tag & QUE_BUFTAG_BIT) |
2310 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2311 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2312 | if (!hbq_entry) | |
2313 | return NULL; | |
2314 | return &hbq_entry->dbuf; | |
76bb24ef | 2315 | } |
57127f15 | 2316 | |
3772a991 JS |
2317 | /** |
2318 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2319 | * @phba: Pointer to HBA context object. | |
2320 | * @pring: Pointer to driver SLI ring object. | |
2321 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2322 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2323 | * @fch_type: the type for the first frame of the sequence. | |
2324 | * | |
2325 | * This function is called with no lock held. This function uses the r_ctl and | |
2326 | * type of the received sequence to find the correct callback function to call | |
2327 | * to process the sequence. | |
2328 | **/ | |
2329 | static int | |
2330 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2331 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2332 | uint32_t fch_type) | |
2333 | { | |
2334 | int i; | |
2335 | ||
2336 | /* unSolicited Responses */ | |
2337 | if (pring->prt[0].profile) { | |
2338 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2339 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2340 | saveq); | |
2341 | return 1; | |
2342 | } | |
2343 | /* We must search, based on rctl / type | |
2344 | for the right routine */ | |
2345 | for (i = 0; i < pring->num_mask; i++) { | |
2346 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2347 | (pring->prt[i].type == fch_type)) { | |
2348 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2349 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2350 | (phba, pring, saveq); | |
2351 | return 1; | |
2352 | } | |
2353 | } | |
2354 | return 0; | |
2355 | } | |
e59058c4 JS |
2356 | |
2357 | /** | |
3621a710 | 2358 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2359 | * @phba: Pointer to HBA context object. |
2360 | * @pring: Pointer to driver SLI ring object. | |
2361 | * @saveq: Pointer to the unsolicited iocb. | |
2362 | * | |
2363 | * This function is called with no lock held by the ring event handler | |
2364 | * when there is an unsolicited iocb posted to the response ring by the | |
2365 | * firmware. This function gets the buffer associated with the iocbs | |
2366 | * and calls the event handler for the ring. This function handles both | |
2367 | * qring buffers and hbq buffers. | |
2368 | * When the function returns 1 the caller can free the iocb object otherwise | |
2369 | * upper layer functions will free the iocb objects. | |
2370 | **/ | |
dea3101e | 2371 | static int |
2372 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2373 | struct lpfc_iocbq *saveq) | |
2374 | { | |
2375 | IOCB_t * irsp; | |
2376 | WORD5 * w5p; | |
2377 | uint32_t Rctl, Type; | |
3772a991 | 2378 | uint32_t match; |
76bb24ef | 2379 | struct lpfc_iocbq *iocbq; |
3163f725 | 2380 | struct lpfc_dmabuf *dmzbuf; |
dea3101e | 2381 | |
2382 | match = 0; | |
2383 | irsp = &(saveq->iocb); | |
57127f15 JS |
2384 | |
2385 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2386 | if (pring->lpfc_sli_rcv_async_status) | |
2387 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2388 | else | |
2389 | lpfc_printf_log(phba, | |
2390 | KERN_WARNING, | |
2391 | LOG_SLI, | |
2392 | "0316 Ring %d handler: unexpected " | |
2393 | "ASYNC_STATUS iocb received evt_code " | |
2394 | "0x%x\n", | |
2395 | pring->ringno, | |
2396 | irsp->un.asyncstat.evt_code); | |
2397 | return 1; | |
2398 | } | |
2399 | ||
3163f725 JS |
2400 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2401 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2402 | if (irsp->ulpBdeCount > 0) { | |
2403 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2404 | irsp->un.ulpWord[3]); | |
2405 | lpfc_in_buf_free(phba, dmzbuf); | |
2406 | } | |
2407 | ||
2408 | if (irsp->ulpBdeCount > 1) { | |
2409 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2410 | irsp->unsli3.sli3Words[3]); | |
2411 | lpfc_in_buf_free(phba, dmzbuf); | |
2412 | } | |
2413 | ||
2414 | if (irsp->ulpBdeCount > 2) { | |
2415 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2416 | irsp->unsli3.sli3Words[7]); | |
2417 | lpfc_in_buf_free(phba, dmzbuf); | |
2418 | } | |
2419 | ||
2420 | return 1; | |
2421 | } | |
2422 | ||
92d7f7b0 | 2423 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2424 | if (irsp->ulpBdeCount != 0) { |
2425 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2426 | irsp->un.ulpWord[3]); | |
2427 | if (!saveq->context2) | |
2428 | lpfc_printf_log(phba, | |
2429 | KERN_ERR, | |
2430 | LOG_SLI, | |
2431 | "0341 Ring %d Cannot find buffer for " | |
2432 | "an unsolicited iocb. tag 0x%x\n", | |
2433 | pring->ringno, | |
2434 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2435 | } |
2436 | if (irsp->ulpBdeCount == 2) { | |
2437 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2438 | irsp->unsli3.sli3Words[7]); | |
2439 | if (!saveq->context3) | |
2440 | lpfc_printf_log(phba, | |
2441 | KERN_ERR, | |
2442 | LOG_SLI, | |
2443 | "0342 Ring %d Cannot find buffer for an" | |
2444 | " unsolicited iocb. tag 0x%x\n", | |
2445 | pring->ringno, | |
2446 | irsp->unsli3.sli3Words[7]); | |
2447 | } | |
2448 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2449 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2450 | if (irsp->ulpBdeCount != 0) { |
2451 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2452 | irsp->un.ulpWord[3]); | |
9c2face6 | 2453 | if (!iocbq->context2) |
76bb24ef JS |
2454 | lpfc_printf_log(phba, |
2455 | KERN_ERR, | |
2456 | LOG_SLI, | |
2457 | "0343 Ring %d Cannot find " | |
2458 | "buffer for an unsolicited iocb" | |
2459 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2460 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2461 | } |
2462 | if (irsp->ulpBdeCount == 2) { | |
2463 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2464 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2465 | if (!iocbq->context3) |
76bb24ef JS |
2466 | lpfc_printf_log(phba, |
2467 | KERN_ERR, | |
2468 | LOG_SLI, | |
2469 | "0344 Ring %d Cannot find " | |
2470 | "buffer for an unsolicited " | |
2471 | "iocb. tag 0x%x\n", | |
2472 | pring->ringno, | |
2473 | irsp->unsli3.sli3Words[7]); | |
2474 | } | |
2475 | } | |
92d7f7b0 | 2476 | } |
9c2face6 JS |
2477 | if (irsp->ulpBdeCount != 0 && |
2478 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2479 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2480 | int found = 0; | |
2481 | ||
2482 | /* search continue save q for same XRI */ | |
2483 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
2484 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { | |
2485 | list_add_tail(&saveq->list, &iocbq->list); | |
2486 | found = 1; | |
2487 | break; | |
2488 | } | |
2489 | } | |
2490 | if (!found) | |
2491 | list_add_tail(&saveq->clist, | |
2492 | &pring->iocb_continue_saveq); | |
2493 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2494 | list_del_init(&iocbq->clist); | |
2495 | saveq = iocbq; | |
2496 | irsp = &(saveq->iocb); | |
2497 | } else | |
2498 | return 0; | |
2499 | } | |
2500 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2501 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2502 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2503 | Rctl = FC_RCTL_ELS_REQ; |
2504 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2505 | } else { |
2506 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2507 | Rctl = w5p->hcsw.Rctl; | |
2508 | Type = w5p->hcsw.Type; | |
2509 | ||
2510 | /* Firmware Workaround */ | |
2511 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2512 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2513 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2514 | Rctl = FC_RCTL_ELS_REQ; |
2515 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2516 | w5p->hcsw.Rctl = Rctl; |
2517 | w5p->hcsw.Type = Type; | |
2518 | } | |
2519 | } | |
92d7f7b0 | 2520 | |
3772a991 | 2521 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2522 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2523 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2524 | "Type x%x received\n", |
e8b62011 | 2525 | pring->ringno, Rctl, Type); |
3772a991 | 2526 | |
92d7f7b0 | 2527 | return 1; |
dea3101e | 2528 | } |
2529 | ||
e59058c4 | 2530 | /** |
3621a710 | 2531 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2532 | * @phba: Pointer to HBA context object. |
2533 | * @pring: Pointer to driver SLI ring object. | |
2534 | * @prspiocb: Pointer to response iocb object. | |
2535 | * | |
2536 | * This function looks up the iocb_lookup table to get the command iocb | |
2537 | * corresponding to the given response iocb using the iotag of the | |
2538 | * response iocb. This function is called with the hbalock held. | |
2539 | * This function returns the command iocb object if it finds the command | |
2540 | * iocb else returns NULL. | |
2541 | **/ | |
dea3101e | 2542 | static struct lpfc_iocbq * |
2e0fef85 JS |
2543 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2544 | struct lpfc_sli_ring *pring, | |
2545 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2546 | { |
dea3101e | 2547 | struct lpfc_iocbq *cmd_iocb = NULL; |
2548 | uint16_t iotag; | |
2549 | ||
604a3e30 JB |
2550 | iotag = prspiocb->iocb.ulpIoTag; |
2551 | ||
2552 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2553 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2554 | list_del_init(&cmd_iocb->list); |
2a9bf3d0 JS |
2555 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2556 | pring->txcmplq_cnt--; | |
2557 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2558 | } | |
604a3e30 | 2559 | return cmd_iocb; |
dea3101e | 2560 | } |
2561 | ||
dea3101e | 2562 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2563 | "0317 iotag x%x is out off " |
604a3e30 | 2564 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2565 | iotag, phba->sli.last_iotag, |
604a3e30 | 2566 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e | 2567 | return NULL; |
2568 | } | |
2569 | ||
3772a991 JS |
2570 | /** |
2571 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2572 | * @phba: Pointer to HBA context object. | |
2573 | * @pring: Pointer to driver SLI ring object. | |
2574 | * @iotag: IOCB tag. | |
2575 | * | |
2576 | * This function looks up the iocb_lookup table to get the command iocb | |
2577 | * corresponding to the given iotag. This function is called with the | |
2578 | * hbalock held. | |
2579 | * This function returns the command iocb object if it finds the command | |
2580 | * iocb else returns NULL. | |
2581 | **/ | |
2582 | static struct lpfc_iocbq * | |
2583 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2584 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2585 | { | |
2586 | struct lpfc_iocbq *cmd_iocb; | |
2587 | ||
2588 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2589 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
2590 | list_del_init(&cmd_iocb->list); | |
2a9bf3d0 JS |
2591 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2592 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2593 | pring->txcmplq_cnt--; | |
2594 | } | |
3772a991 JS |
2595 | return cmd_iocb; |
2596 | } | |
2597 | ||
2598 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2599 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2600 | iotag, phba->sli.last_iotag); | |
2601 | return NULL; | |
2602 | } | |
2603 | ||
e59058c4 | 2604 | /** |
3621a710 | 2605 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2606 | * @phba: Pointer to HBA context object. |
2607 | * @pring: Pointer to driver SLI ring object. | |
2608 | * @saveq: Pointer to the response iocb to be processed. | |
2609 | * | |
2610 | * This function is called by the ring event handler for non-fcp | |
2611 | * rings when there is a new response iocb in the response ring. | |
2612 | * The caller is not required to hold any locks. This function | |
2613 | * gets the command iocb associated with the response iocb and | |
2614 | * calls the completion handler for the command iocb. If there | |
2615 | * is no completion handler, the function will free the resources | |
2616 | * associated with command iocb. If the response iocb is for | |
2617 | * an already aborted command iocb, the status of the completion | |
2618 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2619 | * This function always returns 1. | |
2620 | **/ | |
dea3101e | 2621 | static int |
2e0fef85 | 2622 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e | 2623 | struct lpfc_iocbq *saveq) |
2624 | { | |
2e0fef85 | 2625 | struct lpfc_iocbq *cmdiocbp; |
dea3101e | 2626 | int rc = 1; |
2627 | unsigned long iflag; | |
2628 | ||
2629 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2630 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2631 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2632 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2633 | ||
dea3101e | 2634 | if (cmdiocbp) { |
2635 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2636 | /* |
2637 | * If an ELS command failed send an event to mgmt | |
2638 | * application. | |
2639 | */ | |
2640 | if (saveq->iocb.ulpStatus && | |
2641 | (pring->ringno == LPFC_ELS_RING) && | |
2642 | (cmdiocbp->iocb.ulpCommand == | |
2643 | CMD_ELS_REQUEST64_CR)) | |
2644 | lpfc_send_els_failure_event(phba, | |
2645 | cmdiocbp, saveq); | |
2646 | ||
dea3101e | 2647 | /* |
2648 | * Post all ELS completions to the worker thread. | |
2649 | * All other are passed to the completion callback. | |
2650 | */ | |
2651 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2652 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2653 | (cmdiocbp->iocb_flag & | |
2654 | LPFC_DRIVER_ABORTED)) { | |
2655 | spin_lock_irqsave(&phba->hbalock, | |
2656 | iflag); | |
07951076 JS |
2657 | cmdiocbp->iocb_flag &= |
2658 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2659 | spin_unlock_irqrestore(&phba->hbalock, |
2660 | iflag); | |
07951076 JS |
2661 | saveq->iocb.ulpStatus = |
2662 | IOSTAT_LOCAL_REJECT; | |
2663 | saveq->iocb.un.ulpWord[4] = | |
2664 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2665 | |
2666 | /* Firmware could still be in progress | |
2667 | * of DMAing payload, so don't free data | |
2668 | * buffer till after a hbeat. | |
2669 | */ | |
341af102 JS |
2670 | spin_lock_irqsave(&phba->hbalock, |
2671 | iflag); | |
0ff10d46 | 2672 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2673 | spin_unlock_irqrestore(&phba->hbalock, |
2674 | iflag); | |
2675 | } | |
0f65ff68 JS |
2676 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2677 | if (saveq->iocb_flag & | |
2678 | LPFC_EXCHANGE_BUSY) { | |
2679 | /* Set cmdiocb flag for the | |
2680 | * exchange busy so sgl (xri) | |
2681 | * will not be released until | |
2682 | * the abort xri is received | |
2683 | * from hba. | |
2684 | */ | |
2685 | spin_lock_irqsave( | |
2686 | &phba->hbalock, iflag); | |
2687 | cmdiocbp->iocb_flag |= | |
2688 | LPFC_EXCHANGE_BUSY; | |
2689 | spin_unlock_irqrestore( | |
2690 | &phba->hbalock, iflag); | |
2691 | } | |
2692 | if (cmdiocbp->iocb_flag & | |
2693 | LPFC_DRIVER_ABORTED) { | |
2694 | /* | |
2695 | * Clear LPFC_DRIVER_ABORTED | |
2696 | * bit in case it was driver | |
2697 | * initiated abort. | |
2698 | */ | |
2699 | spin_lock_irqsave( | |
2700 | &phba->hbalock, iflag); | |
2701 | cmdiocbp->iocb_flag &= | |
2702 | ~LPFC_DRIVER_ABORTED; | |
2703 | spin_unlock_irqrestore( | |
2704 | &phba->hbalock, iflag); | |
2705 | cmdiocbp->iocb.ulpStatus = | |
2706 | IOSTAT_LOCAL_REJECT; | |
2707 | cmdiocbp->iocb.un.ulpWord[4] = | |
2708 | IOERR_ABORT_REQUESTED; | |
2709 | /* | |
2710 | * For SLI4, irsiocb contains | |
2711 | * NO_XRI in sli_xritag, it | |
2712 | * shall not affect releasing | |
2713 | * sgl (xri) process. | |
2714 | */ | |
2715 | saveq->iocb.ulpStatus = | |
2716 | IOSTAT_LOCAL_REJECT; | |
2717 | saveq->iocb.un.ulpWord[4] = | |
2718 | IOERR_SLI_ABORTED; | |
2719 | spin_lock_irqsave( | |
2720 | &phba->hbalock, iflag); | |
2721 | saveq->iocb_flag |= | |
2722 | LPFC_DELAY_MEM_FREE; | |
2723 | spin_unlock_irqrestore( | |
2724 | &phba->hbalock, iflag); | |
2725 | } | |
07951076 | 2726 | } |
dea3101e | 2727 | } |
2e0fef85 | 2728 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2729 | } else |
2730 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e | 2731 | } else { |
2732 | /* | |
2733 | * Unknown initiating command based on the response iotag. | |
2734 | * This could be the case on the ELS ring because of | |
2735 | * lpfc_els_abort(). | |
2736 | */ | |
2737 | if (pring->ringno != LPFC_ELS_RING) { | |
2738 | /* | |
2739 | * Ring <ringno> handler: unexpected completion IoTag | |
2740 | * <IoTag> | |
2741 | */ | |
a257bf90 | 2742 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2743 | "0322 Ring %d handler: " |
2744 | "unexpected completion IoTag x%x " | |
2745 | "Data: x%x x%x x%x x%x\n", | |
2746 | pring->ringno, | |
2747 | saveq->iocb.ulpIoTag, | |
2748 | saveq->iocb.ulpStatus, | |
2749 | saveq->iocb.un.ulpWord[4], | |
2750 | saveq->iocb.ulpCommand, | |
2751 | saveq->iocb.ulpContext); | |
dea3101e | 2752 | } |
2753 | } | |
68876920 | 2754 | |
dea3101e | 2755 | return rc; |
2756 | } | |
2757 | ||
e59058c4 | 2758 | /** |
3621a710 | 2759 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2760 | * @phba: Pointer to HBA context object. |
2761 | * @pring: Pointer to driver SLI ring object. | |
2762 | * | |
2763 | * This function is called from the iocb ring event handlers when | |
2764 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2765 | * an error attention condition to the worker thread and the worker | |
2766 | * thread will transition the HBA to offline state. | |
2767 | **/ | |
2e0fef85 JS |
2768 | static void |
2769 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2770 | { |
34b02dcd | 2771 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2772 | /* |
025dfdaf | 2773 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2774 | * rsp ring <portRspMax> |
2775 | */ | |
2776 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2777 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2778 | "is bigger than rsp ring %d\n", |
e8b62011 | 2779 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
2780 | pring->numRiocb); |
2781 | ||
2e0fef85 | 2782 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2783 | |
2784 | /* | |
2785 | * All error attention handlers are posted to | |
2786 | * worker thread | |
2787 | */ | |
2788 | phba->work_ha |= HA_ERATT; | |
2789 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2790 | |
5e9d9b82 | 2791 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2792 | |
2793 | return; | |
2794 | } | |
2795 | ||
9399627f | 2796 | /** |
3621a710 | 2797 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2798 | * @ptr: Pointer to address of HBA context object. |
2799 | * | |
2800 | * This function is invoked by the Error Attention polling timer when the | |
2801 | * timer times out. It will check the SLI Error Attention register for | |
2802 | * possible attention events. If so, it will post an Error Attention event | |
2803 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2804 | * Error Attention polling timer for the next poll. | |
2805 | **/ | |
2806 | void lpfc_poll_eratt(unsigned long ptr) | |
2807 | { | |
2808 | struct lpfc_hba *phba; | |
2809 | uint32_t eratt = 0; | |
2810 | ||
2811 | phba = (struct lpfc_hba *)ptr; | |
2812 | ||
2813 | /* Check chip HA register for error event */ | |
2814 | eratt = lpfc_sli_check_eratt(phba); | |
2815 | ||
2816 | if (eratt) | |
2817 | /* Tell the worker thread there is work to do */ | |
2818 | lpfc_worker_wake_up(phba); | |
2819 | else | |
2820 | /* Restart the timer for next eratt poll */ | |
2821 | mod_timer(&phba->eratt_poll, jiffies + | |
2822 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2823 | return; | |
2824 | } | |
2825 | ||
875fbdfe | 2826 | |
e59058c4 | 2827 | /** |
3621a710 | 2828 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2829 | * @phba: Pointer to HBA context object. |
2830 | * @pring: Pointer to driver SLI ring object. | |
2831 | * @mask: Host attention register mask for this ring. | |
2832 | * | |
2833 | * This function is called from the interrupt context when there is a ring | |
2834 | * event for the fcp ring. The caller does not hold any lock. | |
2835 | * The function processes each response iocb in the response ring until it | |
2836 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | |
2837 | * LE bit set. The function will call the completion handler of the command iocb | |
2838 | * if the response iocb indicates a completion for a command iocb or it is | |
2839 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2840 | * function if this is an unsolicited iocb. | |
dea3101e | 2841 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2842 | * to check it explicitly. |
2843 | */ | |
2844 | int | |
2e0fef85 JS |
2845 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2846 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2847 | { |
34b02dcd | 2848 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2849 | IOCB_t *irsp = NULL; |
87f6eaff | 2850 | IOCB_t *entry = NULL; |
dea3101e | 2851 | struct lpfc_iocbq *cmdiocbq = NULL; |
2852 | struct lpfc_iocbq rspiocbq; | |
dea3101e | 2853 | uint32_t status; |
2854 | uint32_t portRspPut, portRspMax; | |
2855 | int rc = 1; | |
2856 | lpfc_iocb_type type; | |
2857 | unsigned long iflag; | |
2858 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2859 | |
2e0fef85 | 2860 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 2861 | pring->stats.iocb_event++; |
2862 | ||
dea3101e | 2863 | /* |
2864 | * The next available response entry should never exceed the maximum | |
2865 | * entries. If it does, treat it as an adapter hardware error. | |
2866 | */ | |
2867 | portRspMax = pring->numRiocb; | |
2868 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2869 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2870 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2871 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 2872 | return 1; |
2873 | } | |
45ed1190 JS |
2874 | if (phba->fcp_ring_in_use) { |
2875 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2876 | return 1; | |
2877 | } else | |
2878 | phba->fcp_ring_in_use = 1; | |
dea3101e | 2879 | |
2880 | rmb(); | |
2881 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
2882 | /* |
2883 | * Fetch an entry off the ring and copy it into a local data | |
2884 | * structure. The copy involves a byte-swap since the | |
2885 | * network byte order and pci byte orders are different. | |
2886 | */ | |
ed957684 | 2887 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2888 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
2889 | |
2890 | if (++pring->rspidx >= portRspMax) | |
2891 | pring->rspidx = 0; | |
2892 | ||
87f6eaff JSEC |
2893 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2894 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2895 | phba->iocb_rsp_size); |
a4bc3379 | 2896 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2897 | irsp = &rspiocbq.iocb; |
2898 | ||
dea3101e | 2899 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2900 | pring->stats.iocb_rsp++; | |
2901 | rsp_cmpl++; | |
2902 | ||
2903 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2904 | /* |
2905 | * If resource errors reported from HBA, reduce | |
2906 | * queuedepths of the SCSI device. | |
2907 | */ | |
2908 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2909 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2910 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2911 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2912 | spin_lock_irqsave(&phba->hbalock, iflag); |
2913 | } | |
2914 | ||
dea3101e | 2915 | /* Rsp ring <ringno> error: IOCB */ |
2916 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2917 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2918 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2919 | pring->ringno, |
92d7f7b0 JS |
2920 | irsp->un.ulpWord[0], |
2921 | irsp->un.ulpWord[1], | |
2922 | irsp->un.ulpWord[2], | |
2923 | irsp->un.ulpWord[3], | |
2924 | irsp->un.ulpWord[4], | |
2925 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2926 | *(uint32_t *)&irsp->un1, |
2927 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e | 2928 | } |
2929 | ||
2930 | switch (type) { | |
2931 | case LPFC_ABORT_IOCB: | |
2932 | case LPFC_SOL_IOCB: | |
2933 | /* | |
2934 | * Idle exchange closed via ABTS from port. No iocb | |
2935 | * resources need to be recovered. | |
2936 | */ | |
2937 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2938 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2939 | "0333 IOCB cmd 0x%x" |
dca9479b | 2940 | " processed. Skipping" |
92d7f7b0 | 2941 | " completion\n", |
dca9479b | 2942 | irsp->ulpCommand); |
dea3101e | 2943 | break; |
2944 | } | |
2945 | ||
604a3e30 JB |
2946 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2947 | &rspiocbq); | |
0f65ff68 JS |
2948 | if (unlikely(!cmdiocbq)) |
2949 | break; | |
2950 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2951 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2952 | if (cmdiocbq->iocb_cmpl) { | |
2953 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2954 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2955 | &rspiocbq); | |
2956 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2957 | } | |
dea3101e | 2958 | break; |
a4bc3379 | 2959 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2960 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2961 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2962 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2963 | break; |
dea3101e | 2964 | default: |
2965 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2966 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2967 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2968 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2969 | MAX_MSG_DATA); | |
898eb71c JP |
2970 | dev_warn(&((phba->pcidev)->dev), |
2971 | "lpfc%d: %s\n", | |
dea3101e | 2972 | phba->brd_no, adaptermsg); |
2973 | } else { | |
2974 | /* Unknown IOCB command */ | |
2975 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2976 | "0334 Unknown IOCB command " |
92d7f7b0 | 2977 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2978 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2979 | irsp->ulpStatus, |
2980 | irsp->ulpIoTag, | |
2981 | irsp->ulpContext); | |
dea3101e | 2982 | } |
2983 | break; | |
2984 | } | |
2985 | ||
2986 | /* | |
2987 | * The response IOCB has been processed. Update the ring | |
2988 | * pointer in SLIM. If the port response put pointer has not | |
2989 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2990 | * response put pointer. | |
2991 | */ | |
ed957684 | 2992 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 2993 | |
2994 | if (pring->rspidx == portRspPut) | |
2995 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2996 | } | |
2997 | ||
2998 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
2999 | pring->stats.iocb_rsp_full++; | |
3000 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3001 | writel(status, phba->CAregaddr); | |
3002 | readl(phba->CAregaddr); | |
3003 | } | |
3004 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3005 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3006 | pring->stats.iocb_cmd_empty++; | |
3007 | ||
3008 | /* Force update of the local copy of cmdGetInx */ | |
3009 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3010 | lpfc_sli_resume_iocb(phba, pring); | |
3011 | ||
3012 | if ((pring->lpfc_sli_cmd_available)) | |
3013 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3014 | ||
3015 | } | |
3016 | ||
45ed1190 | 3017 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3018 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 3019 | return rc; |
3020 | } | |
3021 | ||
e59058c4 | 3022 | /** |
3772a991 JS |
3023 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3024 | * @phba: Pointer to HBA context object. | |
3025 | * @pring: Pointer to driver SLI ring object. | |
3026 | * @rspiocbp: Pointer to driver response IOCB object. | |
3027 | * | |
3028 | * This function is called from the worker thread when there is a slow-path | |
3029 | * response IOCB to process. This function chains all the response iocbs until | |
3030 | * seeing the iocb with the LE bit set. The function will call | |
3031 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3032 | * completion of a command iocb. The function will call the | |
3033 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3034 | * The function frees the resources or calls the completion handler if this | |
3035 | * iocb is an abort completion. The function returns NULL when the response | |
3036 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3037 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3038 | * response iocb passed in. | |
3039 | **/ | |
3040 | static struct lpfc_iocbq * | |
3041 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3042 | struct lpfc_iocbq *rspiocbp) | |
3043 | { | |
3044 | struct lpfc_iocbq *saveq; | |
3045 | struct lpfc_iocbq *cmdiocbp; | |
3046 | struct lpfc_iocbq *next_iocb; | |
3047 | IOCB_t *irsp = NULL; | |
3048 | uint32_t free_saveq; | |
3049 | uint8_t iocb_cmd_type; | |
3050 | lpfc_iocb_type type; | |
3051 | unsigned long iflag; | |
3052 | int rc; | |
3053 | ||
3054 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3055 | /* First add the response iocb to the countinueq list */ | |
3056 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3057 | pring->iocb_continueq_cnt++; | |
3058 | ||
3059 | /* Now, determine whetehr the list is completed for processing */ | |
3060 | irsp = &rspiocbp->iocb; | |
3061 | if (irsp->ulpLe) { | |
3062 | /* | |
3063 | * By default, the driver expects to free all resources | |
3064 | * associated with this iocb completion. | |
3065 | */ | |
3066 | free_saveq = 1; | |
3067 | saveq = list_get_first(&pring->iocb_continueq, | |
3068 | struct lpfc_iocbq, list); | |
3069 | irsp = &(saveq->iocb); | |
3070 | list_del_init(&pring->iocb_continueq); | |
3071 | pring->iocb_continueq_cnt = 0; | |
3072 | ||
3073 | pring->stats.iocb_rsp++; | |
3074 | ||
3075 | /* | |
3076 | * If resource errors reported from HBA, reduce | |
3077 | * queuedepths of the SCSI device. | |
3078 | */ | |
3079 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3080 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3081 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3082 | phba->lpfc_rampdown_queue_depth(phba); | |
3083 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3084 | } | |
3085 | ||
3086 | if (irsp->ulpStatus) { | |
3087 | /* Rsp ring <ringno> error: IOCB */ | |
3088 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3089 | "0328 Rsp Ring %d error: " | |
3090 | "IOCB Data: " | |
3091 | "x%x x%x x%x x%x " | |
3092 | "x%x x%x x%x x%x " | |
3093 | "x%x x%x x%x x%x " | |
3094 | "x%x x%x x%x x%x\n", | |
3095 | pring->ringno, | |
3096 | irsp->un.ulpWord[0], | |
3097 | irsp->un.ulpWord[1], | |
3098 | irsp->un.ulpWord[2], | |
3099 | irsp->un.ulpWord[3], | |
3100 | irsp->un.ulpWord[4], | |
3101 | irsp->un.ulpWord[5], | |
3102 | *(((uint32_t *) irsp) + 6), | |
3103 | *(((uint32_t *) irsp) + 7), | |
3104 | *(((uint32_t *) irsp) + 8), | |
3105 | *(((uint32_t *) irsp) + 9), | |
3106 | *(((uint32_t *) irsp) + 10), | |
3107 | *(((uint32_t *) irsp) + 11), | |
3108 | *(((uint32_t *) irsp) + 12), | |
3109 | *(((uint32_t *) irsp) + 13), | |
3110 | *(((uint32_t *) irsp) + 14), | |
3111 | *(((uint32_t *) irsp) + 15)); | |
3112 | } | |
3113 | ||
3114 | /* | |
3115 | * Fetch the IOCB command type and call the correct completion | |
3116 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3117 | * get freed back to the lpfc_iocb_list by the discovery | |
3118 | * kernel thread. | |
3119 | */ | |
3120 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3121 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3122 | switch (type) { | |
3123 | case LPFC_SOL_IOCB: | |
3124 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3125 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3126 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3127 | break; | |
3128 | ||
3129 | case LPFC_UNSOL_IOCB: | |
3130 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3131 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3132 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3133 | if (!rc) | |
3134 | free_saveq = 0; | |
3135 | break; | |
3136 | ||
3137 | case LPFC_ABORT_IOCB: | |
3138 | cmdiocbp = NULL; | |
3139 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3140 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3141 | saveq); | |
3142 | if (cmdiocbp) { | |
3143 | /* Call the specified completion routine */ | |
3144 | if (cmdiocbp->iocb_cmpl) { | |
3145 | spin_unlock_irqrestore(&phba->hbalock, | |
3146 | iflag); | |
3147 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3148 | saveq); | |
3149 | spin_lock_irqsave(&phba->hbalock, | |
3150 | iflag); | |
3151 | } else | |
3152 | __lpfc_sli_release_iocbq(phba, | |
3153 | cmdiocbp); | |
3154 | } | |
3155 | break; | |
3156 | ||
3157 | case LPFC_UNKNOWN_IOCB: | |
3158 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3159 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3160 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3161 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3162 | MAX_MSG_DATA); | |
3163 | dev_warn(&((phba->pcidev)->dev), | |
3164 | "lpfc%d: %s\n", | |
3165 | phba->brd_no, adaptermsg); | |
3166 | } else { | |
3167 | /* Unknown IOCB command */ | |
3168 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3169 | "0335 Unknown IOCB " | |
3170 | "command Data: x%x " | |
3171 | "x%x x%x x%x\n", | |
3172 | irsp->ulpCommand, | |
3173 | irsp->ulpStatus, | |
3174 | irsp->ulpIoTag, | |
3175 | irsp->ulpContext); | |
3176 | } | |
3177 | break; | |
3178 | } | |
3179 | ||
3180 | if (free_saveq) { | |
3181 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3182 | &saveq->list, list) { | |
3183 | list_del(&rspiocbp->list); | |
3184 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3185 | } | |
3186 | __lpfc_sli_release_iocbq(phba, saveq); | |
3187 | } | |
3188 | rspiocbp = NULL; | |
3189 | } | |
3190 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3191 | return rspiocbp; | |
3192 | } | |
3193 | ||
3194 | /** | |
3195 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
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 | * | |
3772a991 JS |
3200 | * This routine wraps the actual slow_ring event process routine from the |
3201 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3202 | **/ |
3772a991 | 3203 | void |
2e0fef85 JS |
3204 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3205 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3206 | { |
3207 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3208 | } | |
3209 | ||
3210 | /** | |
3211 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3212 | * @phba: Pointer to HBA context object. | |
3213 | * @pring: Pointer to driver SLI ring object. | |
3214 | * @mask: Host attention register mask for this ring. | |
3215 | * | |
3216 | * This function is called from the worker thread when there is a ring event | |
3217 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3218 | * remove each response iocb in the response ring and calls the handle | |
3219 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3220 | **/ | |
3221 | static void | |
3222 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3223 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3224 | { |
34b02dcd | 3225 | struct lpfc_pgp *pgp; |
dea3101e | 3226 | IOCB_t *entry; |
3227 | IOCB_t *irsp = NULL; | |
3228 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3229 | uint32_t portRspPut, portRspMax; |
dea3101e | 3230 | unsigned long iflag; |
3772a991 | 3231 | uint32_t status; |
dea3101e | 3232 | |
34b02dcd | 3233 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3234 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 3235 | pring->stats.iocb_event++; |
3236 | ||
dea3101e | 3237 | /* |
3238 | * The next available response entry should never exceed the maximum | |
3239 | * entries. If it does, treat it as an adapter hardware error. | |
3240 | */ | |
3241 | portRspMax = pring->numRiocb; | |
3242 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3243 | if (portRspPut >= portRspMax) { | |
3244 | /* | |
025dfdaf | 3245 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e | 3246 | * rsp ring <portRspMax> |
3247 | */ | |
ed957684 | 3248 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3249 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3250 | "is bigger than rsp ring %d\n", |
e8b62011 | 3251 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3252 | |
2e0fef85 JS |
3253 | phba->link_state = LPFC_HBA_ERROR; |
3254 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e | 3255 | |
3256 | phba->work_hs = HS_FFER3; | |
3257 | lpfc_handle_eratt(phba); | |
3258 | ||
3772a991 | 3259 | return; |
dea3101e | 3260 | } |
3261 | ||
3262 | rmb(); | |
dea3101e | 3263 | while (pring->rspidx != portRspPut) { |
3264 | /* | |
3265 | * Build a completion list and call the appropriate handler. | |
3266 | * The process is to get the next available response iocb, get | |
3267 | * a free iocb from the list, copy the response data into the | |
3268 | * free iocb, insert to the continuation list, and update the | |
3269 | * next response index to slim. This process makes response | |
3270 | * iocb's in the ring available to DMA as fast as possible but | |
3271 | * pays a penalty for a copy operation. Since the iocb is | |
3272 | * only 32 bytes, this penalty is considered small relative to | |
3273 | * the PCI reads for register values and a slim write. When | |
3274 | * the ulpLe field is set, the entire Command has been | |
3275 | * received. | |
3276 | */ | |
ed957684 JS |
3277 | entry = lpfc_resp_iocb(phba, pring); |
3278 | ||
858c9f6c | 3279 | phba->last_completion_time = jiffies; |
2e0fef85 | 3280 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 3281 | if (rspiocbp == NULL) { |
3282 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3283 | "completion.\n", __func__); |
dea3101e | 3284 | break; |
3285 | } | |
3286 | ||
ed957684 JS |
3287 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3288 | phba->iocb_rsp_size); | |
dea3101e | 3289 | irsp = &rspiocbp->iocb; |
3290 | ||
3291 | if (++pring->rspidx >= portRspMax) | |
3292 | pring->rspidx = 0; | |
3293 | ||
a58cbd52 JS |
3294 | if (pring->ringno == LPFC_ELS_RING) { |
3295 | lpfc_debugfs_slow_ring_trc(phba, | |
3296 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3297 | *(((uint32_t *) irsp) + 4), | |
3298 | *(((uint32_t *) irsp) + 6), | |
3299 | *(((uint32_t *) irsp) + 7)); | |
3300 | } | |
3301 | ||
ed957684 | 3302 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 3303 | |
3772a991 JS |
3304 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3305 | /* Handle the response IOCB */ | |
3306 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3307 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e | 3308 | |
3309 | /* | |
3310 | * If the port response put pointer has not been updated, sync | |
3311 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3312 | * response put pointer. | |
3313 | */ | |
3314 | if (pring->rspidx == portRspPut) { | |
3315 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3316 | } | |
3317 | } /* while (pring->rspidx != portRspPut) */ | |
3318 | ||
92d7f7b0 | 3319 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e | 3320 | /* At least one response entry has been freed */ |
3321 | pring->stats.iocb_rsp_full++; | |
3322 | /* SET RxRE_RSP in Chip Att register */ | |
3323 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3324 | writel(status, phba->CAregaddr); | |
3325 | readl(phba->CAregaddr); /* flush */ | |
3326 | } | |
3327 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3328 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3329 | pring->stats.iocb_cmd_empty++; | |
3330 | ||
3331 | /* Force update of the local copy of cmdGetInx */ | |
3332 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3333 | lpfc_sli_resume_iocb(phba, pring); | |
3334 | ||
3335 | if ((pring->lpfc_sli_cmd_available)) | |
3336 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3337 | ||
3338 | } | |
3339 | ||
2e0fef85 | 3340 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3341 | return; |
dea3101e | 3342 | } |
3343 | ||
4f774513 JS |
3344 | /** |
3345 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3346 | * @phba: Pointer to HBA context object. | |
3347 | * @pring: Pointer to driver SLI ring object. | |
3348 | * @mask: Host attention register mask for this ring. | |
3349 | * | |
3350 | * This function is called from the worker thread when there is a pending | |
3351 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3352 | * queue. The caller does not hold any lock. The function will remove each | |
3353 | * response iocb from the response worker queue and calls the handle | |
3354 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3355 | **/ | |
3356 | static void | |
3357 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3358 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3359 | { | |
3360 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3361 | struct hbq_dmabuf *dmabuf; |
3362 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3363 | unsigned long iflag; |
3364 | ||
45ed1190 JS |
3365 | spin_lock_irqsave(&phba->hbalock, iflag); |
3366 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3367 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3368 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3369 | /* Get the response iocb from the head of work queue */ |
3370 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3371 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3372 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3373 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3374 | |
3375 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3376 | case CQE_CODE_COMPL_WQE: | |
3377 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3378 | cq_event); | |
45ed1190 JS |
3379 | /* Translate ELS WCQE to response IOCBQ */ |
3380 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3381 | irspiocbq); | |
3382 | if (irspiocbq) | |
3383 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3384 | irspiocbq); | |
4d9ab994 JS |
3385 | break; |
3386 | case CQE_CODE_RECEIVE: | |
3387 | dmabuf = container_of(cq_event, struct hbq_dmabuf, | |
3388 | cq_event); | |
3389 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3390 | break; | |
3391 | default: | |
3392 | break; | |
3393 | } | |
4f774513 JS |
3394 | } |
3395 | } | |
3396 | ||
e59058c4 | 3397 | /** |
3621a710 | 3398 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3399 | * @phba: Pointer to HBA context object. |
3400 | * @pring: Pointer to driver SLI ring object. | |
3401 | * | |
3402 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3403 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3404 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3405 | * the return of this function. The caller is not required to hold any locks. | |
3406 | **/ | |
2e0fef85 | 3407 | void |
dea3101e | 3408 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3409 | { | |
2534ba75 | 3410 | LIST_HEAD(completions); |
dea3101e | 3411 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3412 | |
92d7f7b0 JS |
3413 | if (pring->ringno == LPFC_ELS_RING) { |
3414 | lpfc_fabric_abort_hba(phba); | |
3415 | } | |
3416 | ||
dea3101e | 3417 | /* Error everything on txq and txcmplq |
3418 | * First do the txq. | |
3419 | */ | |
2e0fef85 | 3420 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3421 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3422 | pring->txq_cnt = 0; |
dea3101e | 3423 | |
3424 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3425 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3426 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3427 | |
2e0fef85 | 3428 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3429 | |
a257bf90 JS |
3430 | /* Cancel all the IOCBs from the completions list */ |
3431 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3432 | IOERR_SLI_ABORTED); | |
dea3101e | 3433 | } |
3434 | ||
a8e497d5 | 3435 | /** |
3621a710 | 3436 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3437 | * @phba: Pointer to HBA context object. |
3438 | * | |
3439 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3440 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3441 | * for all the iocb commands in txcmplq, they will just be returned with | |
3442 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3443 | * slot has been permanently disabled. | |
3444 | **/ | |
3445 | void | |
3446 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3447 | { | |
3448 | LIST_HEAD(txq); | |
3449 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3450 | struct lpfc_sli *psli = &phba->sli; |
3451 | struct lpfc_sli_ring *pring; | |
3452 | ||
3453 | /* Currently, only one fcp ring */ | |
3454 | pring = &psli->ring[psli->fcp_ring]; | |
3455 | ||
3456 | spin_lock_irq(&phba->hbalock); | |
3457 | /* Retrieve everything on txq */ | |
3458 | list_splice_init(&pring->txq, &txq); | |
3459 | pring->txq_cnt = 0; | |
3460 | ||
3461 | /* Retrieve everything on the txcmplq */ | |
3462 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3463 | pring->txcmplq_cnt = 0; | |
3464 | spin_unlock_irq(&phba->hbalock); | |
3465 | ||
3466 | /* Flush the txq */ | |
a257bf90 JS |
3467 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3468 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3469 | |
3470 | /* Flush the txcmpq */ | |
a257bf90 JS |
3471 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3472 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3473 | } |
3474 | ||
e59058c4 | 3475 | /** |
3772a991 | 3476 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3477 | * @phba: Pointer to HBA context object. |
3478 | * @mask: Bit mask to be checked. | |
3479 | * | |
3480 | * This function reads the host status register and compares | |
3481 | * with the provided bit mask to check if HBA completed | |
3482 | * the restart. This function will wait in a loop for the | |
3483 | * HBA to complete restart. If the HBA does not restart within | |
3484 | * 15 iterations, the function will reset the HBA again. The | |
3485 | * function returns 1 when HBA fail to restart otherwise returns | |
3486 | * zero. | |
3487 | **/ | |
3772a991 JS |
3488 | static int |
3489 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3490 | { |
41415862 JW |
3491 | uint32_t status; |
3492 | int i = 0; | |
3493 | int retval = 0; | |
dea3101e | 3494 | |
41415862 JW |
3495 | /* Read the HBA Host Status Register */ |
3496 | status = readl(phba->HSregaddr); | |
dea3101e | 3497 | |
41415862 JW |
3498 | /* |
3499 | * Check status register every 100ms for 5 retries, then every | |
3500 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3501 | * every 2.5 sec for 4. | |
3502 | * Break our of the loop if errors occurred during init. | |
3503 | */ | |
3504 | while (((status & mask) != mask) && | |
3505 | !(status & HS_FFERM) && | |
3506 | i++ < 20) { | |
dea3101e | 3507 | |
41415862 JW |
3508 | if (i <= 5) |
3509 | msleep(10); | |
3510 | else if (i <= 10) | |
3511 | msleep(500); | |
3512 | else | |
3513 | msleep(2500); | |
dea3101e | 3514 | |
41415862 | 3515 | if (i == 15) { |
2e0fef85 | 3516 | /* Do post */ |
92d7f7b0 | 3517 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3518 | lpfc_sli_brdrestart(phba); |
3519 | } | |
3520 | /* Read the HBA Host Status Register */ | |
3521 | status = readl(phba->HSregaddr); | |
3522 | } | |
dea3101e | 3523 | |
41415862 JW |
3524 | /* Check to see if any errors occurred during init */ |
3525 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3526 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3527 | "2751 Adapter failed to restart, " | |
3528 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3529 | status, | |
3530 | readl(phba->MBslimaddr + 0xa8), | |
3531 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3532 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3533 | retval = 1; |
dea3101e | 3534 | } |
dea3101e | 3535 | |
41415862 JW |
3536 | return retval; |
3537 | } | |
dea3101e | 3538 | |
da0436e9 JS |
3539 | /** |
3540 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3541 | * @phba: Pointer to HBA context object. | |
3542 | * @mask: Bit mask to be checked. | |
3543 | * | |
3544 | * This function checks the host status register to check if HBA is | |
3545 | * ready. This function will wait in a loop for the HBA to be ready | |
3546 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3547 | * function again. The function returns 1 when HBA fail to be ready | |
3548 | * otherwise returns zero. | |
3549 | **/ | |
3550 | static int | |
3551 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3552 | { | |
3553 | uint32_t status; | |
3554 | int retval = 0; | |
3555 | ||
3556 | /* Read the HBA Host Status Register */ | |
3557 | status = lpfc_sli4_post_status_check(phba); | |
3558 | ||
3559 | if (status) { | |
3560 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3561 | lpfc_sli_brdrestart(phba); | |
3562 | status = lpfc_sli4_post_status_check(phba); | |
3563 | } | |
3564 | ||
3565 | /* Check to see if any errors occurred during init */ | |
3566 | if (status) { | |
3567 | phba->link_state = LPFC_HBA_ERROR; | |
3568 | retval = 1; | |
3569 | } else | |
3570 | phba->sli4_hba.intr_enable = 0; | |
3571 | ||
3572 | return retval; | |
3573 | } | |
3574 | ||
3575 | /** | |
3576 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3577 | * @phba: Pointer to HBA context object. | |
3578 | * @mask: Bit mask to be checked. | |
3579 | * | |
3580 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3581 | * from the API jump table function pointer from the lpfc_hba struct. | |
3582 | **/ | |
3583 | int | |
3584 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3585 | { | |
3586 | return phba->lpfc_sli_brdready(phba, mask); | |
3587 | } | |
3588 | ||
9290831f JS |
3589 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3590 | ||
e59058c4 | 3591 | /** |
3621a710 | 3592 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3593 | * @phba: Pointer to HBA context object. |
3594 | * | |
3595 | * This function is called before resetting an HBA. This | |
3596 | * function requests HBA to quiesce DMAs before a reset. | |
3597 | **/ | |
2e0fef85 | 3598 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3599 | { |
65a29c16 JS |
3600 | uint32_t __iomem *resp_buf; |
3601 | uint32_t __iomem *mbox_buf; | |
9290831f JS |
3602 | volatile uint32_t mbox; |
3603 | uint32_t hc_copy; | |
3604 | int i; | |
3605 | uint8_t hdrtype; | |
3606 | ||
3607 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3608 | if (hdrtype != 0x80 || | |
3609 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3610 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3611 | return; | |
3612 | ||
3613 | /* | |
3614 | * Tell the other part of the chip to suspend temporarily all | |
3615 | * its DMA activity. | |
3616 | */ | |
65a29c16 | 3617 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3618 | |
3619 | /* Disable the error attention */ | |
3620 | hc_copy = readl(phba->HCregaddr); | |
3621 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); | |
3622 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3623 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f JS |
3624 | |
3625 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3626 | /* Clear Chip error bit */ | |
3627 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3628 | phba->pport->stopped = 1; |
9290831f JS |
3629 | } |
3630 | ||
3631 | mbox = 0; | |
3632 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3633 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3634 | ||
3635 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3636 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3637 | writel(mbox, mbox_buf); |
3638 | ||
3639 | for (i = 0; | |
3640 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) | |
3641 | mdelay(1); | |
3642 | ||
3643 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3644 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3645 | phba->pport->stopped) |
9290831f JS |
3646 | goto restore_hc; |
3647 | else | |
3648 | goto clear_errat; | |
3649 | } | |
3650 | ||
3651 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
3652 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) | |
3653 | mdelay(1); | |
3654 | ||
3655 | clear_errat: | |
3656 | ||
3657 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) | |
3658 | mdelay(1); | |
3659 | ||
3660 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3661 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3662 | phba->pport->stopped = 1; |
9290831f JS |
3663 | } |
3664 | ||
3665 | restore_hc: | |
2e0fef85 | 3666 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3667 | writel(hc_copy, phba->HCregaddr); |
3668 | readl(phba->HCregaddr); /* flush */ | |
3669 | } | |
3670 | ||
e59058c4 | 3671 | /** |
3621a710 | 3672 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3673 | * @phba: Pointer to HBA context object. |
3674 | * | |
3675 | * This function issues a kill_board mailbox command and waits for | |
3676 | * the error attention interrupt. This function is called for stopping | |
3677 | * the firmware processing. The caller is not required to hold any | |
3678 | * locks. This function calls lpfc_hba_down_post function to free | |
3679 | * any pending commands after the kill. The function will return 1 when it | |
3680 | * fails to kill the board else will return 0. | |
3681 | **/ | |
41415862 | 3682 | int |
2e0fef85 | 3683 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3684 | { |
3685 | struct lpfc_sli *psli; | |
3686 | LPFC_MBOXQ_t *pmb; | |
3687 | uint32_t status; | |
3688 | uint32_t ha_copy; | |
3689 | int retval; | |
3690 | int i = 0; | |
dea3101e | 3691 | |
41415862 | 3692 | psli = &phba->sli; |
dea3101e | 3693 | |
41415862 | 3694 | /* Kill HBA */ |
ed957684 | 3695 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3696 | "0329 Kill HBA Data: x%x x%x\n", |
3697 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3698 | |
98c9ea5c JS |
3699 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3700 | if (!pmb) | |
41415862 | 3701 | return 1; |
41415862 JW |
3702 | |
3703 | /* Disable the error attention */ | |
2e0fef85 | 3704 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
3705 | status = readl(phba->HCregaddr); |
3706 | status &= ~HC_ERINT_ENA; | |
3707 | writel(status, phba->HCregaddr); | |
3708 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3709 | phba->link_flag |= LS_IGNORE_ERATT; |
3710 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3711 | |
3712 | lpfc_kill_board(phba, pmb); | |
3713 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3714 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3715 | ||
3716 | if (retval != MBX_SUCCESS) { | |
3717 | if (retval != MBX_BUSY) | |
3718 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3719 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3720 | "2752 KILL_BOARD command failed retval %d\n", | |
3721 | retval); | |
2e0fef85 JS |
3722 | spin_lock_irq(&phba->hbalock); |
3723 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3724 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3725 | return 1; |
3726 | } | |
3727 | ||
f4b4c68f JS |
3728 | spin_lock_irq(&phba->hbalock); |
3729 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3730 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3731 | |
41415862 JW |
3732 | mempool_free(pmb, phba->mbox_mem_pool); |
3733 | ||
3734 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3735 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3736 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3737 | * board is now undefined. | |
3738 | */ | |
3739 | ha_copy = readl(phba->HAregaddr); | |
3740 | ||
3741 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { | |
3742 | mdelay(100); | |
3743 | ha_copy = readl(phba->HAregaddr); | |
3744 | } | |
3745 | ||
3746 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3747 | if (ha_copy & HA_ERATT) { |
3748 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3749 | phba->pport->stopped = 1; |
9290831f | 3750 | } |
2e0fef85 | 3751 | spin_lock_irq(&phba->hbalock); |
41415862 | 3752 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3753 | psli->mbox_active = NULL; |
2e0fef85 JS |
3754 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3755 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3756 | |
41415862 | 3757 | lpfc_hba_down_post(phba); |
2e0fef85 | 3758 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3759 | |
2e0fef85 | 3760 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e | 3761 | } |
3762 | ||
e59058c4 | 3763 | /** |
3772a991 | 3764 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3765 | * @phba: Pointer to HBA context object. |
3766 | * | |
3767 | * This function resets the HBA by writing HC_INITFF to the control | |
3768 | * register. After the HBA resets, this function resets all the iocb ring | |
3769 | * indices. This function disables PCI layer parity checking during | |
3770 | * the reset. | |
3771 | * This function returns 0 always. | |
3772 | * The caller is not required to hold any locks. | |
3773 | **/ | |
41415862 | 3774 | int |
2e0fef85 | 3775 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3776 | { |
41415862 | 3777 | struct lpfc_sli *psli; |
dea3101e | 3778 | struct lpfc_sli_ring *pring; |
41415862 | 3779 | uint16_t cfg_value; |
dea3101e | 3780 | int i; |
dea3101e | 3781 | |
41415862 | 3782 | psli = &phba->sli; |
dea3101e | 3783 | |
41415862 JW |
3784 | /* Reset HBA */ |
3785 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3786 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3787 | phba->pport->port_state, psli->sli_flag); |
dea3101e | 3788 | |
3789 | /* perform board reset */ | |
3790 | phba->fc_eventTag = 0; | |
4d9ab994 | 3791 | phba->link_events = 0; |
2e0fef85 JS |
3792 | phba->pport->fc_myDID = 0; |
3793 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3794 | |
41415862 JW |
3795 | /* Turn off parity checking and serr during the physical reset */ |
3796 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3797 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3798 | (cfg_value & | |
3799 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3800 | ||
3772a991 JS |
3801 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3802 | ||
41415862 JW |
3803 | /* Now toggle INITFF bit in the Host Control Register */ |
3804 | writel(HC_INITFF, phba->HCregaddr); | |
3805 | mdelay(1); | |
3806 | readl(phba->HCregaddr); /* flush */ | |
3807 | writel(0, phba->HCregaddr); | |
3808 | readl(phba->HCregaddr); /* flush */ | |
3809 | ||
3810 | /* Restore PCI cmd register */ | |
3811 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e | 3812 | |
3813 | /* Initialize relevant SLI info */ | |
41415862 JW |
3814 | for (i = 0; i < psli->num_rings; i++) { |
3815 | pring = &psli->ring[i]; | |
dea3101e | 3816 | pring->flag = 0; |
3817 | pring->rspidx = 0; | |
3818 | pring->next_cmdidx = 0; | |
3819 | pring->local_getidx = 0; | |
3820 | pring->cmdidx = 0; | |
3821 | pring->missbufcnt = 0; | |
3822 | } | |
dea3101e | 3823 | |
2e0fef85 | 3824 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3825 | return 0; |
3826 | } | |
3827 | ||
e59058c4 | 3828 | /** |
da0436e9 JS |
3829 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3830 | * @phba: Pointer to HBA context object. | |
3831 | * | |
3832 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3833 | * checking during resets the device. The caller is not required to hold | |
3834 | * any locks. | |
3835 | * | |
3836 | * This function returns 0 always. | |
3837 | **/ | |
3838 | int | |
3839 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3840 | { | |
3841 | struct lpfc_sli *psli = &phba->sli; | |
3842 | uint16_t cfg_value; | |
3843 | uint8_t qindx; | |
3844 | ||
3845 | /* Reset HBA */ | |
3846 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3847 | "0295 Reset HBA Data: x%x x%x\n", | |
3848 | phba->pport->port_state, psli->sli_flag); | |
3849 | ||
3850 | /* perform board reset */ | |
3851 | phba->fc_eventTag = 0; | |
4d9ab994 | 3852 | phba->link_events = 0; |
da0436e9 JS |
3853 | phba->pport->fc_myDID = 0; |
3854 | phba->pport->fc_prevDID = 0; | |
3855 | ||
da0436e9 JS |
3856 | spin_lock_irq(&phba->hbalock); |
3857 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3858 | phba->fcf.fcf_flag = 0; | |
3859 | /* Clean up the child queue list for the CQs */ | |
3860 | list_del_init(&phba->sli4_hba.mbx_wq->list); | |
3861 | list_del_init(&phba->sli4_hba.els_wq->list); | |
3862 | list_del_init(&phba->sli4_hba.hdr_rq->list); | |
3863 | list_del_init(&phba->sli4_hba.dat_rq->list); | |
3864 | list_del_init(&phba->sli4_hba.mbx_cq->list); | |
3865 | list_del_init(&phba->sli4_hba.els_cq->list); | |
da0436e9 JS |
3866 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
3867 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | |
3868 | for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++) | |
3869 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); | |
3870 | spin_unlock_irq(&phba->hbalock); | |
3871 | ||
3872 | /* Now physically reset the device */ | |
3873 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3874 | "0389 Performing PCI function reset!\n"); | |
be858b65 JS |
3875 | |
3876 | /* Turn off parity checking and serr during the physical reset */ | |
3877 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3878 | pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value & | |
3879 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3880 | ||
da0436e9 JS |
3881 | /* Perform FCoE PCI function reset */ |
3882 | lpfc_pci_function_reset(phba); | |
3883 | ||
be858b65 JS |
3884 | /* Restore PCI cmd register */ |
3885 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
3886 | ||
da0436e9 JS |
3887 | return 0; |
3888 | } | |
3889 | ||
3890 | /** | |
3891 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3892 | * @phba: Pointer to HBA context object. |
3893 | * | |
3894 | * This function is called in the SLI initialization code path to | |
3895 | * restart the HBA. The caller is not required to hold any lock. | |
3896 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3897 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3898 | * function to free any pending commands. The function enables | |
3899 | * POST only during the first initialization. The function returns zero. | |
3900 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3901 | * command before the return of this function. | |
3902 | **/ | |
da0436e9 JS |
3903 | static int |
3904 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3905 | { |
3906 | MAILBOX_t *mb; | |
3907 | struct lpfc_sli *psli; | |
41415862 JW |
3908 | volatile uint32_t word0; |
3909 | void __iomem *to_slim; | |
0d878419 | 3910 | uint32_t hba_aer_enabled; |
41415862 | 3911 | |
2e0fef85 | 3912 | spin_lock_irq(&phba->hbalock); |
41415862 | 3913 | |
0d878419 JS |
3914 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3915 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3916 | ||
41415862 JW |
3917 | psli = &phba->sli; |
3918 | ||
3919 | /* Restart HBA */ | |
3920 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3921 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3922 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3923 | |
3924 | word0 = 0; | |
3925 | mb = (MAILBOX_t *) &word0; | |
3926 | mb->mbxCommand = MBX_RESTART; | |
3927 | mb->mbxHc = 1; | |
3928 | ||
9290831f JS |
3929 | lpfc_reset_barrier(phba); |
3930 | ||
41415862 JW |
3931 | to_slim = phba->MBslimaddr; |
3932 | writel(*(uint32_t *) mb, to_slim); | |
3933 | readl(to_slim); /* flush */ | |
3934 | ||
3935 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3936 | if (phba->pport->port_state) |
41415862 | 3937 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 3938 | else |
41415862 | 3939 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 3940 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
3941 | writel(*(uint32_t *) mb, to_slim); |
3942 | readl(to_slim); /* flush */ | |
dea3101e | 3943 | |
41415862 | 3944 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
3945 | phba->pport->stopped = 0; |
3946 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 3947 | phba->hba_flag = 0; |
2e0fef85 | 3948 | spin_unlock_irq(&phba->hbalock); |
41415862 | 3949 | |
64ba8818 JS |
3950 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
3951 | psli->stats_start = get_seconds(); | |
3952 | ||
eaf15d5b JS |
3953 | /* Give the INITFF and Post time to settle. */ |
3954 | mdelay(100); | |
41415862 | 3955 | |
0d878419 JS |
3956 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3957 | if (hba_aer_enabled) | |
3958 | pci_disable_pcie_error_reporting(phba->pcidev); | |
3959 | ||
41415862 | 3960 | lpfc_hba_down_post(phba); |
dea3101e | 3961 | |
3962 | return 0; | |
3963 | } | |
3964 | ||
da0436e9 JS |
3965 | /** |
3966 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
3967 | * @phba: Pointer to HBA context object. | |
3968 | * | |
3969 | * This function is called in the SLI initialization code path to restart | |
3970 | * a SLI4 HBA. The caller is not required to hold any lock. | |
3971 | * At the end of the function, it calls lpfc_hba_down_post function to | |
3972 | * free any pending commands. | |
3973 | **/ | |
3974 | static int | |
3975 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
3976 | { | |
3977 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 3978 | uint32_t hba_aer_enabled; |
da0436e9 JS |
3979 | |
3980 | /* Restart HBA */ | |
3981 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3982 | "0296 Restart HBA Data: x%x x%x\n", | |
3983 | phba->pport->port_state, psli->sli_flag); | |
3984 | ||
75baf696 JS |
3985 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3986 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3987 | ||
da0436e9 JS |
3988 | lpfc_sli4_brdreset(phba); |
3989 | ||
3990 | spin_lock_irq(&phba->hbalock); | |
3991 | phba->pport->stopped = 0; | |
3992 | phba->link_state = LPFC_INIT_START; | |
3993 | phba->hba_flag = 0; | |
3994 | spin_unlock_irq(&phba->hbalock); | |
3995 | ||
3996 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
3997 | psli->stats_start = get_seconds(); | |
3998 | ||
75baf696 JS |
3999 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
4000 | if (hba_aer_enabled) | |
4001 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4002 | ||
da0436e9 JS |
4003 | lpfc_hba_down_post(phba); |
4004 | ||
4005 | return 0; | |
4006 | } | |
4007 | ||
4008 | /** | |
4009 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4010 | * @phba: Pointer to HBA context object. | |
4011 | * | |
4012 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4013 | * API jump table function pointer from the lpfc_hba struct. | |
4014 | **/ | |
4015 | int | |
4016 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4017 | { | |
4018 | return phba->lpfc_sli_brdrestart(phba); | |
4019 | } | |
4020 | ||
e59058c4 | 4021 | /** |
3621a710 | 4022 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4023 | * @phba: Pointer to HBA context object. |
4024 | * | |
4025 | * This function is called after a HBA restart to wait for successful | |
4026 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4027 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4028 | * iteration, the function will restart the HBA again. The function returns | |
4029 | * zero if HBA successfully restarted else returns negative error code. | |
4030 | **/ | |
dea3101e | 4031 | static int |
4032 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4033 | { | |
4034 | uint32_t status, i = 0; | |
4035 | ||
4036 | /* Read the HBA Host Status Register */ | |
4037 | status = readl(phba->HSregaddr); | |
4038 | ||
4039 | /* Check status register to see what current state is */ | |
4040 | i = 0; | |
4041 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4042 | ||
dcf2a4e0 JS |
4043 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4044 | * retries, then every 1 sec for 50 retires for a total of | |
4045 | * ~60 seconds before reset the board again and check every | |
4046 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4047 | * board ready is required by the Falcon FIPS zeroization | |
4048 | * complete, and any reset the board in between shall cause | |
4049 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4050 | */ |
dcf2a4e0 | 4051 | if (i++ >= 200) { |
dea3101e | 4052 | /* Adapter failed to init, timeout, status reg |
4053 | <status> */ | |
ed957684 | 4054 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4055 | "0436 Adapter failed to init, " |
09372820 JS |
4056 | "timeout, status reg x%x, " |
4057 | "FW Data: A8 x%x AC x%x\n", status, | |
4058 | readl(phba->MBslimaddr + 0xa8), | |
4059 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4060 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4061 | return -ETIMEDOUT; |
4062 | } | |
4063 | ||
4064 | /* Check to see if any errors occurred during init */ | |
4065 | if (status & HS_FFERM) { | |
4066 | /* ERROR: During chipset initialization */ | |
4067 | /* Adapter failed to init, chipset, status reg | |
4068 | <status> */ | |
ed957684 | 4069 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4070 | "0437 Adapter failed to init, " |
09372820 JS |
4071 | "chipset, status reg x%x, " |
4072 | "FW Data: A8 x%x AC x%x\n", status, | |
4073 | readl(phba->MBslimaddr + 0xa8), | |
4074 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4075 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4076 | return -EIO; |
4077 | } | |
4078 | ||
dcf2a4e0 | 4079 | if (i <= 10) |
dea3101e | 4080 | msleep(10); |
dcf2a4e0 JS |
4081 | else if (i <= 100) |
4082 | msleep(100); | |
4083 | else | |
4084 | msleep(1000); | |
dea3101e | 4085 | |
dcf2a4e0 JS |
4086 | if (i == 150) { |
4087 | /* Do post */ | |
92d7f7b0 | 4088 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4089 | lpfc_sli_brdrestart(phba); |
dea3101e | 4090 | } |
4091 | /* Read the HBA Host Status Register */ | |
4092 | status = readl(phba->HSregaddr); | |
4093 | } | |
4094 | ||
4095 | /* Check to see if any errors occurred during init */ | |
4096 | if (status & HS_FFERM) { | |
4097 | /* ERROR: During chipset initialization */ | |
4098 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4099 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4100 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4101 | "status reg x%x, " |
4102 | "FW Data: A8 x%x AC x%x\n", status, | |
4103 | readl(phba->MBslimaddr + 0xa8), | |
4104 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4105 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4106 | return -EIO; |
4107 | } | |
4108 | ||
4109 | /* Clear all interrupt enable conditions */ | |
4110 | writel(0, phba->HCregaddr); | |
4111 | readl(phba->HCregaddr); /* flush */ | |
4112 | ||
4113 | /* setup host attn register */ | |
4114 | writel(0xffffffff, phba->HAregaddr); | |
4115 | readl(phba->HAregaddr); /* flush */ | |
4116 | return 0; | |
4117 | } | |
4118 | ||
e59058c4 | 4119 | /** |
3621a710 | 4120 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4121 | * |
4122 | * This function calculates and returns the number of HBQs required to be | |
4123 | * configured. | |
4124 | **/ | |
78b2d852 | 4125 | int |
ed957684 JS |
4126 | lpfc_sli_hbq_count(void) |
4127 | { | |
92d7f7b0 | 4128 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4129 | } |
4130 | ||
e59058c4 | 4131 | /** |
3621a710 | 4132 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4133 | * |
4134 | * This function adds the number of hbq entries in every HBQ to get | |
4135 | * the total number of hbq entries required for the HBA and returns | |
4136 | * the total count. | |
4137 | **/ | |
ed957684 JS |
4138 | static int |
4139 | lpfc_sli_hbq_entry_count(void) | |
4140 | { | |
4141 | int hbq_count = lpfc_sli_hbq_count(); | |
4142 | int count = 0; | |
4143 | int i; | |
4144 | ||
4145 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4146 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4147 | return count; |
4148 | } | |
4149 | ||
e59058c4 | 4150 | /** |
3621a710 | 4151 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4152 | * |
4153 | * This function calculates amount of memory required for all hbq entries | |
4154 | * to be configured and returns the total memory required. | |
4155 | **/ | |
dea3101e | 4156 | int |
ed957684 JS |
4157 | lpfc_sli_hbq_size(void) |
4158 | { | |
4159 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4160 | } | |
4161 | ||
e59058c4 | 4162 | /** |
3621a710 | 4163 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4164 | * @phba: Pointer to HBA context object. |
4165 | * | |
4166 | * This function is called during the SLI initialization to configure | |
4167 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4168 | * required to hold any locks. This function will return zero if successful | |
4169 | * else it will return negative error code. | |
4170 | **/ | |
ed957684 JS |
4171 | static int |
4172 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4173 | { | |
4174 | int hbq_count = lpfc_sli_hbq_count(); | |
4175 | LPFC_MBOXQ_t *pmb; | |
4176 | MAILBOX_t *pmbox; | |
4177 | uint32_t hbqno; | |
4178 | uint32_t hbq_entry_index; | |
ed957684 | 4179 | |
92d7f7b0 JS |
4180 | /* Get a Mailbox buffer to setup mailbox |
4181 | * commands for HBA initialization | |
4182 | */ | |
ed957684 JS |
4183 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4184 | ||
4185 | if (!pmb) | |
4186 | return -ENOMEM; | |
4187 | ||
04c68496 | 4188 | pmbox = &pmb->u.mb; |
ed957684 JS |
4189 | |
4190 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4191 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4192 | phba->hbq_in_use = 1; |
ed957684 JS |
4193 | |
4194 | hbq_entry_index = 0; | |
4195 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4196 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4197 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4198 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4199 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4200 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4201 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4202 | hbq_entry_index, pmb); | |
ed957684 JS |
4203 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4204 | ||
4205 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4206 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4207 | mbxStatus <status>, ring <num> */ | |
4208 | ||
4209 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4210 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4211 | "1805 Adapter failed to init. " |
ed957684 | 4212 | "Data: x%x x%x x%x\n", |
e8b62011 | 4213 | pmbox->mbxCommand, |
ed957684 JS |
4214 | pmbox->mbxStatus, hbqno); |
4215 | ||
4216 | phba->link_state = LPFC_HBA_ERROR; | |
4217 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4218 | return -ENXIO; |
ed957684 JS |
4219 | } |
4220 | } | |
4221 | phba->hbq_count = hbq_count; | |
4222 | ||
ed957684 JS |
4223 | mempool_free(pmb, phba->mbox_mem_pool); |
4224 | ||
92d7f7b0 | 4225 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4226 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4227 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4228 | return 0; |
4229 | } | |
4230 | ||
4f774513 JS |
4231 | /** |
4232 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4233 | * @phba: Pointer to HBA context object. | |
4234 | * | |
4235 | * This function is called during the SLI initialization to configure | |
4236 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4237 | * required to hold any locks. This function will return zero if successful | |
4238 | * else it will return negative error code. | |
4239 | **/ | |
4240 | static int | |
4241 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4242 | { | |
4243 | phba->hbq_in_use = 1; | |
4244 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4245 | phba->hbq_count = 1; | |
4246 | /* Initially populate or replenish the HBQs */ | |
4247 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4248 | return 0; | |
4249 | } | |
4250 | ||
e59058c4 | 4251 | /** |
3621a710 | 4252 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4253 | * @phba: Pointer to HBA context object. |
4254 | * @sli_mode: sli mode - 2/3 | |
4255 | * | |
4256 | * This function is called by the sli intialization code path | |
4257 | * to issue config_port mailbox command. This function restarts the | |
4258 | * HBA firmware and issues a config_port mailbox command to configure | |
4259 | * the SLI interface in the sli mode specified by sli_mode | |
4260 | * variable. The caller is not required to hold any locks. | |
4261 | * The function returns 0 if successful, else returns negative error | |
4262 | * code. | |
4263 | **/ | |
9399627f JS |
4264 | int |
4265 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e | 4266 | { |
4267 | LPFC_MBOXQ_t *pmb; | |
4268 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4269 | ||
4270 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4271 | if (!pmb) { | |
2e0fef85 | 4272 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 4273 | return -ENOMEM; |
4274 | } | |
4275 | ||
ed957684 | 4276 | phba->sli_rev = sli_mode; |
dea3101e | 4277 | while (resetcount < 2 && !done) { |
2e0fef85 | 4278 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4279 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4280 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4281 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4282 | lpfc_sli_brdrestart(phba); |
dea3101e | 4283 | rc = lpfc_sli_chipset_init(phba); |
4284 | if (rc) | |
4285 | break; | |
4286 | ||
2e0fef85 | 4287 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4288 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4289 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4290 | resetcount++; |
4291 | ||
ed957684 JS |
4292 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4293 | * value of 0 means the call was successful. Any other | |
4294 | * nonzero value is a failure, but if ERESTART is returned, | |
4295 | * the driver may reset the HBA and try again. | |
4296 | */ | |
dea3101e | 4297 | rc = lpfc_config_port_prep(phba); |
4298 | if (rc == -ERESTART) { | |
ed957684 | 4299 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4300 | continue; |
34b02dcd | 4301 | } else if (rc) |
dea3101e | 4302 | break; |
2e0fef85 | 4303 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 4304 | lpfc_config_port(phba, pmb); |
4305 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4306 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4307 | LPFC_SLI3_HBQ_ENABLED | | |
4308 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4309 | LPFC_SLI3_BG_ENABLED | |
4310 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4311 | if (rc != MBX_SUCCESS) { |
dea3101e | 4312 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4313 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4314 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4315 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4316 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4317 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4318 | spin_unlock_irq(&phba->hbalock); |
4319 | rc = -ENXIO; | |
04c68496 JS |
4320 | } else { |
4321 | /* Allow asynchronous mailbox command to go through */ | |
4322 | spin_lock_irq(&phba->hbalock); | |
4323 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4324 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4325 | done = 1; |
04c68496 | 4326 | } |
dea3101e | 4327 | } |
ed957684 JS |
4328 | if (!done) { |
4329 | rc = -EINVAL; | |
4330 | goto do_prep_failed; | |
4331 | } | |
04c68496 JS |
4332 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4333 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4334 | rc = -ENXIO; |
4335 | goto do_prep_failed; | |
4336 | } | |
04c68496 | 4337 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4338 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4339 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4340 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4341 | phba->max_vpi : phba->max_vports; | |
4342 | ||
34b02dcd JS |
4343 | } else |
4344 | phba->max_vpi = 0; | |
bc73905a JS |
4345 | phba->fips_level = 0; |
4346 | phba->fips_spec_rev = 0; | |
4347 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4348 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4349 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4350 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4351 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4352 | "2850 Security Crypto Active. FIPS x%d " | |
4353 | "(Spec Rev: x%d)", | |
4354 | phba->fips_level, phba->fips_spec_rev); | |
4355 | } | |
4356 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4357 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4358 | "2856 Config Port Security Crypto " | |
4359 | "Error: x%x ", | |
4360 | pmb->u.mb.un.varCfgPort.sec_err); | |
4361 | } | |
04c68496 | 4362 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4363 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4364 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4365 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4366 | |
4367 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4368 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4369 | |
4370 | if (phba->cfg_enable_bg) { | |
04c68496 | 4371 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4372 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4373 | else | |
4374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4375 | "0443 Adapter did not grant " | |
4376 | "BlockGuard\n"); | |
4377 | } | |
34b02dcd | 4378 | } else { |
8f34f4ce | 4379 | phba->hbq_get = NULL; |
34b02dcd | 4380 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4381 | phba->max_vpi = 0; |
ed957684 | 4382 | } |
92d7f7b0 | 4383 | do_prep_failed: |
ed957684 JS |
4384 | mempool_free(pmb, phba->mbox_mem_pool); |
4385 | return rc; | |
4386 | } | |
4387 | ||
e59058c4 JS |
4388 | |
4389 | /** | |
3621a710 | 4390 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4391 | * @phba: Pointer to HBA context object. |
4392 | * | |
4393 | * This function is the main SLI intialization function. This function | |
4394 | * is called by the HBA intialization code, HBA reset code and HBA | |
4395 | * error attention handler code. Caller is not required to hold any | |
4396 | * locks. This function issues config_port mailbox command to configure | |
4397 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4398 | * calls the config_port_post function to issue init_link mailbox | |
4399 | * command and to start the discovery. The function will return zero | |
4400 | * if successful, else it will return negative error code. | |
4401 | **/ | |
ed957684 JS |
4402 | int |
4403 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4404 | { | |
4405 | uint32_t rc; | |
92d7f7b0 | 4406 | int mode = 3; |
ed957684 JS |
4407 | |
4408 | switch (lpfc_sli_mode) { | |
4409 | case 2: | |
78b2d852 | 4410 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4412 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4413 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4414 | lpfc_sli_mode); |
92d7f7b0 JS |
4415 | break; |
4416 | } | |
ed957684 JS |
4417 | mode = 2; |
4418 | break; | |
4419 | case 0: | |
4420 | case 3: | |
4421 | break; | |
4422 | default: | |
92d7f7b0 | 4423 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4424 | "1819 Unrecognized lpfc_sli_mode " |
4425 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4426 | |
4427 | break; | |
4428 | } | |
4429 | ||
9399627f JS |
4430 | rc = lpfc_sli_config_port(phba, mode); |
4431 | ||
ed957684 | 4432 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4433 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4434 | "1820 Unable to select SLI-3. " |
4435 | "Not supported by adapter.\n"); | |
ed957684 | 4436 | if (rc && mode != 2) |
9399627f | 4437 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4438 | if (rc) |
dea3101e | 4439 | goto lpfc_sli_hba_setup_error; |
4440 | ||
0d878419 JS |
4441 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4442 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4443 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4444 | if (!rc) { | |
4445 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4446 | "2709 This device supports " | |
4447 | "Advanced Error Reporting (AER)\n"); | |
4448 | spin_lock_irq(&phba->hbalock); | |
4449 | phba->hba_flag |= HBA_AER_ENABLED; | |
4450 | spin_unlock_irq(&phba->hbalock); | |
4451 | } else { | |
4452 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4453 | "2708 This device does not support " | |
4454 | "Advanced Error Reporting (AER)\n"); | |
4455 | phba->cfg_aer_support = 0; | |
4456 | } | |
4457 | } | |
4458 | ||
ed957684 JS |
4459 | if (phba->sli_rev == 3) { |
4460 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4461 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4462 | } else { |
4463 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4464 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4465 | phba->sli3_options = 0; |
ed957684 JS |
4466 | } |
4467 | ||
4468 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4469 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4470 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4471 | rc = lpfc_sli_ring_map(phba); |
dea3101e | 4472 | |
4473 | if (rc) | |
4474 | goto lpfc_sli_hba_setup_error; | |
4475 | ||
9399627f | 4476 | /* Init HBQs */ |
ed957684 JS |
4477 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4478 | rc = lpfc_sli_hbq_setup(phba); | |
4479 | if (rc) | |
4480 | goto lpfc_sli_hba_setup_error; | |
4481 | } | |
04c68496 | 4482 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4483 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4484 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4485 | |
4486 | rc = lpfc_config_port_post(phba); | |
4487 | if (rc) | |
4488 | goto lpfc_sli_hba_setup_error; | |
4489 | ||
ed957684 JS |
4490 | return rc; |
4491 | ||
92d7f7b0 | 4492 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4493 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4495 | "0445 Firmware initialization failed\n"); |
dea3101e | 4496 | return rc; |
4497 | } | |
4498 | ||
e59058c4 | 4499 | /** |
da0436e9 JS |
4500 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4501 | * @phba: Pointer to HBA context object. | |
4502 | * @mboxq: mailbox pointer. | |
4503 | * This function issue a dump mailbox command to read config region | |
4504 | * 23 and parse the records in the region and populate driver | |
4505 | * data structure. | |
e59058c4 | 4506 | **/ |
da0436e9 JS |
4507 | static int |
4508 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, | |
4509 | LPFC_MBOXQ_t *mboxq) | |
dea3101e | 4510 | { |
da0436e9 JS |
4511 | struct lpfc_dmabuf *mp; |
4512 | struct lpfc_mqe *mqe; | |
4513 | uint32_t data_length; | |
4514 | int rc; | |
dea3101e | 4515 | |
da0436e9 JS |
4516 | /* Program the default value of vlan_id and fc_map */ |
4517 | phba->valid_vlan = 0; | |
4518 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4519 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4520 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4521 | |
da0436e9 JS |
4522 | mqe = &mboxq->u.mqe; |
4523 | if (lpfc_dump_fcoe_param(phba, mboxq)) | |
4524 | return -ENOMEM; | |
4525 | ||
4526 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4527 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4528 | ||
4529 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4530 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4531 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4532 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4533 | "CQ: x%x x%x x%x x%x\n", | |
4534 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4535 | bf_get(lpfc_mqe_command, mqe), | |
4536 | bf_get(lpfc_mqe_status, mqe), | |
4537 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4538 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4539 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4540 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4541 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4542 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4543 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4544 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4545 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4546 | mboxq->mcqe.word0, | |
4547 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4548 | mboxq->mcqe.trailer); | |
4549 | ||
4550 | if (rc) { | |
4551 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4552 | kfree(mp); | |
4553 | return -EIO; | |
4554 | } | |
4555 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4556 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4557 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4558 | kfree(mp); | |
da0436e9 | 4559 | return -EIO; |
d11e31dd | 4560 | } |
dea3101e | 4561 | |
da0436e9 JS |
4562 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4563 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4564 | kfree(mp); | |
4565 | return 0; | |
4566 | } | |
e59058c4 JS |
4567 | |
4568 | /** | |
da0436e9 JS |
4569 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4570 | * @phba: pointer to lpfc hba data structure. | |
4571 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4572 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4573 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4574 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4575 | * |
da0436e9 JS |
4576 | * This routine executes a READ_REV SLI4 mailbox command. In |
4577 | * addition, this routine gets the port vpd data. | |
4578 | * | |
4579 | * Return codes | |
af901ca1 | 4580 | * 0 - successful |
d439d286 | 4581 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4582 | **/ |
da0436e9 JS |
4583 | static int |
4584 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4585 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4586 | { |
da0436e9 JS |
4587 | int rc = 0; |
4588 | uint32_t dma_size; | |
4589 | struct lpfc_dmabuf *dmabuf; | |
4590 | struct lpfc_mqe *mqe; | |
dea3101e | 4591 | |
da0436e9 JS |
4592 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4593 | if (!dmabuf) | |
4594 | return -ENOMEM; | |
4595 | ||
4596 | /* | |
4597 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4598 | * mailbox command. | |
a257bf90 | 4599 | */ |
da0436e9 JS |
4600 | dma_size = *vpd_size; |
4601 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4602 | dma_size, | |
4603 | &dmabuf->phys, | |
4604 | GFP_KERNEL); | |
4605 | if (!dmabuf->virt) { | |
4606 | kfree(dmabuf); | |
4607 | return -ENOMEM; | |
a257bf90 | 4608 | } |
da0436e9 | 4609 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4610 | |
da0436e9 JS |
4611 | /* |
4612 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4613 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4614 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4615 | */ |
da0436e9 JS |
4616 | lpfc_read_rev(phba, mboxq); |
4617 | mqe = &mboxq->u.mqe; | |
4618 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4619 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4620 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4621 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4622 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4623 | ||
4624 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4625 | if (rc) { | |
4626 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4627 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4628 | kfree(dmabuf); |
da0436e9 JS |
4629 | return -EIO; |
4630 | } | |
1dcb58e5 | 4631 | |
da0436e9 JS |
4632 | /* |
4633 | * The available vpd length cannot be bigger than the | |
4634 | * DMA buffer passed to the port. Catch the less than | |
4635 | * case and update the caller's size. | |
4636 | */ | |
4637 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4638 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4639 | |
d7c47992 JS |
4640 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4641 | ||
da0436e9 JS |
4642 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4643 | dmabuf->virt, dmabuf->phys); | |
4644 | kfree(dmabuf); | |
4645 | return 0; | |
dea3101e | 4646 | } |
4647 | ||
e59058c4 | 4648 | /** |
da0436e9 JS |
4649 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4650 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4651 | * |
da0436e9 JS |
4652 | * This routine is called to explicitly arm the SLI4 device's completion and |
4653 | * event queues | |
4654 | **/ | |
4655 | static void | |
4656 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4657 | { | |
4658 | uint8_t fcp_eqidx; | |
4659 | ||
4660 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4661 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
da0436e9 JS |
4662 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) |
4663 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], | |
4664 | LPFC_QUEUE_REARM); | |
4665 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); | |
4666 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | |
4667 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | |
4668 | LPFC_QUEUE_REARM); | |
4669 | } | |
4670 | ||
4671 | /** | |
4672 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
4673 | * @phba: Pointer to HBA context object. | |
4674 | * | |
4675 | * This function is the main SLI4 device intialization PCI function. This | |
4676 | * function is called by the HBA intialization code, HBA reset code and | |
4677 | * HBA error attention handler code. Caller is not required to hold any | |
4678 | * locks. | |
4679 | **/ | |
4680 | int | |
4681 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
4682 | { | |
4683 | int rc; | |
4684 | LPFC_MBOXQ_t *mboxq; | |
4685 | struct lpfc_mqe *mqe; | |
4686 | uint8_t *vpd; | |
4687 | uint32_t vpd_size; | |
4688 | uint32_t ftr_rsp = 0; | |
4689 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
4690 | struct lpfc_vport *vport = phba->pport; | |
4691 | struct lpfc_dmabuf *mp; | |
4692 | ||
4693 | /* Perform a PCI function reset to start from clean */ | |
4694 | rc = lpfc_pci_function_reset(phba); | |
4695 | if (unlikely(rc)) | |
4696 | return -ENODEV; | |
4697 | ||
4698 | /* Check the HBA Host Status Register for readyness */ | |
4699 | rc = lpfc_sli4_post_status_check(phba); | |
4700 | if (unlikely(rc)) | |
4701 | return -ENODEV; | |
4702 | else { | |
4703 | spin_lock_irq(&phba->hbalock); | |
4704 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
4705 | spin_unlock_irq(&phba->hbalock); | |
4706 | } | |
4707 | ||
4708 | /* | |
4709 | * Allocate a single mailbox container for initializing the | |
4710 | * port. | |
4711 | */ | |
4712 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4713 | if (!mboxq) | |
4714 | return -ENOMEM; | |
4715 | ||
4716 | /* | |
4717 | * Continue initialization with default values even if driver failed | |
4718 | * to read FCoE param config regions | |
4719 | */ | |
4720 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) | |
4721 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
e4e74273 | 4722 | "2570 Failed to read FCoE parameters\n"); |
da0436e9 JS |
4723 | |
4724 | /* Issue READ_REV to collect vpd and FW information. */ | |
49198b37 | 4725 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
4726 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
4727 | if (!vpd) { | |
4728 | rc = -ENOMEM; | |
4729 | goto out_free_mbox; | |
4730 | } | |
4731 | ||
4732 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
4733 | if (unlikely(rc)) { |
4734 | kfree(vpd); | |
4735 | goto out_free_mbox; | |
4736 | } | |
da0436e9 | 4737 | mqe = &mboxq->u.mqe; |
f1126688 JS |
4738 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
4739 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
4740 | phba->hba_flag |= HBA_FCOE_MODE; |
4741 | else | |
4742 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
4743 | |
4744 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
4745 | LPFC_DCBX_CEE_MODE) | |
4746 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
4747 | else | |
4748 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
4749 | ||
f1126688 | 4750 | if (phba->sli_rev != LPFC_SLI_REV4 || |
76a95d75 | 4751 | !(phba->hba_flag & HBA_FCOE_MODE)) { |
da0436e9 JS |
4752 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4753 | "0376 READ_REV Error. SLI Level %d " | |
4754 | "FCoE enabled %d\n", | |
76a95d75 | 4755 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 4756 | rc = -EIO; |
76a95d75 JS |
4757 | kfree(vpd); |
4758 | goto out_free_mbox; | |
da0436e9 | 4759 | } |
da0436e9 JS |
4760 | /* |
4761 | * Evaluate the read rev and vpd data. Populate the driver | |
4762 | * state with the results. If this routine fails, the failure | |
4763 | * is not fatal as the driver will use generic values. | |
4764 | */ | |
4765 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
4766 | if (unlikely(!rc)) { | |
4767 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4768 | "0377 Error %d parsing vpd. " | |
4769 | "Using defaults.\n", rc); | |
4770 | rc = 0; | |
4771 | } | |
76a95d75 | 4772 | kfree(vpd); |
da0436e9 | 4773 | |
f1126688 JS |
4774 | /* Save information as VPD data */ |
4775 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
4776 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
4777 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
4778 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
4779 | &mqe->un.read_rev); | |
4780 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
4781 | &mqe->un.read_rev); | |
4782 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
4783 | &mqe->un.read_rev); | |
4784 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
4785 | &mqe->un.read_rev); | |
4786 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
4787 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
4788 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
4789 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
4790 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
4791 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
4792 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4793 | "(%d):0380 READ_REV Status x%x " | |
4794 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
4795 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4796 | bf_get(lpfc_mqe_status, mqe), | |
4797 | phba->vpd.rev.opFwName, | |
4798 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
4799 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
4800 | |
4801 | /* | |
4802 | * Discover the port's supported feature set and match it against the | |
4803 | * hosts requests. | |
4804 | */ | |
4805 | lpfc_request_features(phba, mboxq); | |
4806 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4807 | if (unlikely(rc)) { | |
4808 | rc = -EIO; | |
76a95d75 | 4809 | goto out_free_mbox; |
da0436e9 JS |
4810 | } |
4811 | ||
4812 | /* | |
4813 | * The port must support FCP initiator mode as this is the | |
4814 | * only mode running in the host. | |
4815 | */ | |
4816 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
4817 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4818 | "0378 No support for fcpi mode.\n"); | |
4819 | ftr_rsp++; | |
4820 | } | |
4821 | ||
4822 | /* | |
4823 | * If the port cannot support the host's requested features | |
4824 | * then turn off the global config parameters to disable the | |
4825 | * feature in the driver. This is not a fatal error. | |
4826 | */ | |
4827 | if ((phba->cfg_enable_bg) && | |
4828 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4829 | ftr_rsp++; | |
4830 | ||
4831 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
4832 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4833 | ftr_rsp++; | |
4834 | ||
4835 | if (ftr_rsp) { | |
4836 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4837 | "0379 Feature Mismatch Data: x%08x %08x " | |
4838 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
4839 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
4840 | phba->cfg_enable_npiv, phba->max_vpi); | |
4841 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4842 | phba->cfg_enable_bg = 0; | |
4843 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4844 | phba->cfg_enable_npiv = 0; | |
4845 | } | |
4846 | ||
4847 | /* These SLI3 features are assumed in SLI4 */ | |
4848 | spin_lock_irq(&phba->hbalock); | |
4849 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
4850 | spin_unlock_irq(&phba->hbalock); | |
4851 | ||
4852 | /* Read the port's service parameters. */ | |
9f1177a3 JS |
4853 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
4854 | if (rc) { | |
4855 | phba->link_state = LPFC_HBA_ERROR; | |
4856 | rc = -ENOMEM; | |
76a95d75 | 4857 | goto out_free_mbox; |
9f1177a3 JS |
4858 | } |
4859 | ||
da0436e9 JS |
4860 | mboxq->vport = vport; |
4861 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4862 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4863 | if (rc == MBX_SUCCESS) { | |
4864 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
4865 | rc = 0; | |
4866 | } | |
4867 | ||
4868 | /* | |
4869 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
4870 | * it to the mbuf pool. | |
4871 | */ | |
4872 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4873 | kfree(mp); | |
4874 | mboxq->context1 = NULL; | |
4875 | if (unlikely(rc)) { | |
4876 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4877 | "0382 READ_SPARAM command failed " | |
4878 | "status %d, mbxStatus x%x\n", | |
4879 | rc, bf_get(lpfc_mqe_status, mqe)); | |
4880 | phba->link_state = LPFC_HBA_ERROR; | |
4881 | rc = -EIO; | |
76a95d75 | 4882 | goto out_free_mbox; |
da0436e9 JS |
4883 | } |
4884 | ||
4885 | if (phba->cfg_soft_wwnn) | |
4886 | u64_to_wwn(phba->cfg_soft_wwnn, | |
4887 | vport->fc_sparam.nodeName.u.wwn); | |
4888 | if (phba->cfg_soft_wwpn) | |
4889 | u64_to_wwn(phba->cfg_soft_wwpn, | |
4890 | vport->fc_sparam.portName.u.wwn); | |
4891 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
4892 | sizeof(struct lpfc_name)); | |
4893 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
4894 | sizeof(struct lpfc_name)); | |
4895 | ||
4896 | /* Update the fc_host data structures with new wwn. */ | |
4897 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
4898 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
4899 | ||
4900 | /* Register SGL pool to the device using non-embedded mailbox command */ | |
4901 | rc = lpfc_sli4_post_sgl_list(phba); | |
4902 | if (unlikely(rc)) { | |
4903 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4904 | "0582 Error %d during sgl post operation\n", |
4905 | rc); | |
da0436e9 | 4906 | rc = -ENODEV; |
76a95d75 | 4907 | goto out_free_mbox; |
da0436e9 JS |
4908 | } |
4909 | ||
4910 | /* Register SCSI SGL pool to the device */ | |
4911 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
4912 | if (unlikely(rc)) { | |
4913 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4914 | "0383 Error %d during scsi sgl post " |
4915 | "operation\n", rc); | |
da0436e9 JS |
4916 | /* Some Scsi buffers were moved to the abort scsi list */ |
4917 | /* A pci function reset will repost them */ | |
4918 | rc = -ENODEV; | |
76a95d75 | 4919 | goto out_free_mbox; |
da0436e9 JS |
4920 | } |
4921 | ||
4922 | /* Post the rpi header region to the device. */ | |
4923 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
4924 | if (unlikely(rc)) { | |
4925 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4926 | "0393 Error %d during rpi post operation\n", | |
4927 | rc); | |
4928 | rc = -ENODEV; | |
76a95d75 | 4929 | goto out_free_mbox; |
da0436e9 | 4930 | } |
da0436e9 JS |
4931 | |
4932 | /* Set up all the queues to the device */ | |
4933 | rc = lpfc_sli4_queue_setup(phba); | |
4934 | if (unlikely(rc)) { | |
4935 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4936 | "0381 Error %d during queue setup.\n ", rc); | |
4937 | goto out_stop_timers; | |
4938 | } | |
4939 | ||
4940 | /* Arm the CQs and then EQs on device */ | |
4941 | lpfc_sli4_arm_cqeq_intr(phba); | |
4942 | ||
4943 | /* Indicate device interrupt mode */ | |
4944 | phba->sli4_hba.intr_enable = 1; | |
4945 | ||
4946 | /* Allow asynchronous mailbox command to go through */ | |
4947 | spin_lock_irq(&phba->hbalock); | |
4948 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4949 | spin_unlock_irq(&phba->hbalock); | |
4950 | ||
4951 | /* Post receive buffers to the device */ | |
4952 | lpfc_sli4_rb_setup(phba); | |
4953 | ||
fc2b989b JS |
4954 | /* Reset HBA FCF states after HBA reset */ |
4955 | phba->fcf.fcf_flag = 0; | |
4956 | phba->fcf.current_rec.flag = 0; | |
4957 | ||
da0436e9 | 4958 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
4959 | mod_timer(&vport->els_tmofunc, |
4960 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
4961 | |
4962 | /* Start heart beat timer */ | |
4963 | mod_timer(&phba->hb_tmofunc, | |
4964 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
4965 | phba->hb_outstanding = 0; | |
4966 | phba->last_completion_time = jiffies; | |
4967 | ||
4968 | /* Start error attention (ERATT) polling timer */ | |
4969 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
4970 | ||
75baf696 JS |
4971 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4972 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4973 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4974 | if (!rc) { | |
4975 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4976 | "2829 This device supports " | |
4977 | "Advanced Error Reporting (AER)\n"); | |
4978 | spin_lock_irq(&phba->hbalock); | |
4979 | phba->hba_flag |= HBA_AER_ENABLED; | |
4980 | spin_unlock_irq(&phba->hbalock); | |
4981 | } else { | |
4982 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4983 | "2830 This device does not support " | |
4984 | "Advanced Error Reporting (AER)\n"); | |
4985 | phba->cfg_aer_support = 0; | |
4986 | } | |
4987 | } | |
4988 | ||
76a95d75 JS |
4989 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
4990 | /* | |
4991 | * The FC Port needs to register FCFI (index 0) | |
4992 | */ | |
4993 | lpfc_reg_fcfi(phba, mboxq); | |
4994 | mboxq->vport = phba->pport; | |
4995 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4996 | if (rc == MBX_SUCCESS) | |
4997 | rc = 0; | |
4998 | else | |
4999 | goto out_unset_queue; | |
5000 | } | |
da0436e9 JS |
5001 | /* |
5002 | * The port is ready, set the host's link state to LINK_DOWN | |
5003 | * in preparation for link interrupts. | |
5004 | */ | |
da0436e9 JS |
5005 | spin_lock_irq(&phba->hbalock); |
5006 | phba->link_state = LPFC_LINK_DOWN; | |
5007 | spin_unlock_irq(&phba->hbalock); | |
76a95d75 JS |
5008 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
5009 | out_unset_queue: | |
da0436e9 JS |
5010 | /* Unset all the queues set up in this routine when error out */ |
5011 | if (rc) | |
5012 | lpfc_sli4_queue_unset(phba); | |
da0436e9 JS |
5013 | out_stop_timers: |
5014 | if (rc) | |
5015 | lpfc_stop_hba_timers(phba); | |
da0436e9 JS |
5016 | out_free_mbox: |
5017 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5018 | return rc; | |
5019 | } | |
5020 | ||
5021 | /** | |
5022 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
5023 | * @ptr: context object - pointer to hba structure. | |
5024 | * | |
5025 | * This is the callback function for mailbox timer. The mailbox | |
5026 | * timer is armed when a new mailbox command is issued and the timer | |
5027 | * is deleted when the mailbox complete. The function is called by | |
5028 | * the kernel timer code when a mailbox does not complete within | |
5029 | * expected time. This function wakes up the worker thread to | |
5030 | * process the mailbox timeout and returns. All the processing is | |
5031 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
5032 | **/ | |
5033 | void | |
5034 | lpfc_mbox_timeout(unsigned long ptr) | |
5035 | { | |
5036 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
5037 | unsigned long iflag; | |
5038 | uint32_t tmo_posted; | |
5039 | ||
5040 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
5041 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
5042 | if (!tmo_posted) | |
5043 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
5044 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
5045 | ||
5046 | if (!tmo_posted) | |
5047 | lpfc_worker_wake_up(phba); | |
5048 | return; | |
5049 | } | |
5050 | ||
5051 | ||
5052 | /** | |
5053 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
5054 | * @phba: Pointer to HBA context object. | |
5055 | * | |
5056 | * This function is called from worker thread when a mailbox command times out. | |
5057 | * The caller is not required to hold any locks. This function will reset the | |
5058 | * HBA and recover all the pending commands. | |
5059 | **/ | |
5060 | void | |
5061 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
5062 | { | |
5063 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 5064 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
5065 | struct lpfc_sli *psli = &phba->sli; |
5066 | struct lpfc_sli_ring *pring; | |
5067 | ||
5068 | /* Check the pmbox pointer first. There is a race condition | |
5069 | * between the mbox timeout handler getting executed in the | |
5070 | * worklist and the mailbox actually completing. When this | |
5071 | * race condition occurs, the mbox_active will be NULL. | |
5072 | */ | |
5073 | spin_lock_irq(&phba->hbalock); | |
5074 | if (pmbox == NULL) { | |
5075 | lpfc_printf_log(phba, KERN_WARNING, | |
5076 | LOG_MBOX | LOG_SLI, | |
5077 | "0353 Active Mailbox cleared - mailbox timeout " | |
5078 | "exiting\n"); | |
5079 | spin_unlock_irq(&phba->hbalock); | |
5080 | return; | |
5081 | } | |
5082 | ||
5083 | /* Mbox cmd <mbxCommand> timeout */ | |
5084 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5085 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
5086 | mb->mbxCommand, | |
5087 | phba->pport->port_state, | |
5088 | phba->sli.sli_flag, | |
5089 | phba->sli.mbox_active); | |
5090 | spin_unlock_irq(&phba->hbalock); | |
5091 | ||
5092 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
5093 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
5094 | * it to fail all oustanding SCSI IO. | |
5095 | */ | |
5096 | spin_lock_irq(&phba->pport->work_port_lock); | |
5097 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
5098 | spin_unlock_irq(&phba->pport->work_port_lock); | |
5099 | spin_lock_irq(&phba->hbalock); | |
5100 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 5101 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
5102 | spin_unlock_irq(&phba->hbalock); |
5103 | ||
5104 | pring = &psli->ring[psli->fcp_ring]; | |
5105 | lpfc_sli_abort_iocb_ring(phba, pring); | |
5106 | ||
5107 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5108 | "0345 Resetting board due to mailbox timeout\n"); | |
5109 | ||
5110 | /* Reset the HBA device */ | |
5111 | lpfc_reset_hba(phba); | |
5112 | } | |
5113 | ||
5114 | /** | |
5115 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
5116 | * @phba: Pointer to HBA context object. | |
5117 | * @pmbox: Pointer to mailbox object. | |
5118 | * @flag: Flag indicating how the mailbox need to be processed. | |
5119 | * | |
5120 | * This function is called by discovery code and HBA management code | |
5121 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
5122 | * function gets the hbalock to protect the data structures. | |
5123 | * The mailbox command can be submitted in polling mode, in which case | |
5124 | * this function will wait in a polling loop for the completion of the | |
5125 | * mailbox. | |
5126 | * If the mailbox is submitted in no_wait mode (not polling) the | |
5127 | * function will submit the command and returns immediately without waiting | |
5128 | * for the mailbox completion. The no_wait is supported only when HBA | |
5129 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
5130 | * The SLI interface allows only one mailbox pending at a time. If the | |
5131 | * mailbox is issued in polling mode and there is already a mailbox | |
5132 | * pending, then the function will return an error. If the mailbox is issued | |
5133 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
5134 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
5135 | * The sli layer owns the mailbox object until the completion of mailbox | |
5136 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
5137 | * return codes the caller owns the mailbox command after the return of | |
5138 | * the function. | |
e59058c4 | 5139 | **/ |
3772a991 JS |
5140 | static int |
5141 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
5142 | uint32_t flag) | |
dea3101e | 5143 | { |
dea3101e | 5144 | MAILBOX_t *mb; |
2e0fef85 | 5145 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 5146 | uint32_t status, evtctr; |
5147 | uint32_t ha_copy; | |
5148 | int i; | |
09372820 | 5149 | unsigned long timeout; |
dea3101e | 5150 | unsigned long drvr_flag = 0; |
34b02dcd | 5151 | uint32_t word0, ldata; |
dea3101e | 5152 | void __iomem *to_slim; |
58da1ffb JS |
5153 | int processing_queue = 0; |
5154 | ||
5155 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5156 | if (!pmbox) { | |
8568a4d2 | 5157 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 5158 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
5159 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
5160 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5161 | return MBX_SUCCESS; | |
5162 | } | |
58da1ffb | 5163 | processing_queue = 1; |
58da1ffb JS |
5164 | pmbox = lpfc_mbox_get(phba); |
5165 | if (!pmbox) { | |
5166 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5167 | return MBX_SUCCESS; | |
5168 | } | |
5169 | } | |
dea3101e | 5170 | |
ed957684 | 5171 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 5172 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 5173 | if(!pmbox->vport) { |
58da1ffb | 5174 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 5175 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 5176 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 5177 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 5178 | pmbox->u.mb.mbxCommand); |
ed957684 | 5179 | dump_stack(); |
58da1ffb | 5180 | goto out_not_finished; |
ed957684 JS |
5181 | } |
5182 | } | |
5183 | ||
8d63f375 | 5184 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
5185 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
5186 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5187 | goto out_not_finished; | |
5188 | } | |
8d63f375 | 5189 | |
a257bf90 JS |
5190 | /* If HBA has a deferred error attention, fail the iocb. */ |
5191 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
5192 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5193 | goto out_not_finished; | |
5194 | } | |
5195 | ||
dea3101e | 5196 | psli = &phba->sli; |
92d7f7b0 | 5197 | |
3772a991 | 5198 | mb = &pmbox->u.mb; |
dea3101e | 5199 | status = MBX_SUCCESS; |
5200 | ||
2e0fef85 JS |
5201 | if (phba->link_state == LPFC_HBA_ERROR) { |
5202 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
5203 | |
5204 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
5205 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5206 | "(%d):0311 Mailbox command x%x cannot " | |
5207 | "issue Data: x%x x%x\n", | |
5208 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5209 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 5210 | goto out_not_finished; |
41415862 JW |
5211 | } |
5212 | ||
9290831f JS |
5213 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
5214 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { | |
2e0fef85 | 5215 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3772a991 JS |
5216 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5217 | "(%d):2528 Mailbox command x%x cannot " | |
5218 | "issue Data: x%x x%x\n", | |
5219 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5220 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 5221 | goto out_not_finished; |
9290831f JS |
5222 | } |
5223 | ||
dea3101e | 5224 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
5225 | /* Polling for a mbox command when another one is already active | |
5226 | * is not allowed in SLI. Also, the driver must have established | |
5227 | * SLI2 mode to queue and process multiple mbox commands. | |
5228 | */ | |
5229 | ||
5230 | if (flag & MBX_POLL) { | |
2e0fef85 | 5231 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5232 | |
5233 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
5234 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5235 | "(%d):2529 Mailbox command x%x " | |
5236 | "cannot issue Data: x%x x%x\n", | |
5237 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5238 | pmbox->u.mb.mbxCommand, | |
5239 | psli->sli_flag, flag); | |
58da1ffb | 5240 | goto out_not_finished; |
dea3101e | 5241 | } |
5242 | ||
3772a991 | 5243 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 5244 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5245 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
5246 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5247 | "(%d):2530 Mailbox command x%x " | |
5248 | "cannot issue Data: x%x x%x\n", | |
5249 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5250 | pmbox->u.mb.mbxCommand, | |
5251 | psli->sli_flag, flag); | |
58da1ffb | 5252 | goto out_not_finished; |
dea3101e | 5253 | } |
5254 | ||
dea3101e | 5255 | /* Another mailbox command is still being processed, queue this |
5256 | * command to be processed later. | |
5257 | */ | |
5258 | lpfc_mbox_put(phba, pmbox); | |
5259 | ||
5260 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 5261 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 5262 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 5263 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
5264 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
5265 | mb->mbxCommand, phba->pport->port_state, | |
5266 | psli->sli_flag, flag); | |
dea3101e | 5267 | |
5268 | psli->slistat.mbox_busy++; | |
2e0fef85 | 5269 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5270 | |
858c9f6c JS |
5271 | if (pmbox->vport) { |
5272 | lpfc_debugfs_disc_trc(pmbox->vport, | |
5273 | LPFC_DISC_TRC_MBOX_VPORT, | |
5274 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
5275 | (uint32_t)mb->mbxCommand, | |
5276 | mb->un.varWords[0], mb->un.varWords[1]); | |
5277 | } | |
5278 | else { | |
5279 | lpfc_debugfs_disc_trc(phba->pport, | |
5280 | LPFC_DISC_TRC_MBOX, | |
5281 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
5282 | (uint32_t)mb->mbxCommand, | |
5283 | mb->un.varWords[0], mb->un.varWords[1]); | |
5284 | } | |
5285 | ||
2e0fef85 | 5286 | return MBX_BUSY; |
dea3101e | 5287 | } |
5288 | ||
dea3101e | 5289 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
5290 | ||
5291 | /* If we are not polling, we MUST be in SLI2 mode */ | |
5292 | if (flag != MBX_POLL) { | |
3772a991 | 5293 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 5294 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 5295 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5296 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5297 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
5298 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5299 | "(%d):2531 Mailbox command x%x " | |
5300 | "cannot issue Data: x%x x%x\n", | |
5301 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5302 | pmbox->u.mb.mbxCommand, | |
5303 | psli->sli_flag, flag); | |
58da1ffb | 5304 | goto out_not_finished; |
dea3101e | 5305 | } |
5306 | /* timeout active mbox command */ | |
a309a6b6 JS |
5307 | mod_timer(&psli->mbox_tmo, (jiffies + |
5308 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | |
dea3101e | 5309 | } |
5310 | ||
5311 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 5312 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 5313 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 5314 | "x%x\n", |
e8b62011 | 5315 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
5316 | mb->mbxCommand, phba->pport->port_state, |
5317 | psli->sli_flag, flag); | |
dea3101e | 5318 | |
858c9f6c JS |
5319 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
5320 | if (pmbox->vport) { | |
5321 | lpfc_debugfs_disc_trc(pmbox->vport, | |
5322 | LPFC_DISC_TRC_MBOX_VPORT, | |
5323 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5324 | (uint32_t)mb->mbxCommand, | |
5325 | mb->un.varWords[0], mb->un.varWords[1]); | |
5326 | } | |
5327 | else { | |
5328 | lpfc_debugfs_disc_trc(phba->pport, | |
5329 | LPFC_DISC_TRC_MBOX, | |
5330 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5331 | (uint32_t)mb->mbxCommand, | |
5332 | mb->un.varWords[0], mb->un.varWords[1]); | |
5333 | } | |
5334 | } | |
5335 | ||
dea3101e | 5336 | psli->slistat.mbox_cmd++; |
5337 | evtctr = psli->slistat.mbox_event; | |
5338 | ||
5339 | /* next set own bit for the adapter and copy over command word */ | |
5340 | mb->mbxOwner = OWN_CHIP; | |
5341 | ||
3772a991 | 5342 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
5343 | /* Populate mbox extension offset word. */ |
5344 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
5345 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
5346 | = (uint8_t *)phba->mbox_ext | |
5347 | - (uint8_t *)phba->mbox; | |
5348 | } | |
5349 | ||
5350 | /* Copy the mailbox extension data */ | |
5351 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
5352 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
5353 | (uint8_t *)phba->mbox_ext, | |
5354 | pmbox->in_ext_byte_len); | |
5355 | } | |
5356 | /* Copy command data to host SLIM area */ | |
34b02dcd | 5357 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 5358 | } else { |
7a470277 JS |
5359 | /* Populate mbox extension offset word. */ |
5360 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
5361 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
5362 | = MAILBOX_HBA_EXT_OFFSET; | |
5363 | ||
5364 | /* Copy the mailbox extension data */ | |
5365 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
5366 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
5367 | MAILBOX_HBA_EXT_OFFSET, | |
5368 | pmbox->context2, pmbox->in_ext_byte_len); | |
5369 | ||
5370 | } | |
9290831f | 5371 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 5372 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 5373 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 5374 | } |
5375 | ||
5376 | /* First copy mbox command data to HBA SLIM, skip past first | |
5377 | word */ | |
5378 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
5379 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
5380 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
5381 | ||
5382 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 5383 | ldata = *((uint32_t *)mb); |
dea3101e | 5384 | to_slim = phba->MBslimaddr; |
5385 | writel(ldata, to_slim); | |
5386 | readl(to_slim); /* flush */ | |
5387 | ||
5388 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5389 | /* switch over to host mailbox */ | |
3772a991 | 5390 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e | 5391 | } |
5392 | } | |
5393 | ||
5394 | wmb(); | |
dea3101e | 5395 | |
5396 | switch (flag) { | |
5397 | case MBX_NOWAIT: | |
09372820 | 5398 | /* Set up reference to mailbox command */ |
dea3101e | 5399 | psli->mbox_active = pmbox; |
09372820 JS |
5400 | /* Interrupt board to do it */ |
5401 | writel(CA_MBATT, phba->CAregaddr); | |
5402 | readl(phba->CAregaddr); /* flush */ | |
5403 | /* Don't wait for it to finish, just return */ | |
dea3101e | 5404 | break; |
5405 | ||
5406 | case MBX_POLL: | |
09372820 | 5407 | /* Set up null reference to mailbox command */ |
dea3101e | 5408 | psli->mbox_active = NULL; |
09372820 JS |
5409 | /* Interrupt board to do it */ |
5410 | writel(CA_MBATT, phba->CAregaddr); | |
5411 | readl(phba->CAregaddr); /* flush */ | |
5412 | ||
3772a991 | 5413 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5414 | /* First read mbox status word */ |
34b02dcd | 5415 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 5416 | word0 = le32_to_cpu(word0); |
5417 | } else { | |
5418 | /* First read mbox status word */ | |
5419 | word0 = readl(phba->MBslimaddr); | |
5420 | } | |
5421 | ||
5422 | /* Read the HBA Host Attention Register */ | |
5423 | ha_copy = readl(phba->HAregaddr); | |
09372820 JS |
5424 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
5425 | mb->mbxCommand) * | |
5426 | 1000) + jiffies; | |
5427 | i = 0; | |
dea3101e | 5428 | /* Wait for command to complete */ |
41415862 JW |
5429 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
5430 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 5431 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 5432 | if (time_after(jiffies, timeout)) { |
dea3101e | 5433 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5434 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 5435 | drvr_flag); |
58da1ffb | 5436 | goto out_not_finished; |
dea3101e | 5437 | } |
5438 | ||
5439 | /* Check if we took a mbox interrupt while we were | |
5440 | polling */ | |
5441 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
5442 | && (evtctr != psli->slistat.mbox_event)) | |
5443 | break; | |
5444 | ||
09372820 JS |
5445 | if (i++ > 10) { |
5446 | spin_unlock_irqrestore(&phba->hbalock, | |
5447 | drvr_flag); | |
5448 | msleep(1); | |
5449 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5450 | } | |
dea3101e | 5451 | |
3772a991 | 5452 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5453 | /* First copy command data */ |
34b02dcd | 5454 | word0 = *((uint32_t *)phba->mbox); |
dea3101e | 5455 | word0 = le32_to_cpu(word0); |
5456 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5457 | MAILBOX_t *slimmb; | |
34b02dcd | 5458 | uint32_t slimword0; |
dea3101e | 5459 | /* Check real SLIM for any errors */ |
5460 | slimword0 = readl(phba->MBslimaddr); | |
5461 | slimmb = (MAILBOX_t *) & slimword0; | |
5462 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
5463 | && slimmb->mbxStatus) { | |
5464 | psli->sli_flag &= | |
3772a991 | 5465 | ~LPFC_SLI_ACTIVE; |
dea3101e | 5466 | word0 = slimword0; |
5467 | } | |
5468 | } | |
5469 | } else { | |
5470 | /* First copy command data */ | |
5471 | word0 = readl(phba->MBslimaddr); | |
5472 | } | |
5473 | /* Read the HBA Host Attention Register */ | |
5474 | ha_copy = readl(phba->HAregaddr); | |
5475 | } | |
5476 | ||
3772a991 | 5477 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5478 | /* copy results back to user */ |
34b02dcd | 5479 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
5480 | /* Copy the mailbox extension data */ |
5481 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5482 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
5483 | pmbox->context2, | |
5484 | pmbox->out_ext_byte_len); | |
5485 | } | |
dea3101e | 5486 | } else { |
5487 | /* First copy command data */ | |
5488 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
5489 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
5490 | /* Copy the mailbox extension data */ |
5491 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5492 | lpfc_memcpy_from_slim(pmbox->context2, | |
5493 | phba->MBslimaddr + | |
5494 | MAILBOX_HBA_EXT_OFFSET, | |
5495 | pmbox->out_ext_byte_len); | |
dea3101e | 5496 | } |
5497 | } | |
5498 | ||
5499 | writel(HA_MBATT, phba->HAregaddr); | |
5500 | readl(phba->HAregaddr); /* flush */ | |
5501 | ||
5502 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5503 | status = mb->mbxStatus; | |
5504 | } | |
5505 | ||
2e0fef85 JS |
5506 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
5507 | return status; | |
58da1ffb JS |
5508 | |
5509 | out_not_finished: | |
5510 | if (processing_queue) { | |
da0436e9 | 5511 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
5512 | lpfc_mbox_cmpl_put(phba, pmbox); |
5513 | } | |
5514 | return MBX_NOT_FINISHED; | |
dea3101e | 5515 | } |
5516 | ||
f1126688 JS |
5517 | /** |
5518 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
5519 | * @phba: Pointer to HBA context object. | |
5520 | * | |
5521 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
5522 | * the driver internal pending mailbox queue. It will then try to wait out the | |
5523 | * possible outstanding mailbox command before return. | |
5524 | * | |
5525 | * Returns: | |
5526 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
5527 | * the outstanding mailbox command timed out. | |
5528 | **/ | |
5529 | static int | |
5530 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
5531 | { | |
5532 | struct lpfc_sli *psli = &phba->sli; | |
5533 | uint8_t actcmd = MBX_HEARTBEAT; | |
5534 | int rc = 0; | |
5535 | unsigned long timeout; | |
5536 | ||
5537 | /* Mark the asynchronous mailbox command posting as blocked */ | |
5538 | spin_lock_irq(&phba->hbalock); | |
5539 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
5540 | if (phba->sli.mbox_active) | |
5541 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
5542 | spin_unlock_irq(&phba->hbalock); | |
5543 | /* Determine how long we might wait for the active mailbox | |
5544 | * command to be gracefully completed by firmware. | |
5545 | */ | |
5546 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
5547 | jiffies; | |
5548 | /* Wait for the outstnading mailbox command to complete */ | |
5549 | while (phba->sli.mbox_active) { | |
5550 | /* Check active mailbox complete status every 2ms */ | |
5551 | msleep(2); | |
5552 | if (time_after(jiffies, timeout)) { | |
5553 | /* Timeout, marked the outstanding cmd not complete */ | |
5554 | rc = 1; | |
5555 | break; | |
5556 | } | |
5557 | } | |
5558 | ||
5559 | /* Can not cleanly block async mailbox command, fails it */ | |
5560 | if (rc) { | |
5561 | spin_lock_irq(&phba->hbalock); | |
5562 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5563 | spin_unlock_irq(&phba->hbalock); | |
5564 | } | |
5565 | return rc; | |
5566 | } | |
5567 | ||
5568 | /** | |
5569 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
5570 | * @phba: Pointer to HBA context object. | |
5571 | * | |
5572 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
5573 | * commands from the driver internal pending mailbox queue. It makes sure | |
5574 | * that there is no outstanding mailbox command before resuming posting | |
5575 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
5576 | * mailbox command, it will try to wait it out before resuming asynchronous | |
5577 | * mailbox command posting. | |
5578 | **/ | |
5579 | static void | |
5580 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
5581 | { | |
5582 | struct lpfc_sli *psli = &phba->sli; | |
5583 | ||
5584 | spin_lock_irq(&phba->hbalock); | |
5585 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5586 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
5587 | spin_unlock_irq(&phba->hbalock); | |
5588 | return; | |
5589 | } | |
5590 | ||
5591 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
5592 | * successful or timeout, after timing-out the outstanding mailbox | |
5593 | * command shall always be removed, so just unblock posting async | |
5594 | * mailbox command and resume | |
5595 | */ | |
5596 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5597 | spin_unlock_irq(&phba->hbalock); | |
5598 | ||
5599 | /* wake up worker thread to post asynchronlous mailbox command */ | |
5600 | lpfc_worker_wake_up(phba); | |
5601 | } | |
5602 | ||
da0436e9 JS |
5603 | /** |
5604 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
5605 | * @phba: Pointer to HBA context object. | |
5606 | * @mboxq: Pointer to mailbox object. | |
5607 | * | |
5608 | * The function posts a mailbox to the port. The mailbox is expected | |
5609 | * to be comletely filled in and ready for the port to operate on it. | |
5610 | * This routine executes a synchronous completion operation on the | |
5611 | * mailbox by polling for its completion. | |
5612 | * | |
5613 | * The caller must not be holding any locks when calling this routine. | |
5614 | * | |
5615 | * Returns: | |
5616 | * MBX_SUCCESS - mailbox posted successfully | |
5617 | * Any of the MBX error values. | |
5618 | **/ | |
5619 | static int | |
5620 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
5621 | { | |
5622 | int rc = MBX_SUCCESS; | |
5623 | unsigned long iflag; | |
5624 | uint32_t db_ready; | |
5625 | uint32_t mcqe_status; | |
5626 | uint32_t mbx_cmnd; | |
5627 | unsigned long timeout; | |
5628 | struct lpfc_sli *psli = &phba->sli; | |
5629 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
5630 | struct lpfc_bmbx_create *mbox_rgn; | |
5631 | struct dma_address *dma_address; | |
5632 | struct lpfc_register bmbx_reg; | |
5633 | ||
5634 | /* | |
5635 | * Only one mailbox can be active to the bootstrap mailbox region | |
5636 | * at a time and there is no queueing provided. | |
5637 | */ | |
5638 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5639 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5640 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5641 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5642 | "(%d):2532 Mailbox command x%x (x%x) " | |
5643 | "cannot issue Data: x%x x%x\n", | |
5644 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5645 | mboxq->u.mb.mbxCommand, | |
5646 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5647 | psli->sli_flag, MBX_POLL); | |
5648 | return MBXERR_ERROR; | |
5649 | } | |
5650 | /* The server grabs the token and owns it until release */ | |
5651 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5652 | phba->sli.mbox_active = mboxq; | |
5653 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5654 | ||
5655 | /* | |
5656 | * Initialize the bootstrap memory region to avoid stale data areas | |
5657 | * in the mailbox post. Then copy the caller's mailbox contents to | |
5658 | * the bmbx mailbox region. | |
5659 | */ | |
5660 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
5661 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
5662 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
5663 | sizeof(struct lpfc_mqe)); | |
5664 | ||
5665 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
5666 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5667 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
5668 | ||
5669 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5670 | * 1000) + jiffies; | |
5671 | do { | |
5672 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5673 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5674 | if (!db_ready) | |
5675 | msleep(2); | |
5676 | ||
5677 | if (time_after(jiffies, timeout)) { | |
5678 | rc = MBXERR_ERROR; | |
5679 | goto exit; | |
5680 | } | |
5681 | } while (!db_ready); | |
5682 | ||
5683 | /* Post the low mailbox dma address to the port. */ | |
5684 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
5685 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5686 | * 1000) + jiffies; | |
5687 | do { | |
5688 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5689 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5690 | if (!db_ready) | |
5691 | msleep(2); | |
5692 | ||
5693 | if (time_after(jiffies, timeout)) { | |
5694 | rc = MBXERR_ERROR; | |
5695 | goto exit; | |
5696 | } | |
5697 | } while (!db_ready); | |
5698 | ||
5699 | /* | |
5700 | * Read the CQ to ensure the mailbox has completed. | |
5701 | * If so, update the mailbox status so that the upper layers | |
5702 | * can complete the request normally. | |
5703 | */ | |
5704 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
5705 | sizeof(struct lpfc_mqe)); | |
5706 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
5707 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
5708 | sizeof(struct lpfc_mcqe)); | |
5709 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
5710 | ||
5711 | /* Prefix the mailbox status with range x4000 to note SLI4 status. */ | |
5712 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
5713 | bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status); | |
5714 | rc = MBXERR_ERROR; | |
d7c47992 JS |
5715 | } else |
5716 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
5717 | |
5718 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5719 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " | |
5720 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" | |
5721 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
5722 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5723 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5724 | bf_get(lpfc_mqe_status, mb), | |
5725 | mb->un.mb_words[0], mb->un.mb_words[1], | |
5726 | mb->un.mb_words[2], mb->un.mb_words[3], | |
5727 | mb->un.mb_words[4], mb->un.mb_words[5], | |
5728 | mb->un.mb_words[6], mb->un.mb_words[7], | |
5729 | mb->un.mb_words[8], mb->un.mb_words[9], | |
5730 | mb->un.mb_words[10], mb->un.mb_words[11], | |
5731 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
5732 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
5733 | mboxq->mcqe.trailer); | |
5734 | exit: | |
5735 | /* We are holding the token, no needed for lock when release */ | |
5736 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5737 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5738 | phba->sli.mbox_active = NULL; | |
5739 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5740 | return rc; | |
5741 | } | |
5742 | ||
5743 | /** | |
5744 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
5745 | * @phba: Pointer to HBA context object. | |
5746 | * @pmbox: Pointer to mailbox object. | |
5747 | * @flag: Flag indicating how the mailbox need to be processed. | |
5748 | * | |
5749 | * This function is called by discovery code and HBA management code to submit | |
5750 | * a mailbox command to firmware with SLI-4 interface spec. | |
5751 | * | |
5752 | * Return codes the caller owns the mailbox command after the return of the | |
5753 | * function. | |
5754 | **/ | |
5755 | static int | |
5756 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
5757 | uint32_t flag) | |
5758 | { | |
5759 | struct lpfc_sli *psli = &phba->sli; | |
5760 | unsigned long iflags; | |
5761 | int rc; | |
5762 | ||
8fa38513 JS |
5763 | rc = lpfc_mbox_dev_check(phba); |
5764 | if (unlikely(rc)) { | |
5765 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5766 | "(%d):2544 Mailbox command x%x (x%x) " | |
5767 | "cannot issue Data: x%x x%x\n", | |
5768 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5769 | mboxq->u.mb.mbxCommand, | |
5770 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5771 | psli->sli_flag, flag); | |
5772 | goto out_not_finished; | |
5773 | } | |
5774 | ||
da0436e9 JS |
5775 | /* Detect polling mode and jump to a handler */ |
5776 | if (!phba->sli4_hba.intr_enable) { | |
5777 | if (flag == MBX_POLL) | |
5778 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5779 | else | |
5780 | rc = -EIO; | |
5781 | if (rc != MBX_SUCCESS) | |
5782 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5783 | "(%d):2541 Mailbox command x%x " | |
5784 | "(x%x) cannot issue Data: x%x x%x\n", | |
5785 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5786 | mboxq->u.mb.mbxCommand, | |
5787 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5788 | psli->sli_flag, flag); | |
5789 | return rc; | |
5790 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
5791 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
5792 | "(%d):2542 Try to issue mailbox command " | |
5793 | "x%x (x%x) synchronously ahead of async" | |
5794 | "mailbox command queue: x%x x%x\n", | |
da0436e9 JS |
5795 | mboxq->vport ? mboxq->vport->vpi : 0, |
5796 | mboxq->u.mb.mbxCommand, | |
5797 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5798 | psli->sli_flag, flag); | |
f1126688 JS |
5799 | /* Try to block the asynchronous mailbox posting */ |
5800 | rc = lpfc_sli4_async_mbox_block(phba); | |
5801 | if (!rc) { | |
5802 | /* Successfully blocked, now issue sync mbox cmd */ | |
5803 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5804 | if (rc != MBX_SUCCESS) | |
5805 | lpfc_printf_log(phba, KERN_ERR, | |
5806 | LOG_MBOX | LOG_SLI, | |
5807 | "(%d):2597 Mailbox command " | |
5808 | "x%x (x%x) cannot issue " | |
5809 | "Data: x%x x%x\n", | |
5810 | mboxq->vport ? | |
5811 | mboxq->vport->vpi : 0, | |
5812 | mboxq->u.mb.mbxCommand, | |
5813 | lpfc_sli4_mbox_opcode_get(phba, | |
5814 | mboxq), | |
5815 | psli->sli_flag, flag); | |
5816 | /* Unblock the async mailbox posting afterward */ | |
5817 | lpfc_sli4_async_mbox_unblock(phba); | |
5818 | } | |
5819 | return rc; | |
da0436e9 JS |
5820 | } |
5821 | ||
5822 | /* Now, interrupt mode asynchrous mailbox command */ | |
5823 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
5824 | if (rc) { | |
5825 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5826 | "(%d):2543 Mailbox command x%x (x%x) " | |
5827 | "cannot issue Data: x%x x%x\n", | |
5828 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5829 | mboxq->u.mb.mbxCommand, | |
5830 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5831 | psli->sli_flag, flag); | |
5832 | goto out_not_finished; | |
5833 | } | |
da0436e9 JS |
5834 | |
5835 | /* Put the mailbox command to the driver internal FIFO */ | |
5836 | psli->slistat.mbox_busy++; | |
5837 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5838 | lpfc_mbox_put(phba, mboxq); | |
5839 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5840 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5841 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
5842 | "x%x (x%x) x%x x%x x%x\n", | |
5843 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, | |
5844 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5845 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5846 | phba->pport->port_state, | |
5847 | psli->sli_flag, MBX_NOWAIT); | |
5848 | /* Wake up worker thread to transport mailbox command from head */ | |
5849 | lpfc_worker_wake_up(phba); | |
5850 | ||
5851 | return MBX_BUSY; | |
5852 | ||
5853 | out_not_finished: | |
5854 | return MBX_NOT_FINISHED; | |
5855 | } | |
5856 | ||
5857 | /** | |
5858 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
5859 | * @phba: Pointer to HBA context object. | |
5860 | * | |
5861 | * This function is called by worker thread to send a mailbox command to | |
5862 | * SLI4 HBA firmware. | |
5863 | * | |
5864 | **/ | |
5865 | int | |
5866 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
5867 | { | |
5868 | struct lpfc_sli *psli = &phba->sli; | |
5869 | LPFC_MBOXQ_t *mboxq; | |
5870 | int rc = MBX_SUCCESS; | |
5871 | unsigned long iflags; | |
5872 | struct lpfc_mqe *mqe; | |
5873 | uint32_t mbx_cmnd; | |
5874 | ||
5875 | /* Check interrupt mode before post async mailbox command */ | |
5876 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
5877 | return MBX_NOT_FINISHED; | |
5878 | ||
5879 | /* Check for mailbox command service token */ | |
5880 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5881 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5882 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5883 | return MBX_NOT_FINISHED; | |
5884 | } | |
5885 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5886 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5887 | return MBX_NOT_FINISHED; | |
5888 | } | |
5889 | if (unlikely(phba->sli.mbox_active)) { | |
5890 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5891 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5892 | "0384 There is pending active mailbox cmd\n"); | |
5893 | return MBX_NOT_FINISHED; | |
5894 | } | |
5895 | /* Take the mailbox command service token */ | |
5896 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5897 | ||
5898 | /* Get the next mailbox command from head of queue */ | |
5899 | mboxq = lpfc_mbox_get(phba); | |
5900 | ||
5901 | /* If no more mailbox command waiting for post, we're done */ | |
5902 | if (!mboxq) { | |
5903 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5904 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5905 | return MBX_SUCCESS; | |
5906 | } | |
5907 | phba->sli.mbox_active = mboxq; | |
5908 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5909 | ||
5910 | /* Check device readiness for posting mailbox command */ | |
5911 | rc = lpfc_mbox_dev_check(phba); | |
5912 | if (unlikely(rc)) | |
5913 | /* Driver clean routine will clean up pending mailbox */ | |
5914 | goto out_not_finished; | |
5915 | ||
5916 | /* Prepare the mbox command to be posted */ | |
5917 | mqe = &mboxq->u.mqe; | |
5918 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
5919 | ||
5920 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
5921 | mod_timer(&psli->mbox_tmo, (jiffies + | |
5922 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); | |
5923 | ||
5924 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5925 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " | |
5926 | "x%x x%x\n", | |
5927 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
5928 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5929 | phba->pport->port_state, psli->sli_flag); | |
5930 | ||
5931 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
5932 | if (mboxq->vport) { | |
5933 | lpfc_debugfs_disc_trc(mboxq->vport, | |
5934 | LPFC_DISC_TRC_MBOX_VPORT, | |
5935 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5936 | mbx_cmnd, mqe->un.mb_words[0], | |
5937 | mqe->un.mb_words[1]); | |
5938 | } else { | |
5939 | lpfc_debugfs_disc_trc(phba->pport, | |
5940 | LPFC_DISC_TRC_MBOX, | |
5941 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5942 | mbx_cmnd, mqe->un.mb_words[0], | |
5943 | mqe->un.mb_words[1]); | |
5944 | } | |
5945 | } | |
5946 | psli->slistat.mbox_cmd++; | |
5947 | ||
5948 | /* Post the mailbox command to the port */ | |
5949 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
5950 | if (rc != MBX_SUCCESS) { | |
5951 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5952 | "(%d):2533 Mailbox command x%x (x%x) " | |
5953 | "cannot issue Data: x%x x%x\n", | |
5954 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5955 | mboxq->u.mb.mbxCommand, | |
5956 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5957 | psli->sli_flag, MBX_NOWAIT); | |
5958 | goto out_not_finished; | |
5959 | } | |
5960 | ||
5961 | return rc; | |
5962 | ||
5963 | out_not_finished: | |
5964 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5965 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
5966 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
5967 | /* Release the token */ | |
5968 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5969 | phba->sli.mbox_active = NULL; | |
5970 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5971 | ||
5972 | return MBX_NOT_FINISHED; | |
5973 | } | |
5974 | ||
5975 | /** | |
5976 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
5977 | * @phba: Pointer to HBA context object. | |
5978 | * @pmbox: Pointer to mailbox object. | |
5979 | * @flag: Flag indicating how the mailbox need to be processed. | |
5980 | * | |
5981 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
5982 | * the API jump table function pointer from the lpfc_hba struct. | |
5983 | * | |
5984 | * Return codes the caller owns the mailbox command after the return of the | |
5985 | * function. | |
5986 | **/ | |
5987 | int | |
5988 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
5989 | { | |
5990 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
5991 | } | |
5992 | ||
5993 | /** | |
5994 | * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table | |
5995 | * @phba: The hba struct for which this call is being executed. | |
5996 | * @dev_grp: The HBA PCI-Device group number. | |
5997 | * | |
5998 | * This routine sets up the mbox interface API function jump table in @phba | |
5999 | * struct. | |
6000 | * Returns: 0 - success, -ENODEV - failure. | |
6001 | **/ | |
6002 | int | |
6003 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6004 | { | |
6005 | ||
6006 | switch (dev_grp) { | |
6007 | case LPFC_PCI_DEV_LP: | |
6008 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
6009 | phba->lpfc_sli_handle_slow_ring_event = | |
6010 | lpfc_sli_handle_slow_ring_event_s3; | |
6011 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
6012 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
6013 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
6014 | break; | |
6015 | case LPFC_PCI_DEV_OC: | |
6016 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
6017 | phba->lpfc_sli_handle_slow_ring_event = | |
6018 | lpfc_sli_handle_slow_ring_event_s4; | |
6019 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
6020 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
6021 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
6022 | break; | |
6023 | default: | |
6024 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6025 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
6026 | dev_grp); | |
6027 | return -ENODEV; | |
6028 | break; | |
6029 | } | |
6030 | return 0; | |
6031 | } | |
6032 | ||
e59058c4 | 6033 | /** |
3621a710 | 6034 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
6035 | * @phba: Pointer to HBA context object. |
6036 | * @pring: Pointer to driver SLI ring object. | |
6037 | * @piocb: Pointer to address of newly added command iocb. | |
6038 | * | |
6039 | * This function is called with hbalock held to add a command | |
6040 | * iocb to the txq when SLI layer cannot submit the command iocb | |
6041 | * to the ring. | |
6042 | **/ | |
2a9bf3d0 | 6043 | void |
92d7f7b0 | 6044 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 6045 | struct lpfc_iocbq *piocb) |
dea3101e | 6046 | { |
6047 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
6048 | list_add_tail(&piocb->list, &pring->txq); | |
6049 | pring->txq_cnt++; | |
dea3101e | 6050 | } |
6051 | ||
e59058c4 | 6052 | /** |
3621a710 | 6053 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
6054 | * @phba: Pointer to HBA context object. |
6055 | * @pring: Pointer to driver SLI ring object. | |
6056 | * @piocb: Pointer to address of newly added command iocb. | |
6057 | * | |
6058 | * This function is called with hbalock held before a new | |
6059 | * iocb is submitted to the firmware. This function checks | |
6060 | * txq to flush the iocbs in txq to Firmware before | |
6061 | * submitting new iocbs to the Firmware. | |
6062 | * If there are iocbs in the txq which need to be submitted | |
6063 | * to firmware, lpfc_sli_next_iocb returns the first element | |
6064 | * of the txq after dequeuing it from txq. | |
6065 | * If there is no iocb in the txq then the function will return | |
6066 | * *piocb and *piocb is set to NULL. Caller needs to check | |
6067 | * *piocb to find if there are more commands in the txq. | |
6068 | **/ | |
dea3101e | 6069 | static struct lpfc_iocbq * |
6070 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 6071 | struct lpfc_iocbq **piocb) |
dea3101e | 6072 | { |
6073 | struct lpfc_iocbq * nextiocb; | |
6074 | ||
6075 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
6076 | if (!nextiocb) { | |
6077 | nextiocb = *piocb; | |
6078 | *piocb = NULL; | |
6079 | } | |
6080 | ||
6081 | return nextiocb; | |
6082 | } | |
6083 | ||
e59058c4 | 6084 | /** |
3772a991 | 6085 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 6086 | * @phba: Pointer to HBA context object. |
3772a991 | 6087 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
6088 | * @piocb: Pointer to command iocb. |
6089 | * @flag: Flag indicating if this command can be put into txq. | |
6090 | * | |
3772a991 JS |
6091 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
6092 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
6093 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
6094 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
6095 | * this function allows only iocbs for posting buffers. This function finds | |
6096 | * next available slot in the command ring and posts the command to the | |
6097 | * available slot and writes the port attention register to request HBA start | |
6098 | * processing new iocb. If there is no slot available in the ring and | |
6099 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
6100 | * the function returns IOCB_BUSY. | |
e59058c4 | 6101 | * |
3772a991 JS |
6102 | * This function is called with hbalock held. The function will return success |
6103 | * after it successfully submit the iocb to firmware or after adding to the | |
6104 | * txq. | |
e59058c4 | 6105 | **/ |
98c9ea5c | 6106 | static int |
3772a991 | 6107 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e | 6108 | struct lpfc_iocbq *piocb, uint32_t flag) |
6109 | { | |
6110 | struct lpfc_iocbq *nextiocb; | |
6111 | IOCB_t *iocb; | |
3772a991 | 6112 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 6113 | |
92d7f7b0 JS |
6114 | if (piocb->iocb_cmpl && (!piocb->vport) && |
6115 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
6116 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
6117 | lpfc_printf_log(phba, KERN_ERR, | |
6118 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 6119 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
6120 | piocb->iocb.ulpCommand); |
6121 | dump_stack(); | |
6122 | return IOCB_ERROR; | |
6123 | } | |
6124 | ||
6125 | ||
8d63f375 LV |
6126 | /* If the PCI channel is in offline state, do not post iocbs. */ |
6127 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
6128 | return IOCB_ERROR; | |
6129 | ||
a257bf90 JS |
6130 | /* If HBA has a deferred error attention, fail the iocb. */ |
6131 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
6132 | return IOCB_ERROR; | |
6133 | ||
dea3101e | 6134 | /* |
6135 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
6136 | */ | |
2e0fef85 | 6137 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e | 6138 | return IOCB_ERROR; |
6139 | ||
6140 | /* | |
6141 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 6142 | * outstanding event. |
dea3101e | 6143 | */ |
0b727fea | 6144 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e | 6145 | goto iocb_busy; |
6146 | ||
2e0fef85 | 6147 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 6148 | /* |
2680eeaa | 6149 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e | 6150 | * can be issued if the link is not up. |
6151 | */ | |
6152 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
6153 | case CMD_GEN_REQUEST64_CR: |
6154 | case CMD_GEN_REQUEST64_CX: | |
6155 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
6156 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 6157 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
6158 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
6159 | MENLO_TRANSPORT_TYPE)) | |
6160 | ||
6161 | goto iocb_busy; | |
6162 | break; | |
dea3101e | 6163 | case CMD_QUE_RING_BUF_CN: |
6164 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e | 6165 | /* |
6166 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
6167 | * completion, iocb_cmpl MUST be 0. | |
6168 | */ | |
6169 | if (piocb->iocb_cmpl) | |
6170 | piocb->iocb_cmpl = NULL; | |
6171 | /*FALLTHROUGH*/ | |
6172 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
6173 | case CMD_CLOSE_XRI_CN: |
6174 | case CMD_CLOSE_XRI_CX: | |
dea3101e | 6175 | break; |
6176 | default: | |
6177 | goto iocb_busy; | |
6178 | } | |
6179 | ||
6180 | /* | |
6181 | * For FCP commands, we must be in a state where we can process link | |
6182 | * attention events. | |
6183 | */ | |
6184 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 6185 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 6186 | goto iocb_busy; |
92d7f7b0 | 6187 | } |
dea3101e | 6188 | |
dea3101e | 6189 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
6190 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
6191 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
6192 | ||
6193 | if (iocb) | |
6194 | lpfc_sli_update_ring(phba, pring); | |
6195 | else | |
6196 | lpfc_sli_update_full_ring(phba, pring); | |
6197 | ||
6198 | if (!piocb) | |
6199 | return IOCB_SUCCESS; | |
6200 | ||
6201 | goto out_busy; | |
6202 | ||
6203 | iocb_busy: | |
6204 | pring->stats.iocb_cmd_delay++; | |
6205 | ||
6206 | out_busy: | |
6207 | ||
6208 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 6209 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e | 6210 | return IOCB_SUCCESS; |
6211 | } | |
6212 | ||
6213 | return IOCB_BUSY; | |
6214 | } | |
6215 | ||
3772a991 | 6216 | /** |
4f774513 JS |
6217 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
6218 | * @phba: Pointer to HBA context object. | |
6219 | * @piocb: Pointer to command iocb. | |
6220 | * @sglq: Pointer to the scatter gather queue object. | |
6221 | * | |
6222 | * This routine converts the bpl or bde that is in the IOCB | |
6223 | * to a sgl list for the sli4 hardware. The physical address | |
6224 | * of the bpl/bde is converted back to a virtual address. | |
6225 | * If the IOCB contains a BPL then the list of BDE's is | |
6226 | * converted to sli4_sge's. If the IOCB contains a single | |
6227 | * BDE then it is converted to a single sli_sge. | |
6228 | * The IOCB is still in cpu endianess so the contents of | |
6229 | * the bpl can be used without byte swapping. | |
6230 | * | |
6231 | * Returns valid XRI = Success, NO_XRI = Failure. | |
6232 | **/ | |
6233 | static uint16_t | |
6234 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
6235 | struct lpfc_sglq *sglq) | |
3772a991 | 6236 | { |
4f774513 JS |
6237 | uint16_t xritag = NO_XRI; |
6238 | struct ulp_bde64 *bpl = NULL; | |
6239 | struct ulp_bde64 bde; | |
6240 | struct sli4_sge *sgl = NULL; | |
6241 | IOCB_t *icmd; | |
6242 | int numBdes = 0; | |
6243 | int i = 0; | |
63e801ce JS |
6244 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
6245 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 6246 | |
4f774513 JS |
6247 | if (!piocbq || !sglq) |
6248 | return xritag; | |
6249 | ||
6250 | sgl = (struct sli4_sge *)sglq->sgl; | |
6251 | icmd = &piocbq->iocb; | |
6252 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
6253 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
6254 | sizeof(struct ulp_bde64); | |
6255 | /* The addrHigh and addrLow fields within the IOCB | |
6256 | * have not been byteswapped yet so there is no | |
6257 | * need to swap them back. | |
6258 | */ | |
6259 | bpl = (struct ulp_bde64 *) | |
6260 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | |
6261 | ||
6262 | if (!bpl) | |
6263 | return xritag; | |
6264 | ||
6265 | for (i = 0; i < numBdes; i++) { | |
6266 | /* Should already be byte swapped. */ | |
28baac74 JS |
6267 | sgl->addr_hi = bpl->addrHigh; |
6268 | sgl->addr_lo = bpl->addrLow; | |
6269 | ||
4f774513 JS |
6270 | if ((i+1) == numBdes) |
6271 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
6272 | else | |
6273 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
6274 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
6275 | /* swap the size field back to the cpu so we |
6276 | * can assign it to the sgl. | |
6277 | */ | |
6278 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
6279 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
6280 | /* The offsets in the sgl need to be accumulated |
6281 | * separately for the request and reply lists. | |
6282 | * The request is always first, the reply follows. | |
6283 | */ | |
6284 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
6285 | /* add up the reply sg entries */ | |
6286 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
6287 | inbound++; | |
6288 | /* first inbound? reset the offset */ | |
6289 | if (inbound == 1) | |
6290 | offset = 0; | |
6291 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
6292 | offset += bde.tus.f.bdeSize; | |
6293 | } | |
4f774513 JS |
6294 | bpl++; |
6295 | sgl++; | |
6296 | } | |
6297 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
6298 | /* The addrHigh and addrLow fields of the BDE have not | |
6299 | * been byteswapped yet so they need to be swapped | |
6300 | * before putting them in the sgl. | |
6301 | */ | |
6302 | sgl->addr_hi = | |
6303 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
6304 | sgl->addr_lo = | |
6305 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
4f774513 JS |
6306 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
6307 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
6308 | sgl->sge_len = |
6309 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
6310 | } |
6311 | return sglq->sli4_xritag; | |
3772a991 | 6312 | } |
92d7f7b0 | 6313 | |
e59058c4 | 6314 | /** |
4f774513 | 6315 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 6316 | * @phba: Pointer to HBA context object. |
e59058c4 | 6317 | * |
a93ff37a | 6318 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
6319 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
6320 | * held. | |
4f774513 JS |
6321 | * |
6322 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 6323 | **/ |
4f774513 | 6324 | static uint32_t |
8fa38513 | 6325 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 6326 | { |
8fa38513 JS |
6327 | ++phba->fcp_qidx; |
6328 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) | |
6329 | phba->fcp_qidx = 0; | |
92d7f7b0 | 6330 | |
8fa38513 | 6331 | return phba->fcp_qidx; |
92d7f7b0 JS |
6332 | } |
6333 | ||
e59058c4 | 6334 | /** |
4f774513 | 6335 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 6336 | * @phba: Pointer to HBA context object. |
4f774513 JS |
6337 | * @piocb: Pointer to command iocb. |
6338 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 6339 | * |
4f774513 JS |
6340 | * This routine converts the iocb command to its Work Queue Entry |
6341 | * equivalent. The wqe pointer should not have any fields set when | |
6342 | * this routine is called because it will memcpy over them. | |
6343 | * This routine does not set the CQ_ID or the WQEC bits in the | |
6344 | * wqe. | |
e59058c4 | 6345 | * |
4f774513 | 6346 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 6347 | **/ |
cf5bf97e | 6348 | static int |
4f774513 JS |
6349 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
6350 | union lpfc_wqe *wqe) | |
cf5bf97e | 6351 | { |
5ffc266e | 6352 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
6353 | uint8_t ct = 0; |
6354 | uint32_t fip; | |
6355 | uint32_t abort_tag; | |
6356 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
6357 | uint8_t cmnd; | |
6358 | uint16_t xritag; | |
dcf2a4e0 JS |
6359 | uint16_t abrt_iotag; |
6360 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 6361 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 6362 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
6363 | int numBdes, i; |
6364 | struct ulp_bde64 bde; | |
4f774513 | 6365 | |
45ed1190 | 6366 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 6367 | /* The fcp commands will set command type */ |
0c287589 | 6368 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 6369 | command_type = FCP_COMMAND; |
c868595d | 6370 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
6371 | command_type = ELS_COMMAND_FIP; |
6372 | else | |
6373 | command_type = ELS_COMMAND_NON_FIP; | |
6374 | ||
4f774513 JS |
6375 | /* Some of the fields are in the right position already */ |
6376 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
6377 | abort_tag = (uint32_t) iocbq->iotag; | |
6378 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 6379 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
6380 | /* words0-2 bpl convert bde */ |
6381 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
6382 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
6383 | sizeof(struct ulp_bde64); | |
4f774513 JS |
6384 | bpl = (struct ulp_bde64 *) |
6385 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
6386 | if (!bpl) | |
6387 | return IOCB_ERROR; | |
cf5bf97e | 6388 | |
4f774513 JS |
6389 | /* Should already be byte swapped. */ |
6390 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
6391 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
6392 | /* swap the size field back to the cpu so we | |
6393 | * can assign it to the sgl. | |
6394 | */ | |
6395 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
6396 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
6397 | total_len = 0; | |
6398 | for (i = 0; i < numBdes; i++) { | |
6399 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
6400 | total_len += bde.tus.f.bdeSize; | |
6401 | } | |
4f774513 | 6402 | } else |
5ffc266e | 6403 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 6404 | |
4f774513 JS |
6405 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
6406 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 6407 | |
4f774513 JS |
6408 | switch (iocbq->iocb.ulpCommand) { |
6409 | case CMD_ELS_REQUEST64_CR: | |
6410 | if (!iocbq->iocb.ulpLe) { | |
6411 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6412 | "2007 Only Limited Edition cmd Format" | |
6413 | " supported 0x%x\n", | |
6414 | iocbq->iocb.ulpCommand); | |
6415 | return IOCB_ERROR; | |
6416 | } | |
5ffc266e | 6417 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
6418 | /* Els_reguest64 has a TMO */ |
6419 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
6420 | iocbq->iocb.ulpTimeout); | |
6421 | /* Need a VF for word 4 set the vf bit*/ | |
6422 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
6423 | /* And a VFID for word 12 */ | |
6424 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
6425 | /* | |
6426 | * Set ct field to 3, indicates that the context_tag field | |
6427 | * contains the FCFI and remote N_Port_ID is | |
6428 | * in word 5. | |
6429 | */ | |
4f774513 | 6430 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
6431 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
6432 | iocbq->iocb.ulpContext); | |
6433 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
6434 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 6435 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
c868595d JS |
6436 | if (command_type == ELS_COMMAND_FIP) { |
6437 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) | |
6438 | >> LPFC_FIP_ELS_ID_SHIFT); | |
6439 | } | |
f0d9bccc JS |
6440 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
6441 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
6442 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
6443 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
6444 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
6445 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
4f774513 | 6446 | break; |
5ffc266e | 6447 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
6448 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
6449 | iocbq->iocb.un.ulpWord[3]); | |
6450 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
6451 | iocbq->iocb.ulpContext); | |
5ffc266e JS |
6452 | /* The entire sequence is transmitted for this IOCB */ |
6453 | xmit_len = total_len; | |
6454 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
4f774513 | 6455 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
6456 | /* word3 iocb=io_tag32 wqe=reserved */ |
6457 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
6458 | /* word4 relative_offset memcpy */ |
6459 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
6460 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
6461 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
6462 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
6463 | LPFC_WQE_IOD_WRITE); | |
6464 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
6465 | LPFC_WQE_LENLOC_WORD12); | |
6466 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
6467 | wqe->xmit_sequence.xmit_len = xmit_len; |
6468 | command_type = OTHER_COMMAND; | |
4f774513 JS |
6469 | break; |
6470 | case CMD_XMIT_BCAST64_CN: | |
f0d9bccc JS |
6471 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
6472 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
6473 | /* word4 iocb=rsvd wqe=rsvd */ |
6474 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
6475 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 6476 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 6477 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
6478 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
6479 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
6480 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
6481 | LPFC_WQE_LENLOC_WORD3); | |
6482 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
4f774513 JS |
6483 | break; |
6484 | case CMD_FCP_IWRITE64_CR: | |
6485 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
6486 | /* word3 iocb=iotag wqe=payload_offset_len */ |
6487 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
6488 | wqe->fcp_iwrite.payload_offset_len = | |
6489 | xmit_len + sizeof(struct fcp_rsp); | |
6490 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
6491 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
6492 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
6493 | iocbq->iocb.ulpFCP2Rcvy); | |
6494 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
6495 | /* Always open the exchange */ | |
6496 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
6497 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
6498 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); | |
6499 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
6500 | LPFC_WQE_LENLOC_WORD4); | |
6501 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
6502 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
6503 | break; | |
4f774513 | 6504 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
6505 | /* word3 iocb=iotag wqe=payload_offset_len */ |
6506 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
6507 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 6508 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
6509 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
6510 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
6511 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
6512 | iocbq->iocb.ulpFCP2Rcvy); | |
6513 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
6514 | /* Always open the exchange */ |
6515 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
6516 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
6517 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); | |
6518 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
6519 | LPFC_WQE_LENLOC_WORD4); | |
6520 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
6521 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
6522 | break; | |
4f774513 | 6523 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
6524 | /* word3 iocb=IO_TAG wqe=reserved */ |
6525 | wqe->fcp_icmd.rsrvd3 = 0; | |
6526 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 6527 | /* Always open the exchange */ |
f0d9bccc JS |
6528 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
6529 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
6530 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
6531 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
6532 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
6533 | LPFC_WQE_LENLOC_NONE); | |
6534 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 JS |
6535 | break; |
6536 | case CMD_GEN_REQUEST64_CR: | |
63e801ce JS |
6537 | /* For this command calculate the xmit length of the |
6538 | * request bde. | |
6539 | */ | |
6540 | xmit_len = 0; | |
6541 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
6542 | sizeof(struct ulp_bde64); | |
6543 | for (i = 0; i < numBdes; i++) { | |
6544 | if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64) | |
6545 | break; | |
6546 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
6547 | xmit_len += bde.tus.f.bdeSize; | |
6548 | } | |
f0d9bccc JS |
6549 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
6550 | wqe->gen_req.request_payload_len = xmit_len; | |
6551 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
6552 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
6553 | /* word6 context tag copied in memcpy */ |
6554 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
6555 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
6556 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6557 | "2015 Invalid CT %x command 0x%x\n", | |
6558 | ct, iocbq->iocb.ulpCommand); | |
6559 | return IOCB_ERROR; | |
6560 | } | |
f0d9bccc JS |
6561 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
6562 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
6563 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
6564 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
6565 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
6566 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
6567 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
6568 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 JS |
6569 | command_type = OTHER_COMMAND; |
6570 | break; | |
6571 | case CMD_XMIT_ELS_RSP64_CX: | |
6572 | /* words0-2 BDE memcpy */ | |
f0d9bccc JS |
6573 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
6574 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
4f774513 | 6575 | /* word4 iocb=did wge=rsvd. */ |
f0d9bccc | 6576 | wqe->xmit_els_rsp.rsvd4 = 0; |
4f774513 JS |
6577 | /* word5 iocb=rsvd wge=did */ |
6578 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
6579 | iocbq->iocb.un.elsreq64.remoteID); | |
f0d9bccc JS |
6580 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
6581 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
6582 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
6583 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
6584 | iocbq->iocb.ulpContext); | |
4f774513 | 6585 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 6586 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
4f774513 | 6587 | iocbq->vport->vpi + phba->vpi_base); |
f0d9bccc JS |
6588 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
6589 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
6590 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
6591 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
6592 | LPFC_WQE_LENLOC_WORD3); | |
6593 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
4f774513 JS |
6594 | command_type = OTHER_COMMAND; |
6595 | break; | |
6596 | case CMD_CLOSE_XRI_CN: | |
6597 | case CMD_ABORT_XRI_CN: | |
6598 | case CMD_ABORT_XRI_CX: | |
6599 | /* words 0-2 memcpy should be 0 rserved */ | |
6600 | /* port will send abts */ | |
dcf2a4e0 JS |
6601 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
6602 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
6603 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
6604 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
6605 | } else | |
6606 | fip = 0; | |
6607 | ||
6608 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 6609 | /* |
dcf2a4e0 JS |
6610 | * The link is down, or the command was ELS_FIP |
6611 | * so the fw does not need to send abts | |
4f774513 JS |
6612 | * on the wire. |
6613 | */ | |
6614 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
6615 | else | |
6616 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
6617 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
6618 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
6619 | wqe->abort_cmd.rsrvd5 = 0; | |
6620 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
6621 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
6622 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
6623 | /* |
6624 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
6625 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
6626 | */ | |
f0d9bccc JS |
6627 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
6628 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
6629 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
6630 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
6631 | cmnd = CMD_ABORT_XRI_CX; |
6632 | command_type = OTHER_COMMAND; | |
6633 | xritag = 0; | |
6634 | break; | |
6669f9bb JS |
6635 | case CMD_XMIT_BLS_RSP64_CX: |
6636 | /* As BLS ABTS-ACC WQE is very different from other WQEs, | |
6637 | * we re-construct this WQE here based on information in | |
6638 | * iocbq from scratch. | |
6639 | */ | |
6640 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 6641 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 6642 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
5ffc266e JS |
6643 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc)); |
6644 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) == | |
6645 | LPFC_ABTS_UNSOL_INT) { | |
6646 | /* ABTS sent by initiator to CT exchange, the | |
6647 | * RX_ID field will be filled with the newly | |
6648 | * allocated responder XRI. | |
6649 | */ | |
6650 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6651 | iocbq->sli4_xritag); | |
6652 | } else { | |
6653 | /* ABTS sent by responder to CT exchange, the | |
6654 | * RX_ID field will be filled with the responder | |
6655 | * RX_ID from ABTS. | |
6656 | */ | |
6657 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6658 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc)); | |
6659 | } | |
6669f9bb JS |
6660 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
6661 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6662 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, | |
6663 | iocbq->iocb.ulpContext); | |
f0d9bccc JS |
6664 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
6665 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
6666 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
6667 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
6668 | command_type = OTHER_COMMAND; | |
6669 | break; | |
4f774513 JS |
6670 | case CMD_XRI_ABORTED_CX: |
6671 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
6672 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
6673 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
6674 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
6675 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
6676 | default: | |
6677 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6678 | "2014 Invalid command 0x%x\n", | |
6679 | iocbq->iocb.ulpCommand); | |
6680 | return IOCB_ERROR; | |
6681 | break; | |
4f774513 | 6682 | } |
f0d9bccc JS |
6683 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
6684 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
6685 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
6686 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
6687 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
6688 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
6689 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
6690 | return 0; |
6691 | } | |
6692 | ||
6693 | /** | |
6694 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
6695 | * @phba: Pointer to HBA context object. | |
6696 | * @ring_number: SLI ring number to issue iocb on. | |
6697 | * @piocb: Pointer to command iocb. | |
6698 | * @flag: Flag indicating if this command can be put into txq. | |
6699 | * | |
6700 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
6701 | * an iocb command to an HBA with SLI-4 interface spec. | |
6702 | * | |
6703 | * This function is called with hbalock held. The function will return success | |
6704 | * after it successfully submit the iocb to firmware or after adding to the | |
6705 | * txq. | |
6706 | **/ | |
6707 | static int | |
6708 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
6709 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6710 | { | |
6711 | struct lpfc_sglq *sglq; | |
4f774513 JS |
6712 | union lpfc_wqe wqe; |
6713 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
6714 | |
6715 | if (piocb->sli4_xritag == NO_XRI) { | |
6716 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6669f9bb | 6717 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
6718 | sglq = NULL; |
6719 | else { | |
2a9bf3d0 JS |
6720 | if (pring->txq_cnt) { |
6721 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6722 | __lpfc_sli_ringtx_put(phba, | |
6723 | pring, piocb); | |
6724 | return IOCB_SUCCESS; | |
6725 | } else { | |
6726 | return IOCB_BUSY; | |
6727 | } | |
6728 | } else { | |
19ca7609 | 6729 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
6730 | if (!sglq) { |
6731 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6732 | __lpfc_sli_ringtx_put(phba, | |
6733 | pring, | |
6734 | piocb); | |
6735 | return IOCB_SUCCESS; | |
6736 | } else | |
6737 | return IOCB_BUSY; | |
6738 | } | |
6739 | } | |
4f774513 JS |
6740 | } |
6741 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6742 | sglq = NULL; /* These IO's already have an XRI and | |
6743 | * a mapped sgl. | |
6744 | */ | |
6745 | } else { | |
6746 | /* This is a continuation of a commandi,(CX) so this | |
6747 | * sglq is on the active list | |
6748 | */ | |
6749 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
6750 | if (!sglq) | |
6751 | return IOCB_ERROR; | |
6752 | } | |
6753 | ||
6754 | if (sglq) { | |
2a9bf3d0 JS |
6755 | piocb->sli4_xritag = sglq->sli4_xritag; |
6756 | ||
6757 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) | |
4f774513 JS |
6758 | return IOCB_ERROR; |
6759 | } | |
6760 | ||
6761 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
6762 | return IOCB_ERROR; | |
6763 | ||
341af102 JS |
6764 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
6765 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
6766 | /* |
6767 | * For FCP command IOCB, get a new WQ index to distribute | |
6768 | * WQE across the WQsr. On the other hand, for abort IOCB, | |
6769 | * it carries the same WQ index to the original command | |
6770 | * IOCB. | |
6771 | */ | |
341af102 | 6772 | if (piocb->iocb_flag & LPFC_IO_FCP) |
5ffc266e JS |
6773 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
6774 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], | |
6775 | &wqe)) | |
4f774513 JS |
6776 | return IOCB_ERROR; |
6777 | } else { | |
6778 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
6779 | return IOCB_ERROR; | |
6780 | } | |
6781 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
6782 | ||
6783 | return 0; | |
6784 | } | |
6785 | ||
6786 | /** | |
6787 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
6788 | * | |
6789 | * This routine wraps the actual lockless version for issusing IOCB function | |
6790 | * pointer from the lpfc_hba struct. | |
6791 | * | |
6792 | * Return codes: | |
6793 | * IOCB_ERROR - Error | |
6794 | * IOCB_SUCCESS - Success | |
6795 | * IOCB_BUSY - Busy | |
6796 | **/ | |
2a9bf3d0 | 6797 | int |
4f774513 JS |
6798 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
6799 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6800 | { | |
6801 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6802 | } | |
6803 | ||
6804 | /** | |
6805 | * lpfc_sli_api_table_setup - Set up sli api fucntion jump table | |
6806 | * @phba: The hba struct for which this call is being executed. | |
6807 | * @dev_grp: The HBA PCI-Device group number. | |
6808 | * | |
6809 | * This routine sets up the SLI interface API function jump table in @phba | |
6810 | * struct. | |
6811 | * Returns: 0 - success, -ENODEV - failure. | |
6812 | **/ | |
6813 | int | |
6814 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6815 | { | |
6816 | ||
6817 | switch (dev_grp) { | |
6818 | case LPFC_PCI_DEV_LP: | |
6819 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
6820 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
6821 | break; | |
6822 | case LPFC_PCI_DEV_OC: | |
6823 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
6824 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
6825 | break; | |
6826 | default: | |
6827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6828 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
6829 | dev_grp); | |
6830 | return -ENODEV; | |
6831 | break; | |
6832 | } | |
6833 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
6834 | return 0; | |
6835 | } | |
6836 | ||
6837 | /** | |
6838 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
6839 | * @phba: Pointer to HBA context object. | |
6840 | * @pring: Pointer to driver SLI ring object. | |
6841 | * @piocb: Pointer to command iocb. | |
6842 | * @flag: Flag indicating if this command can be put into txq. | |
6843 | * | |
6844 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
6845 | * function. This function gets the hbalock and calls | |
6846 | * __lpfc_sli_issue_iocb function and will return the error returned | |
6847 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
6848 | * functions which do not hold hbalock. | |
6849 | **/ | |
6850 | int | |
6851 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
6852 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6853 | { | |
6854 | unsigned long iflags; | |
6855 | int rc; | |
6856 | ||
6857 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6858 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6859 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6860 | ||
6861 | return rc; | |
6862 | } | |
6863 | ||
6864 | /** | |
6865 | * lpfc_extra_ring_setup - Extra ring setup function | |
6866 | * @phba: Pointer to HBA context object. | |
6867 | * | |
6868 | * This function is called while driver attaches with the | |
6869 | * HBA to setup the extra ring. The extra ring is used | |
6870 | * only when driver needs to support target mode functionality | |
6871 | * or IP over FC functionalities. | |
6872 | * | |
6873 | * This function is called with no lock held. | |
6874 | **/ | |
6875 | static int | |
6876 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
6877 | { | |
6878 | struct lpfc_sli *psli; | |
6879 | struct lpfc_sli_ring *pring; | |
6880 | ||
6881 | psli = &phba->sli; | |
6882 | ||
6883 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
6884 | ||
6885 | /* Take some away from the FCP ring */ | |
6886 | pring = &psli->ring[psli->fcp_ring]; | |
6887 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
6888 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
cf5bf97e JW |
6889 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
6890 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6891 | ||
a4bc3379 JS |
6892 | /* and give them to the extra ring */ |
6893 | pring = &psli->ring[psli->extra_ring]; | |
6894 | ||
cf5bf97e JW |
6895 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
6896 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
6897 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
6898 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6899 | ||
6900 | /* Setup default profile for this ring */ | |
6901 | pring->iotag_max = 4096; | |
6902 | pring->num_mask = 1; | |
6903 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
6904 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
6905 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
6906 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
6907 | return 0; | |
6908 | } | |
6909 | ||
e59058c4 | 6910 | /** |
3621a710 | 6911 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
6912 | * @phba: Pointer to HBA context object. |
6913 | * @pring: Pointer to driver SLI ring object. | |
6914 | * @iocbq: Pointer to iocb object. | |
6915 | * | |
6916 | * This function is called by the slow ring event handler | |
6917 | * function when there is an ASYNC event iocb in the ring. | |
6918 | * This function is called with no lock held. | |
6919 | * Currently this function handles only temperature related | |
6920 | * ASYNC events. The function decodes the temperature sensor | |
6921 | * event message and posts events for the management applications. | |
6922 | **/ | |
98c9ea5c | 6923 | static void |
57127f15 JS |
6924 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
6925 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
6926 | { | |
6927 | IOCB_t *icmd; | |
6928 | uint16_t evt_code; | |
6929 | uint16_t temp; | |
6930 | struct temp_event temp_event_data; | |
6931 | struct Scsi_Host *shost; | |
a257bf90 | 6932 | uint32_t *iocb_w; |
57127f15 JS |
6933 | |
6934 | icmd = &iocbq->iocb; | |
6935 | evt_code = icmd->un.asyncstat.evt_code; | |
6936 | temp = icmd->ulpContext; | |
6937 | ||
6938 | if ((evt_code != ASYNC_TEMP_WARN) && | |
6939 | (evt_code != ASYNC_TEMP_SAFE)) { | |
a257bf90 | 6940 | iocb_w = (uint32_t *) icmd; |
57127f15 JS |
6941 | lpfc_printf_log(phba, |
6942 | KERN_ERR, | |
6943 | LOG_SLI, | |
76bb24ef | 6944 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 6945 | " evt_code 0x%x\n" |
a257bf90 JS |
6946 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
6947 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
6948 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
6949 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
57127f15 | 6950 | pring->ringno, |
a257bf90 JS |
6951 | icmd->un.asyncstat.evt_code, |
6952 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], | |
6953 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
6954 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
6955 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
6956 | ||
57127f15 JS |
6957 | return; |
6958 | } | |
6959 | temp_event_data.data = (uint32_t)temp; | |
6960 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
6961 | if (evt_code == ASYNC_TEMP_WARN) { | |
6962 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
6963 | lpfc_printf_log(phba, | |
09372820 | 6964 | KERN_ERR, |
57127f15 | 6965 | LOG_TEMP, |
76bb24ef | 6966 | "0347 Adapter is very hot, please take " |
57127f15 JS |
6967 | "corrective action. temperature : %d Celsius\n", |
6968 | temp); | |
6969 | } | |
6970 | if (evt_code == ASYNC_TEMP_SAFE) { | |
6971 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
6972 | lpfc_printf_log(phba, | |
09372820 | 6973 | KERN_ERR, |
57127f15 JS |
6974 | LOG_TEMP, |
6975 | "0340 Adapter temperature is OK now. " | |
6976 | "temperature : %d Celsius\n", | |
6977 | temp); | |
6978 | } | |
6979 | ||
6980 | /* Send temperature change event to applications */ | |
6981 | shost = lpfc_shost_from_vport(phba->pport); | |
6982 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
6983 | sizeof(temp_event_data), (char *) &temp_event_data, | |
ddcc50f0 | 6984 | LPFC_NL_VENDOR_ID); |
57127f15 JS |
6985 | |
6986 | } | |
6987 | ||
6988 | ||
e59058c4 | 6989 | /** |
3621a710 | 6990 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
6991 | * @phba: Pointer to HBA context object. |
6992 | * | |
6993 | * lpfc_sli_setup sets up rings of the SLI interface with | |
6994 | * number of iocbs per ring and iotags. This function is | |
6995 | * called while driver attach to the HBA and before the | |
6996 | * interrupts are enabled. So there is no need for locking. | |
6997 | * | |
6998 | * This function always returns 0. | |
6999 | **/ | |
dea3101e | 7000 | int |
7001 | lpfc_sli_setup(struct lpfc_hba *phba) | |
7002 | { | |
ed957684 | 7003 | int i, totiocbsize = 0; |
dea3101e | 7004 | struct lpfc_sli *psli = &phba->sli; |
7005 | struct lpfc_sli_ring *pring; | |
7006 | ||
7007 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
7008 | psli->sli_flag = 0; | |
7009 | psli->fcp_ring = LPFC_FCP_RING; | |
7010 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 7011 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 7012 | |
604a3e30 JB |
7013 | psli->iocbq_lookup = NULL; |
7014 | psli->iocbq_lookup_len = 0; | |
7015 | psli->last_iotag = 0; | |
7016 | ||
dea3101e | 7017 | for (i = 0; i < psli->num_rings; i++) { |
7018 | pring = &psli->ring[i]; | |
7019 | switch (i) { | |
7020 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
7021 | /* numCiocb and numRiocb are used in config_port */ | |
7022 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
7023 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
7024 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
7025 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
7026 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
7027 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 7028 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7029 | SLI3_IOCB_CMD_SIZE : |
7030 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7031 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7032 | SLI3_IOCB_RSP_SIZE : |
7033 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 7034 | pring->iotag_ctr = 0; |
7035 | pring->iotag_max = | |
92d7f7b0 | 7036 | (phba->cfg_hba_queue_depth * 2); |
dea3101e | 7037 | pring->fast_iotag = pring->iotag_max; |
7038 | pring->num_mask = 0; | |
7039 | break; | |
a4bc3379 | 7040 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e | 7041 | /* numCiocb and numRiocb are used in config_port */ |
7042 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
7043 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 7044 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7045 | SLI3_IOCB_CMD_SIZE : |
7046 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7047 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7048 | SLI3_IOCB_RSP_SIZE : |
7049 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 7050 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e | 7051 | pring->num_mask = 0; |
7052 | break; | |
7053 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
7054 | /* numCiocb and numRiocb are used in config_port */ | |
7055 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
7056 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 7057 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7058 | SLI3_IOCB_CMD_SIZE : |
7059 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7060 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7061 | SLI3_IOCB_RSP_SIZE : |
7062 | SLI2_IOCB_RSP_SIZE; | |
dea3101e | 7063 | pring->fast_iotag = 0; |
7064 | pring->iotag_ctr = 0; | |
7065 | pring->iotag_max = 4096; | |
57127f15 JS |
7066 | pring->lpfc_sli_rcv_async_status = |
7067 | lpfc_sli_async_event_handler; | |
6669f9bb | 7068 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 7069 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
7070 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
7071 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 7072 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7073 | lpfc_els_unsol_event; |
dea3101e | 7074 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
7075 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
7076 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 7077 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7078 | lpfc_els_unsol_event; |
dea3101e | 7079 | pring->prt[2].profile = 0; /* Mask 2 */ |
7080 | /* NameServer Inquiry */ | |
6a9c52cf | 7081 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 7082 | /* NameServer */ |
6a9c52cf | 7083 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 7084 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7085 | lpfc_ct_unsol_event; |
dea3101e | 7086 | pring->prt[3].profile = 0; /* Mask 3 */ |
7087 | /* NameServer response */ | |
6a9c52cf | 7088 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 7089 | /* NameServer */ |
6a9c52cf | 7090 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 7091 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7092 | lpfc_ct_unsol_event; |
6669f9bb JS |
7093 | /* abort unsolicited sequence */ |
7094 | pring->prt[4].profile = 0; /* Mask 4 */ | |
7095 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
7096 | pring->prt[4].type = FC_TYPE_BLS; | |
7097 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
7098 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e | 7099 | break; |
7100 | } | |
ed957684 | 7101 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 7102 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 7103 | } |
ed957684 | 7104 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 7105 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
7106 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
7107 | "SLI2 SLIM Data: x%x x%lx\n", | |
7108 | phba->brd_no, totiocbsize, | |
7109 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 7110 | } |
cf5bf97e JW |
7111 | if (phba->cfg_multi_ring_support == 2) |
7112 | lpfc_extra_ring_setup(phba); | |
dea3101e | 7113 | |
7114 | return 0; | |
7115 | } | |
7116 | ||
e59058c4 | 7117 | /** |
3621a710 | 7118 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
7119 | * @phba: Pointer to HBA context object. |
7120 | * | |
7121 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
7122 | * ring. This function also initializes ring indices of each ring. | |
7123 | * This function is called during the initialization of the SLI | |
7124 | * interface of an HBA. | |
7125 | * This function is called with no lock held and always returns | |
7126 | * 1. | |
7127 | **/ | |
dea3101e | 7128 | int |
2e0fef85 | 7129 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e | 7130 | { |
7131 | struct lpfc_sli *psli; | |
7132 | struct lpfc_sli_ring *pring; | |
604a3e30 | 7133 | int i; |
dea3101e | 7134 | |
7135 | psli = &phba->sli; | |
2e0fef85 | 7136 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7137 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 7138 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e | 7139 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
7140 | for (i = 0; i < psli->num_rings; i++) { | |
7141 | pring = &psli->ring[i]; | |
7142 | pring->ringno = i; | |
7143 | pring->next_cmdidx = 0; | |
7144 | pring->local_getidx = 0; | |
7145 | pring->cmdidx = 0; | |
7146 | INIT_LIST_HEAD(&pring->txq); | |
7147 | INIT_LIST_HEAD(&pring->txcmplq); | |
7148 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 7149 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 7150 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 7151 | } |
2e0fef85 JS |
7152 | spin_unlock_irq(&phba->hbalock); |
7153 | return 1; | |
dea3101e | 7154 | } |
7155 | ||
04c68496 JS |
7156 | /** |
7157 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
7158 | * @phba: Pointer to HBA context object. | |
7159 | * | |
7160 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
7161 | * flush all the mailbox commands in the three possible stages in the mailbox | |
7162 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
7163 | * command; and completed mailbox command queue. It is caller's responsibility | |
7164 | * to make sure that the driver is in the proper state to flush the mailbox | |
7165 | * command sub-system. Namely, the posting of mailbox commands into the | |
7166 | * pending mailbox command queue from the various clients must be stopped; | |
7167 | * either the HBA is in a state that it will never works on the outstanding | |
7168 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
7169 | * mailbox command has been completed. | |
7170 | **/ | |
7171 | static void | |
7172 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
7173 | { | |
7174 | LIST_HEAD(completions); | |
7175 | struct lpfc_sli *psli = &phba->sli; | |
7176 | LPFC_MBOXQ_t *pmb; | |
7177 | unsigned long iflag; | |
7178 | ||
7179 | /* Flush all the mailbox commands in the mbox system */ | |
7180 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7181 | /* The pending mailbox command queue */ | |
7182 | list_splice_init(&phba->sli.mboxq, &completions); | |
7183 | /* The outstanding active mailbox command */ | |
7184 | if (psli->mbox_active) { | |
7185 | list_add_tail(&psli->mbox_active->list, &completions); | |
7186 | psli->mbox_active = NULL; | |
7187 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7188 | } | |
7189 | /* The completed mailbox command queue */ | |
7190 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
7191 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7192 | ||
7193 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
7194 | while (!list_empty(&completions)) { | |
7195 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
7196 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7197 | if (pmb->mbox_cmpl) | |
7198 | pmb->mbox_cmpl(phba, pmb); | |
7199 | } | |
7200 | } | |
7201 | ||
e59058c4 | 7202 | /** |
3621a710 | 7203 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
7204 | * @vport: Pointer to virtual port object. |
7205 | * | |
7206 | * lpfc_sli_host_down is called to clean up the resources | |
7207 | * associated with a vport before destroying virtual | |
7208 | * port data structures. | |
7209 | * This function does following operations: | |
7210 | * - Free discovery resources associated with this virtual | |
7211 | * port. | |
7212 | * - Free iocbs associated with this virtual port in | |
7213 | * the txq. | |
7214 | * - Send abort for all iocb commands associated with this | |
7215 | * vport in txcmplq. | |
7216 | * | |
7217 | * This function is called with no lock held and always returns 1. | |
7218 | **/ | |
92d7f7b0 JS |
7219 | int |
7220 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
7221 | { | |
858c9f6c | 7222 | LIST_HEAD(completions); |
92d7f7b0 JS |
7223 | struct lpfc_hba *phba = vport->phba; |
7224 | struct lpfc_sli *psli = &phba->sli; | |
7225 | struct lpfc_sli_ring *pring; | |
7226 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
7227 | int i; |
7228 | unsigned long flags = 0; | |
7229 | uint16_t prev_pring_flag; | |
7230 | ||
7231 | lpfc_cleanup_discovery_resources(vport); | |
7232 | ||
7233 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
7234 | for (i = 0; i < psli->num_rings; i++) { |
7235 | pring = &psli->ring[i]; | |
7236 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
7237 | /* Only slow rings */ |
7238 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 7239 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
7240 | /* Set the lpfc data pending flag */ |
7241 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
7242 | } | |
92d7f7b0 JS |
7243 | /* |
7244 | * Error everything on the txq since these iocbs have not been | |
7245 | * given to the FW yet. | |
7246 | */ | |
92d7f7b0 JS |
7247 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
7248 | if (iocb->vport != vport) | |
7249 | continue; | |
858c9f6c | 7250 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 7251 | pring->txq_cnt--; |
92d7f7b0 JS |
7252 | } |
7253 | ||
7254 | /* Next issue ABTS for everything on the txcmplq */ | |
7255 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
7256 | list) { | |
7257 | if (iocb->vport != vport) | |
7258 | continue; | |
7259 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
7260 | } | |
7261 | ||
7262 | pring->flag = prev_pring_flag; | |
7263 | } | |
7264 | ||
7265 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
7266 | ||
a257bf90 JS |
7267 | /* Cancel all the IOCBs from the completions list */ |
7268 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7269 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
7270 | return 1; |
7271 | } | |
7272 | ||
e59058c4 | 7273 | /** |
3621a710 | 7274 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
7275 | * @phba: Pointer to HBA context object. |
7276 | * | |
7277 | * This function cleans up all iocb, buffers, mailbox commands | |
7278 | * while shutting down the HBA. This function is called with no | |
7279 | * lock held and always returns 1. | |
7280 | * This function does the following to cleanup driver resources: | |
7281 | * - Free discovery resources for each virtual port | |
7282 | * - Cleanup any pending fabric iocbs | |
7283 | * - Iterate through the iocb txq and free each entry | |
7284 | * in the list. | |
7285 | * - Free up any buffer posted to the HBA | |
7286 | * - Free mailbox commands in the mailbox queue. | |
7287 | **/ | |
dea3101e | 7288 | int |
2e0fef85 | 7289 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 7290 | { |
2534ba75 | 7291 | LIST_HEAD(completions); |
2e0fef85 | 7292 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 7293 | struct lpfc_sli_ring *pring; |
0ff10d46 | 7294 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 7295 | unsigned long flags = 0; |
04c68496 JS |
7296 | int i; |
7297 | ||
7298 | /* Shutdown the mailbox command sub-system */ | |
7299 | lpfc_sli_mbox_sys_shutdown(phba); | |
dea3101e | 7300 | |
dea3101e | 7301 | lpfc_hba_down_prep(phba); |
7302 | ||
92d7f7b0 JS |
7303 | lpfc_fabric_abort_hba(phba); |
7304 | ||
2e0fef85 | 7305 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e | 7306 | for (i = 0; i < psli->num_rings; i++) { |
7307 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
7308 | /* Only slow rings */ |
7309 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 7310 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
7311 | /* Set the lpfc data pending flag */ |
7312 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
7313 | } | |
dea3101e | 7314 | |
7315 | /* | |
7316 | * Error everything on the txq since these iocbs have not been | |
7317 | * given to the FW yet. | |
7318 | */ | |
2534ba75 | 7319 | list_splice_init(&pring->txq, &completions); |
dea3101e | 7320 | pring->txq_cnt = 0; |
7321 | ||
2534ba75 | 7322 | } |
2e0fef85 | 7323 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 7324 | |
a257bf90 JS |
7325 | /* Cancel all the IOCBs from the completions list */ |
7326 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7327 | IOERR_SLI_DOWN); | |
dea3101e | 7328 | |
0ff10d46 JS |
7329 | spin_lock_irqsave(&phba->hbalock, flags); |
7330 | list_splice_init(&phba->elsbuf, &completions); | |
7331 | phba->elsbuf_cnt = 0; | |
7332 | phba->elsbuf_prev_cnt = 0; | |
7333 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
7334 | ||
7335 | while (!list_empty(&completions)) { | |
7336 | list_remove_head(&completions, buf_ptr, | |
7337 | struct lpfc_dmabuf, list); | |
7338 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
7339 | kfree(buf_ptr); | |
7340 | } | |
7341 | ||
dea3101e | 7342 | /* Return any active mbox cmds */ |
7343 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 7344 | |
da0436e9 | 7345 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 7346 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 7347 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 7348 | |
da0436e9 JS |
7349 | return 1; |
7350 | } | |
7351 | ||
e59058c4 | 7352 | /** |
3621a710 | 7353 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
7354 | * @srcp: Source memory pointer. |
7355 | * @destp: Destination memory pointer. | |
7356 | * @cnt: Number of words required to be copied. | |
7357 | * | |
7358 | * This function is used for copying data between driver memory | |
7359 | * and the SLI memory. This function also changes the endianness | |
7360 | * of each word if native endianness is different from SLI | |
7361 | * endianness. This function can be called with or without | |
7362 | * lock. | |
7363 | **/ | |
dea3101e | 7364 | void |
7365 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
7366 | { | |
7367 | uint32_t *src = srcp; | |
7368 | uint32_t *dest = destp; | |
7369 | uint32_t ldata; | |
7370 | int i; | |
7371 | ||
7372 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
7373 | ldata = *src; | |
7374 | ldata = le32_to_cpu(ldata); | |
7375 | *dest = ldata; | |
7376 | src++; | |
7377 | dest++; | |
7378 | } | |
7379 | } | |
7380 | ||
e59058c4 | 7381 | |
a0c87cbd JS |
7382 | /** |
7383 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
7384 | * @srcp: Source memory pointer. | |
7385 | * @destp: Destination memory pointer. | |
7386 | * @cnt: Number of words required to be copied. | |
7387 | * | |
7388 | * This function is used for copying data between a data structure | |
7389 | * with big endian representation to local endianness. | |
7390 | * This function can be called with or without lock. | |
7391 | **/ | |
7392 | void | |
7393 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
7394 | { | |
7395 | uint32_t *src = srcp; | |
7396 | uint32_t *dest = destp; | |
7397 | uint32_t ldata; | |
7398 | int i; | |
7399 | ||
7400 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
7401 | ldata = *src; | |
7402 | ldata = be32_to_cpu(ldata); | |
7403 | *dest = ldata; | |
7404 | src++; | |
7405 | dest++; | |
7406 | } | |
7407 | } | |
7408 | ||
e59058c4 | 7409 | /** |
3621a710 | 7410 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
7411 | * @phba: Pointer to HBA context object. |
7412 | * @pring: Pointer to driver SLI ring object. | |
7413 | * @mp: Pointer to driver buffer object. | |
7414 | * | |
7415 | * This function is called with no lock held. | |
7416 | * It always return zero after adding the buffer to the postbufq | |
7417 | * buffer list. | |
7418 | **/ | |
dea3101e | 7419 | int |
2e0fef85 JS |
7420 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
7421 | struct lpfc_dmabuf *mp) | |
dea3101e | 7422 | { |
7423 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
7424 | later */ | |
2e0fef85 | 7425 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7426 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 7427 | pring->postbufq_cnt++; |
2e0fef85 | 7428 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7429 | return 0; |
7430 | } | |
7431 | ||
e59058c4 | 7432 | /** |
3621a710 | 7433 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
7434 | * @phba: Pointer to HBA context object. |
7435 | * | |
7436 | * When HBQ is enabled, buffers are searched based on tags. This function | |
7437 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
7438 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
7439 | * does not conflict with tags of buffer posted for unsolicited events. | |
7440 | * The function returns the allocated tag. The function is called with | |
7441 | * no locks held. | |
7442 | **/ | |
76bb24ef JS |
7443 | uint32_t |
7444 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
7445 | { | |
7446 | spin_lock_irq(&phba->hbalock); | |
7447 | phba->buffer_tag_count++; | |
7448 | /* | |
7449 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
7450 | * a tag assigned by HBQ. | |
7451 | */ | |
7452 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
7453 | spin_unlock_irq(&phba->hbalock); | |
7454 | return phba->buffer_tag_count; | |
7455 | } | |
7456 | ||
e59058c4 | 7457 | /** |
3621a710 | 7458 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
7459 | * @phba: Pointer to HBA context object. |
7460 | * @pring: Pointer to driver SLI ring object. | |
7461 | * @tag: Buffer tag. | |
7462 | * | |
7463 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
7464 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
7465 | * iocb is posted to the response ring with the tag of the buffer. | |
7466 | * This function searches the pring->postbufq list using the tag | |
7467 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
7468 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
7469 | * buffer is returned to the caller else NULL is returned. | |
7470 | * This function is called with no lock held. | |
7471 | **/ | |
76bb24ef JS |
7472 | struct lpfc_dmabuf * |
7473 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7474 | uint32_t tag) | |
7475 | { | |
7476 | struct lpfc_dmabuf *mp, *next_mp; | |
7477 | struct list_head *slp = &pring->postbufq; | |
7478 | ||
7479 | /* Search postbufq, from the begining, looking for a match on tag */ | |
7480 | spin_lock_irq(&phba->hbalock); | |
7481 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
7482 | if (mp->buffer_tag == tag) { | |
7483 | list_del_init(&mp->list); | |
7484 | pring->postbufq_cnt--; | |
7485 | spin_unlock_irq(&phba->hbalock); | |
7486 | return mp; | |
7487 | } | |
7488 | } | |
7489 | ||
7490 | spin_unlock_irq(&phba->hbalock); | |
7491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 7492 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
7493 | "ring %d Data x%lx x%p x%p x%x\n", |
7494 | pring->ringno, (unsigned long) tag, | |
7495 | slp->next, slp->prev, pring->postbufq_cnt); | |
7496 | ||
7497 | return NULL; | |
7498 | } | |
dea3101e | 7499 | |
e59058c4 | 7500 | /** |
3621a710 | 7501 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
7502 | * @phba: Pointer to HBA context object. |
7503 | * @pring: Pointer to driver SLI ring object. | |
7504 | * @phys: DMA address of the buffer. | |
7505 | * | |
7506 | * This function searches the buffer list using the dma_address | |
7507 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
7508 | * corresponding to the dma_address. The function returns the | |
7509 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
7510 | * This function is called by the ct and els unsolicited event | |
7511 | * handlers to get the buffer associated with the unsolicited | |
7512 | * event. | |
7513 | * | |
7514 | * This function is called with no lock held. | |
7515 | **/ | |
dea3101e | 7516 | struct lpfc_dmabuf * |
7517 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7518 | dma_addr_t phys) | |
7519 | { | |
7520 | struct lpfc_dmabuf *mp, *next_mp; | |
7521 | struct list_head *slp = &pring->postbufq; | |
7522 | ||
7523 | /* Search postbufq, from the begining, looking for a match on phys */ | |
2e0fef85 | 7524 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7525 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
7526 | if (mp->phys == phys) { | |
7527 | list_del_init(&mp->list); | |
7528 | pring->postbufq_cnt--; | |
2e0fef85 | 7529 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7530 | return mp; |
7531 | } | |
7532 | } | |
7533 | ||
2e0fef85 | 7534 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7535 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 7536 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 7537 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 7538 | pring->ringno, (unsigned long long)phys, |
dea3101e | 7539 | slp->next, slp->prev, pring->postbufq_cnt); |
7540 | return NULL; | |
7541 | } | |
7542 | ||
e59058c4 | 7543 | /** |
3621a710 | 7544 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
7545 | * @phba: Pointer to HBA context object. |
7546 | * @cmdiocb: Pointer to driver command iocb object. | |
7547 | * @rspiocb: Pointer to driver response iocb object. | |
7548 | * | |
7549 | * This function is the completion handler for the abort iocbs for | |
7550 | * ELS commands. This function is called from the ELS ring event | |
7551 | * handler with no lock held. This function frees memory resources | |
7552 | * associated with the abort iocb. | |
7553 | **/ | |
dea3101e | 7554 | static void |
2e0fef85 JS |
7555 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7556 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 7557 | { |
2e0fef85 | 7558 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 7559 | uint16_t abort_iotag, abort_context; |
92d7f7b0 | 7560 | struct lpfc_iocbq *abort_iocb; |
2680eeaa JS |
7561 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
7562 | ||
7563 | abort_iocb = NULL; | |
2680eeaa JS |
7564 | |
7565 | if (irsp->ulpStatus) { | |
7566 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | |
7567 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
7568 | ||
2e0fef85 | 7569 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
7570 | if (phba->sli_rev < LPFC_SLI_REV4) { |
7571 | if (abort_iotag != 0 && | |
7572 | abort_iotag <= phba->sli.last_iotag) | |
7573 | abort_iocb = | |
7574 | phba->sli.iocbq_lookup[abort_iotag]; | |
7575 | } else | |
7576 | /* For sli4 the abort_tag is the XRI, | |
7577 | * so the abort routine puts the iotag of the iocb | |
7578 | * being aborted in the context field of the abort | |
7579 | * IOCB. | |
7580 | */ | |
7581 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 7582 | |
58da1ffb JS |
7583 | /* |
7584 | * If the iocb is not found in Firmware queue the iocb | |
7585 | * might have completed already. Do not free it again. | |
7586 | */ | |
9b379605 | 7587 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
45ed1190 JS |
7588 | if (irsp->un.ulpWord[4] != IOERR_NO_XRI) { |
7589 | spin_unlock_irq(&phba->hbalock); | |
7590 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
7591 | return; | |
7592 | } | |
7593 | /* For SLI4 the ulpContext field for abort IOCB | |
7594 | * holds the iotag of the IOCB being aborted so | |
7595 | * the local abort_context needs to be reset to | |
7596 | * match the aborted IOCBs ulpContext. | |
7597 | */ | |
7598 | if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4) | |
7599 | abort_context = abort_iocb->iocb.ulpContext; | |
58da1ffb | 7600 | } |
2a9bf3d0 JS |
7601 | |
7602 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, | |
7603 | "0327 Cannot abort els iocb %p " | |
7604 | "with tag %x context %x, abort status %x, " | |
7605 | "abort code %x\n", | |
7606 | abort_iocb, abort_iotag, abort_context, | |
7607 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
2680eeaa JS |
7608 | /* |
7609 | * make sure we have the right iocbq before taking it | |
7610 | * off the txcmplq and try to call completion routine. | |
7611 | */ | |
2e0fef85 JS |
7612 | if (!abort_iocb || |
7613 | abort_iocb->iocb.ulpContext != abort_context || | |
7614 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | |
7615 | spin_unlock_irq(&phba->hbalock); | |
341af102 JS |
7616 | else if (phba->sli_rev < LPFC_SLI_REV4) { |
7617 | /* | |
7618 | * leave the SLI4 aborted command on the txcmplq | |
7619 | * list and the command complete WCQE's XB bit | |
7620 | * will tell whether the SGL (XRI) can be released | |
7621 | * immediately or to the aborted SGL list for the | |
7622 | * following abort XRI from the HBA. | |
7623 | */ | |
92d7f7b0 | 7624 | list_del_init(&abort_iocb->list); |
2a9bf3d0 JS |
7625 | if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) { |
7626 | abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
7627 | pring->txcmplq_cnt--; | |
7628 | } | |
2680eeaa | 7629 | |
0ff10d46 JS |
7630 | /* Firmware could still be in progress of DMAing |
7631 | * payload, so don't free data buffer till after | |
7632 | * a hbeat. | |
7633 | */ | |
7634 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
92d7f7b0 | 7635 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
341af102 JS |
7636 | spin_unlock_irq(&phba->hbalock); |
7637 | ||
92d7f7b0 | 7638 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
341af102 | 7639 | abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED; |
92d7f7b0 | 7640 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
49198b37 JS |
7641 | } else |
7642 | spin_unlock_irq(&phba->hbalock); | |
2680eeaa JS |
7643 | } |
7644 | ||
604a3e30 | 7645 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e | 7646 | return; |
7647 | } | |
7648 | ||
e59058c4 | 7649 | /** |
3621a710 | 7650 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
7651 | * @phba: Pointer to HBA context object. |
7652 | * @cmdiocb: Pointer to driver command iocb object. | |
7653 | * @rspiocb: Pointer to driver response iocb object. | |
7654 | * | |
7655 | * The function is called from SLI ring event handler with no | |
7656 | * lock held. This function is the completion handler for ELS commands | |
7657 | * which are aborted. The function frees memory resources used for | |
7658 | * the aborted ELS commands. | |
7659 | **/ | |
92d7f7b0 JS |
7660 | static void |
7661 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
7662 | struct lpfc_iocbq *rspiocb) | |
7663 | { | |
7664 | IOCB_t *irsp = &rspiocb->iocb; | |
7665 | ||
7666 | /* ELS cmd tag <ulpIoTag> completes */ | |
7667 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 7668 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 7669 | "x%x x%x x%x\n", |
e8b62011 | 7670 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 7671 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
7672 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
7673 | lpfc_ct_free_iocb(phba, cmdiocb); | |
7674 | else | |
7675 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
7676 | return; |
7677 | } | |
7678 | ||
e59058c4 | 7679 | /** |
5af5eee7 | 7680 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
7681 | * @phba: Pointer to HBA context object. |
7682 | * @pring: Pointer to driver SLI ring object. | |
7683 | * @cmdiocb: Pointer to driver command iocb object. | |
7684 | * | |
5af5eee7 JS |
7685 | * This function issues an abort iocb for the provided command iocb down to |
7686 | * the port. Other than the case the outstanding command iocb is an abort | |
7687 | * request, this function issues abort out unconditionally. This function is | |
7688 | * called with hbalock held. The function returns 0 when it fails due to | |
7689 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 7690 | **/ |
5af5eee7 JS |
7691 | static int |
7692 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7693 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 7694 | { |
2e0fef85 | 7695 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 7696 | struct lpfc_iocbq *abtsiocbp; |
dea3101e | 7697 | IOCB_t *icmd = NULL; |
7698 | IOCB_t *iabt = NULL; | |
5af5eee7 | 7699 | int retval; |
07951076 | 7700 | |
92d7f7b0 JS |
7701 | /* |
7702 | * There are certain command types we don't want to abort. And we | |
7703 | * don't want to abort commands that are already in the process of | |
7704 | * being aborted. | |
07951076 JS |
7705 | */ |
7706 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 7707 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
7708 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
7709 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
7710 | return 0; |
7711 | ||
dea3101e | 7712 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 7713 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e | 7714 | if (abtsiocbp == NULL) |
7715 | return 0; | |
dea3101e | 7716 | |
07951076 | 7717 | /* This signals the response to set the correct status |
341af102 | 7718 | * before calling the completion handler |
07951076 JS |
7719 | */ |
7720 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
7721 | ||
dea3101e | 7722 | iabt = &abtsiocbp->iocb; |
07951076 JS |
7723 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
7724 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 7725 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 7726 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
7727 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
7728 | } | |
da0436e9 JS |
7729 | else |
7730 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
7731 | iabt->ulpLe = 1; |
7732 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 7733 | |
5ffc266e JS |
7734 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
7735 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
7736 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
7737 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 7738 | |
2e0fef85 | 7739 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
7740 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
7741 | else | |
7742 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 7743 | |
07951076 | 7744 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 7745 | |
e8b62011 JS |
7746 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
7747 | "0339 Abort xri x%x, original iotag x%x, " | |
7748 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 7749 | iabt->un.acxri.abortIoTag, |
e8b62011 | 7750 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 7751 | abtsiocbp->iotag); |
da0436e9 | 7752 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
dea3101e | 7753 | |
d7c255b2 JS |
7754 | if (retval) |
7755 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
7756 | |
7757 | /* | |
7758 | * Caller to this routine should check for IOCB_ERROR | |
7759 | * and handle it properly. This routine no longer removes | |
7760 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
7761 | */ | |
7762 | return retval; | |
7763 | } | |
7764 | ||
7765 | /** | |
7766 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
7767 | * @phba: Pointer to HBA context object. | |
7768 | * @pring: Pointer to driver SLI ring object. | |
7769 | * @cmdiocb: Pointer to driver command iocb object. | |
7770 | * | |
7771 | * This function issues an abort iocb for the provided command iocb. In case | |
7772 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
7773 | * ring. Instead, the callback function shall be changed to those commands | |
7774 | * so that nothing happens when them finishes. This function is called with | |
7775 | * hbalock held. The function returns 0 when the command iocb is an abort | |
7776 | * request. | |
7777 | **/ | |
7778 | int | |
7779 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7780 | struct lpfc_iocbq *cmdiocb) | |
7781 | { | |
7782 | struct lpfc_vport *vport = cmdiocb->vport; | |
7783 | int retval = IOCB_ERROR; | |
7784 | IOCB_t *icmd = NULL; | |
7785 | ||
7786 | /* | |
7787 | * There are certain command types we don't want to abort. And we | |
7788 | * don't want to abort commands that are already in the process of | |
7789 | * being aborted. | |
7790 | */ | |
7791 | icmd = &cmdiocb->iocb; | |
7792 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
7793 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
7794 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
7795 | return 0; | |
7796 | ||
7797 | /* | |
7798 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
7799 | * the callback so that nothing happens when it finishes. | |
7800 | */ | |
7801 | if ((vport->load_flag & FC_UNLOADING) && | |
7802 | (pring->ringno == LPFC_ELS_RING)) { | |
7803 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
7804 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
7805 | else | |
7806 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
7807 | goto abort_iotag_exit; | |
7808 | } | |
7809 | ||
7810 | /* Now, we try to issue the abort to the cmdiocb out */ | |
7811 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
7812 | ||
07951076 | 7813 | abort_iotag_exit: |
2e0fef85 JS |
7814 | /* |
7815 | * Caller to this routine should check for IOCB_ERROR | |
7816 | * and handle it properly. This routine no longer removes | |
7817 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 7818 | */ |
2e0fef85 | 7819 | return retval; |
dea3101e | 7820 | } |
7821 | ||
5af5eee7 JS |
7822 | /** |
7823 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
7824 | * @phba: Pointer to HBA context object. | |
7825 | * @pring: Pointer to driver SLI ring object. | |
7826 | * | |
7827 | * This function aborts all iocbs in the given ring and frees all the iocb | |
7828 | * objects in txq. This function issues abort iocbs unconditionally for all | |
7829 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
7830 | * to complete before the return of this function. The caller is not required | |
7831 | * to hold any locks. | |
7832 | **/ | |
7833 | static void | |
7834 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
7835 | { | |
7836 | LIST_HEAD(completions); | |
7837 | struct lpfc_iocbq *iocb, *next_iocb; | |
7838 | ||
7839 | if (pring->ringno == LPFC_ELS_RING) | |
7840 | lpfc_fabric_abort_hba(phba); | |
7841 | ||
7842 | spin_lock_irq(&phba->hbalock); | |
7843 | ||
7844 | /* Take off all the iocbs on txq for cancelling */ | |
7845 | list_splice_init(&pring->txq, &completions); | |
7846 | pring->txq_cnt = 0; | |
7847 | ||
7848 | /* Next issue ABTS for everything on the txcmplq */ | |
7849 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
7850 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
7851 | ||
7852 | spin_unlock_irq(&phba->hbalock); | |
7853 | ||
7854 | /* Cancel all the IOCBs from the completions list */ | |
7855 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7856 | IOERR_SLI_ABORTED); | |
7857 | } | |
7858 | ||
7859 | /** | |
7860 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
7861 | * @phba: pointer to lpfc HBA data structure. | |
7862 | * | |
7863 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
7864 | **/ | |
7865 | void | |
7866 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
7867 | { | |
7868 | struct lpfc_sli *psli = &phba->sli; | |
7869 | struct lpfc_sli_ring *pring; | |
7870 | int i; | |
7871 | ||
7872 | for (i = 0; i < psli->num_rings; i++) { | |
7873 | pring = &psli->ring[i]; | |
7874 | lpfc_sli_iocb_ring_abort(phba, pring); | |
7875 | } | |
7876 | } | |
7877 | ||
e59058c4 | 7878 | /** |
3621a710 | 7879 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
7880 | * @iocbq: Pointer to driver iocb object. |
7881 | * @vport: Pointer to driver virtual port object. | |
7882 | * @tgt_id: SCSI ID of the target. | |
7883 | * @lun_id: LUN ID of the scsi device. | |
7884 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
7885 | * | |
3621a710 | 7886 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
7887 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
7888 | * 0 if the filtering criteria is met for the given iocb and will return | |
7889 | * 1 if the filtering criteria is not met. | |
7890 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
7891 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
7892 | * lun_id parameter. | |
7893 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
7894 | * given iocb is for the SCSI target specified by vport and tgt_id | |
7895 | * parameters. | |
7896 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
7897 | * given iocb is for the SCSI host associated with the given vport. | |
7898 | * This function is called with no locks held. | |
7899 | **/ | |
dea3101e | 7900 | static int |
51ef4c26 JS |
7901 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
7902 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 7903 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 7904 | { |
0bd4ca25 | 7905 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 7906 | int rc = 1; |
7907 | ||
0bd4ca25 JSEC |
7908 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
7909 | return rc; | |
7910 | ||
51ef4c26 JS |
7911 | if (iocbq->vport != vport) |
7912 | return rc; | |
7913 | ||
0bd4ca25 | 7914 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 7915 | |
495a714c | 7916 | if (lpfc_cmd->pCmd == NULL) |
dea3101e | 7917 | return rc; |
7918 | ||
7919 | switch (ctx_cmd) { | |
7920 | case LPFC_CTX_LUN: | |
495a714c JS |
7921 | if ((lpfc_cmd->rdata->pnode) && |
7922 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
7923 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e | 7924 | rc = 0; |
7925 | break; | |
7926 | case LPFC_CTX_TGT: | |
495a714c JS |
7927 | if ((lpfc_cmd->rdata->pnode) && |
7928 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e | 7929 | rc = 0; |
7930 | break; | |
dea3101e | 7931 | case LPFC_CTX_HOST: |
7932 | rc = 0; | |
7933 | break; | |
7934 | default: | |
7935 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 7936 | __func__, ctx_cmd); |
dea3101e | 7937 | break; |
7938 | } | |
7939 | ||
7940 | return rc; | |
7941 | } | |
7942 | ||
e59058c4 | 7943 | /** |
3621a710 | 7944 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
7945 | * @vport: Pointer to virtual port. |
7946 | * @tgt_id: SCSI ID of the target. | |
7947 | * @lun_id: LUN ID of the scsi device. | |
7948 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
7949 | * | |
7950 | * This function returns number of FCP commands pending for the vport. | |
7951 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
7952 | * commands pending on the vport associated with SCSI device specified | |
7953 | * by tgt_id and lun_id parameters. | |
7954 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
7955 | * commands pending on the vport associated with SCSI target specified | |
7956 | * by tgt_id parameter. | |
7957 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
7958 | * commands pending on the vport. | |
7959 | * This function returns the number of iocbs which satisfy the filter. | |
7960 | * This function is called without any lock held. | |
7961 | **/ | |
dea3101e | 7962 | int |
51ef4c26 JS |
7963 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
7964 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 7965 | { |
51ef4c26 | 7966 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
7967 | struct lpfc_iocbq *iocbq; |
7968 | int sum, i; | |
dea3101e | 7969 | |
0bd4ca25 JSEC |
7970 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
7971 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 7972 | |
51ef4c26 JS |
7973 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
7974 | ctx_cmd) == 0) | |
0bd4ca25 | 7975 | sum++; |
dea3101e | 7976 | } |
0bd4ca25 | 7977 | |
dea3101e | 7978 | return sum; |
7979 | } | |
7980 | ||
e59058c4 | 7981 | /** |
3621a710 | 7982 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
7983 | * @phba: Pointer to HBA context object |
7984 | * @cmdiocb: Pointer to command iocb object. | |
7985 | * @rspiocb: Pointer to response iocb object. | |
7986 | * | |
7987 | * This function is called when an aborted FCP iocb completes. This | |
7988 | * function is called by the ring event handler with no lock held. | |
7989 | * This function frees the iocb. | |
7990 | **/ | |
5eb95af0 | 7991 | void |
2e0fef85 JS |
7992 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7993 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 7994 | { |
604a3e30 | 7995 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
7996 | return; |
7997 | } | |
7998 | ||
e59058c4 | 7999 | /** |
3621a710 | 8000 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
8001 | * @vport: Pointer to virtual port. |
8002 | * @pring: Pointer to driver SLI ring object. | |
8003 | * @tgt_id: SCSI ID of the target. | |
8004 | * @lun_id: LUN ID of the scsi device. | |
8005 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
8006 | * | |
8007 | * This function sends an abort command for every SCSI command | |
8008 | * associated with the given virtual port pending on the ring | |
8009 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
8010 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
8011 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
8012 | * parameters | |
8013 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
8014 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
8015 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
8016 | * FCP iocbs associated with virtual port. | |
8017 | * This function returns number of iocbs it failed to abort. | |
8018 | * This function is called with no locks held. | |
8019 | **/ | |
dea3101e | 8020 | int |
51ef4c26 JS |
8021 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
8022 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 8023 | { |
51ef4c26 | 8024 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
8025 | struct lpfc_iocbq *iocbq; |
8026 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 8027 | IOCB_t *cmd = NULL; |
dea3101e | 8028 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 8029 | int i; |
dea3101e | 8030 | |
0bd4ca25 JSEC |
8031 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
8032 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 8033 | |
51ef4c26 | 8034 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 8035 | abort_cmd) != 0) |
dea3101e | 8036 | continue; |
8037 | ||
8038 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 8039 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e | 8040 | if (abtsiocb == NULL) { |
8041 | errcnt++; | |
8042 | continue; | |
8043 | } | |
dea3101e | 8044 | |
0bd4ca25 | 8045 | cmd = &iocbq->iocb; |
dea3101e | 8046 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
8047 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
8048 | if (phba->sli_rev == LPFC_SLI_REV4) |
8049 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
8050 | else | |
8051 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e | 8052 | abtsiocb->iocb.ulpLe = 1; |
8053 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 8054 | abtsiocb->vport = phba->pport; |
dea3101e | 8055 | |
5ffc266e JS |
8056 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
8057 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
8058 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
8059 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 8060 | |
2e0fef85 | 8061 | if (lpfc_is_link_up(phba)) |
dea3101e | 8062 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
8063 | else | |
8064 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
8065 | ||
5eb95af0 JSEC |
8066 | /* Setup callback routine and issue the command. */ |
8067 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
8068 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
8069 | abtsiocb, 0); | |
dea3101e | 8070 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 8071 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e | 8072 | errcnt++; |
8073 | continue; | |
8074 | } | |
8075 | } | |
8076 | ||
8077 | return errcnt; | |
8078 | } | |
8079 | ||
e59058c4 | 8080 | /** |
3621a710 | 8081 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
8082 | * @phba: Pointer to HBA context object. |
8083 | * @cmdiocbq: Pointer to command iocb. | |
8084 | * @rspiocbq: Pointer to response iocb. | |
8085 | * | |
8086 | * This function is the completion handler for iocbs issued using | |
8087 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
8088 | * ring event handler function without any lock held. This function | |
8089 | * can be called from both worker thread context and interrupt | |
8090 | * context. This function also can be called from other thread which | |
8091 | * cleans up the SLI layer objects. | |
8092 | * This function copy the contents of the response iocb to the | |
8093 | * response iocb memory object provided by the caller of | |
8094 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
8095 | * sleeps for the iocb completion. | |
8096 | **/ | |
68876920 JSEC |
8097 | static void |
8098 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
8099 | struct lpfc_iocbq *cmdiocbq, | |
8100 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 8101 | { |
68876920 JSEC |
8102 | wait_queue_head_t *pdone_q; |
8103 | unsigned long iflags; | |
0f65ff68 | 8104 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 8105 | |
2e0fef85 | 8106 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
8107 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
8108 | if (cmdiocbq->context2 && rspiocbq) | |
8109 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
8110 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
8111 | ||
0f65ff68 JS |
8112 | /* Set the exchange busy flag for task management commands */ |
8113 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
8114 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
8115 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
8116 | cur_iocbq); | |
8117 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
8118 | } | |
8119 | ||
68876920 | 8120 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
8121 | if (pdone_q) |
8122 | wake_up(pdone_q); | |
858c9f6c | 8123 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e | 8124 | return; |
8125 | } | |
8126 | ||
d11e31dd JS |
8127 | /** |
8128 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
8129 | * @phba: Pointer to HBA context object.. | |
8130 | * @piocbq: Pointer to command iocb. | |
8131 | * @flag: Flag to test. | |
8132 | * | |
8133 | * This routine grabs the hbalock and then test the iocb_flag to | |
8134 | * see if the passed in flag is set. | |
8135 | * Returns: | |
8136 | * 1 if flag is set. | |
8137 | * 0 if flag is not set. | |
8138 | **/ | |
8139 | static int | |
8140 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
8141 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
8142 | { | |
8143 | unsigned long iflags; | |
8144 | int ret; | |
8145 | ||
8146 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8147 | ret = piocbq->iocb_flag & flag; | |
8148 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8149 | return ret; | |
8150 | ||
8151 | } | |
8152 | ||
e59058c4 | 8153 | /** |
3621a710 | 8154 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
8155 | * @phba: Pointer to HBA context object.. |
8156 | * @pring: Pointer to sli ring. | |
8157 | * @piocb: Pointer to command iocb. | |
8158 | * @prspiocbq: Pointer to response iocb. | |
8159 | * @timeout: Timeout in number of seconds. | |
8160 | * | |
8161 | * This function issues the iocb to firmware and waits for the | |
8162 | * iocb to complete. If the iocb command is not | |
8163 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
8164 | * Caller should not free the iocb resources if this function | |
8165 | * returns IOCB_TIMEDOUT. | |
8166 | * The function waits for the iocb completion using an | |
8167 | * non-interruptible wait. | |
8168 | * This function will sleep while waiting for iocb completion. | |
8169 | * So, this function should not be called from any context which | |
8170 | * does not allow sleeping. Due to the same reason, this function | |
8171 | * cannot be called with interrupt disabled. | |
8172 | * This function assumes that the iocb completions occur while | |
8173 | * this function sleep. So, this function cannot be called from | |
8174 | * the thread which process iocb completion for this ring. | |
8175 | * This function clears the iocb_flag of the iocb object before | |
8176 | * issuing the iocb and the iocb completion handler sets this | |
8177 | * flag and wakes this thread when the iocb completes. | |
8178 | * The contents of the response iocb will be copied to prspiocbq | |
8179 | * by the completion handler when the command completes. | |
8180 | * This function returns IOCB_SUCCESS when success. | |
8181 | * This function is called with no lock held. | |
8182 | **/ | |
dea3101e | 8183 | int |
2e0fef85 | 8184 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 8185 | uint32_t ring_number, |
2e0fef85 JS |
8186 | struct lpfc_iocbq *piocb, |
8187 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 8188 | uint32_t timeout) |
dea3101e | 8189 | { |
7259f0d0 | 8190 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
8191 | long timeleft, timeout_req = 0; |
8192 | int retval = IOCB_SUCCESS; | |
875fbdfe | 8193 | uint32_t creg_val; |
2a9bf3d0 | 8194 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 8195 | /* |
68876920 JSEC |
8196 | * If the caller has provided a response iocbq buffer, then context2 |
8197 | * is NULL or its an error. | |
dea3101e | 8198 | */ |
68876920 JSEC |
8199 | if (prspiocbq) { |
8200 | if (piocb->context2) | |
8201 | return IOCB_ERROR; | |
8202 | piocb->context2 = prspiocbq; | |
dea3101e | 8203 | } |
8204 | ||
68876920 JSEC |
8205 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
8206 | piocb->context_un.wait_queue = &done_q; | |
8207 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 8208 | |
875fbdfe JSEC |
8209 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
8210 | creg_val = readl(phba->HCregaddr); | |
8211 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
8212 | writel(creg_val, phba->HCregaddr); | |
8213 | readl(phba->HCregaddr); /* flush */ | |
8214 | } | |
8215 | ||
2a9bf3d0 JS |
8216 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
8217 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
8218 | if (retval == IOCB_SUCCESS) { |
8219 | timeout_req = timeout * HZ; | |
68876920 | 8220 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 8221 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 8222 | timeout_req); |
dea3101e | 8223 | |
7054a606 JS |
8224 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
8225 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 8226 | "0331 IOCB wake signaled\n"); |
7054a606 | 8227 | } else if (timeleft == 0) { |
68876920 | 8228 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
8229 | "0338 IOCB wait timeout error - no " |
8230 | "wake response Data x%x\n", timeout); | |
68876920 | 8231 | retval = IOCB_TIMEDOUT; |
7054a606 | 8232 | } else { |
68876920 | 8233 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
8234 | "0330 IOCB wake NOT set, " |
8235 | "Data x%x x%lx\n", | |
68876920 JSEC |
8236 | timeout, (timeleft / jiffies)); |
8237 | retval = IOCB_TIMEDOUT; | |
dea3101e | 8238 | } |
2a9bf3d0 JS |
8239 | } else if (retval == IOCB_BUSY) { |
8240 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8241 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
8242 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
8243 | return retval; | |
68876920 JSEC |
8244 | } else { |
8245 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 8246 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 8247 | retval); |
68876920 | 8248 | retval = IOCB_ERROR; |
dea3101e | 8249 | } |
8250 | ||
875fbdfe JSEC |
8251 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
8252 | creg_val = readl(phba->HCregaddr); | |
8253 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | |
8254 | writel(creg_val, phba->HCregaddr); | |
8255 | readl(phba->HCregaddr); /* flush */ | |
8256 | } | |
8257 | ||
68876920 JSEC |
8258 | if (prspiocbq) |
8259 | piocb->context2 = NULL; | |
8260 | ||
8261 | piocb->context_un.wait_queue = NULL; | |
8262 | piocb->iocb_cmpl = NULL; | |
dea3101e | 8263 | return retval; |
8264 | } | |
68876920 | 8265 | |
e59058c4 | 8266 | /** |
3621a710 | 8267 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
8268 | * @phba: Pointer to HBA context object. |
8269 | * @pmboxq: Pointer to driver mailbox object. | |
8270 | * @timeout: Timeout in number of seconds. | |
8271 | * | |
8272 | * This function issues the mailbox to firmware and waits for the | |
8273 | * mailbox command to complete. If the mailbox command is not | |
8274 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
8275 | * The function waits for the mailbox completion using an | |
8276 | * interruptible wait. If the thread is woken up due to a | |
8277 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
8278 | * should not free the mailbox resources, if this function returns | |
8279 | * MBX_TIMEOUT. | |
8280 | * This function will sleep while waiting for mailbox completion. | |
8281 | * So, this function should not be called from any context which | |
8282 | * does not allow sleeping. Due to the same reason, this function | |
8283 | * cannot be called with interrupt disabled. | |
8284 | * This function assumes that the mailbox completion occurs while | |
8285 | * this function sleep. So, this function cannot be called from | |
8286 | * the worker thread which processes mailbox completion. | |
8287 | * This function is called in the context of HBA management | |
8288 | * applications. | |
8289 | * This function returns MBX_SUCCESS when successful. | |
8290 | * This function is called with no lock held. | |
8291 | **/ | |
dea3101e | 8292 | int |
2e0fef85 | 8293 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e | 8294 | uint32_t timeout) |
8295 | { | |
7259f0d0 | 8296 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 8297 | int retval; |
858c9f6c | 8298 | unsigned long flag; |
dea3101e | 8299 | |
8300 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 8301 | if (pmboxq->context1) |
2e0fef85 | 8302 | return MBX_NOT_FINISHED; |
dea3101e | 8303 | |
495a714c | 8304 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e | 8305 | /* setup wake call as IOCB callback */ |
8306 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
8307 | /* setup context field to pass wait_queue pointer to wake function */ | |
8308 | pmboxq->context1 = &done_q; | |
8309 | ||
dea3101e | 8310 | /* now issue the command */ |
8311 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
8312 | ||
8313 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | |
7054a606 JS |
8314 | wait_event_interruptible_timeout(done_q, |
8315 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
8316 | timeout * HZ); | |
8317 | ||
858c9f6c | 8318 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 8319 | pmboxq->context1 = NULL; |
7054a606 JS |
8320 | /* |
8321 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
8322 | * else do not free the resources. | |
8323 | */ | |
d7c47992 | 8324 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 8325 | retval = MBX_SUCCESS; |
d7c47992 JS |
8326 | lpfc_sli4_swap_str(phba, pmboxq); |
8327 | } else { | |
7054a606 | 8328 | retval = MBX_TIMEOUT; |
858c9f6c JS |
8329 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
8330 | } | |
8331 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e | 8332 | } |
8333 | ||
dea3101e | 8334 | return retval; |
8335 | } | |
8336 | ||
e59058c4 | 8337 | /** |
3772a991 | 8338 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
8339 | * @phba: Pointer to HBA context. |
8340 | * | |
3772a991 JS |
8341 | * This function is called to shutdown the driver's mailbox sub-system. |
8342 | * It first marks the mailbox sub-system is in a block state to prevent | |
8343 | * the asynchronous mailbox command from issued off the pending mailbox | |
8344 | * command queue. If the mailbox command sub-system shutdown is due to | |
8345 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
8346 | * the mailbox sub-system flush routine to forcefully bring down the | |
8347 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
8348 | * as with offline or HBA function reset), this routine will wait for the | |
8349 | * outstanding mailbox command to complete before invoking the mailbox | |
8350 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 8351 | **/ |
3772a991 JS |
8352 | void |
8353 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) | |
b4c02652 | 8354 | { |
3772a991 JS |
8355 | struct lpfc_sli *psli = &phba->sli; |
8356 | uint8_t actcmd = MBX_HEARTBEAT; | |
8357 | unsigned long timeout; | |
b4c02652 | 8358 | |
3772a991 JS |
8359 | spin_lock_irq(&phba->hbalock); |
8360 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
8361 | spin_unlock_irq(&phba->hbalock); | |
b4c02652 | 8362 | |
3772a991 | 8363 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
ed957684 | 8364 | spin_lock_irq(&phba->hbalock); |
3772a991 JS |
8365 | if (phba->sli.mbox_active) |
8366 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
ed957684 | 8367 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
8368 | /* Determine how long we might wait for the active mailbox |
8369 | * command to be gracefully completed by firmware. | |
8370 | */ | |
8371 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * | |
8372 | 1000) + jiffies; | |
8373 | while (phba->sli.mbox_active) { | |
8374 | /* Check active mailbox complete status every 2ms */ | |
8375 | msleep(2); | |
8376 | if (time_after(jiffies, timeout)) | |
8377 | /* Timeout, let the mailbox flush routine to | |
8378 | * forcefully release active mailbox command | |
8379 | */ | |
8380 | break; | |
8381 | } | |
8382 | } | |
8383 | lpfc_sli_mbox_sys_flush(phba); | |
8384 | } | |
ed957684 | 8385 | |
3772a991 JS |
8386 | /** |
8387 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
8388 | * @phba: Pointer to HBA context. | |
8389 | * | |
8390 | * This function is called to read the SLI3 device error attention registers | |
8391 | * for possible error attention events. The caller must hold the hostlock | |
8392 | * with spin_lock_irq(). | |
8393 | * | |
8394 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
8395 | * Register and returns 0 otherwise. | |
8396 | **/ | |
8397 | static int | |
8398 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
8399 | { | |
8400 | uint32_t ha_copy; | |
b4c02652 | 8401 | |
3772a991 JS |
8402 | /* Read chip Host Attention (HA) register */ |
8403 | ha_copy = readl(phba->HAregaddr); | |
8404 | if (ha_copy & HA_ERATT) { | |
8405 | /* Read host status register to retrieve error event */ | |
8406 | lpfc_sli_read_hs(phba); | |
b4c02652 | 8407 | |
3772a991 JS |
8408 | /* Check if there is a deferred error condition is active */ |
8409 | if ((HS_FFER1 & phba->work_hs) && | |
8410 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 8411 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 8412 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
8413 | /* Clear all interrupt enable conditions */ |
8414 | writel(0, phba->HCregaddr); | |
8415 | readl(phba->HCregaddr); | |
8416 | } | |
8417 | ||
8418 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
8419 | phba->work_ha |= HA_ERATT; |
8420 | /* Indicate polling handles this ERATT */ | |
8421 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
8422 | return 1; |
8423 | } | |
8424 | return 0; | |
b4c02652 JS |
8425 | } |
8426 | ||
da0436e9 JS |
8427 | /** |
8428 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
8429 | * @phba: Pointer to HBA context. | |
8430 | * | |
8431 | * This function is called to read the SLI4 device error attention registers | |
8432 | * for possible error attention events. The caller must hold the hostlock | |
8433 | * with spin_lock_irq(). | |
8434 | * | |
8435 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
8436 | * Register and returns 0 otherwise. | |
8437 | **/ | |
8438 | static int | |
8439 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
8440 | { | |
8441 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
da0436e9 JS |
8442 | |
8443 | /* For now, use the SLI4 device internal unrecoverable error | |
8444 | * registers for error attention. This can be changed later. | |
8445 | */ | |
a747c9ce JS |
8446 | uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr); |
8447 | uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr); | |
8448 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || | |
8449 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
8450 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8451 | "1423 HBA Unrecoverable error: " | |
8452 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
8453 | "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n", | |
8454 | uerr_sta_lo, uerr_sta_hi, | |
8455 | phba->sli4_hba.ue_mask_lo, | |
8456 | phba->sli4_hba.ue_mask_hi); | |
8457 | phba->work_status[0] = uerr_sta_lo; | |
8458 | phba->work_status[1] = uerr_sta_hi; | |
8459 | /* Set the driver HA work bitmap */ | |
8460 | phba->work_ha |= HA_ERATT; | |
8461 | /* Indicate polling handles this ERATT */ | |
8462 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8463 | return 1; | |
da0436e9 JS |
8464 | } |
8465 | return 0; | |
8466 | } | |
8467 | ||
e59058c4 | 8468 | /** |
3621a710 | 8469 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
8470 | * @phba: Pointer to HBA context. |
8471 | * | |
3772a991 | 8472 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
8473 | * error attention register bit for error attention events. |
8474 | * | |
8475 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
8476 | * Register and returns 0 otherwise. | |
8477 | **/ | |
8478 | int | |
8479 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
8480 | { | |
8481 | uint32_t ha_copy; | |
8482 | ||
8483 | /* If somebody is waiting to handle an eratt, don't process it | |
8484 | * here. The brdkill function will do this. | |
8485 | */ | |
8486 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8487 | return 0; | |
8488 | ||
8489 | /* Check if interrupt handler handles this ERATT */ | |
8490 | spin_lock_irq(&phba->hbalock); | |
8491 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
8492 | /* Interrupt handler has handled ERATT */ | |
8493 | spin_unlock_irq(&phba->hbalock); | |
8494 | return 0; | |
8495 | } | |
8496 | ||
a257bf90 JS |
8497 | /* |
8498 | * If there is deferred error attention, do not check for error | |
8499 | * attention | |
8500 | */ | |
8501 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
8502 | spin_unlock_irq(&phba->hbalock); | |
8503 | return 0; | |
8504 | } | |
8505 | ||
3772a991 JS |
8506 | /* If PCI channel is offline, don't process it */ |
8507 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 8508 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
8509 | return 0; |
8510 | } | |
8511 | ||
8512 | switch (phba->sli_rev) { | |
8513 | case LPFC_SLI_REV2: | |
8514 | case LPFC_SLI_REV3: | |
8515 | /* Read chip Host Attention (HA) register */ | |
8516 | ha_copy = lpfc_sli_eratt_read(phba); | |
8517 | break; | |
da0436e9 JS |
8518 | case LPFC_SLI_REV4: |
8519 | /* Read devcie Uncoverable Error (UERR) registers */ | |
8520 | ha_copy = lpfc_sli4_eratt_read(phba); | |
8521 | break; | |
3772a991 JS |
8522 | default: |
8523 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8524 | "0299 Invalid SLI revision (%d)\n", | |
8525 | phba->sli_rev); | |
8526 | ha_copy = 0; | |
8527 | break; | |
9399627f JS |
8528 | } |
8529 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
8530 | |
8531 | return ha_copy; | |
8532 | } | |
8533 | ||
8534 | /** | |
8535 | * lpfc_intr_state_check - Check device state for interrupt handling | |
8536 | * @phba: Pointer to HBA context. | |
8537 | * | |
8538 | * This inline routine checks whether a device or its PCI slot is in a state | |
8539 | * that the interrupt should be handled. | |
8540 | * | |
8541 | * This function returns 0 if the device or the PCI slot is in a state that | |
8542 | * interrupt should be handled, otherwise -EIO. | |
8543 | */ | |
8544 | static inline int | |
8545 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
8546 | { | |
8547 | /* If the pci channel is offline, ignore all the interrupts */ | |
8548 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
8549 | return -EIO; | |
8550 | ||
8551 | /* Update device level interrupt statistics */ | |
8552 | phba->sli.slistat.sli_intr++; | |
8553 | ||
8554 | /* Ignore all interrupts during initialization. */ | |
8555 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
8556 | return -EIO; | |
8557 | ||
9399627f JS |
8558 | return 0; |
8559 | } | |
8560 | ||
8561 | /** | |
3772a991 | 8562 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
8563 | * @irq: Interrupt number. |
8564 | * @dev_id: The device context pointer. | |
8565 | * | |
9399627f | 8566 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
8567 | * service routine when device with SLI-3 interface spec is enabled with |
8568 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
8569 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
8570 | * interrupt mode, this function is called as part of the device-level | |
8571 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
8572 | * is undergoing initialization, the interrupt handler will not process | |
8573 | * the interrupt. The link attention and ELS ring attention events are | |
8574 | * handled by the worker thread. The interrupt handler signals the worker | |
8575 | * thread and returns for these events. This function is called without | |
8576 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
8577 | * structures. |
8578 | * | |
8579 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8580 | * returns IRQ_NONE. | |
e59058c4 | 8581 | **/ |
dea3101e | 8582 | irqreturn_t |
3772a991 | 8583 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 8584 | { |
2e0fef85 | 8585 | struct lpfc_hba *phba; |
a747c9ce | 8586 | uint32_t ha_copy, hc_copy; |
dea3101e | 8587 | uint32_t work_ha_copy; |
8588 | unsigned long status; | |
5b75da2f | 8589 | unsigned long iflag; |
dea3101e | 8590 | uint32_t control; |
8591 | ||
92d7f7b0 | 8592 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
8593 | struct lpfc_vport *vport; |
8594 | struct lpfc_nodelist *ndlp; | |
8595 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
8596 | LPFC_MBOXQ_t *pmb; |
8597 | int rc; | |
8598 | ||
dea3101e | 8599 | /* |
8600 | * Get the driver's phba structure from the dev_id and | |
8601 | * assume the HBA is not interrupting. | |
8602 | */ | |
9399627f | 8603 | phba = (struct lpfc_hba *)dev_id; |
dea3101e | 8604 | |
8605 | if (unlikely(!phba)) | |
8606 | return IRQ_NONE; | |
8607 | ||
dea3101e | 8608 | /* |
9399627f JS |
8609 | * Stuff needs to be attented to when this function is invoked as an |
8610 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 8611 | */ |
9399627f | 8612 | if (phba->intr_type == MSIX) { |
3772a991 JS |
8613 | /* Check device state for handling interrupt */ |
8614 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8615 | return IRQ_NONE; |
8616 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 8617 | spin_lock_irqsave(&phba->hbalock, iflag); |
34b02dcd | 8618 | ha_copy = readl(phba->HAregaddr); |
9399627f JS |
8619 | /* If somebody is waiting to handle an eratt don't process it |
8620 | * here. The brdkill function will do this. | |
8621 | */ | |
8622 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8623 | ha_copy &= ~HA_ERATT; | |
8624 | /* Check the need for handling ERATT in interrupt handler */ | |
8625 | if (ha_copy & HA_ERATT) { | |
8626 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8627 | /* ERATT polling has handled ERATT */ | |
8628 | ha_copy &= ~HA_ERATT; | |
8629 | else | |
8630 | /* Indicate interrupt handler handles ERATT */ | |
8631 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8632 | } | |
a257bf90 JS |
8633 | |
8634 | /* | |
8635 | * If there is deferred error attention, do not check for any | |
8636 | * interrupt. | |
8637 | */ | |
8638 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8639 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8640 | return IRQ_NONE; |
8641 | } | |
8642 | ||
9399627f | 8643 | /* Clear up only attention source related to slow-path */ |
a747c9ce JS |
8644 | hc_copy = readl(phba->HCregaddr); |
8645 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | | |
8646 | HC_LAINT_ENA | HC_ERINT_ENA), | |
8647 | phba->HCregaddr); | |
9399627f JS |
8648 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
8649 | phba->HAregaddr); | |
a747c9ce | 8650 | writel(hc_copy, phba->HCregaddr); |
9399627f | 8651 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 8652 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8653 | } else |
8654 | ha_copy = phba->ha_copy; | |
dea3101e | 8655 | |
dea3101e | 8656 | work_ha_copy = ha_copy & phba->work_ha_mask; |
8657 | ||
9399627f | 8658 | if (work_ha_copy) { |
dea3101e | 8659 | if (work_ha_copy & HA_LATT) { |
8660 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
8661 | /* | |
8662 | * Turn off Link Attention interrupts | |
8663 | * until CLEAR_LA done | |
8664 | */ | |
5b75da2f | 8665 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 8666 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
8667 | control = readl(phba->HCregaddr); | |
8668 | control &= ~HC_LAINT_ENA; | |
8669 | writel(control, phba->HCregaddr); | |
8670 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 8671 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 8672 | } |
8673 | else | |
8674 | work_ha_copy &= ~HA_LATT; | |
8675 | } | |
8676 | ||
9399627f | 8677 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
8678 | /* |
8679 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
8680 | * the only slow ring. | |
8681 | */ | |
8682 | status = (work_ha_copy & | |
8683 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
8684 | status >>= (4*LPFC_ELS_RING); | |
8685 | if (status & HA_RXMASK) { | |
5b75da2f | 8686 | spin_lock_irqsave(&phba->hbalock, iflag); |
858c9f6c | 8687 | control = readl(phba->HCregaddr); |
a58cbd52 JS |
8688 | |
8689 | lpfc_debugfs_slow_ring_trc(phba, | |
8690 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
8691 | control, status, | |
8692 | (uint32_t)phba->sli.slistat.sli_intr); | |
8693 | ||
858c9f6c | 8694 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
8695 | lpfc_debugfs_slow_ring_trc(phba, |
8696 | "ISR Disable ring:" | |
8697 | "pwork:x%x hawork:x%x wait:x%x", | |
8698 | phba->work_ha, work_ha_copy, | |
8699 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8700 | &phba->work_waitq)); |
a58cbd52 | 8701 | |
858c9f6c JS |
8702 | control &= |
8703 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e | 8704 | writel(control, phba->HCregaddr); |
8705 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 8706 | } |
a58cbd52 JS |
8707 | else { |
8708 | lpfc_debugfs_slow_ring_trc(phba, | |
8709 | "ISR slow ring: pwork:" | |
8710 | "x%x hawork:x%x wait:x%x", | |
8711 | phba->work_ha, work_ha_copy, | |
8712 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8713 | &phba->work_waitq)); |
a58cbd52 | 8714 | } |
5b75da2f | 8715 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e | 8716 | } |
8717 | } | |
5b75da2f | 8718 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 8719 | if (work_ha_copy & HA_ERATT) { |
9399627f | 8720 | lpfc_sli_read_hs(phba); |
a257bf90 JS |
8721 | /* |
8722 | * Check if there is a deferred error condition | |
8723 | * is active | |
8724 | */ | |
8725 | if ((HS_FFER1 & phba->work_hs) && | |
8726 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
8727 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
8728 | phba->work_hs)) { | |
a257bf90 JS |
8729 | phba->hba_flag |= DEFER_ERATT; |
8730 | /* Clear all interrupt enable conditions */ | |
8731 | writel(0, phba->HCregaddr); | |
8732 | readl(phba->HCregaddr); | |
8733 | } | |
8734 | } | |
8735 | ||
9399627f | 8736 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 8737 | pmb = phba->sli.mbox_active; |
04c68496 | 8738 | pmbox = &pmb->u.mb; |
34b02dcd | 8739 | mbox = phba->mbox; |
858c9f6c | 8740 | vport = pmb->vport; |
92d7f7b0 JS |
8741 | |
8742 | /* First check out the status word */ | |
8743 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
8744 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 8745 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
8746 | /* |
8747 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
8748 | * mbxStatus <status> | |
8749 | */ | |
09372820 | 8750 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 8751 | LOG_SLI, |
e8b62011 | 8752 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
8753 | "Interrupt mbxCommand x%x " |
8754 | "mbxStatus x%x\n", | |
e8b62011 | 8755 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
8756 | pmbox->mbxCommand, |
8757 | pmbox->mbxStatus); | |
09372820 JS |
8758 | /* clear mailbox attention bit */ |
8759 | work_ha_copy &= ~HA_MBATT; | |
8760 | } else { | |
97eab634 | 8761 | phba->sli.mbox_active = NULL; |
5b75da2f | 8762 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
8763 | phba->last_completion_time = jiffies; |
8764 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
8765 | if (pmb->mbox_cmpl) { |
8766 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
8767 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
8768 | if (pmb->out_ext_byte_len && |
8769 | pmb->context2) | |
8770 | lpfc_sli_pcimem_bcopy( | |
8771 | phba->mbox_ext, | |
8772 | pmb->context2, | |
8773 | pmb->out_ext_byte_len); | |
09372820 JS |
8774 | } |
8775 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
8776 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
8777 | ||
8778 | lpfc_debugfs_disc_trc(vport, | |
8779 | LPFC_DISC_TRC_MBOX_VPORT, | |
8780 | "MBOX dflt rpi: : " | |
8781 | "status:x%x rpi:x%x", | |
8782 | (uint32_t)pmbox->mbxStatus, | |
8783 | pmbox->un.varWords[0], 0); | |
8784 | ||
8785 | if (!pmbox->mbxStatus) { | |
8786 | mp = (struct lpfc_dmabuf *) | |
8787 | (pmb->context1); | |
8788 | ndlp = (struct lpfc_nodelist *) | |
8789 | pmb->context2; | |
8790 | ||
8791 | /* Reg_LOGIN of dflt RPI was | |
8792 | * successful. new lets get | |
8793 | * rid of the RPI using the | |
8794 | * same mbox buffer. | |
8795 | */ | |
8796 | lpfc_unreg_login(phba, | |
8797 | vport->vpi, | |
8798 | pmbox->un.varWords[0], | |
8799 | pmb); | |
8800 | pmb->mbox_cmpl = | |
8801 | lpfc_mbx_cmpl_dflt_rpi; | |
8802 | pmb->context1 = mp; | |
8803 | pmb->context2 = ndlp; | |
8804 | pmb->vport = vport; | |
58da1ffb JS |
8805 | rc = lpfc_sli_issue_mbox(phba, |
8806 | pmb, | |
8807 | MBX_NOWAIT); | |
8808 | if (rc != MBX_BUSY) | |
8809 | lpfc_printf_log(phba, | |
8810 | KERN_ERR, | |
8811 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 8812 | "0350 rc should have" |
6a9c52cf | 8813 | "been MBX_BUSY\n"); |
3772a991 JS |
8814 | if (rc != MBX_NOT_FINISHED) |
8815 | goto send_current_mbox; | |
09372820 | 8816 | } |
858c9f6c | 8817 | } |
5b75da2f JS |
8818 | spin_lock_irqsave( |
8819 | &phba->pport->work_port_lock, | |
8820 | iflag); | |
09372820 JS |
8821 | phba->pport->work_port_events &= |
8822 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
8823 | spin_unlock_irqrestore( |
8824 | &phba->pport->work_port_lock, | |
8825 | iflag); | |
09372820 | 8826 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 8827 | } |
97eab634 | 8828 | } else |
5b75da2f | 8829 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 8830 | |
92d7f7b0 JS |
8831 | if ((work_ha_copy & HA_MBATT) && |
8832 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 8833 | send_current_mbox: |
92d7f7b0 | 8834 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
8835 | do { |
8836 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
8837 | MBX_NOWAIT); | |
8838 | } while (rc == MBX_NOT_FINISHED); | |
8839 | if (rc != MBX_SUCCESS) | |
8840 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
8841 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 8842 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
8843 | } |
8844 | ||
5b75da2f | 8845 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 8846 | phba->work_ha |= work_ha_copy; |
5b75da2f | 8847 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 8848 | lpfc_worker_wake_up(phba); |
dea3101e | 8849 | } |
9399627f | 8850 | return IRQ_HANDLED; |
dea3101e | 8851 | |
3772a991 | 8852 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
8853 | |
8854 | /** | |
3772a991 | 8855 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
8856 | * @irq: Interrupt number. |
8857 | * @dev_id: The device context pointer. | |
8858 | * | |
8859 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
8860 | * service routine when device with SLI-3 interface spec is enabled with |
8861 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
8862 | * ring event in the HBA. However, when the device is enabled with either | |
8863 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
8864 | * device-level interrupt handler. When the PCI slot is in error recovery | |
8865 | * or the HBA is undergoing initialization, the interrupt handler will not | |
8866 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
8867 | * the intrrupt context. This function is called without any lock held. | |
8868 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
8869 | * |
8870 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8871 | * returns IRQ_NONE. | |
8872 | **/ | |
8873 | irqreturn_t | |
3772a991 | 8874 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
8875 | { |
8876 | struct lpfc_hba *phba; | |
8877 | uint32_t ha_copy; | |
8878 | unsigned long status; | |
5b75da2f | 8879 | unsigned long iflag; |
9399627f JS |
8880 | |
8881 | /* Get the driver's phba structure from the dev_id and | |
8882 | * assume the HBA is not interrupting. | |
8883 | */ | |
8884 | phba = (struct lpfc_hba *) dev_id; | |
8885 | ||
8886 | if (unlikely(!phba)) | |
8887 | return IRQ_NONE; | |
8888 | ||
8889 | /* | |
8890 | * Stuff needs to be attented to when this function is invoked as an | |
8891 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
8892 | */ | |
8893 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
8894 | /* Check device state for handling interrupt */ |
8895 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8896 | return IRQ_NONE; |
8897 | /* Need to read HA REG for FCP ring and other ring events */ | |
8898 | ha_copy = readl(phba->HAregaddr); | |
8899 | /* Clear up only attention source related to fast-path */ | |
5b75da2f | 8900 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
8901 | /* |
8902 | * If there is deferred error attention, do not check for | |
8903 | * any interrupt. | |
8904 | */ | |
8905 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8906 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8907 | return IRQ_NONE; |
8908 | } | |
9399627f JS |
8909 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
8910 | phba->HAregaddr); | |
8911 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 8912 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8913 | } else |
8914 | ha_copy = phba->ha_copy; | |
dea3101e | 8915 | |
8916 | /* | |
9399627f | 8917 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 8918 | */ |
9399627f JS |
8919 | ha_copy &= ~(phba->work_ha_mask); |
8920 | ||
8921 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 8922 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 8923 | if (status & HA_RXMASK) |
dea3101e | 8924 | lpfc_sli_handle_fast_ring_event(phba, |
8925 | &phba->sli.ring[LPFC_FCP_RING], | |
8926 | status); | |
a4bc3379 JS |
8927 | |
8928 | if (phba->cfg_multi_ring_support == 2) { | |
8929 | /* | |
9399627f JS |
8930 | * Process all events on extra ring. Take the optimized path |
8931 | * for extra ring IO. | |
a4bc3379 | 8932 | */ |
9399627f | 8933 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 8934 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 8935 | if (status & HA_RXMASK) { |
a4bc3379 JS |
8936 | lpfc_sli_handle_fast_ring_event(phba, |
8937 | &phba->sli.ring[LPFC_EXTRA_RING], | |
8938 | status); | |
8939 | } | |
8940 | } | |
dea3101e | 8941 | return IRQ_HANDLED; |
3772a991 | 8942 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
8943 | |
8944 | /** | |
3772a991 | 8945 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
8946 | * @irq: Interrupt number. |
8947 | * @dev_id: The device context pointer. | |
8948 | * | |
3772a991 JS |
8949 | * This function is the HBA device-level interrupt handler to device with |
8950 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
8951 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
8952 | * requires driver attention. This function invokes the slow-path interrupt | |
8953 | * attention handling function and fast-path interrupt attention handling | |
8954 | * function in turn to process the relevant HBA attention events. This | |
8955 | * function is called without any lock held. It gets the hbalock to access | |
8956 | * and update SLI data structures. | |
9399627f JS |
8957 | * |
8958 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
8959 | * returns IRQ_NONE. | |
8960 | **/ | |
8961 | irqreturn_t | |
3772a991 | 8962 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
8963 | { |
8964 | struct lpfc_hba *phba; | |
8965 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
8966 | unsigned long status1, status2; | |
a747c9ce | 8967 | uint32_t hc_copy; |
9399627f JS |
8968 | |
8969 | /* | |
8970 | * Get the driver's phba structure from the dev_id and | |
8971 | * assume the HBA is not interrupting. | |
8972 | */ | |
8973 | phba = (struct lpfc_hba *) dev_id; | |
8974 | ||
8975 | if (unlikely(!phba)) | |
8976 | return IRQ_NONE; | |
8977 | ||
3772a991 JS |
8978 | /* Check device state for handling interrupt */ |
8979 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8980 | return IRQ_NONE; |
8981 | ||
8982 | spin_lock(&phba->hbalock); | |
8983 | phba->ha_copy = readl(phba->HAregaddr); | |
8984 | if (unlikely(!phba->ha_copy)) { | |
8985 | spin_unlock(&phba->hbalock); | |
8986 | return IRQ_NONE; | |
8987 | } else if (phba->ha_copy & HA_ERATT) { | |
8988 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8989 | /* ERATT polling has handled ERATT */ | |
8990 | phba->ha_copy &= ~HA_ERATT; | |
8991 | else | |
8992 | /* Indicate interrupt handler handles ERATT */ | |
8993 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8994 | } | |
8995 | ||
a257bf90 JS |
8996 | /* |
8997 | * If there is deferred error attention, do not check for any interrupt. | |
8998 | */ | |
8999 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 9000 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
9001 | return IRQ_NONE; |
9002 | } | |
9003 | ||
9399627f | 9004 | /* Clear attention sources except link and error attentions */ |
a747c9ce JS |
9005 | hc_copy = readl(phba->HCregaddr); |
9006 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA | |
9007 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
9008 | phba->HCregaddr); | |
9399627f | 9009 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 9010 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
9011 | readl(phba->HAregaddr); /* flush */ |
9012 | spin_unlock(&phba->hbalock); | |
9013 | ||
9014 | /* | |
9015 | * Invokes slow-path host attention interrupt handling as appropriate. | |
9016 | */ | |
9017 | ||
9018 | /* status of events with mailbox and link attention */ | |
9019 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
9020 | ||
9021 | /* status of events with ELS ring */ | |
9022 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
9023 | status2 >>= (4*LPFC_ELS_RING); | |
9024 | ||
9025 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 9026 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
9027 | else |
9028 | sp_irq_rc = IRQ_NONE; | |
9029 | ||
9030 | /* | |
9031 | * Invoke fast-path host attention interrupt handling as appropriate. | |
9032 | */ | |
9033 | ||
9034 | /* status of events with FCP ring */ | |
9035 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
9036 | status1 >>= (4*LPFC_FCP_RING); | |
9037 | ||
9038 | /* status of events with extra ring */ | |
9039 | if (phba->cfg_multi_ring_support == 2) { | |
9040 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
9041 | status2 >>= (4*LPFC_EXTRA_RING); | |
9042 | } else | |
9043 | status2 = 0; | |
9044 | ||
9045 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 9046 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
9047 | else |
9048 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 9049 | |
9399627f JS |
9050 | /* Return device-level interrupt handling status */ |
9051 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 9052 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
9053 | |
9054 | /** | |
9055 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
9056 | * @phba: pointer to lpfc hba data structure. | |
9057 | * | |
9058 | * This routine is invoked by the worker thread to process all the pending | |
9059 | * SLI4 FCP abort XRI events. | |
9060 | **/ | |
9061 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
9062 | { | |
9063 | struct lpfc_cq_event *cq_event; | |
9064 | ||
9065 | /* First, declare the fcp xri abort event has been handled */ | |
9066 | spin_lock_irq(&phba->hbalock); | |
9067 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
9068 | spin_unlock_irq(&phba->hbalock); | |
9069 | /* Now, handle all the fcp xri abort events */ | |
9070 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
9071 | /* Get the first event from the head of the event queue */ | |
9072 | spin_lock_irq(&phba->hbalock); | |
9073 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
9074 | cq_event, struct lpfc_cq_event, list); | |
9075 | spin_unlock_irq(&phba->hbalock); | |
9076 | /* Notify aborted XRI for FCP work queue */ | |
9077 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
9078 | /* Free the event processed back to the free pool */ | |
9079 | lpfc_sli4_cq_event_release(phba, cq_event); | |
9080 | } | |
9081 | } | |
9082 | ||
9083 | /** | |
9084 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
9085 | * @phba: pointer to lpfc hba data structure. | |
9086 | * | |
9087 | * This routine is invoked by the worker thread to process all the pending | |
9088 | * SLI4 els abort xri events. | |
9089 | **/ | |
9090 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
9091 | { | |
9092 | struct lpfc_cq_event *cq_event; | |
9093 | ||
9094 | /* First, declare the els xri abort event has been handled */ | |
9095 | spin_lock_irq(&phba->hbalock); | |
9096 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
9097 | spin_unlock_irq(&phba->hbalock); | |
9098 | /* Now, handle all the els xri abort events */ | |
9099 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
9100 | /* Get the first event from the head of the event queue */ | |
9101 | spin_lock_irq(&phba->hbalock); | |
9102 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
9103 | cq_event, struct lpfc_cq_event, list); | |
9104 | spin_unlock_irq(&phba->hbalock); | |
9105 | /* Notify aborted XRI for ELS work queue */ | |
9106 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
9107 | /* Free the event processed back to the free pool */ | |
9108 | lpfc_sli4_cq_event_release(phba, cq_event); | |
9109 | } | |
9110 | } | |
9111 | ||
341af102 JS |
9112 | /** |
9113 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
9114 | * @phba: pointer to lpfc hba data structure | |
9115 | * @pIocbIn: pointer to the rspiocbq | |
9116 | * @pIocbOut: pointer to the cmdiocbq | |
9117 | * @wcqe: pointer to the complete wcqe | |
9118 | * | |
9119 | * This routine transfers the fields of a command iocbq to a response iocbq | |
9120 | * by copying all the IOCB fields from command iocbq and transferring the | |
9121 | * completion status information from the complete wcqe. | |
9122 | **/ | |
4f774513 | 9123 | static void |
341af102 JS |
9124 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
9125 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
9126 | struct lpfc_iocbq *pIocbOut, |
9127 | struct lpfc_wcqe_complete *wcqe) | |
9128 | { | |
341af102 | 9129 | unsigned long iflags; |
4f774513 JS |
9130 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
9131 | ||
9132 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
9133 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 JS |
9134 | /* Map WCQE parameters into irspiocb parameters */ |
9135 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | |
9136 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | |
9137 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
9138 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
9139 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
9140 | wcqe->total_data_placed; | |
9141 | else | |
9142 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 9143 | else { |
4f774513 | 9144 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
9145 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
9146 | } | |
341af102 JS |
9147 | |
9148 | /* Pick up HBA exchange busy condition */ | |
9149 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
9150 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9151 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
9152 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9153 | } | |
4f774513 JS |
9154 | } |
9155 | ||
45ed1190 JS |
9156 | /** |
9157 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
9158 | * @phba: Pointer to HBA context object. | |
9159 | * @wcqe: Pointer to work-queue completion queue entry. | |
9160 | * | |
9161 | * This routine handles an ELS work-queue completion event and construct | |
9162 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
9163 | * discovery engine to handle. | |
9164 | * | |
9165 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
9166 | **/ | |
9167 | static struct lpfc_iocbq * | |
9168 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
9169 | struct lpfc_iocbq *irspiocbq) | |
9170 | { | |
9171 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
9172 | struct lpfc_iocbq *cmdiocbq; | |
9173 | struct lpfc_wcqe_complete *wcqe; | |
9174 | unsigned long iflags; | |
9175 | ||
9176 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
9177 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9178 | pring->stats.iocb_event++; | |
9179 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
9180 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9181 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9182 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9183 | ||
9184 | if (unlikely(!cmdiocbq)) { | |
9185 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9186 | "0386 ELS complete with no corresponding " | |
9187 | "cmdiocb: iotag (%d)\n", | |
9188 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9189 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
9190 | return NULL; | |
9191 | } | |
9192 | ||
9193 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 9194 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
9195 | |
9196 | return irspiocbq; | |
9197 | } | |
9198 | ||
04c68496 JS |
9199 | /** |
9200 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
9201 | * @phba: Pointer to HBA context object. | |
9202 | * @cqe: Pointer to mailbox completion queue entry. | |
9203 | * | |
9204 | * This routine process a mailbox completion queue entry with asynchrous | |
9205 | * event. | |
9206 | * | |
9207 | * Return: true if work posted to worker thread, otherwise false. | |
9208 | **/ | |
9209 | static bool | |
9210 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
9211 | { | |
9212 | struct lpfc_cq_event *cq_event; | |
9213 | unsigned long iflags; | |
9214 | ||
9215 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9216 | "0392 Async Event: word0:x%x, word1:x%x, " | |
9217 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
9218 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
9219 | ||
9220 | /* Allocate a new internal CQ_EVENT entry */ | |
9221 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
9222 | if (!cq_event) { | |
9223 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9224 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
9225 | return false; | |
9226 | } | |
9227 | ||
9228 | /* Move the CQE into an asynchronous event entry */ | |
9229 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
9230 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9231 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
9232 | /* Set the async event flag */ | |
9233 | phba->hba_flag |= ASYNC_EVENT; | |
9234 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9235 | ||
9236 | return true; | |
9237 | } | |
9238 | ||
9239 | /** | |
9240 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
9241 | * @phba: Pointer to HBA context object. | |
9242 | * @cqe: Pointer to mailbox completion queue entry. | |
9243 | * | |
9244 | * This routine process a mailbox completion queue entry with mailbox | |
9245 | * completion event. | |
9246 | * | |
9247 | * Return: true if work posted to worker thread, otherwise false. | |
9248 | **/ | |
9249 | static bool | |
9250 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
9251 | { | |
9252 | uint32_t mcqe_status; | |
9253 | MAILBOX_t *mbox, *pmbox; | |
9254 | struct lpfc_mqe *mqe; | |
9255 | struct lpfc_vport *vport; | |
9256 | struct lpfc_nodelist *ndlp; | |
9257 | struct lpfc_dmabuf *mp; | |
9258 | unsigned long iflags; | |
9259 | LPFC_MBOXQ_t *pmb; | |
9260 | bool workposted = false; | |
9261 | int rc; | |
9262 | ||
9263 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
9264 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
9265 | goto out_no_mqe_complete; | |
9266 | ||
9267 | /* Get the reference to the active mbox command */ | |
9268 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9269 | pmb = phba->sli.mbox_active; | |
9270 | if (unlikely(!pmb)) { | |
9271 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
9272 | "1832 No pending MBOX command to handle\n"); | |
9273 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9274 | goto out_no_mqe_complete; | |
9275 | } | |
9276 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9277 | mqe = &pmb->u.mqe; | |
9278 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
9279 | mbox = phba->mbox; | |
9280 | vport = pmb->vport; | |
9281 | ||
9282 | /* Reset heartbeat timer */ | |
9283 | phba->last_completion_time = jiffies; | |
9284 | del_timer(&phba->sli.mbox_tmo); | |
9285 | ||
9286 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
9287 | if (pmb->mbox_cmpl && mbox) | |
9288 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
9289 | /* Set the mailbox status with SLI4 range 0x4000 */ | |
9290 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
9291 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) | |
9292 | bf_set(lpfc_mqe_status, mqe, | |
9293 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
9294 | ||
9295 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
9296 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
9297 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
9298 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
9299 | mcqe_status, | |
9300 | pmbox->un.varWords[0], 0); | |
9301 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
9302 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
9303 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
9304 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
9305 | * RID of the PPI using the same mbox buffer. | |
9306 | */ | |
9307 | lpfc_unreg_login(phba, vport->vpi, | |
9308 | pmbox->un.varWords[0], pmb); | |
9309 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
9310 | pmb->context1 = mp; | |
9311 | pmb->context2 = ndlp; | |
9312 | pmb->vport = vport; | |
9313 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
9314 | if (rc != MBX_BUSY) | |
9315 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
9316 | LOG_SLI, "0385 rc should " | |
9317 | "have been MBX_BUSY\n"); | |
9318 | if (rc != MBX_NOT_FINISHED) | |
9319 | goto send_current_mbox; | |
9320 | } | |
9321 | } | |
9322 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
9323 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
9324 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
9325 | ||
9326 | /* There is mailbox completion work to do */ | |
9327 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9328 | __lpfc_mbox_cmpl_put(phba, pmb); | |
9329 | phba->work_ha |= HA_MBATT; | |
9330 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9331 | workposted = true; | |
9332 | ||
9333 | send_current_mbox: | |
9334 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9335 | /* Release the mailbox command posting token */ | |
9336 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9337 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
9338 | phba->sli.mbox_active = NULL; | |
9339 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9340 | /* Wake up worker thread to post the next pending mailbox command */ | |
9341 | lpfc_worker_wake_up(phba); | |
9342 | out_no_mqe_complete: | |
9343 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
9344 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
9345 | return workposted; | |
9346 | } | |
9347 | ||
9348 | /** | |
9349 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
9350 | * @phba: Pointer to HBA context object. | |
9351 | * @cqe: Pointer to mailbox completion queue entry. | |
9352 | * | |
9353 | * This routine process a mailbox completion queue entry, it invokes the | |
9354 | * proper mailbox complete handling or asynchrous event handling routine | |
9355 | * according to the MCQE's async bit. | |
9356 | * | |
9357 | * Return: true if work posted to worker thread, otherwise false. | |
9358 | **/ | |
9359 | static bool | |
9360 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
9361 | { | |
9362 | struct lpfc_mcqe mcqe; | |
9363 | bool workposted; | |
9364 | ||
9365 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
9366 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
9367 | ||
9368 | /* Invoke the proper event handling routine */ | |
9369 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
9370 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
9371 | else | |
9372 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
9373 | return workposted; | |
9374 | } | |
9375 | ||
4f774513 JS |
9376 | /** |
9377 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
9378 | * @phba: Pointer to HBA context object. | |
9379 | * @wcqe: Pointer to work-queue completion queue entry. | |
9380 | * | |
9381 | * This routine handles an ELS work-queue completion event. | |
9382 | * | |
9383 | * Return: true if work posted to worker thread, otherwise false. | |
9384 | **/ | |
9385 | static bool | |
9386 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | |
9387 | struct lpfc_wcqe_complete *wcqe) | |
9388 | { | |
4f774513 JS |
9389 | struct lpfc_iocbq *irspiocbq; |
9390 | unsigned long iflags; | |
2a9bf3d0 | 9391 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
4f774513 | 9392 | |
45ed1190 | 9393 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
9394 | irspiocbq = lpfc_sli_get_iocbq(phba); |
9395 | if (!irspiocbq) { | |
9396 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
9397 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
9398 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
9399 | pring->txq_cnt, phba->iocb_cnt, | |
9400 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
9401 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 9402 | return false; |
4f774513 | 9403 | } |
4f774513 | 9404 | |
45ed1190 JS |
9405 | /* Save off the slow-path queue event for work thread to process */ |
9406 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 9407 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 9408 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
9409 | &phba->sli4_hba.sp_queue_event); |
9410 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 9411 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 9412 | |
45ed1190 | 9413 | return true; |
4f774513 JS |
9414 | } |
9415 | ||
9416 | /** | |
9417 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
9418 | * @phba: Pointer to HBA context object. | |
9419 | * @wcqe: Pointer to work-queue completion queue entry. | |
9420 | * | |
9421 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
9422 | * proper WQ release routine to the slow-path WQ. | |
9423 | **/ | |
9424 | static void | |
9425 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
9426 | struct lpfc_wcqe_release *wcqe) | |
9427 | { | |
9428 | /* Check for the slow-path ELS work queue */ | |
9429 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
9430 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
9431 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9432 | else | |
9433 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9434 | "2579 Slow-path wqe consume event carries " | |
9435 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
9436 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
9437 | phba->sli4_hba.els_wq->queue_id); | |
9438 | } | |
9439 | ||
9440 | /** | |
9441 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
9442 | * @phba: Pointer to HBA context object. | |
9443 | * @cq: Pointer to a WQ completion queue. | |
9444 | * @wcqe: Pointer to work-queue completion queue entry. | |
9445 | * | |
9446 | * This routine handles an XRI abort event. | |
9447 | * | |
9448 | * Return: true if work posted to worker thread, otherwise false. | |
9449 | **/ | |
9450 | static bool | |
9451 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
9452 | struct lpfc_queue *cq, | |
9453 | struct sli4_wcqe_xri_aborted *wcqe) | |
9454 | { | |
9455 | bool workposted = false; | |
9456 | struct lpfc_cq_event *cq_event; | |
9457 | unsigned long iflags; | |
9458 | ||
9459 | /* Allocate a new internal CQ_EVENT entry */ | |
9460 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
9461 | if (!cq_event) { | |
9462 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9463 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
9464 | return false; | |
9465 | } | |
9466 | ||
9467 | /* Move the CQE into the proper xri abort event list */ | |
9468 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
9469 | switch (cq->subtype) { | |
9470 | case LPFC_FCP: | |
9471 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9472 | list_add_tail(&cq_event->list, | |
9473 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
9474 | /* Set the fcp xri abort event flag */ | |
9475 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
9476 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9477 | workposted = true; | |
9478 | break; | |
9479 | case LPFC_ELS: | |
9480 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9481 | list_add_tail(&cq_event->list, | |
9482 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
9483 | /* Set the els xri abort event flag */ | |
9484 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
9485 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9486 | workposted = true; | |
9487 | break; | |
9488 | default: | |
9489 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9490 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
9491 | cq->subtype); | |
9492 | workposted = false; | |
9493 | break; | |
9494 | } | |
9495 | return workposted; | |
9496 | } | |
9497 | ||
4f774513 JS |
9498 | /** |
9499 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
9500 | * @phba: Pointer to HBA context object. | |
9501 | * @rcqe: Pointer to receive-queue completion queue entry. | |
9502 | * | |
9503 | * This routine process a receive-queue completion queue entry. | |
9504 | * | |
9505 | * Return: true if work posted to worker thread, otherwise false. | |
9506 | **/ | |
9507 | static bool | |
4d9ab994 | 9508 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 9509 | { |
4f774513 JS |
9510 | bool workposted = false; |
9511 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
9512 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
9513 | struct hbq_dmabuf *dma_buf; | |
9514 | uint32_t status; | |
9515 | unsigned long iflags; | |
9516 | ||
4d9ab994 | 9517 | if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id) |
4f774513 JS |
9518 | goto out; |
9519 | ||
4d9ab994 | 9520 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
9521 | switch (status) { |
9522 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
9523 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9524 | "2537 Receive Frame Truncated!!\n"); | |
9525 | case FC_STATUS_RQ_SUCCESS: | |
5ffc266e | 9526 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
9527 | spin_lock_irqsave(&phba->hbalock, iflags); |
9528 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
9529 | if (!dma_buf) { | |
9530 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9531 | goto out; | |
9532 | } | |
4d9ab994 | 9533 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 9534 | /* save off the frame for the word thread to process */ |
4d9ab994 | 9535 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 9536 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 9537 | /* Frame received */ |
45ed1190 | 9538 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
9539 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
9540 | workposted = true; | |
9541 | break; | |
9542 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
9543 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
9544 | /* Post more buffers if possible */ | |
9545 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9546 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
9547 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9548 | workposted = true; | |
9549 | break; | |
9550 | } | |
9551 | out: | |
9552 | return workposted; | |
4f774513 JS |
9553 | } |
9554 | ||
4d9ab994 JS |
9555 | /** |
9556 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
9557 | * @phba: Pointer to HBA context object. | |
9558 | * @cq: Pointer to the completion queue. | |
9559 | * @wcqe: Pointer to a completion queue entry. | |
9560 | * | |
9561 | * This routine process a slow-path work-queue or recieve queue completion queue | |
9562 | * entry. | |
9563 | * | |
9564 | * Return: true if work posted to worker thread, otherwise false. | |
9565 | **/ | |
9566 | static bool | |
9567 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9568 | struct lpfc_cqe *cqe) | |
9569 | { | |
45ed1190 | 9570 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
9571 | bool workposted = false; |
9572 | ||
9573 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 9574 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
9575 | |
9576 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 9577 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 9578 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 9579 | /* Process the WQ/RQ complete event */ |
bc73905a | 9580 | phba->last_completion_time = jiffies; |
4d9ab994 | 9581 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
45ed1190 | 9582 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
9583 | break; |
9584 | case CQE_CODE_RELEASE_WQE: | |
9585 | /* Process the WQ release event */ | |
9586 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 9587 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
9588 | break; |
9589 | case CQE_CODE_XRI_ABORTED: | |
9590 | /* Process the WQ XRI abort event */ | |
bc73905a | 9591 | phba->last_completion_time = jiffies; |
4d9ab994 | 9592 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 9593 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
9594 | break; |
9595 | case CQE_CODE_RECEIVE: | |
9596 | /* Process the RQ event */ | |
bc73905a | 9597 | phba->last_completion_time = jiffies; |
4d9ab994 | 9598 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 9599 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
9600 | break; |
9601 | default: | |
9602 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9603 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 9604 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
9605 | break; |
9606 | } | |
9607 | return workposted; | |
9608 | } | |
9609 | ||
4f774513 JS |
9610 | /** |
9611 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
9612 | * @phba: Pointer to HBA context object. | |
9613 | * @eqe: Pointer to fast-path event queue entry. | |
9614 | * | |
9615 | * This routine process a event queue entry from the slow-path event queue. | |
9616 | * It will check the MajorCode and MinorCode to determine this is for a | |
9617 | * completion event on a completion queue, if not, an error shall be logged | |
9618 | * and just return. Otherwise, it will get to the corresponding completion | |
9619 | * queue and process all the entries on that completion queue, rearm the | |
9620 | * completion queue, and then return. | |
9621 | * | |
9622 | **/ | |
9623 | static void | |
9624 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
9625 | { | |
9626 | struct lpfc_queue *cq = NULL, *childq, *speq; | |
9627 | struct lpfc_cqe *cqe; | |
9628 | bool workposted = false; | |
9629 | int ecount = 0; | |
9630 | uint16_t cqid; | |
9631 | ||
cb5172ea | 9632 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
4f774513 JS |
9633 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9634 | "0359 Not a valid slow-path completion " | |
9635 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9636 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9637 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9638 | return; |
9639 | } | |
9640 | ||
9641 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9642 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9643 | |
9644 | /* Search for completion queue pointer matching this cqid */ | |
9645 | speq = phba->sli4_hba.sp_eq; | |
9646 | list_for_each_entry(childq, &speq->child_list, list) { | |
9647 | if (childq->queue_id == cqid) { | |
9648 | cq = childq; | |
9649 | break; | |
9650 | } | |
9651 | } | |
9652 | if (unlikely(!cq)) { | |
75baf696 JS |
9653 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
9654 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9655 | "0365 Slow-path CQ identifier " | |
9656 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
9657 | return; |
9658 | } | |
9659 | ||
9660 | /* Process all the entries to the CQ */ | |
9661 | switch (cq->type) { | |
9662 | case LPFC_MCQ: | |
9663 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9664 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
9665 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9666 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9667 | } | |
9668 | break; | |
9669 | case LPFC_WCQ: | |
9670 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
4d9ab994 | 9671 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe); |
4f774513 JS |
9672 | if (!(++ecount % LPFC_GET_QE_REL_INT)) |
9673 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9674 | } | |
9675 | break; | |
9676 | default: | |
9677 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9678 | "0370 Invalid completion queue type (%d)\n", | |
9679 | cq->type); | |
9680 | return; | |
9681 | } | |
9682 | ||
9683 | /* Catch the no cq entry condition, log an error */ | |
9684 | if (unlikely(ecount == 0)) | |
9685 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9686 | "0371 No entry from the CQ: identifier " | |
9687 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
9688 | ||
9689 | /* In any case, flash and re-arm the RCQ */ | |
9690 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9691 | ||
9692 | /* wake up worker thread if there are works to be done */ | |
9693 | if (workposted) | |
9694 | lpfc_worker_wake_up(phba); | |
9695 | } | |
9696 | ||
9697 | /** | |
9698 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
9699 | * @eqe: Pointer to fast-path completion queue entry. | |
9700 | * | |
9701 | * This routine process a fast-path work queue completion entry from fast-path | |
9702 | * event queue for FCP command response completion. | |
9703 | **/ | |
9704 | static void | |
9705 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | |
9706 | struct lpfc_wcqe_complete *wcqe) | |
9707 | { | |
9708 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | |
9709 | struct lpfc_iocbq *cmdiocbq; | |
9710 | struct lpfc_iocbq irspiocbq; | |
9711 | unsigned long iflags; | |
9712 | ||
9713 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9714 | pring->stats.iocb_event++; | |
9715 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9716 | ||
9717 | /* Check for response status */ | |
9718 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
9719 | /* If resource errors reported from HBA, reduce queue | |
9720 | * depth of the SCSI device. | |
9721 | */ | |
9722 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
9723 | IOSTAT_LOCAL_REJECT) && | |
9724 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
9725 | phba->lpfc_rampdown_queue_depth(phba); | |
9726 | } | |
9727 | /* Log the error status */ | |
9728 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9729 | "0373 FCP complete error: status=x%x, " | |
9730 | "hw_status=x%x, total_data_specified=%d, " | |
9731 | "parameter=x%x, word3=x%x\n", | |
9732 | bf_get(lpfc_wcqe_c_status, wcqe), | |
9733 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
9734 | wcqe->total_data_placed, wcqe->parameter, | |
9735 | wcqe->word3); | |
9736 | } | |
9737 | ||
9738 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
9739 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9740 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9741 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9742 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9743 | if (unlikely(!cmdiocbq)) { | |
9744 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9745 | "0374 FCP complete with no corresponding " | |
9746 | "cmdiocb: iotag (%d)\n", | |
9747 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9748 | return; | |
9749 | } | |
9750 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
9751 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9752 | "0375 FCP cmdiocb not callback function " | |
9753 | "iotag: (%d)\n", | |
9754 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9755 | return; | |
9756 | } | |
9757 | ||
9758 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 9759 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 9760 | |
0f65ff68 JS |
9761 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
9762 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9763 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
9764 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9765 | } | |
9766 | ||
4f774513 JS |
9767 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
9768 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
9769 | } | |
9770 | ||
9771 | /** | |
9772 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
9773 | * @phba: Pointer to HBA context object. | |
9774 | * @cq: Pointer to completion queue. | |
9775 | * @wcqe: Pointer to work-queue completion queue entry. | |
9776 | * | |
9777 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
9778 | * proper WQ release routine to the slow-path WQ. | |
9779 | **/ | |
9780 | static void | |
9781 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9782 | struct lpfc_wcqe_release *wcqe) | |
9783 | { | |
9784 | struct lpfc_queue *childwq; | |
9785 | bool wqid_matched = false; | |
9786 | uint16_t fcp_wqid; | |
9787 | ||
9788 | /* Check for fast-path FCP work queue release */ | |
9789 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
9790 | list_for_each_entry(childwq, &cq->child_list, list) { | |
9791 | if (childwq->queue_id == fcp_wqid) { | |
9792 | lpfc_sli4_wq_release(childwq, | |
9793 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9794 | wqid_matched = true; | |
9795 | break; | |
9796 | } | |
9797 | } | |
9798 | /* Report warning log message if no match found */ | |
9799 | if (wqid_matched != true) | |
9800 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9801 | "2580 Fast-path wqe consume event carries " | |
9802 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
9803 | } | |
9804 | ||
9805 | /** | |
9806 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
9807 | * @cq: Pointer to the completion queue. | |
9808 | * @eqe: Pointer to fast-path completion queue entry. | |
9809 | * | |
9810 | * This routine process a fast-path work queue completion entry from fast-path | |
9811 | * event queue for FCP command response completion. | |
9812 | **/ | |
9813 | static int | |
9814 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9815 | struct lpfc_cqe *cqe) | |
9816 | { | |
9817 | struct lpfc_wcqe_release wcqe; | |
9818 | bool workposted = false; | |
9819 | ||
9820 | /* Copy the work queue CQE and convert endian order if needed */ | |
9821 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
9822 | ||
9823 | /* Check and process for different type of WCQE and dispatch */ | |
9824 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
9825 | case CQE_CODE_COMPL_WQE: | |
9826 | /* Process the WQ complete event */ | |
98fc5dd9 | 9827 | phba->last_completion_time = jiffies; |
4f774513 JS |
9828 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
9829 | (struct lpfc_wcqe_complete *)&wcqe); | |
9830 | break; | |
9831 | case CQE_CODE_RELEASE_WQE: | |
9832 | /* Process the WQ release event */ | |
9833 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
9834 | (struct lpfc_wcqe_release *)&wcqe); | |
9835 | break; | |
9836 | case CQE_CODE_XRI_ABORTED: | |
9837 | /* Process the WQ XRI abort event */ | |
bc73905a | 9838 | phba->last_completion_time = jiffies; |
4f774513 JS |
9839 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
9840 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
9841 | break; | |
9842 | default: | |
9843 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9844 | "0144 Not a valid WCQE code: x%x\n", | |
9845 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
9846 | break; | |
9847 | } | |
9848 | return workposted; | |
9849 | } | |
9850 | ||
9851 | /** | |
9852 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | |
9853 | * @phba: Pointer to HBA context object. | |
9854 | * @eqe: Pointer to fast-path event queue entry. | |
9855 | * | |
9856 | * This routine process a event queue entry from the fast-path event queue. | |
9857 | * It will check the MajorCode and MinorCode to determine this is for a | |
9858 | * completion event on a completion queue, if not, an error shall be logged | |
9859 | * and just return. Otherwise, it will get to the corresponding completion | |
9860 | * queue and process all the entries on the completion queue, rearm the | |
9861 | * completion queue, and then return. | |
9862 | **/ | |
9863 | static void | |
9864 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | |
9865 | uint32_t fcp_cqidx) | |
9866 | { | |
9867 | struct lpfc_queue *cq; | |
9868 | struct lpfc_cqe *cqe; | |
9869 | bool workposted = false; | |
9870 | uint16_t cqid; | |
9871 | int ecount = 0; | |
9872 | ||
cb5172ea | 9873 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 JS |
9874 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9875 | "0366 Not a valid fast-path completion " | |
9876 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9877 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9878 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9879 | return; |
9880 | } | |
9881 | ||
9882 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | |
9883 | if (unlikely(!cq)) { | |
75baf696 JS |
9884 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
9885 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9886 | "0367 Fast-path completion queue " | |
9887 | "does not exist\n"); | |
4f774513 JS |
9888 | return; |
9889 | } | |
9890 | ||
9891 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9892 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9893 | if (unlikely(cqid != cq->queue_id)) { |
9894 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9895 | "0368 Miss-matched fast-path completion " | |
9896 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
9897 | cqid, cq->queue_id); | |
9898 | return; | |
9899 | } | |
9900 | ||
9901 | /* Process all the entries to the CQ */ | |
9902 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9903 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
9904 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9905 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9906 | } | |
9907 | ||
9908 | /* Catch the no cq entry condition */ | |
9909 | if (unlikely(ecount == 0)) | |
9910 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9911 | "0369 No entry from fast-path completion " | |
9912 | "queue fcpcqid=%d\n", cq->queue_id); | |
9913 | ||
9914 | /* In any case, flash and re-arm the CQ */ | |
9915 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9916 | ||
9917 | /* wake up worker thread if there are works to be done */ | |
9918 | if (workposted) | |
9919 | lpfc_worker_wake_up(phba); | |
9920 | } | |
9921 | ||
9922 | static void | |
9923 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
9924 | { | |
9925 | struct lpfc_eqe *eqe; | |
9926 | ||
9927 | /* walk all the EQ entries and drop on the floor */ | |
9928 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
9929 | ; | |
9930 | ||
9931 | /* Clear and re-arm the EQ */ | |
9932 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
9933 | } | |
9934 | ||
9935 | /** | |
9936 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | |
9937 | * @irq: Interrupt number. | |
9938 | * @dev_id: The device context pointer. | |
9939 | * | |
9940 | * This function is directly called from the PCI layer as an interrupt | |
9941 | * service routine when device with SLI-4 interface spec is enabled with | |
9942 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
9943 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
9944 | * interrupt mode, this function is called as part of the device-level | |
9945 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | |
9946 | * undergoing initialization, the interrupt handler will not process the | |
9947 | * interrupt. The link attention and ELS ring attention events are handled | |
9948 | * by the worker thread. The interrupt handler signals the worker thread | |
9949 | * and returns for these events. This function is called without any lock | |
9950 | * held. It gets the hbalock to access and update SLI data structures. | |
9951 | * | |
9952 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
9953 | * returns IRQ_NONE. | |
9954 | **/ | |
9955 | irqreturn_t | |
9956 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | |
9957 | { | |
9958 | struct lpfc_hba *phba; | |
9959 | struct lpfc_queue *speq; | |
9960 | struct lpfc_eqe *eqe; | |
9961 | unsigned long iflag; | |
9962 | int ecount = 0; | |
9963 | ||
9964 | /* | |
9965 | * Get the driver's phba structure from the dev_id | |
9966 | */ | |
9967 | phba = (struct lpfc_hba *)dev_id; | |
9968 | ||
9969 | if (unlikely(!phba)) | |
9970 | return IRQ_NONE; | |
9971 | ||
9972 | /* Get to the EQ struct associated with this vector */ | |
9973 | speq = phba->sli4_hba.sp_eq; | |
9974 | ||
9975 | /* Check device state for handling interrupt */ | |
9976 | if (unlikely(lpfc_intr_state_check(phba))) { | |
9977 | /* Check again for link_state with lock held */ | |
9978 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9979 | if (phba->link_state < LPFC_LINK_DOWN) | |
9980 | /* Flush, clear interrupt, and rearm the EQ */ | |
9981 | lpfc_sli4_eq_flush(phba, speq); | |
9982 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9983 | return IRQ_NONE; | |
9984 | } | |
9985 | ||
9986 | /* | |
9987 | * Process all the event on FCP slow-path EQ | |
9988 | */ | |
9989 | while ((eqe = lpfc_sli4_eq_get(speq))) { | |
9990 | lpfc_sli4_sp_handle_eqe(phba, eqe); | |
9991 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9992 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); | |
9993 | } | |
9994 | ||
9995 | /* Always clear and re-arm the slow-path EQ */ | |
9996 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | |
9997 | ||
9998 | /* Catch the no cq entry condition */ | |
9999 | if (unlikely(ecount == 0)) { | |
10000 | if (phba->intr_type == MSIX) | |
10001 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10002 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10003 | "0357 MSI-X interrupt with no EQE\n"); | |
10004 | else | |
10005 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10006 | return IRQ_NONE; | |
10007 | } | |
10008 | ||
10009 | return IRQ_HANDLED; | |
10010 | } /* lpfc_sli4_sp_intr_handler */ | |
10011 | ||
10012 | /** | |
10013 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | |
10014 | * @irq: Interrupt number. | |
10015 | * @dev_id: The device context pointer. | |
10016 | * | |
10017 | * This function is directly called from the PCI layer as an interrupt | |
10018 | * service routine when device with SLI-4 interface spec is enabled with | |
10019 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10020 | * ring event in the HBA. However, when the device is enabled with either | |
10021 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10022 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10023 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10024 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
10025 | * the intrrupt context. This function is called without any lock held. | |
10026 | * It gets the hbalock to access and update SLI data structures. Note that, | |
10027 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
10028 | * equal to that of FCP CQ index. | |
10029 | * | |
10030 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10031 | * returns IRQ_NONE. | |
10032 | **/ | |
10033 | irqreturn_t | |
10034 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | |
10035 | { | |
10036 | struct lpfc_hba *phba; | |
10037 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
10038 | struct lpfc_queue *fpeq; | |
10039 | struct lpfc_eqe *eqe; | |
10040 | unsigned long iflag; | |
10041 | int ecount = 0; | |
10042 | uint32_t fcp_eqidx; | |
10043 | ||
10044 | /* Get the driver's phba structure from the dev_id */ | |
10045 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
10046 | phba = fcp_eq_hdl->phba; | |
10047 | fcp_eqidx = fcp_eq_hdl->idx; | |
10048 | ||
10049 | if (unlikely(!phba)) | |
10050 | return IRQ_NONE; | |
10051 | ||
10052 | /* Get to the EQ struct associated with this vector */ | |
10053 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | |
10054 | ||
10055 | /* Check device state for handling interrupt */ | |
10056 | if (unlikely(lpfc_intr_state_check(phba))) { | |
10057 | /* Check again for link_state with lock held */ | |
10058 | spin_lock_irqsave(&phba->hbalock, iflag); | |
10059 | if (phba->link_state < LPFC_LINK_DOWN) | |
10060 | /* Flush, clear interrupt, and rearm the EQ */ | |
10061 | lpfc_sli4_eq_flush(phba, fpeq); | |
10062 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10063 | return IRQ_NONE; | |
10064 | } | |
10065 | ||
10066 | /* | |
10067 | * Process all the event on FCP fast-path EQ | |
10068 | */ | |
10069 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
10070 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | |
10071 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10072 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); | |
10073 | } | |
10074 | ||
10075 | /* Always clear and re-arm the fast-path EQ */ | |
10076 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
10077 | ||
10078 | if (unlikely(ecount == 0)) { | |
10079 | if (phba->intr_type == MSIX) | |
10080 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10081 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10082 | "0358 MSI-X interrupt with no EQE\n"); | |
10083 | else | |
10084 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10085 | return IRQ_NONE; | |
10086 | } | |
10087 | ||
10088 | return IRQ_HANDLED; | |
10089 | } /* lpfc_sli4_fp_intr_handler */ | |
10090 | ||
10091 | /** | |
10092 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
10093 | * @irq: Interrupt number. | |
10094 | * @dev_id: The device context pointer. | |
10095 | * | |
10096 | * This function is the device-level interrupt handler to device with SLI-4 | |
10097 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
10098 | * interrupt mode is enabled and there is an event in the HBA which requires | |
10099 | * driver attention. This function invokes the slow-path interrupt attention | |
10100 | * handling function and fast-path interrupt attention handling function in | |
10101 | * turn to process the relevant HBA attention events. This function is called | |
10102 | * without any lock held. It gets the hbalock to access and update SLI data | |
10103 | * structures. | |
10104 | * | |
10105 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
10106 | * returns IRQ_NONE. | |
10107 | **/ | |
10108 | irqreturn_t | |
10109 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
10110 | { | |
10111 | struct lpfc_hba *phba; | |
10112 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
10113 | bool fp_handled = false; | |
10114 | uint32_t fcp_eqidx; | |
10115 | ||
10116 | /* Get the driver's phba structure from the dev_id */ | |
10117 | phba = (struct lpfc_hba *)dev_id; | |
10118 | ||
10119 | if (unlikely(!phba)) | |
10120 | return IRQ_NONE; | |
10121 | ||
10122 | /* | |
10123 | * Invokes slow-path host attention interrupt handling as appropriate. | |
10124 | */ | |
10125 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | |
10126 | ||
10127 | /* | |
10128 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10129 | */ | |
10130 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
10131 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | |
10132 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | |
10133 | if (fp_irq_rc == IRQ_HANDLED) | |
10134 | fp_handled |= true; | |
10135 | } | |
10136 | ||
10137 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | |
10138 | } /* lpfc_sli4_intr_handler */ | |
10139 | ||
10140 | /** | |
10141 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
10142 | * @queue: The queue structure to free. | |
10143 | * | |
10144 | * This function frees a queue structure and the DMAable memeory used for | |
10145 | * the host resident queue. This function must be called after destroying the | |
10146 | * queue on the HBA. | |
10147 | **/ | |
10148 | void | |
10149 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
10150 | { | |
10151 | struct lpfc_dmabuf *dmabuf; | |
10152 | ||
10153 | if (!queue) | |
10154 | return; | |
10155 | ||
10156 | while (!list_empty(&queue->page_list)) { | |
10157 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
10158 | list); | |
49198b37 | 10159 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
10160 | dmabuf->virt, dmabuf->phys); |
10161 | kfree(dmabuf); | |
10162 | } | |
10163 | kfree(queue); | |
10164 | return; | |
10165 | } | |
10166 | ||
10167 | /** | |
10168 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
10169 | * @phba: The HBA that this queue is being created on. | |
10170 | * @entry_size: The size of each queue entry for this queue. | |
10171 | * @entry count: The number of entries that this queue will handle. | |
10172 | * | |
10173 | * This function allocates a queue structure and the DMAable memory used for | |
10174 | * the host resident queue. This function must be called before creating the | |
10175 | * queue on the HBA. | |
10176 | **/ | |
10177 | struct lpfc_queue * | |
10178 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
10179 | uint32_t entry_count) | |
10180 | { | |
10181 | struct lpfc_queue *queue; | |
10182 | struct lpfc_dmabuf *dmabuf; | |
10183 | int x, total_qe_count; | |
10184 | void *dma_pointer; | |
cb5172ea | 10185 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 10186 | |
cb5172ea JS |
10187 | if (!phba->sli4_hba.pc_sli4_params.supported) |
10188 | hw_page_size = SLI4_PAGE_SIZE; | |
10189 | ||
4f774513 JS |
10190 | queue = kzalloc(sizeof(struct lpfc_queue) + |
10191 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
10192 | if (!queue) | |
10193 | return NULL; | |
cb5172ea JS |
10194 | queue->page_count = (ALIGN(entry_size * entry_count, |
10195 | hw_page_size))/hw_page_size; | |
4f774513 JS |
10196 | INIT_LIST_HEAD(&queue->list); |
10197 | INIT_LIST_HEAD(&queue->page_list); | |
10198 | INIT_LIST_HEAD(&queue->child_list); | |
10199 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
10200 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
10201 | if (!dmabuf) | |
10202 | goto out_fail; | |
10203 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 10204 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
10205 | GFP_KERNEL); |
10206 | if (!dmabuf->virt) { | |
10207 | kfree(dmabuf); | |
10208 | goto out_fail; | |
10209 | } | |
cb5172ea | 10210 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10211 | dmabuf->buffer_tag = x; |
10212 | list_add_tail(&dmabuf->list, &queue->page_list); | |
10213 | /* initialize queue's entry array */ | |
10214 | dma_pointer = dmabuf->virt; | |
10215 | for (; total_qe_count < entry_count && | |
cb5172ea | 10216 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
10217 | total_qe_count++, dma_pointer += entry_size) { |
10218 | queue->qe[total_qe_count].address = dma_pointer; | |
10219 | } | |
10220 | } | |
10221 | queue->entry_size = entry_size; | |
10222 | queue->entry_count = entry_count; | |
10223 | queue->phba = phba; | |
10224 | ||
10225 | return queue; | |
10226 | out_fail: | |
10227 | lpfc_sli4_queue_free(queue); | |
10228 | return NULL; | |
10229 | } | |
10230 | ||
10231 | /** | |
10232 | * lpfc_eq_create - Create an Event Queue on the HBA | |
10233 | * @phba: HBA structure that indicates port to create a queue on. | |
10234 | * @eq: The queue structure to use to create the event queue. | |
10235 | * @imax: The maximum interrupt per second limit. | |
10236 | * | |
10237 | * This function creates an event queue, as detailed in @eq, on a port, | |
10238 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
10239 | * | |
10240 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
10241 | * is used to get the entry count and entry size that are necessary to | |
10242 | * determine the number of pages to allocate and use for this queue. This | |
10243 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
10244 | * event queue. This function is asynchronous and will wait for the mailbox | |
10245 | * command to finish before continuing. | |
10246 | * | |
10247 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10248 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10249 | * fails this function will return -ENXIO. | |
4f774513 JS |
10250 | **/ |
10251 | uint32_t | |
10252 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
10253 | { | |
10254 | struct lpfc_mbx_eq_create *eq_create; | |
10255 | LPFC_MBOXQ_t *mbox; | |
10256 | int rc, length, status = 0; | |
10257 | struct lpfc_dmabuf *dmabuf; | |
10258 | uint32_t shdr_status, shdr_add_status; | |
10259 | union lpfc_sli4_cfg_shdr *shdr; | |
10260 | uint16_t dmult; | |
49198b37 JS |
10261 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10262 | ||
10263 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10264 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10265 | |
10266 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10267 | if (!mbox) | |
10268 | return -ENOMEM; | |
10269 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
10270 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10271 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10272 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
10273 | length, LPFC_SLI4_MBX_EMBED); | |
10274 | eq_create = &mbox->u.mqe.un.eq_create; | |
10275 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
10276 | eq->page_count); | |
10277 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
10278 | LPFC_EQE_SIZE); | |
10279 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
10280 | /* Calculate delay multiper from maximum interrupt per second */ | |
10281 | dmult = LPFC_DMULT_CONST/imax - 1; | |
10282 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
10283 | dmult); | |
10284 | switch (eq->entry_count) { | |
10285 | default: | |
10286 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10287 | "0360 Unsupported EQ count. (%d)\n", | |
10288 | eq->entry_count); | |
10289 | if (eq->entry_count < 256) | |
10290 | return -EINVAL; | |
10291 | /* otherwise default to smallest count (drop through) */ | |
10292 | case 256: | |
10293 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10294 | LPFC_EQ_CNT_256); | |
10295 | break; | |
10296 | case 512: | |
10297 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10298 | LPFC_EQ_CNT_512); | |
10299 | break; | |
10300 | case 1024: | |
10301 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10302 | LPFC_EQ_CNT_1024); | |
10303 | break; | |
10304 | case 2048: | |
10305 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10306 | LPFC_EQ_CNT_2048); | |
10307 | break; | |
10308 | case 4096: | |
10309 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10310 | LPFC_EQ_CNT_4096); | |
10311 | break; | |
10312 | } | |
10313 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 10314 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10315 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10316 | putPaddrLow(dmabuf->phys); | |
10317 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10318 | putPaddrHigh(dmabuf->phys); | |
10319 | } | |
10320 | mbox->vport = phba->pport; | |
10321 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10322 | mbox->context1 = NULL; | |
10323 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10324 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
10325 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10326 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10327 | if (shdr_status || shdr_add_status || rc) { | |
10328 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10329 | "2500 EQ_CREATE mailbox failed with " | |
10330 | "status x%x add_status x%x, mbx status x%x\n", | |
10331 | shdr_status, shdr_add_status, rc); | |
10332 | status = -ENXIO; | |
10333 | } | |
10334 | eq->type = LPFC_EQ; | |
10335 | eq->subtype = LPFC_NONE; | |
10336 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
10337 | if (eq->queue_id == 0xFFFF) | |
10338 | status = -ENXIO; | |
10339 | eq->host_index = 0; | |
10340 | eq->hba_index = 0; | |
10341 | ||
8fa38513 | 10342 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10343 | return status; |
10344 | } | |
10345 | ||
10346 | /** | |
10347 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
10348 | * @phba: HBA structure that indicates port to create a queue on. | |
10349 | * @cq: The queue structure to use to create the completion queue. | |
10350 | * @eq: The event queue to bind this completion queue to. | |
10351 | * | |
10352 | * This function creates a completion queue, as detailed in @wq, on a port, | |
10353 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
10354 | * | |
10355 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
10356 | * is used to get the entry count and entry size that are necessary to | |
10357 | * determine the number of pages to allocate and use for this queue. The @eq | |
10358 | * is used to indicate which event queue to bind this completion queue to. This | |
10359 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
10360 | * completion queue. This function is asynchronous and will wait for the mailbox | |
10361 | * command to finish before continuing. | |
10362 | * | |
10363 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10364 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10365 | * fails this function will return -ENXIO. | |
4f774513 JS |
10366 | **/ |
10367 | uint32_t | |
10368 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
10369 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
10370 | { | |
10371 | struct lpfc_mbx_cq_create *cq_create; | |
10372 | struct lpfc_dmabuf *dmabuf; | |
10373 | LPFC_MBOXQ_t *mbox; | |
10374 | int rc, length, status = 0; | |
10375 | uint32_t shdr_status, shdr_add_status; | |
10376 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10377 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10378 | ||
10379 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10380 | hw_page_size = SLI4_PAGE_SIZE; | |
10381 | ||
4f774513 JS |
10382 | |
10383 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10384 | if (!mbox) | |
10385 | return -ENOMEM; | |
10386 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
10387 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10388 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10389 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
10390 | length, LPFC_SLI4_MBX_EMBED); | |
10391 | cq_create = &mbox->u.mqe.un.cq_create; | |
10392 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, | |
10393 | cq->page_count); | |
10394 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
10395 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
10396 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id); | |
10397 | switch (cq->entry_count) { | |
10398 | default: | |
10399 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10400 | "0361 Unsupported CQ count. (%d)\n", | |
10401 | cq->entry_count); | |
10402 | if (cq->entry_count < 256) | |
10403 | return -EINVAL; | |
10404 | /* otherwise default to smallest count (drop through) */ | |
10405 | case 256: | |
10406 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10407 | LPFC_CQ_CNT_256); | |
10408 | break; | |
10409 | case 512: | |
10410 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10411 | LPFC_CQ_CNT_512); | |
10412 | break; | |
10413 | case 1024: | |
10414 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10415 | LPFC_CQ_CNT_1024); | |
10416 | break; | |
10417 | } | |
10418 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 10419 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10420 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10421 | putPaddrLow(dmabuf->phys); | |
10422 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10423 | putPaddrHigh(dmabuf->phys); | |
10424 | } | |
10425 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10426 | ||
10427 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10428 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; | |
10429 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10430 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10431 | if (shdr_status || shdr_add_status || rc) { | |
10432 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10433 | "2501 CQ_CREATE mailbox failed with " | |
10434 | "status x%x add_status x%x, mbx status x%x\n", | |
10435 | shdr_status, shdr_add_status, rc); | |
10436 | status = -ENXIO; | |
10437 | goto out; | |
10438 | } | |
10439 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
10440 | if (cq->queue_id == 0xFFFF) { | |
10441 | status = -ENXIO; | |
10442 | goto out; | |
10443 | } | |
10444 | /* link the cq onto the parent eq child list */ | |
10445 | list_add_tail(&cq->list, &eq->child_list); | |
10446 | /* Set up completion queue's type and subtype */ | |
10447 | cq->type = type; | |
10448 | cq->subtype = subtype; | |
10449 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
10450 | cq->host_index = 0; | |
10451 | cq->hba_index = 0; | |
4f774513 | 10452 | |
8fa38513 JS |
10453 | out: |
10454 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
10455 | return status; |
10456 | } | |
10457 | ||
b19a061a JS |
10458 | /** |
10459 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
10460 | * @phba: HBA structure that indicates port to create a queue on. | |
10461 | * @mq: The queue structure to use to create the mailbox queue. | |
10462 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
10463 | * @cq: The completion queue to associate with this cq. | |
10464 | * | |
10465 | * This function provides failback (fb) functionality when the | |
10466 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
10467 | * to mq_create_ext otherwise. | |
10468 | * | |
10469 | * This routine cannot fail as all attributes were previously accessed and | |
10470 | * initialized in mq_create_ext. | |
10471 | **/ | |
10472 | static void | |
10473 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
10474 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
10475 | { | |
10476 | struct lpfc_mbx_mq_create *mq_create; | |
10477 | struct lpfc_dmabuf *dmabuf; | |
10478 | int length; | |
10479 | ||
10480 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
10481 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10482 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10483 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
10484 | length, LPFC_SLI4_MBX_EMBED); | |
10485 | mq_create = &mbox->u.mqe.un.mq_create; | |
10486 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
10487 | mq->page_count); | |
10488 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
10489 | cq->queue_id); | |
10490 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
10491 | switch (mq->entry_count) { | |
10492 | case 16: | |
10493 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10494 | LPFC_MQ_CNT_16); | |
10495 | break; | |
10496 | case 32: | |
10497 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10498 | LPFC_MQ_CNT_32); | |
10499 | break; | |
10500 | case 64: | |
10501 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10502 | LPFC_MQ_CNT_64); | |
10503 | break; | |
10504 | case 128: | |
10505 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10506 | LPFC_MQ_CNT_128); | |
10507 | break; | |
10508 | } | |
10509 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
10510 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
10511 | putPaddrLow(dmabuf->phys); | |
10512 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10513 | putPaddrHigh(dmabuf->phys); | |
10514 | } | |
10515 | } | |
10516 | ||
04c68496 JS |
10517 | /** |
10518 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
10519 | * @phba: HBA structure that indicates port to create a queue on. | |
10520 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
10521 | * @cq: The completion queue to associate with this cq. |
10522 | * @subtype: The queue's subtype. | |
04c68496 JS |
10523 | * |
10524 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
10525 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
10526 | * | |
10527 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
10528 | * is used to get the entry count and entry size that are necessary to | |
10529 | * determine the number of pages to allocate and use for this queue. This | |
10530 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
10531 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
10532 | * command to finish before continuing. | |
10533 | * | |
10534 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10535 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10536 | * fails this function will return -ENXIO. | |
04c68496 | 10537 | **/ |
b19a061a | 10538 | int32_t |
04c68496 JS |
10539 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
10540 | struct lpfc_queue *cq, uint32_t subtype) | |
10541 | { | |
10542 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 10543 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
10544 | struct lpfc_dmabuf *dmabuf; |
10545 | LPFC_MBOXQ_t *mbox; | |
10546 | int rc, length, status = 0; | |
10547 | uint32_t shdr_status, shdr_add_status; | |
10548 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 10549 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 10550 | |
49198b37 JS |
10551 | if (!phba->sli4_hba.pc_sli4_params.supported) |
10552 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 10553 | |
04c68496 JS |
10554 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
10555 | if (!mbox) | |
10556 | return -ENOMEM; | |
b19a061a | 10557 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
10558 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
10559 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 10560 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 10561 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
10562 | |
10563 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
10564 | bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request, | |
04c68496 | 10565 | mq->page_count); |
b19a061a JS |
10566 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request, |
10567 | 1); | |
10568 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste, | |
10569 | &mq_create_ext->u.request, 1); | |
10570 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
10571 | &mq_create_ext->u.request, 1); | |
10572 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
10573 | cq->queue_id); | |
10574 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); | |
04c68496 JS |
10575 | switch (mq->entry_count) { |
10576 | default: | |
10577 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10578 | "0362 Unsupported MQ count. (%d)\n", | |
10579 | mq->entry_count); | |
10580 | if (mq->entry_count < 16) | |
10581 | return -EINVAL; | |
10582 | /* otherwise default to smallest count (drop through) */ | |
10583 | case 16: | |
b19a061a | 10584 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10585 | LPFC_MQ_CNT_16); |
10586 | break; | |
10587 | case 32: | |
b19a061a | 10588 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10589 | LPFC_MQ_CNT_32); |
10590 | break; | |
10591 | case 64: | |
b19a061a | 10592 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10593 | LPFC_MQ_CNT_64); |
10594 | break; | |
10595 | case 128: | |
b19a061a | 10596 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10597 | LPFC_MQ_CNT_128); |
10598 | break; | |
10599 | } | |
10600 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 10601 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 10602 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 10603 | putPaddrLow(dmabuf->phys); |
b19a061a | 10604 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
10605 | putPaddrHigh(dmabuf->phys); |
10606 | } | |
10607 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
10608 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
10609 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10610 | &mq_create_ext->u.response); | |
10611 | if (rc != MBX_SUCCESS) { | |
10612 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10613 | "2795 MQ_CREATE_EXT failed with " | |
10614 | "status x%x. Failback to MQ_CREATE.\n", | |
10615 | rc); | |
10616 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
10617 | mq_create = &mbox->u.mqe.un.mq_create; | |
10618 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10619 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
10620 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10621 | &mq_create->u.response); | |
10622 | } | |
10623 | ||
04c68496 | 10624 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
10625 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
10626 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10627 | if (shdr_status || shdr_add_status || rc) { | |
10628 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10629 | "2502 MQ_CREATE mailbox failed with " | |
10630 | "status x%x add_status x%x, mbx status x%x\n", | |
10631 | shdr_status, shdr_add_status, rc); | |
10632 | status = -ENXIO; | |
10633 | goto out; | |
10634 | } | |
04c68496 JS |
10635 | if (mq->queue_id == 0xFFFF) { |
10636 | status = -ENXIO; | |
10637 | goto out; | |
10638 | } | |
10639 | mq->type = LPFC_MQ; | |
10640 | mq->subtype = subtype; | |
10641 | mq->host_index = 0; | |
10642 | mq->hba_index = 0; | |
10643 | ||
10644 | /* link the mq onto the parent cq child list */ | |
10645 | list_add_tail(&mq->list, &cq->child_list); | |
10646 | out: | |
8fa38513 | 10647 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
10648 | return status; |
10649 | } | |
10650 | ||
4f774513 JS |
10651 | /** |
10652 | * lpfc_wq_create - Create a Work Queue on the HBA | |
10653 | * @phba: HBA structure that indicates port to create a queue on. | |
10654 | * @wq: The queue structure to use to create the work queue. | |
10655 | * @cq: The completion queue to bind this work queue to. | |
10656 | * @subtype: The subtype of the work queue indicating its functionality. | |
10657 | * | |
10658 | * This function creates a work queue, as detailed in @wq, on a port, described | |
10659 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
10660 | * | |
10661 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
10662 | * is used to get the entry count and entry size that are necessary to | |
10663 | * determine the number of pages to allocate and use for this queue. The @cq | |
10664 | * is used to indicate which completion queue to bind this work queue to. This | |
10665 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
10666 | * work queue. This function is asynchronous and will wait for the mailbox | |
10667 | * command to finish before continuing. | |
10668 | * | |
10669 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10670 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10671 | * fails this function will return -ENXIO. | |
4f774513 JS |
10672 | **/ |
10673 | uint32_t | |
10674 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
10675 | struct lpfc_queue *cq, uint32_t subtype) | |
10676 | { | |
10677 | struct lpfc_mbx_wq_create *wq_create; | |
10678 | struct lpfc_dmabuf *dmabuf; | |
10679 | LPFC_MBOXQ_t *mbox; | |
10680 | int rc, length, status = 0; | |
10681 | uint32_t shdr_status, shdr_add_status; | |
10682 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10683 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10684 | ||
10685 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10686 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10687 | |
10688 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10689 | if (!mbox) | |
10690 | return -ENOMEM; | |
10691 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
10692 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10693 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10694 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
10695 | length, LPFC_SLI4_MBX_EMBED); | |
10696 | wq_create = &mbox->u.mqe.un.wq_create; | |
10697 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, | |
10698 | wq->page_count); | |
10699 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
10700 | cq->queue_id); | |
10701 | list_for_each_entry(dmabuf, &wq->page_list, list) { | |
49198b37 | 10702 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10703 | wq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10704 | putPaddrLow(dmabuf->phys); | |
10705 | wq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10706 | putPaddrHigh(dmabuf->phys); | |
10707 | } | |
10708 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10709 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10710 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; | |
10711 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10712 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10713 | if (shdr_status || shdr_add_status || rc) { | |
10714 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10715 | "2503 WQ_CREATE mailbox failed with " | |
10716 | "status x%x add_status x%x, mbx status x%x\n", | |
10717 | shdr_status, shdr_add_status, rc); | |
10718 | status = -ENXIO; | |
10719 | goto out; | |
10720 | } | |
10721 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
10722 | if (wq->queue_id == 0xFFFF) { | |
10723 | status = -ENXIO; | |
10724 | goto out; | |
10725 | } | |
10726 | wq->type = LPFC_WQ; | |
10727 | wq->subtype = subtype; | |
10728 | wq->host_index = 0; | |
10729 | wq->hba_index = 0; | |
10730 | ||
10731 | /* link the wq onto the parent cq child list */ | |
10732 | list_add_tail(&wq->list, &cq->child_list); | |
10733 | out: | |
8fa38513 | 10734 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10735 | return status; |
10736 | } | |
10737 | ||
10738 | /** | |
10739 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
10740 | * @phba: HBA structure that indicates port to create a queue on. | |
10741 | * @hrq: The queue structure to use to create the header receive queue. | |
10742 | * @drq: The queue structure to use to create the data receive queue. | |
10743 | * @cq: The completion queue to bind this work queue to. | |
10744 | * | |
10745 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
10746 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
10747 | * to the HBA. | |
10748 | * | |
10749 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
10750 | * struct is used to get the entry count that is necessary to determine the | |
10751 | * number of pages to use for this queue. The @cq is used to indicate which | |
10752 | * completion queue to bind received buffers that are posted to these queues to. | |
10753 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
10754 | * receive queue pair. This function is asynchronous and will wait for the | |
10755 | * mailbox command to finish before continuing. | |
10756 | * | |
10757 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10758 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10759 | * fails this function will return -ENXIO. | |
4f774513 JS |
10760 | **/ |
10761 | uint32_t | |
10762 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
10763 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
10764 | { | |
10765 | struct lpfc_mbx_rq_create *rq_create; | |
10766 | struct lpfc_dmabuf *dmabuf; | |
10767 | LPFC_MBOXQ_t *mbox; | |
10768 | int rc, length, status = 0; | |
10769 | uint32_t shdr_status, shdr_add_status; | |
10770 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10771 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10772 | ||
10773 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10774 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10775 | |
10776 | if (hrq->entry_count != drq->entry_count) | |
10777 | return -EINVAL; | |
10778 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10779 | if (!mbox) | |
10780 | return -ENOMEM; | |
10781 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
10782 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10783 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10784 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10785 | length, LPFC_SLI4_MBX_EMBED); | |
10786 | rq_create = &mbox->u.mqe.un.rq_create; | |
10787 | switch (hrq->entry_count) { | |
10788 | default: | |
10789 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10790 | "2535 Unsupported RQ count. (%d)\n", | |
10791 | hrq->entry_count); | |
10792 | if (hrq->entry_count < 512) | |
10793 | return -EINVAL; | |
10794 | /* otherwise default to smallest count (drop through) */ | |
10795 | case 512: | |
10796 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10797 | LPFC_RQ_RING_SIZE_512); | |
10798 | break; | |
10799 | case 1024: | |
10800 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10801 | LPFC_RQ_RING_SIZE_1024); | |
10802 | break; | |
10803 | case 2048: | |
10804 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10805 | LPFC_RQ_RING_SIZE_2048); | |
10806 | break; | |
10807 | case 4096: | |
10808 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10809 | LPFC_RQ_RING_SIZE_4096); | |
10810 | break; | |
10811 | } | |
10812 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
10813 | cq->queue_id); | |
10814 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
10815 | hrq->page_count); | |
10816 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
10817 | LPFC_HDR_BUF_SIZE); | |
10818 | list_for_each_entry(dmabuf, &hrq->page_list, list) { | |
49198b37 | 10819 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10820 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10821 | putPaddrLow(dmabuf->phys); | |
10822 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10823 | putPaddrHigh(dmabuf->phys); | |
10824 | } | |
10825 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10826 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10827 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
10828 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10829 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10830 | if (shdr_status || shdr_add_status || rc) { | |
10831 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10832 | "2504 RQ_CREATE mailbox failed with " | |
10833 | "status x%x add_status x%x, mbx status x%x\n", | |
10834 | shdr_status, shdr_add_status, rc); | |
10835 | status = -ENXIO; | |
10836 | goto out; | |
10837 | } | |
10838 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
10839 | if (hrq->queue_id == 0xFFFF) { | |
10840 | status = -ENXIO; | |
10841 | goto out; | |
10842 | } | |
10843 | hrq->type = LPFC_HRQ; | |
10844 | hrq->subtype = subtype; | |
10845 | hrq->host_index = 0; | |
10846 | hrq->hba_index = 0; | |
10847 | ||
10848 | /* now create the data queue */ | |
10849 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10850 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10851 | length, LPFC_SLI4_MBX_EMBED); | |
10852 | switch (drq->entry_count) { | |
10853 | default: | |
10854 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10855 | "2536 Unsupported RQ count. (%d)\n", | |
10856 | drq->entry_count); | |
10857 | if (drq->entry_count < 512) | |
10858 | return -EINVAL; | |
10859 | /* otherwise default to smallest count (drop through) */ | |
10860 | case 512: | |
10861 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10862 | LPFC_RQ_RING_SIZE_512); | |
10863 | break; | |
10864 | case 1024: | |
10865 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10866 | LPFC_RQ_RING_SIZE_1024); | |
10867 | break; | |
10868 | case 2048: | |
10869 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10870 | LPFC_RQ_RING_SIZE_2048); | |
10871 | break; | |
10872 | case 4096: | |
10873 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10874 | LPFC_RQ_RING_SIZE_4096); | |
10875 | break; | |
10876 | } | |
10877 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
10878 | cq->queue_id); | |
10879 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
10880 | drq->page_count); | |
10881 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
10882 | LPFC_DATA_BUF_SIZE); | |
10883 | list_for_each_entry(dmabuf, &drq->page_list, list) { | |
10884 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
10885 | putPaddrLow(dmabuf->phys); | |
10886 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10887 | putPaddrHigh(dmabuf->phys); | |
10888 | } | |
10889 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10890 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10891 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
10892 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10893 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10894 | if (shdr_status || shdr_add_status || rc) { | |
10895 | status = -ENXIO; | |
10896 | goto out; | |
10897 | } | |
10898 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
10899 | if (drq->queue_id == 0xFFFF) { | |
10900 | status = -ENXIO; | |
10901 | goto out; | |
10902 | } | |
10903 | drq->type = LPFC_DRQ; | |
10904 | drq->subtype = subtype; | |
10905 | drq->host_index = 0; | |
10906 | drq->hba_index = 0; | |
10907 | ||
10908 | /* link the header and data RQs onto the parent cq child list */ | |
10909 | list_add_tail(&hrq->list, &cq->child_list); | |
10910 | list_add_tail(&drq->list, &cq->child_list); | |
10911 | ||
10912 | out: | |
8fa38513 | 10913 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10914 | return status; |
10915 | } | |
10916 | ||
10917 | /** | |
10918 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
10919 | * @eq: The queue structure associated with the queue to destroy. | |
10920 | * | |
10921 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
10922 | * command, specific to the type of queue, to the HBA. | |
10923 | * | |
10924 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
10925 | * | |
10926 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 10927 | * command fails this function will return -ENXIO. |
4f774513 JS |
10928 | **/ |
10929 | uint32_t | |
10930 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
10931 | { | |
10932 | LPFC_MBOXQ_t *mbox; | |
10933 | int rc, length, status = 0; | |
10934 | uint32_t shdr_status, shdr_add_status; | |
10935 | union lpfc_sli4_cfg_shdr *shdr; | |
10936 | ||
10937 | if (!eq) | |
10938 | return -ENODEV; | |
10939 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
10940 | if (!mbox) | |
10941 | return -ENOMEM; | |
10942 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
10943 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10944 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10945 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
10946 | length, LPFC_SLI4_MBX_EMBED); | |
10947 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
10948 | eq->queue_id); | |
10949 | mbox->vport = eq->phba->pport; | |
10950 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10951 | ||
10952 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
10953 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10954 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10955 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
10956 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10957 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10958 | if (shdr_status || shdr_add_status || rc) { | |
10959 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10960 | "2505 EQ_DESTROY mailbox failed with " | |
10961 | "status x%x add_status x%x, mbx status x%x\n", | |
10962 | shdr_status, shdr_add_status, rc); | |
10963 | status = -ENXIO; | |
10964 | } | |
10965 | ||
10966 | /* Remove eq from any list */ | |
10967 | list_del_init(&eq->list); | |
8fa38513 | 10968 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
10969 | return status; |
10970 | } | |
10971 | ||
10972 | /** | |
10973 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
10974 | * @cq: The queue structure associated with the queue to destroy. | |
10975 | * | |
10976 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
10977 | * command, specific to the type of queue, to the HBA. | |
10978 | * | |
10979 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
10980 | * | |
10981 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 10982 | * command fails this function will return -ENXIO. |
4f774513 JS |
10983 | **/ |
10984 | uint32_t | |
10985 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
10986 | { | |
10987 | LPFC_MBOXQ_t *mbox; | |
10988 | int rc, length, status = 0; | |
10989 | uint32_t shdr_status, shdr_add_status; | |
10990 | union lpfc_sli4_cfg_shdr *shdr; | |
10991 | ||
10992 | if (!cq) | |
10993 | return -ENODEV; | |
10994 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
10995 | if (!mbox) | |
10996 | return -ENOMEM; | |
10997 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
10998 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10999 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11000 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
11001 | length, LPFC_SLI4_MBX_EMBED); | |
11002 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
11003 | cq->queue_id); | |
11004 | mbox->vport = cq->phba->pport; | |
11005 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11006 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
11007 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11008 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11009 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
11010 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11011 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11012 | if (shdr_status || shdr_add_status || rc) { | |
11013 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11014 | "2506 CQ_DESTROY mailbox failed with " | |
11015 | "status x%x add_status x%x, mbx status x%x\n", | |
11016 | shdr_status, shdr_add_status, rc); | |
11017 | status = -ENXIO; | |
11018 | } | |
11019 | /* Remove cq from any list */ | |
11020 | list_del_init(&cq->list); | |
8fa38513 | 11021 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
11022 | return status; |
11023 | } | |
11024 | ||
04c68496 JS |
11025 | /** |
11026 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
11027 | * @qm: The queue structure associated with the queue to destroy. | |
11028 | * | |
11029 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
11030 | * command, specific to the type of queue, to the HBA. | |
11031 | * | |
11032 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
11033 | * | |
11034 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11035 | * command fails this function will return -ENXIO. |
04c68496 JS |
11036 | **/ |
11037 | uint32_t | |
11038 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
11039 | { | |
11040 | LPFC_MBOXQ_t *mbox; | |
11041 | int rc, length, status = 0; | |
11042 | uint32_t shdr_status, shdr_add_status; | |
11043 | union lpfc_sli4_cfg_shdr *shdr; | |
11044 | ||
11045 | if (!mq) | |
11046 | return -ENODEV; | |
11047 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
11048 | if (!mbox) | |
11049 | return -ENOMEM; | |
11050 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
11051 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11052 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11053 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
11054 | length, LPFC_SLI4_MBX_EMBED); | |
11055 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
11056 | mq->queue_id); | |
11057 | mbox->vport = mq->phba->pport; | |
11058 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11059 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
11060 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11061 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11062 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
11063 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11064 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11065 | if (shdr_status || shdr_add_status || rc) { | |
11066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11067 | "2507 MQ_DESTROY mailbox failed with " | |
11068 | "status x%x add_status x%x, mbx status x%x\n", | |
11069 | shdr_status, shdr_add_status, rc); | |
11070 | status = -ENXIO; | |
11071 | } | |
11072 | /* Remove mq from any list */ | |
11073 | list_del_init(&mq->list); | |
8fa38513 | 11074 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
11075 | return status; |
11076 | } | |
11077 | ||
4f774513 JS |
11078 | /** |
11079 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
11080 | * @wq: The queue structure associated with the queue to destroy. | |
11081 | * | |
11082 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
11083 | * command, specific to the type of queue, to the HBA. | |
11084 | * | |
11085 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
11086 | * | |
11087 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11088 | * command fails this function will return -ENXIO. |
4f774513 JS |
11089 | **/ |
11090 | uint32_t | |
11091 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
11092 | { | |
11093 | LPFC_MBOXQ_t *mbox; | |
11094 | int rc, length, status = 0; | |
11095 | uint32_t shdr_status, shdr_add_status; | |
11096 | union lpfc_sli4_cfg_shdr *shdr; | |
11097 | ||
11098 | if (!wq) | |
11099 | return -ENODEV; | |
11100 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
11101 | if (!mbox) | |
11102 | return -ENOMEM; | |
11103 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
11104 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11105 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11106 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
11107 | length, LPFC_SLI4_MBX_EMBED); | |
11108 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
11109 | wq->queue_id); | |
11110 | mbox->vport = wq->phba->pport; | |
11111 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11112 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
11113 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11114 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
11115 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11116 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11117 | if (shdr_status || shdr_add_status || rc) { | |
11118 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11119 | "2508 WQ_DESTROY mailbox failed with " | |
11120 | "status x%x add_status x%x, mbx status x%x\n", | |
11121 | shdr_status, shdr_add_status, rc); | |
11122 | status = -ENXIO; | |
11123 | } | |
11124 | /* Remove wq from any list */ | |
11125 | list_del_init(&wq->list); | |
8fa38513 | 11126 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
11127 | return status; |
11128 | } | |
11129 | ||
11130 | /** | |
11131 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
11132 | * @rq: The queue structure associated with the queue to destroy. | |
11133 | * | |
11134 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
11135 | * command, specific to the type of queue, to the HBA. | |
11136 | * | |
11137 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
11138 | * | |
11139 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11140 | * command fails this function will return -ENXIO. |
4f774513 JS |
11141 | **/ |
11142 | uint32_t | |
11143 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
11144 | struct lpfc_queue *drq) | |
11145 | { | |
11146 | LPFC_MBOXQ_t *mbox; | |
11147 | int rc, length, status = 0; | |
11148 | uint32_t shdr_status, shdr_add_status; | |
11149 | union lpfc_sli4_cfg_shdr *shdr; | |
11150 | ||
11151 | if (!hrq || !drq) | |
11152 | return -ENODEV; | |
11153 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
11154 | if (!mbox) | |
11155 | return -ENOMEM; | |
11156 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
11157 | sizeof(struct mbox_header)); | |
11158 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11159 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
11160 | length, LPFC_SLI4_MBX_EMBED); | |
11161 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
11162 | hrq->queue_id); | |
11163 | mbox->vport = hrq->phba->pport; | |
11164 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11165 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
11166 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11167 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11168 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
11169 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11170 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11171 | if (shdr_status || shdr_add_status || rc) { | |
11172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11173 | "2509 RQ_DESTROY mailbox failed with " | |
11174 | "status x%x add_status x%x, mbx status x%x\n", | |
11175 | shdr_status, shdr_add_status, rc); | |
11176 | if (rc != MBX_TIMEOUT) | |
11177 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
11178 | return -ENXIO; | |
11179 | } | |
11180 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
11181 | drq->queue_id); | |
11182 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
11183 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11184 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
11185 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11186 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11187 | if (shdr_status || shdr_add_status || rc) { | |
11188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11189 | "2510 RQ_DESTROY mailbox failed with " | |
11190 | "status x%x add_status x%x, mbx status x%x\n", | |
11191 | shdr_status, shdr_add_status, rc); | |
11192 | status = -ENXIO; | |
11193 | } | |
11194 | list_del_init(&hrq->list); | |
11195 | list_del_init(&drq->list); | |
8fa38513 | 11196 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
11197 | return status; |
11198 | } | |
11199 | ||
11200 | /** | |
11201 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
11202 | * @phba: The virtual port for which this call being executed. | |
11203 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
11204 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
11205 | * @xritag: the xritag that ties this io to the SGL pages. | |
11206 | * | |
11207 | * This routine will post the sgl pages for the IO that has the xritag | |
11208 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
11209 | * creation and persists for as long as the driver is loaded. | |
11210 | * if the caller has fewer than 256 scatter gather segments to map then | |
11211 | * pdma_phys_addr1 should be 0. | |
11212 | * If the caller needs to map more than 256 scatter gather segment then | |
11213 | * pdma_phys_addr1 should be a valid physical address. | |
11214 | * physical address for SGLs must be 64 byte aligned. | |
11215 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
11216 | * the second sgl can have between 1 and 256 entries. | |
11217 | * | |
11218 | * Return codes: | |
11219 | * 0 - Success | |
11220 | * -ENXIO, -ENOMEM - Failure | |
11221 | **/ | |
11222 | int | |
11223 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
11224 | dma_addr_t pdma_phys_addr0, | |
11225 | dma_addr_t pdma_phys_addr1, | |
11226 | uint16_t xritag) | |
11227 | { | |
11228 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
11229 | LPFC_MBOXQ_t *mbox; | |
11230 | int rc; | |
11231 | uint32_t shdr_status, shdr_add_status; | |
11232 | union lpfc_sli4_cfg_shdr *shdr; | |
11233 | ||
11234 | if (xritag == NO_XRI) { | |
11235 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11236 | "0364 Invalid param:\n"); | |
11237 | return -EINVAL; | |
11238 | } | |
11239 | ||
11240 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11241 | if (!mbox) | |
11242 | return -ENOMEM; | |
11243 | ||
11244 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11245 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
11246 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
11247 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | |
11248 | ||
11249 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
11250 | &mbox->u.mqe.un.post_sgl_pages; | |
11251 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
11252 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
11253 | ||
11254 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
11255 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
11256 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
11257 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
11258 | ||
11259 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
11260 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
11261 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
11262 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
11263 | if (!phba->sli4_hba.intr_enable) | |
11264 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11265 | else | |
11266 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
11267 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11268 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
11269 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11270 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11271 | if (rc != MBX_TIMEOUT) | |
11272 | mempool_free(mbox, phba->mbox_mem_pool); | |
11273 | if (shdr_status || shdr_add_status || rc) { | |
11274 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11275 | "2511 POST_SGL mailbox failed with " | |
11276 | "status x%x add_status x%x, mbx status x%x\n", | |
11277 | shdr_status, shdr_add_status, rc); | |
11278 | rc = -ENXIO; | |
11279 | } | |
11280 | return 0; | |
11281 | } | |
4f774513 JS |
11282 | |
11283 | /** | |
11284 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
11285 | * @phba: Pointer to HBA context object. | |
11286 | * | |
11287 | * This function gets an xritag for the iocb. If there is no unused xritag | |
11288 | * it will return 0xffff. | |
11289 | * The function returns the allocated xritag if successful, else returns zero. | |
11290 | * Zero is not a valid xritag. | |
11291 | * The caller is not required to hold any lock. | |
11292 | **/ | |
11293 | uint16_t | |
11294 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
11295 | { | |
11296 | uint16_t xritag; | |
11297 | ||
11298 | spin_lock_irq(&phba->hbalock); | |
11299 | xritag = phba->sli4_hba.next_xri; | |
11300 | if ((xritag != (uint16_t) -1) && xritag < | |
11301 | (phba->sli4_hba.max_cfg_param.max_xri | |
11302 | + phba->sli4_hba.max_cfg_param.xri_base)) { | |
11303 | phba->sli4_hba.next_xri++; | |
11304 | phba->sli4_hba.max_cfg_param.xri_used++; | |
11305 | spin_unlock_irq(&phba->hbalock); | |
11306 | return xritag; | |
11307 | } | |
11308 | spin_unlock_irq(&phba->hbalock); | |
6a9c52cf | 11309 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
4f774513 JS |
11310 | "2004 Failed to allocate XRI.last XRITAG is %d" |
11311 | " Max XRI is %d, Used XRI is %d\n", | |
11312 | phba->sli4_hba.next_xri, | |
11313 | phba->sli4_hba.max_cfg_param.max_xri, | |
11314 | phba->sli4_hba.max_cfg_param.xri_used); | |
11315 | return -1; | |
11316 | } | |
11317 | ||
11318 | /** | |
11319 | * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware. | |
11320 | * @phba: pointer to lpfc hba data structure. | |
11321 | * | |
11322 | * This routine is invoked to post a block of driver's sgl pages to the | |
11323 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
11324 | * is only called when the driver is loading and after all IO has been | |
11325 | * stopped. | |
11326 | **/ | |
11327 | int | |
11328 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba) | |
11329 | { | |
11330 | struct lpfc_sglq *sglq_entry; | |
11331 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
11332 | struct sgl_page_pairs *sgl_pg_pairs; | |
11333 | void *viraddr; | |
11334 | LPFC_MBOXQ_t *mbox; | |
11335 | uint32_t reqlen, alloclen, pg_pairs; | |
11336 | uint32_t mbox_tmo; | |
11337 | uint16_t xritag_start = 0; | |
11338 | int els_xri_cnt, rc = 0; | |
11339 | uint32_t shdr_status, shdr_add_status; | |
11340 | union lpfc_sli4_cfg_shdr *shdr; | |
11341 | ||
11342 | /* The number of sgls to be posted */ | |
11343 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
11344 | ||
11345 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
11346 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 11347 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
11348 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
11349 | "2559 Block sgl registration required DMA " | |
11350 | "size (%d) great than a page\n", reqlen); | |
11351 | return -ENOMEM; | |
11352 | } | |
11353 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11354 | if (!mbox) { | |
11355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11356 | "2560 Failed to allocate mbox cmd memory\n"); | |
11357 | return -ENOMEM; | |
11358 | } | |
11359 | ||
11360 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
11361 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11362 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
11363 | LPFC_SLI4_MBX_NEMBED); | |
11364 | ||
11365 | if (alloclen < reqlen) { | |
11366 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11367 | "0285 Allocated DMA memory size (%d) is " | |
11368 | "less than the requested DMA memory " | |
11369 | "size (%d)\n", alloclen, reqlen); | |
11370 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11371 | return -ENOMEM; | |
11372 | } | |
4f774513 | 11373 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
11374 | viraddr = mbox->sge_array->addr[0]; |
11375 | ||
11376 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
11377 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
11378 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
11379 | ||
11380 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | |
11381 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | |
11382 | /* Set up the sge entry */ | |
11383 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
11384 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
11385 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
11386 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
11387 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
11388 | cpu_to_le32(putPaddrLow(0)); | |
11389 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
11390 | cpu_to_le32(putPaddrHigh(0)); | |
11391 | /* Keep the first xritag on the list */ | |
11392 | if (pg_pairs == 0) | |
11393 | xritag_start = sglq_entry->sli4_xritag; | |
11394 | sgl_pg_pairs++; | |
11395 | } | |
11396 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
6a9c52cf | 11397 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
4f774513 JS |
11398 | /* Perform endian conversion if necessary */ |
11399 | sgl->word0 = cpu_to_le32(sgl->word0); | |
11400 | ||
11401 | if (!phba->sli4_hba.intr_enable) | |
11402 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11403 | else { | |
11404 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11405 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11406 | } | |
11407 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11408 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11409 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11410 | if (rc != MBX_TIMEOUT) | |
11411 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11412 | if (shdr_status || shdr_add_status || rc) { | |
11413 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11414 | "2513 POST_SGL_BLOCK mailbox command failed " | |
11415 | "status x%x add_status x%x mbx status x%x\n", | |
11416 | shdr_status, shdr_add_status, rc); | |
11417 | rc = -ENXIO; | |
11418 | } | |
11419 | return rc; | |
11420 | } | |
11421 | ||
11422 | /** | |
11423 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
11424 | * @phba: pointer to lpfc hba data structure. | |
11425 | * @sblist: pointer to scsi buffer list. | |
11426 | * @count: number of scsi buffers on the list. | |
11427 | * | |
11428 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
11429 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
11430 | * No Lock is held. | |
11431 | * | |
11432 | **/ | |
11433 | int | |
11434 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | |
11435 | int cnt) | |
11436 | { | |
11437 | struct lpfc_scsi_buf *psb; | |
11438 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
11439 | struct sgl_page_pairs *sgl_pg_pairs; | |
11440 | void *viraddr; | |
11441 | LPFC_MBOXQ_t *mbox; | |
11442 | uint32_t reqlen, alloclen, pg_pairs; | |
11443 | uint32_t mbox_tmo; | |
11444 | uint16_t xritag_start = 0; | |
11445 | int rc = 0; | |
11446 | uint32_t shdr_status, shdr_add_status; | |
11447 | dma_addr_t pdma_phys_bpl1; | |
11448 | union lpfc_sli4_cfg_shdr *shdr; | |
11449 | ||
11450 | /* Calculate the requested length of the dma memory */ | |
11451 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
11452 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 11453 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
11454 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
11455 | "0217 Block sgl registration required DMA " | |
11456 | "size (%d) great than a page\n", reqlen); | |
11457 | return -ENOMEM; | |
11458 | } | |
11459 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11460 | if (!mbox) { | |
11461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11462 | "0283 Failed to allocate mbox cmd memory\n"); | |
11463 | return -ENOMEM; | |
11464 | } | |
11465 | ||
11466 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
11467 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11468 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
11469 | LPFC_SLI4_MBX_NEMBED); | |
11470 | ||
11471 | if (alloclen < reqlen) { | |
11472 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11473 | "2561 Allocated DMA memory size (%d) is " | |
11474 | "less than the requested DMA memory " | |
11475 | "size (%d)\n", alloclen, reqlen); | |
11476 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11477 | return -ENOMEM; | |
11478 | } | |
4f774513 | 11479 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
11480 | viraddr = mbox->sge_array->addr[0]; |
11481 | ||
11482 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
11483 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
11484 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
11485 | ||
11486 | pg_pairs = 0; | |
11487 | list_for_each_entry(psb, sblist, list) { | |
11488 | /* Set up the sge entry */ | |
11489 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
11490 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
11491 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
11492 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
11493 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
11494 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
11495 | else | |
11496 | pdma_phys_bpl1 = 0; | |
11497 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
11498 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
11499 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
11500 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
11501 | /* Keep the first xritag on the list */ | |
11502 | if (pg_pairs == 0) | |
11503 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
11504 | sgl_pg_pairs++; | |
11505 | pg_pairs++; | |
11506 | } | |
11507 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
11508 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
11509 | /* Perform endian conversion if necessary */ | |
11510 | sgl->word0 = cpu_to_le32(sgl->word0); | |
11511 | ||
11512 | if (!phba->sli4_hba.intr_enable) | |
11513 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11514 | else { | |
11515 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11516 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11517 | } | |
11518 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11519 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11520 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11521 | if (rc != MBX_TIMEOUT) | |
11522 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11523 | if (shdr_status || shdr_add_status || rc) { | |
11524 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11525 | "2564 POST_SGL_BLOCK mailbox command failed " | |
11526 | "status x%x add_status x%x mbx status x%x\n", | |
11527 | shdr_status, shdr_add_status, rc); | |
11528 | rc = -ENXIO; | |
11529 | } | |
11530 | return rc; | |
11531 | } | |
11532 | ||
11533 | /** | |
11534 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
11535 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
11536 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11537 | * | |
11538 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
11539 | * valid type of frame that the LPFC driver will handle. This function will | |
11540 | * return a zero if the frame is a valid frame or a non zero value when the | |
11541 | * frame does not pass the check. | |
11542 | **/ | |
11543 | static int | |
11544 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
11545 | { | |
11546 | char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
11547 | char *type_names[] = FC_TYPE_NAMES_INIT; | |
11548 | struct fc_vft_header *fc_vft_hdr; | |
11549 | ||
11550 | switch (fc_hdr->fh_r_ctl) { | |
11551 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
11552 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
11553 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
11554 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
11555 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
11556 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
11557 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
11558 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
11559 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
11560 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
11561 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
11562 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
11563 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
11564 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
11565 | case FC_RCTL_BA_RMC: /* remove connection */ | |
11566 | case FC_RCTL_BA_ACC: /* basic accept */ | |
11567 | case FC_RCTL_BA_RJT: /* basic reject */ | |
11568 | case FC_RCTL_BA_PRMT: | |
11569 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
11570 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
11571 | case FC_RCTL_P_RJT: /* port reject */ | |
11572 | case FC_RCTL_F_RJT: /* fabric reject */ | |
11573 | case FC_RCTL_P_BSY: /* port busy */ | |
11574 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
11575 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
11576 | case FC_RCTL_LCR: /* link credit reset */ | |
11577 | case FC_RCTL_END: /* end */ | |
11578 | break; | |
11579 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
11580 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11581 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
11582 | return lpfc_fc_frame_check(phba, fc_hdr); | |
11583 | default: | |
11584 | goto drop; | |
11585 | } | |
11586 | switch (fc_hdr->fh_type) { | |
11587 | case FC_TYPE_BLS: | |
11588 | case FC_TYPE_ELS: | |
11589 | case FC_TYPE_FCP: | |
11590 | case FC_TYPE_CT: | |
11591 | break; | |
11592 | case FC_TYPE_IP: | |
11593 | case FC_TYPE_ILS: | |
11594 | default: | |
11595 | goto drop; | |
11596 | } | |
11597 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
11598 | "2538 Received frame rctl:%s type:%s\n", | |
11599 | rctl_names[fc_hdr->fh_r_ctl], | |
11600 | type_names[fc_hdr->fh_type]); | |
11601 | return 0; | |
11602 | drop: | |
11603 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11604 | "2539 Dropped frame rctl:%s type:%s\n", | |
11605 | rctl_names[fc_hdr->fh_r_ctl], | |
11606 | type_names[fc_hdr->fh_type]); | |
11607 | return 1; | |
11608 | } | |
11609 | ||
11610 | /** | |
11611 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
11612 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11613 | * | |
11614 | * This function processes the FC header to retrieve the VFI from the VF | |
11615 | * header, if one exists. This function will return the VFI if one exists | |
11616 | * or 0 if no VSAN Header exists. | |
11617 | **/ | |
11618 | static uint32_t | |
11619 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
11620 | { | |
11621 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11622 | ||
11623 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
11624 | return 0; | |
11625 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
11626 | } | |
11627 | ||
11628 | /** | |
11629 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
11630 | * @phba: Pointer to the HBA structure to search for the vport on | |
11631 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11632 | * @fcfi: The FC Fabric ID that the frame came from | |
11633 | * | |
11634 | * This function searches the @phba for a vport that matches the content of the | |
11635 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
11636 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
11637 | * returns the matching vport pointer or NULL if unable to match frame to a | |
11638 | * vport. | |
11639 | **/ | |
11640 | static struct lpfc_vport * | |
11641 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
11642 | uint16_t fcfi) | |
11643 | { | |
11644 | struct lpfc_vport **vports; | |
11645 | struct lpfc_vport *vport = NULL; | |
11646 | int i; | |
11647 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
11648 | fc_hdr->fh_d_id[1] << 8 | | |
11649 | fc_hdr->fh_d_id[2]); | |
11650 | ||
11651 | vports = lpfc_create_vport_work_array(phba); | |
11652 | if (vports != NULL) | |
11653 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
11654 | if (phba->fcf.fcfi == fcfi && | |
11655 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
11656 | vports[i]->fc_myDID == did) { | |
11657 | vport = vports[i]; | |
11658 | break; | |
11659 | } | |
11660 | } | |
11661 | lpfc_destroy_vport_work_array(phba, vports); | |
11662 | return vport; | |
11663 | } | |
11664 | ||
45ed1190 JS |
11665 | /** |
11666 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
11667 | * @vport: The vport to work on. | |
11668 | * | |
11669 | * This function updates the receive sequence time stamp for this vport. The | |
11670 | * receive sequence time stamp indicates the time that the last frame of the | |
11671 | * the sequence that has been idle for the longest amount of time was received. | |
11672 | * the driver uses this time stamp to indicate if any received sequences have | |
11673 | * timed out. | |
11674 | **/ | |
11675 | void | |
11676 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
11677 | { | |
11678 | struct lpfc_dmabuf *h_buf; | |
11679 | struct hbq_dmabuf *dmabuf = NULL; | |
11680 | ||
11681 | /* get the oldest sequence on the rcv list */ | |
11682 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
11683 | struct lpfc_dmabuf, list); | |
11684 | if (!h_buf) | |
11685 | return; | |
11686 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11687 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
11688 | } | |
11689 | ||
11690 | /** | |
11691 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
11692 | * @vport: The vport that the received sequences were sent to. | |
11693 | * | |
11694 | * This function cleans up all outstanding received sequences. This is called | |
11695 | * by the driver when a link event or user action invalidates all the received | |
11696 | * sequences. | |
11697 | **/ | |
11698 | void | |
11699 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
11700 | { | |
11701 | struct lpfc_dmabuf *h_buf, *hnext; | |
11702 | struct lpfc_dmabuf *d_buf, *dnext; | |
11703 | struct hbq_dmabuf *dmabuf = NULL; | |
11704 | ||
11705 | /* start with the oldest sequence on the rcv list */ | |
11706 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11707 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11708 | list_del_init(&dmabuf->hbuf.list); | |
11709 | list_for_each_entry_safe(d_buf, dnext, | |
11710 | &dmabuf->dbuf.list, list) { | |
11711 | list_del_init(&d_buf->list); | |
11712 | lpfc_in_buf_free(vport->phba, d_buf); | |
11713 | } | |
11714 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11715 | } | |
11716 | } | |
11717 | ||
11718 | /** | |
11719 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
11720 | * @vport: The vport that the received sequences were sent to. | |
11721 | * | |
11722 | * This function determines whether any received sequences have timed out by | |
11723 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
11724 | * indicates that there is at least one timed out sequence this routine will | |
11725 | * go through the received sequences one at a time from most inactive to most | |
11726 | * active to determine which ones need to be cleaned up. Once it has determined | |
11727 | * that a sequence needs to be cleaned up it will simply free up the resources | |
11728 | * without sending an abort. | |
11729 | **/ | |
11730 | void | |
11731 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
11732 | { | |
11733 | struct lpfc_dmabuf *h_buf, *hnext; | |
11734 | struct lpfc_dmabuf *d_buf, *dnext; | |
11735 | struct hbq_dmabuf *dmabuf = NULL; | |
11736 | unsigned long timeout; | |
11737 | int abort_count = 0; | |
11738 | ||
11739 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11740 | vport->rcv_buffer_time_stamp); | |
11741 | if (list_empty(&vport->rcv_buffer_list) || | |
11742 | time_before(jiffies, timeout)) | |
11743 | return; | |
11744 | /* start with the oldest sequence on the rcv list */ | |
11745 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11746 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11747 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11748 | dmabuf->time_stamp); | |
11749 | if (time_before(jiffies, timeout)) | |
11750 | break; | |
11751 | abort_count++; | |
11752 | list_del_init(&dmabuf->hbuf.list); | |
11753 | list_for_each_entry_safe(d_buf, dnext, | |
11754 | &dmabuf->dbuf.list, list) { | |
11755 | list_del_init(&d_buf->list); | |
11756 | lpfc_in_buf_free(vport->phba, d_buf); | |
11757 | } | |
11758 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11759 | } | |
11760 | if (abort_count) | |
11761 | lpfc_update_rcv_time_stamp(vport); | |
11762 | } | |
11763 | ||
4f774513 JS |
11764 | /** |
11765 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
11766 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
11767 | * | |
11768 | * This function searches through the existing incomplete sequences that have | |
11769 | * been sent to this @vport. If the frame matches one of the incomplete | |
11770 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
11771 | * make up that sequence. If no sequence is found that matches this frame then | |
11772 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
11773 | * This function returns a pointer to the first dmabuf in the sequence list that | |
11774 | * the frame was linked to. | |
11775 | **/ | |
11776 | static struct hbq_dmabuf * | |
11777 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
11778 | { | |
11779 | struct fc_frame_header *new_hdr; | |
11780 | struct fc_frame_header *temp_hdr; | |
11781 | struct lpfc_dmabuf *d_buf; | |
11782 | struct lpfc_dmabuf *h_buf; | |
11783 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
11784 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
11785 | ||
4d9ab994 | 11786 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 11787 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
11788 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
11789 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
11790 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
11791 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
11792 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
11793 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
11794 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
11795 | continue; | |
11796 | /* found a pending sequence that matches this frame */ | |
11797 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11798 | break; | |
11799 | } | |
11800 | if (!seq_dmabuf) { | |
11801 | /* | |
11802 | * This indicates first frame received for this sequence. | |
11803 | * Queue the buffer on the vport's rcv_buffer_list. | |
11804 | */ | |
11805 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 11806 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
11807 | return dmabuf; |
11808 | } | |
11809 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
11810 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
11811 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
11812 | list_del_init(&seq_dmabuf->hbuf.list); |
11813 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
11814 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 11815 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
11816 | return dmabuf; |
11817 | } | |
45ed1190 JS |
11818 | /* move this sequence to the tail to indicate a young sequence */ |
11819 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
11820 | seq_dmabuf->time_stamp = jiffies; | |
11821 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
11822 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
11823 | temp_hdr = dmabuf->hbuf.virt; | |
11824 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
11825 | return seq_dmabuf; | |
11826 | } | |
4f774513 JS |
11827 | /* find the correct place in the sequence to insert this frame */ |
11828 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
11829 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
11830 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
11831 | /* | |
11832 | * If the frame's sequence count is greater than the frame on | |
11833 | * the list then insert the frame right after this frame | |
11834 | */ | |
eeead811 JS |
11835 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
11836 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
11837 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
11838 | return seq_dmabuf; | |
11839 | } | |
11840 | } | |
11841 | return NULL; | |
11842 | } | |
11843 | ||
6669f9bb JS |
11844 | /** |
11845 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
11846 | * @vport: pointer to a vitural port | |
11847 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
11848 | * | |
11849 | * This function tries to abort from the partially assembed sequence, described | |
11850 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
11851 | * partially assembled sequence held by the driver. If so, it shall free up all | |
11852 | * the frames from the partially assembled sequence. | |
11853 | * | |
11854 | * Return | |
11855 | * true -- if there is matching partially assembled sequence present and all | |
11856 | * the frames freed with the sequence; | |
11857 | * false -- if there is no matching partially assembled sequence present so | |
11858 | * nothing got aborted in the lower layer driver | |
11859 | **/ | |
11860 | static bool | |
11861 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
11862 | struct hbq_dmabuf *dmabuf) | |
11863 | { | |
11864 | struct fc_frame_header *new_hdr; | |
11865 | struct fc_frame_header *temp_hdr; | |
11866 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
11867 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
11868 | ||
11869 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
11870 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
11871 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
11872 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
11873 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
11874 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
11875 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
11876 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
11877 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
11878 | continue; | |
11879 | /* found a pending sequence that matches this frame */ | |
11880 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11881 | break; | |
11882 | } | |
11883 | ||
11884 | /* Free up all the frames from the partially assembled sequence */ | |
11885 | if (seq_dmabuf) { | |
11886 | list_for_each_entry_safe(d_buf, n_buf, | |
11887 | &seq_dmabuf->dbuf.list, list) { | |
11888 | list_del_init(&d_buf->list); | |
11889 | lpfc_in_buf_free(vport->phba, d_buf); | |
11890 | } | |
11891 | return true; | |
11892 | } | |
11893 | return false; | |
11894 | } | |
11895 | ||
11896 | /** | |
11897 | * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler | |
11898 | * @phba: Pointer to HBA context object. | |
11899 | * @cmd_iocbq: pointer to the command iocbq structure. | |
11900 | * @rsp_iocbq: pointer to the response iocbq structure. | |
11901 | * | |
11902 | * This function handles the sequence abort accept iocb command complete | |
11903 | * event. It properly releases the memory allocated to the sequence abort | |
11904 | * accept iocb. | |
11905 | **/ | |
11906 | static void | |
11907 | lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba, | |
11908 | struct lpfc_iocbq *cmd_iocbq, | |
11909 | struct lpfc_iocbq *rsp_iocbq) | |
11910 | { | |
11911 | if (cmd_iocbq) | |
11912 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
11913 | } | |
11914 | ||
11915 | /** | |
11916 | * lpfc_sli4_seq_abort_acc - Accept sequence abort | |
11917 | * @phba: Pointer to HBA context object. | |
11918 | * @fc_hdr: pointer to a FC frame header. | |
11919 | * | |
11920 | * This function sends a basic accept to a previous unsol sequence abort | |
11921 | * event after aborting the sequence handling. | |
11922 | **/ | |
11923 | static void | |
11924 | lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba, | |
11925 | struct fc_frame_header *fc_hdr) | |
11926 | { | |
11927 | struct lpfc_iocbq *ctiocb = NULL; | |
11928 | struct lpfc_nodelist *ndlp; | |
5ffc266e JS |
11929 | uint16_t oxid, rxid; |
11930 | uint32_t sid, fctl; | |
6669f9bb JS |
11931 | IOCB_t *icmd; |
11932 | ||
11933 | if (!lpfc_is_link_up(phba)) | |
11934 | return; | |
11935 | ||
11936 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
11937 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 11938 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
11939 | |
11940 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
11941 | if (!ndlp) { | |
11942 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11943 | "1268 Find ndlp returned NULL for oxid:x%x " | |
11944 | "SID:x%x\n", oxid, sid); | |
11945 | return; | |
11946 | } | |
19ca7609 JS |
11947 | if (rxid >= phba->sli4_hba.max_cfg_param.xri_base |
11948 | && rxid <= (phba->sli4_hba.max_cfg_param.max_xri | |
11949 | + phba->sli4_hba.max_cfg_param.xri_base)) | |
11950 | lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); | |
6669f9bb JS |
11951 | |
11952 | /* Allocate buffer for acc iocb */ | |
11953 | ctiocb = lpfc_sli_get_iocbq(phba); | |
11954 | if (!ctiocb) | |
11955 | return; | |
11956 | ||
5ffc266e JS |
11957 | /* Extract the F_CTL field from FC_HDR */ |
11958 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
11959 | ||
6669f9bb | 11960 | icmd = &ctiocb->iocb; |
6669f9bb | 11961 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 11962 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
11963 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
11964 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
11965 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
11966 | ||
11967 | /* Fill in the rest of iocb fields */ | |
11968 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
11969 | icmd->ulpBdeCount = 0; | |
11970 | icmd->ulpLe = 1; | |
11971 | icmd->ulpClass = CLASS3; | |
11972 | icmd->ulpContext = ndlp->nlp_rpi; | |
be858b65 | 11973 | ctiocb->context1 = ndlp; |
6669f9bb | 11974 | |
6669f9bb JS |
11975 | ctiocb->iocb_cmpl = NULL; |
11976 | ctiocb->vport = phba->pport; | |
11977 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl; | |
11978 | ||
5ffc266e JS |
11979 | if (fctl & FC_FC_EX_CTX) { |
11980 | /* ABTS sent by responder to CT exchange, construction | |
11981 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
11982 | * field and RX_ID from ABTS for RX_ID field. | |
11983 | */ | |
11984 | bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP); | |
11985 | bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid); | |
11986 | ctiocb->sli4_xritag = oxid; | |
11987 | } else { | |
11988 | /* ABTS sent by initiator to CT exchange, construction | |
11989 | * of BA_ACC will need to allocate a new XRI as for the | |
11990 | * XRI_TAG and RX_ID fields. | |
11991 | */ | |
11992 | bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT); | |
11993 | bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI); | |
11994 | ctiocb->sli4_xritag = NO_XRI; | |
11995 | } | |
11996 | bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid); | |
11997 | ||
6669f9bb JS |
11998 | /* Xmit CT abts accept on exchange <xid> */ |
11999 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
12000 | "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n", | |
12001 | CMD_XMIT_BLS_RSP64_CX, phba->link_state); | |
12002 | lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
12003 | } | |
12004 | ||
12005 | /** | |
12006 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
12007 | * @vport: Pointer to the vport on which this sequence was received | |
12008 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12009 | * | |
12010 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
12011 | * receive sequence is only partially assembed by the driver, it shall abort | |
12012 | * the partially assembled frames for the sequence. Otherwise, if the | |
12013 | * unsolicited receive sequence has been completely assembled and passed to | |
12014 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
12015 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
12016 | * accept to accept the abort. | |
12017 | **/ | |
12018 | void | |
12019 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
12020 | struct hbq_dmabuf *dmabuf) | |
12021 | { | |
12022 | struct lpfc_hba *phba = vport->phba; | |
12023 | struct fc_frame_header fc_hdr; | |
5ffc266e | 12024 | uint32_t fctl; |
6669f9bb JS |
12025 | bool abts_par; |
12026 | ||
6669f9bb JS |
12027 | /* Make a copy of fc_hdr before the dmabuf being released */ |
12028 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 12029 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 12030 | |
5ffc266e JS |
12031 | if (fctl & FC_FC_EX_CTX) { |
12032 | /* | |
12033 | * ABTS sent by responder to exchange, just free the buffer | |
12034 | */ | |
6669f9bb | 12035 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
12036 | } else { |
12037 | /* | |
12038 | * ABTS sent by initiator to exchange, need to do cleanup | |
12039 | */ | |
12040 | /* Try to abort partially assembled seq */ | |
12041 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
12042 | ||
12043 | /* Send abort to ULP if partially seq abort failed */ | |
12044 | if (abts_par == false) | |
12045 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
12046 | else | |
12047 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12048 | } | |
6669f9bb JS |
12049 | /* Send basic accept (BA_ACC) to the abort requester */ |
12050 | lpfc_sli4_seq_abort_acc(phba, &fc_hdr); | |
12051 | } | |
12052 | ||
4f774513 JS |
12053 | /** |
12054 | * lpfc_seq_complete - Indicates if a sequence is complete | |
12055 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12056 | * | |
12057 | * This function checks the sequence, starting with the frame described by | |
12058 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
12059 | * the frames associated with this sequence are linked to the @dmabuf using the | |
12060 | * dbuf list. This function looks for two major things. 1) That the first frame | |
12061 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
12062 | * set. 3) That there are no holes in the sequence count. The function will | |
12063 | * return 1 when the sequence is complete, otherwise it will return 0. | |
12064 | **/ | |
12065 | static int | |
12066 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
12067 | { | |
12068 | struct fc_frame_header *hdr; | |
12069 | struct lpfc_dmabuf *d_buf; | |
12070 | struct hbq_dmabuf *seq_dmabuf; | |
12071 | uint32_t fctl; | |
12072 | int seq_count = 0; | |
12073 | ||
12074 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
12075 | /* make sure first fame of sequence has a sequence count of zero */ | |
12076 | if (hdr->fh_seq_cnt != seq_count) | |
12077 | return 0; | |
12078 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
12079 | hdr->fh_f_ctl[1] << 8 | | |
12080 | hdr->fh_f_ctl[2]); | |
12081 | /* If last frame of sequence we can return success. */ | |
12082 | if (fctl & FC_FC_END_SEQ) | |
12083 | return 1; | |
12084 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
12085 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
12086 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12087 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 12088 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
12089 | return 0; |
12090 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
12091 | hdr->fh_f_ctl[1] << 8 | | |
12092 | hdr->fh_f_ctl[2]); | |
12093 | /* If last frame of sequence we can return success. */ | |
12094 | if (fctl & FC_FC_END_SEQ) | |
12095 | return 1; | |
12096 | } | |
12097 | return 0; | |
12098 | } | |
12099 | ||
12100 | /** | |
12101 | * lpfc_prep_seq - Prep sequence for ULP processing | |
12102 | * @vport: Pointer to the vport on which this sequence was received | |
12103 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12104 | * | |
12105 | * This function takes a sequence, described by a list of frames, and creates | |
12106 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
12107 | * used to issue to the generic unsolicited sequence handler. This routine | |
12108 | * returns a pointer to the first iocbq in the list. If the function is unable | |
12109 | * to allocate an iocbq then it throw out the received frames that were not | |
12110 | * able to be described and return a pointer to the first iocbq. If unable to | |
12111 | * allocate any iocbqs (including the first) this function will return NULL. | |
12112 | **/ | |
12113 | static struct lpfc_iocbq * | |
12114 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
12115 | { | |
12116 | struct lpfc_dmabuf *d_buf, *n_buf; | |
12117 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
12118 | struct fc_frame_header *fc_hdr; | |
12119 | uint32_t sid; | |
eeead811 | 12120 | struct ulp_bde64 *pbde; |
4f774513 JS |
12121 | |
12122 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12123 | /* remove from receive buffer list */ | |
12124 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 12125 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 12126 | /* get the Remote Port's SID */ |
6669f9bb | 12127 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
4f774513 JS |
12128 | /* Get an iocbq struct to fill in. */ |
12129 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
12130 | if (first_iocbq) { | |
12131 | /* Initialize the first IOCB. */ | |
8fa38513 | 12132 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 JS |
12133 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
12134 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
12135 | first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id); | |
12136 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
12137 | vport->vpi + vport->phba->vpi_base; | |
12138 | /* put the first buffer into the first IOCBq */ | |
12139 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
12140 | first_iocbq->context3 = NULL; | |
12141 | first_iocbq->iocb.ulpBdeCount = 1; | |
12142 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
12143 | LPFC_DATA_BUF_SIZE; | |
12144 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
8fa38513 | 12145 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12146 | bf_get(lpfc_rcqe_length, |
12147 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12148 | } |
12149 | iocbq = first_iocbq; | |
12150 | /* | |
12151 | * Each IOCBq can have two Buffers assigned, so go through the list | |
12152 | * of buffers for this sequence and save two buffers in each IOCBq | |
12153 | */ | |
12154 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
12155 | if (!iocbq) { | |
12156 | lpfc_in_buf_free(vport->phba, d_buf); | |
12157 | continue; | |
12158 | } | |
12159 | if (!iocbq->context3) { | |
12160 | iocbq->context3 = d_buf; | |
12161 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
12162 | pbde = (struct ulp_bde64 *) |
12163 | &iocbq->iocb.unsli3.sli3Words[4]; | |
12164 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
8fa38513 | 12165 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12166 | bf_get(lpfc_rcqe_length, |
12167 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12168 | } else { |
12169 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
12170 | if (!iocbq) { | |
12171 | if (first_iocbq) { | |
12172 | first_iocbq->iocb.ulpStatus = | |
12173 | IOSTAT_FCP_RSP_ERROR; | |
12174 | first_iocbq->iocb.un.ulpWord[4] = | |
12175 | IOERR_NO_RESOURCES; | |
12176 | } | |
12177 | lpfc_in_buf_free(vport->phba, d_buf); | |
12178 | continue; | |
12179 | } | |
12180 | iocbq->context2 = d_buf; | |
12181 | iocbq->context3 = NULL; | |
12182 | iocbq->iocb.ulpBdeCount = 1; | |
12183 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
12184 | LPFC_DATA_BUF_SIZE; | |
8fa38513 | 12185 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12186 | bf_get(lpfc_rcqe_length, |
12187 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12188 | iocbq->iocb.un.rcvels.remoteID = sid; |
12189 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
12190 | } | |
12191 | } | |
12192 | return first_iocbq; | |
12193 | } | |
12194 | ||
6669f9bb JS |
12195 | static void |
12196 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
12197 | struct hbq_dmabuf *seq_dmabuf) | |
12198 | { | |
12199 | struct fc_frame_header *fc_hdr; | |
12200 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
12201 | struct lpfc_hba *phba = vport->phba; | |
12202 | ||
12203 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12204 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
12205 | if (!iocbq) { | |
12206 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12207 | "2707 Ring %d handler: Failed to allocate " | |
12208 | "iocb Rctl x%x Type x%x received\n", | |
12209 | LPFC_ELS_RING, | |
12210 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
12211 | return; | |
12212 | } | |
12213 | if (!lpfc_complete_unsol_iocb(phba, | |
12214 | &phba->sli.ring[LPFC_ELS_RING], | |
12215 | iocbq, fc_hdr->fh_r_ctl, | |
12216 | fc_hdr->fh_type)) | |
12217 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12218 | "2540 Ring %d handler: unexpected Rctl " | |
12219 | "x%x Type x%x received\n", | |
12220 | LPFC_ELS_RING, | |
12221 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
12222 | ||
12223 | /* Free iocb created in lpfc_prep_seq */ | |
12224 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
12225 | &iocbq->list, list) { | |
12226 | list_del_init(&curr_iocb->list); | |
12227 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
12228 | } | |
12229 | lpfc_sli_release_iocbq(phba, iocbq); | |
12230 | } | |
12231 | ||
4f774513 JS |
12232 | /** |
12233 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
12234 | * @phba: Pointer to HBA context object. | |
12235 | * | |
12236 | * This function is called with no lock held. This function processes all | |
12237 | * the received buffers and gives it to upper layers when a received buffer | |
12238 | * indicates that it is the final frame in the sequence. The interrupt | |
12239 | * service routine processes received buffers at interrupt contexts and adds | |
12240 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
12241 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
12242 | * appropriate receive function when the final frame in a sequence is received. | |
12243 | **/ | |
4d9ab994 JS |
12244 | void |
12245 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
12246 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 12247 | { |
4d9ab994 | 12248 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
12249 | struct fc_frame_header *fc_hdr; |
12250 | struct lpfc_vport *vport; | |
12251 | uint32_t fcfi; | |
4f774513 | 12252 | |
4f774513 | 12253 | /* Process each received buffer */ |
4d9ab994 JS |
12254 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
12255 | /* check to see if this a valid type of frame */ | |
12256 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
12257 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12258 | return; | |
12259 | } | |
12260 | fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl); | |
12261 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); | |
c868595d | 12262 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
4d9ab994 JS |
12263 | /* throw out the frame */ |
12264 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12265 | return; | |
12266 | } | |
6669f9bb JS |
12267 | /* Handle the basic abort sequence (BA_ABTS) event */ |
12268 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
12269 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
12270 | return; | |
12271 | } | |
12272 | ||
4d9ab994 JS |
12273 | /* Link this frame */ |
12274 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
12275 | if (!seq_dmabuf) { | |
12276 | /* unable to add frame to vport - throw it out */ | |
12277 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12278 | return; | |
12279 | } | |
12280 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 12281 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 12282 | return; |
def9c7a9 | 12283 | |
6669f9bb JS |
12284 | /* Send the complete sequence to the upper layer protocol */ |
12285 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 12286 | } |
6fb120a7 JS |
12287 | |
12288 | /** | |
12289 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
12290 | * @phba: pointer to lpfc hba data structure. | |
12291 | * | |
12292 | * This routine is invoked to post rpi header templates to the | |
12293 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
12294 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
12295 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
12296 | * |
12297 | * This routine does not require any locks. It's usage is expected | |
12298 | * to be driver load or reset recovery when the driver is | |
12299 | * sequential. | |
12300 | * | |
12301 | * Return codes | |
af901ca1 | 12302 | * 0 - successful |
d439d286 | 12303 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
12304 | * When this error occurs, the driver is not guaranteed |
12305 | * to have any rpi regions posted to the device and | |
12306 | * must either attempt to repost the regions or take a | |
12307 | * fatal error. | |
12308 | **/ | |
12309 | int | |
12310 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
12311 | { | |
12312 | struct lpfc_rpi_hdr *rpi_page; | |
12313 | uint32_t rc = 0; | |
12314 | ||
12315 | /* Post all rpi memory regions to the port. */ | |
12316 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
12317 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); | |
12318 | if (rc != MBX_SUCCESS) { | |
12319 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12320 | "2008 Error %d posting all rpi " | |
12321 | "headers\n", rc); | |
12322 | rc = -EIO; | |
12323 | break; | |
12324 | } | |
12325 | } | |
12326 | ||
12327 | return rc; | |
12328 | } | |
12329 | ||
12330 | /** | |
12331 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
12332 | * @phba: pointer to lpfc hba data structure. | |
12333 | * @rpi_page: pointer to the rpi memory region. | |
12334 | * | |
12335 | * This routine is invoked to post a single rpi header to the | |
12336 | * HBA consistent with the SLI-4 interface spec. This memory region | |
12337 | * maps up to 64 rpi context regions. | |
12338 | * | |
12339 | * Return codes | |
af901ca1 | 12340 | * 0 - successful |
d439d286 JS |
12341 | * -ENOMEM - No available memory |
12342 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
12343 | **/ |
12344 | int | |
12345 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
12346 | { | |
12347 | LPFC_MBOXQ_t *mboxq; | |
12348 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
12349 | uint32_t rc = 0; | |
12350 | uint32_t mbox_tmo; | |
12351 | uint32_t shdr_status, shdr_add_status; | |
12352 | union lpfc_sli4_cfg_shdr *shdr; | |
12353 | ||
12354 | /* The port is notified of the header region via a mailbox command. */ | |
12355 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12356 | if (!mboxq) { | |
12357 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12358 | "2001 Unable to allocate memory for issuing " | |
12359 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
12360 | return -ENOMEM; | |
12361 | } | |
12362 | ||
12363 | /* Post all rpi memory regions to the port. */ | |
12364 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
12365 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12366 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12367 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
12368 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
12369 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | |
12370 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, | |
12371 | hdr_tmpl, rpi_page->page_count); | |
12372 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, | |
12373 | rpi_page->start_rpi); | |
12374 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); | |
12375 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 12376 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
12377 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
12378 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12379 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12380 | if (rc != MBX_TIMEOUT) | |
12381 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12382 | if (shdr_status || shdr_add_status || rc) { | |
12383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12384 | "2514 POST_RPI_HDR mailbox failed with " | |
12385 | "status x%x add_status x%x, mbx status x%x\n", | |
12386 | shdr_status, shdr_add_status, rc); | |
12387 | rc = -ENXIO; | |
12388 | } | |
12389 | return rc; | |
12390 | } | |
12391 | ||
12392 | /** | |
12393 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
12394 | * @phba: pointer to lpfc hba data structure. | |
12395 | * | |
12396 | * This routine is invoked to post rpi header templates to the | |
12397 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
12398 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
12399 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
12400 | * |
12401 | * Returns | |
af901ca1 | 12402 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
12403 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
12404 | **/ | |
12405 | int | |
12406 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
12407 | { | |
12408 | int rpi; | |
12409 | uint16_t max_rpi, rpi_base, rpi_limit; | |
12410 | uint16_t rpi_remaining; | |
12411 | struct lpfc_rpi_hdr *rpi_hdr; | |
12412 | ||
12413 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
12414 | rpi_base = phba->sli4_hba.max_cfg_param.rpi_base; | |
12415 | rpi_limit = phba->sli4_hba.next_rpi; | |
12416 | ||
12417 | /* | |
12418 | * The valid rpi range is not guaranteed to be zero-based. Start | |
12419 | * the search at the rpi_base as reported by the port. | |
12420 | */ | |
12421 | spin_lock_irq(&phba->hbalock); | |
12422 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base); | |
12423 | if (rpi >= rpi_limit || rpi < rpi_base) | |
12424 | rpi = LPFC_RPI_ALLOC_ERROR; | |
12425 | else { | |
12426 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
12427 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
12428 | phba->sli4_hba.rpi_count++; | |
12429 | } | |
12430 | ||
12431 | /* | |
12432 | * Don't try to allocate more rpi header regions if the device limit | |
12433 | * on available rpis max has been exhausted. | |
12434 | */ | |
12435 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
12436 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
12437 | spin_unlock_irq(&phba->hbalock); | |
12438 | return rpi; | |
12439 | } | |
12440 | ||
12441 | /* | |
12442 | * If the driver is running low on rpi resources, allocate another | |
12443 | * page now. Note that the next_rpi value is used because | |
12444 | * it represents how many are actually in use whereas max_rpi notes | |
12445 | * how many are supported max by the device. | |
12446 | */ | |
12447 | rpi_remaining = phba->sli4_hba.next_rpi - rpi_base - | |
12448 | phba->sli4_hba.rpi_count; | |
12449 | spin_unlock_irq(&phba->hbalock); | |
12450 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
12451 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
12452 | if (!rpi_hdr) { | |
12453 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12454 | "2002 Error Could not grow rpi " | |
12455 | "count\n"); | |
12456 | } else { | |
12457 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); | |
12458 | } | |
12459 | } | |
12460 | ||
12461 | return rpi; | |
12462 | } | |
12463 | ||
d7c47992 JS |
12464 | /** |
12465 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
12466 | * @phba: pointer to lpfc hba data structure. | |
12467 | * | |
12468 | * This routine is invoked to release an rpi to the pool of | |
12469 | * available rpis maintained by the driver. | |
12470 | **/ | |
12471 | void | |
12472 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
12473 | { | |
12474 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
12475 | phba->sli4_hba.rpi_count--; | |
12476 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
12477 | } | |
12478 | } | |
12479 | ||
6fb120a7 JS |
12480 | /** |
12481 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
12482 | * @phba: pointer to lpfc hba data structure. | |
12483 | * | |
12484 | * This routine is invoked to release an rpi to the pool of | |
12485 | * available rpis maintained by the driver. | |
12486 | **/ | |
12487 | void | |
12488 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
12489 | { | |
12490 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 12491 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
12492 | spin_unlock_irq(&phba->hbalock); |
12493 | } | |
12494 | ||
12495 | /** | |
12496 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
12497 | * @phba: pointer to lpfc hba data structure. | |
12498 | * | |
12499 | * This routine is invoked to remove the memory region that | |
12500 | * provided rpi via a bitmask. | |
12501 | **/ | |
12502 | void | |
12503 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
12504 | { | |
12505 | kfree(phba->sli4_hba.rpi_bmask); | |
12506 | } | |
12507 | ||
12508 | /** | |
12509 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
12510 | * @phba: pointer to lpfc hba data structure. | |
12511 | * | |
12512 | * This routine is invoked to remove the memory region that | |
12513 | * provided rpi via a bitmask. | |
12514 | **/ | |
12515 | int | |
12516 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | |
12517 | { | |
12518 | LPFC_MBOXQ_t *mboxq; | |
12519 | struct lpfc_hba *phba = ndlp->phba; | |
12520 | int rc; | |
12521 | ||
12522 | /* The port is notified of the header region via a mailbox command. */ | |
12523 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12524 | if (!mboxq) | |
12525 | return -ENOMEM; | |
12526 | ||
12527 | /* Post all rpi memory regions to the port. */ | |
12528 | lpfc_resume_rpi(mboxq, ndlp); | |
12529 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12530 | if (rc == MBX_NOT_FINISHED) { | |
12531 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12532 | "2010 Resume RPI Mailbox failed " | |
12533 | "status %d, mbxStatus x%x\n", rc, | |
12534 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
12535 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12536 | return -EIO; | |
12537 | } | |
12538 | return 0; | |
12539 | } | |
12540 | ||
12541 | /** | |
12542 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 12543 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 12544 | * |
76a95d75 | 12545 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
12546 | * |
12547 | * Returns: | |
12548 | * 0 success | |
12549 | * -Evalue otherwise | |
12550 | **/ | |
12551 | int | |
76a95d75 | 12552 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
12553 | { |
12554 | LPFC_MBOXQ_t *mboxq; | |
12555 | int rc = 0; | |
6a9c52cf | 12556 | int retval = MBX_SUCCESS; |
6fb120a7 | 12557 | uint32_t mbox_tmo; |
76a95d75 | 12558 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
12559 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12560 | if (!mboxq) | |
12561 | return -ENOMEM; | |
76a95d75 | 12562 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
6fb120a7 JS |
12563 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI); |
12564 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6fb120a7 | 12565 | if (rc != MBX_SUCCESS) { |
76a95d75 | 12566 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
12567 | "2022 INIT VPI Mailbox failed " |
12568 | "status %d, mbxStatus x%x\n", rc, | |
12569 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 12570 | retval = -EIO; |
6fb120a7 | 12571 | } |
6a9c52cf | 12572 | if (rc != MBX_TIMEOUT) |
76a95d75 | 12573 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
12574 | |
12575 | return retval; | |
6fb120a7 JS |
12576 | } |
12577 | ||
12578 | /** | |
12579 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
12580 | * @phba: pointer to lpfc hba data structure. | |
12581 | * @mboxq: Pointer to mailbox object. | |
12582 | * | |
12583 | * This routine is invoked to manually add a single FCF record. The caller | |
12584 | * must pass a completely initialized FCF_Record. This routine takes | |
12585 | * care of the nonembedded mailbox operations. | |
12586 | **/ | |
12587 | static void | |
12588 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
12589 | { | |
12590 | void *virt_addr; | |
12591 | union lpfc_sli4_cfg_shdr *shdr; | |
12592 | uint32_t shdr_status, shdr_add_status; | |
12593 | ||
12594 | virt_addr = mboxq->sge_array->addr[0]; | |
12595 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12596 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
12597 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12598 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12599 | ||
12600 | if ((shdr_status || shdr_add_status) && | |
12601 | (shdr_status != STATUS_FCF_IN_USE)) | |
12602 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12603 | "2558 ADD_FCF_RECORD mailbox failed with " | |
12604 | "status x%x add_status x%x\n", | |
12605 | shdr_status, shdr_add_status); | |
12606 | ||
12607 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12608 | } | |
12609 | ||
12610 | /** | |
12611 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
12612 | * @phba: pointer to lpfc hba data structure. | |
12613 | * @fcf_record: pointer to the initialized fcf record to add. | |
12614 | * | |
12615 | * This routine is invoked to manually add a single FCF record. The caller | |
12616 | * must pass a completely initialized FCF_Record. This routine takes | |
12617 | * care of the nonembedded mailbox operations. | |
12618 | **/ | |
12619 | int | |
12620 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
12621 | { | |
12622 | int rc = 0; | |
12623 | LPFC_MBOXQ_t *mboxq; | |
12624 | uint8_t *bytep; | |
12625 | void *virt_addr; | |
12626 | dma_addr_t phys_addr; | |
12627 | struct lpfc_mbx_sge sge; | |
12628 | uint32_t alloc_len, req_len; | |
12629 | uint32_t fcfindex; | |
12630 | ||
12631 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12632 | if (!mboxq) { | |
12633 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12634 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
12635 | return -ENOMEM; | |
12636 | } | |
12637 | ||
12638 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
12639 | sizeof(uint32_t); | |
12640 | ||
12641 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
12642 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12643 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
12644 | req_len, LPFC_SLI4_MBX_NEMBED); | |
12645 | if (alloc_len < req_len) { | |
12646 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12647 | "2523 Allocated DMA memory size (x%x) is " | |
12648 | "less than the requested DMA memory " | |
12649 | "size (x%x)\n", alloc_len, req_len); | |
12650 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12651 | return -ENOMEM; | |
12652 | } | |
12653 | ||
12654 | /* | |
12655 | * Get the first SGE entry from the non-embedded DMA memory. This | |
12656 | * routine only uses a single SGE. | |
12657 | */ | |
12658 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
12659 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
12660 | virt_addr = mboxq->sge_array->addr[0]; |
12661 | /* | |
12662 | * Configure the FCF record for FCFI 0. This is the driver's | |
12663 | * hardcoded default and gets used in nonFIP mode. | |
12664 | */ | |
12665 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
12666 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
12667 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
12668 | ||
12669 | /* | |
12670 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
12671 | * the FCoE header plus word10. The data copy needs to be endian | |
12672 | * correct. | |
12673 | */ | |
12674 | bytep += sizeof(uint32_t); | |
12675 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
12676 | mboxq->vport = phba->pport; | |
12677 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
12678 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12679 | if (rc == MBX_NOT_FINISHED) { | |
12680 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12681 | "2515 ADD_FCF_RECORD mailbox failed with " | |
12682 | "status 0x%x\n", rc); | |
12683 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12684 | rc = -EIO; | |
12685 | } else | |
12686 | rc = 0; | |
12687 | ||
12688 | return rc; | |
12689 | } | |
12690 | ||
12691 | /** | |
12692 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
12693 | * @phba: pointer to lpfc hba data structure. | |
12694 | * @fcf_record: pointer to the fcf record to write the default data. | |
12695 | * @fcf_index: FCF table entry index. | |
12696 | * | |
12697 | * This routine is invoked to build the driver's default FCF record. The | |
12698 | * values used are hardcoded. This routine handles memory initialization. | |
12699 | * | |
12700 | **/ | |
12701 | void | |
12702 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
12703 | struct fcf_record *fcf_record, | |
12704 | uint16_t fcf_index) | |
12705 | { | |
12706 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
12707 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
12708 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
12709 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
12710 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
12711 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
12712 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
12713 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
12714 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
12715 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
12716 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
12717 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
12718 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
12719 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 12720 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
12721 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
12722 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
12723 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
12724 | /* Set the VLAN bit map */ | |
12725 | if (phba->valid_vlan) { | |
12726 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
12727 | = 1 << (phba->vlan_id % 8); | |
12728 | } | |
12729 | } | |
12730 | ||
12731 | /** | |
0c9ab6f5 | 12732 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
12733 | * @phba: pointer to lpfc hba data structure. |
12734 | * @fcf_index: FCF table entry offset. | |
12735 | * | |
0c9ab6f5 JS |
12736 | * This routine is invoked to scan the entire FCF table by reading FCF |
12737 | * record and processing it one at a time starting from the @fcf_index | |
12738 | * for initial FCF discovery or fast FCF failover rediscovery. | |
12739 | * | |
12740 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12741 | * otherwise. | |
6fb120a7 JS |
12742 | **/ |
12743 | int | |
0c9ab6f5 | 12744 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
12745 | { |
12746 | int rc = 0, error; | |
12747 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 12748 | |
32b9793f | 12749 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
6fb120a7 JS |
12750 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12751 | if (!mboxq) { | |
12752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12753 | "2000 Failed to allocate mbox for " | |
12754 | "READ_FCF cmd\n"); | |
4d9ab994 | 12755 | error = -ENOMEM; |
0c9ab6f5 | 12756 | goto fail_fcf_scan; |
6fb120a7 | 12757 | } |
ecfd03c6 | 12758 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 12759 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
12760 | if (rc) { |
12761 | error = -EINVAL; | |
0c9ab6f5 | 12762 | goto fail_fcf_scan; |
6fb120a7 | 12763 | } |
ecfd03c6 | 12764 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 12765 | mboxq->vport = phba->pport; |
0c9ab6f5 | 12766 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
12767 | |
12768 | spin_lock_irq(&phba->hbalock); | |
12769 | phba->hba_flag |= FCF_TS_INPROG; | |
12770 | spin_unlock_irq(&phba->hbalock); | |
12771 | ||
6fb120a7 | 12772 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 12773 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 12774 | error = -EIO; |
ecfd03c6 | 12775 | else { |
38b92ef8 JS |
12776 | /* Reset eligible FCF count for new scan */ |
12777 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 12778 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 12779 | error = 0; |
32b9793f | 12780 | } |
0c9ab6f5 | 12781 | fail_fcf_scan: |
4d9ab994 JS |
12782 | if (error) { |
12783 | if (mboxq) | |
12784 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 12785 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 12786 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 12787 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
12788 | spin_unlock_irq(&phba->hbalock); |
12789 | } | |
6fb120a7 JS |
12790 | return error; |
12791 | } | |
a0c87cbd | 12792 | |
0c9ab6f5 | 12793 | /** |
a93ff37a | 12794 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
12795 | * @phba: pointer to lpfc hba data structure. |
12796 | * @fcf_index: FCF table entry offset. | |
12797 | * | |
12798 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 12799 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 JS |
12800 | * |
12801 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12802 | * otherwise. | |
12803 | **/ | |
12804 | int | |
12805 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
12806 | { | |
12807 | int rc = 0, error; | |
12808 | LPFC_MBOXQ_t *mboxq; | |
12809 | ||
12810 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12811 | if (!mboxq) { | |
12812 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
12813 | "2763 Failed to allocate mbox for " | |
12814 | "READ_FCF cmd\n"); | |
12815 | error = -ENOMEM; | |
12816 | goto fail_fcf_read; | |
12817 | } | |
12818 | /* Construct the read FCF record mailbox command */ | |
12819 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
12820 | if (rc) { | |
12821 | error = -EINVAL; | |
12822 | goto fail_fcf_read; | |
12823 | } | |
12824 | /* Issue the mailbox command asynchronously */ | |
12825 | mboxq->vport = phba->pport; | |
12826 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
12827 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12828 | if (rc == MBX_NOT_FINISHED) | |
12829 | error = -EIO; | |
12830 | else | |
12831 | error = 0; | |
12832 | ||
12833 | fail_fcf_read: | |
12834 | if (error && mboxq) | |
12835 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12836 | return error; | |
12837 | } | |
12838 | ||
12839 | /** | |
12840 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
12841 | * @phba: pointer to lpfc hba data structure. | |
12842 | * @fcf_index: FCF table entry offset. | |
12843 | * | |
12844 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 12845 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 JS |
12846 | * |
12847 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12848 | * otherwise. | |
12849 | **/ | |
12850 | int | |
12851 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
12852 | { | |
12853 | int rc = 0, error; | |
12854 | LPFC_MBOXQ_t *mboxq; | |
12855 | ||
12856 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12857 | if (!mboxq) { | |
12858 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
12859 | "2758 Failed to allocate mbox for " | |
12860 | "READ_FCF cmd\n"); | |
12861 | error = -ENOMEM; | |
12862 | goto fail_fcf_read; | |
12863 | } | |
12864 | /* Construct the read FCF record mailbox command */ | |
12865 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
12866 | if (rc) { | |
12867 | error = -EINVAL; | |
12868 | goto fail_fcf_read; | |
12869 | } | |
12870 | /* Issue the mailbox command asynchronously */ | |
12871 | mboxq->vport = phba->pport; | |
12872 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
12873 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12874 | if (rc == MBX_NOT_FINISHED) | |
12875 | error = -EIO; | |
12876 | else | |
12877 | error = 0; | |
12878 | ||
12879 | fail_fcf_read: | |
12880 | if (error && mboxq) | |
12881 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12882 | return error; | |
12883 | } | |
12884 | ||
12885 | /** | |
12886 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
12887 | * @phba: pointer to lpfc hba data structure. | |
12888 | * | |
12889 | * This routine is to get the next eligible FCF record index in a round | |
12890 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 12891 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
12892 | * shall be returned, otherwise, the next eligible FCF record's index |
12893 | * shall be returned. | |
12894 | **/ | |
12895 | uint16_t | |
12896 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
12897 | { | |
12898 | uint16_t next_fcf_index; | |
12899 | ||
3804dc84 JS |
12900 | /* Search start from next bit of currently registered FCF index */ |
12901 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % | |
12902 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
12903 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
12904 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
12905 | next_fcf_index); |
12906 | ||
0c9ab6f5 JS |
12907 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
12908 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) | |
12909 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, | |
12910 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
3804dc84 JS |
12911 | |
12912 | /* Check roundrobin failover list empty condition */ | |
12913 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12914 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
12915 | "2844 No roundrobin failover FCF available\n"); | |
0c9ab6f5 | 12916 | return LPFC_FCOE_FCF_NEXT_NONE; |
3804dc84 JS |
12917 | } |
12918 | ||
3804dc84 | 12919 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
12920 | "2845 Get next roundrobin failover FCF (x%x)\n", |
12921 | next_fcf_index); | |
12922 | ||
0c9ab6f5 JS |
12923 | return next_fcf_index; |
12924 | } | |
12925 | ||
12926 | /** | |
12927 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
12928 | * @phba: pointer to lpfc hba data structure. | |
12929 | * | |
12930 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 12931 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
12932 | * does not go beyond the range of the driver allocated bmask dimension |
12933 | * before setting the bit. | |
12934 | * | |
12935 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
12936 | * -EINVAL. | |
12937 | **/ | |
12938 | int | |
12939 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
12940 | { | |
12941 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12942 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
12943 | "2610 FCF (x%x) reached driver's book " |
12944 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
12945 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
12946 | return -EINVAL; | |
12947 | } | |
12948 | /* Set the eligible FCF record index bmask */ | |
12949 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
12950 | ||
3804dc84 | 12951 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 12952 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
12953 | "bmask\n", fcf_index); |
12954 | ||
0c9ab6f5 JS |
12955 | return 0; |
12956 | } | |
12957 | ||
12958 | /** | |
3804dc84 | 12959 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
12960 | * @phba: pointer to lpfc hba data structure. |
12961 | * | |
12962 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 12963 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
12964 | * does not go beyond the range of the driver allocated bmask dimension |
12965 | * before clearing the bit. | |
12966 | **/ | |
12967 | void | |
12968 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
12969 | { | |
12970 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12971 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
12972 | "2762 FCF (x%x) reached driver's book " |
12973 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
12974 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
12975 | return; | |
12976 | } | |
12977 | /* Clear the eligible FCF record index bmask */ | |
12978 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
3804dc84 JS |
12979 | |
12980 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 12981 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 12982 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
12983 | } |
12984 | ||
ecfd03c6 JS |
12985 | /** |
12986 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
12987 | * @phba: pointer to lpfc hba data structure. | |
12988 | * | |
12989 | * This routine is the completion routine for the rediscover FCF table mailbox | |
12990 | * command. If the mailbox command returned failure, it will try to stop the | |
12991 | * FCF rediscover wait timer. | |
12992 | **/ | |
12993 | void | |
12994 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
12995 | { | |
12996 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
12997 | uint32_t shdr_status, shdr_add_status; | |
12998 | ||
12999 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
13000 | ||
13001 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
13002 | &redisc_fcf->header.cfg_shdr.response); | |
13003 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
13004 | &redisc_fcf->header.cfg_shdr.response); | |
13005 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 13006 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
13007 | "2746 Requesting for FCF rediscovery failed " |
13008 | "status x%x add_status x%x\n", | |
13009 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 13010 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 13011 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 13012 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
13013 | spin_unlock_irq(&phba->hbalock); |
13014 | /* | |
13015 | * CVL event triggered FCF rediscover request failed, | |
13016 | * last resort to re-try current registered FCF entry. | |
13017 | */ | |
13018 | lpfc_retry_pport_discovery(phba); | |
13019 | } else { | |
13020 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 13021 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
13022 | spin_unlock_irq(&phba->hbalock); |
13023 | /* | |
13024 | * DEAD FCF event triggered FCF rediscover request | |
13025 | * failed, last resort to fail over as a link down | |
13026 | * to FCF registration. | |
13027 | */ | |
13028 | lpfc_sli4_fcf_dead_failthrough(phba); | |
13029 | } | |
0c9ab6f5 JS |
13030 | } else { |
13031 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 13032 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
13033 | /* |
13034 | * Start FCF rediscovery wait timer for pending FCF | |
13035 | * before rescan FCF record table. | |
13036 | */ | |
13037 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 13038 | } |
ecfd03c6 JS |
13039 | |
13040 | mempool_free(mbox, phba->mbox_mem_pool); | |
13041 | } | |
13042 | ||
13043 | /** | |
3804dc84 | 13044 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
13045 | * @phba: pointer to lpfc hba data structure. |
13046 | * | |
13047 | * This routine is invoked to request for rediscovery of the entire FCF table | |
13048 | * by the port. | |
13049 | **/ | |
13050 | int | |
13051 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
13052 | { | |
13053 | LPFC_MBOXQ_t *mbox; | |
13054 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
13055 | int rc, length; | |
13056 | ||
0c9ab6f5 JS |
13057 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
13058 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
13059 | ||
ecfd03c6 JS |
13060 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13061 | if (!mbox) { | |
13062 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13063 | "2745 Failed to allocate mbox for " | |
13064 | "requesting FCF rediscover.\n"); | |
13065 | return -ENOMEM; | |
13066 | } | |
13067 | ||
13068 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
13069 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13070 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13071 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
13072 | length, LPFC_SLI4_MBX_EMBED); | |
13073 | ||
13074 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
13075 | /* Set count to 0 for invalidating the entire FCF database */ | |
13076 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
13077 | ||
13078 | /* Issue the mailbox command asynchronously */ | |
13079 | mbox->vport = phba->pport; | |
13080 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
13081 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
13082 | ||
13083 | if (rc == MBX_NOT_FINISHED) { | |
13084 | mempool_free(mbox, phba->mbox_mem_pool); | |
13085 | return -EIO; | |
13086 | } | |
13087 | return 0; | |
13088 | } | |
13089 | ||
fc2b989b JS |
13090 | /** |
13091 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
13092 | * @phba: pointer to lpfc hba data structure. | |
13093 | * | |
13094 | * This function is the failover routine as a last resort to the FCF DEAD | |
13095 | * event when driver failed to perform fast FCF failover. | |
13096 | **/ | |
13097 | void | |
13098 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
13099 | { | |
13100 | uint32_t link_state; | |
13101 | ||
13102 | /* | |
13103 | * Last resort as FCF DEAD event failover will treat this as | |
13104 | * a link down, but save the link state because we don't want | |
13105 | * it to be changed to Link Down unless it is already down. | |
13106 | */ | |
13107 | link_state = phba->link_state; | |
13108 | lpfc_linkdown(phba); | |
13109 | phba->link_state = link_state; | |
13110 | ||
13111 | /* Unregister FCF if no devices connected to it */ | |
13112 | lpfc_unregister_unused_fcf(phba); | |
13113 | } | |
13114 | ||
a0c87cbd JS |
13115 | /** |
13116 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
13117 | * @phba: pointer to lpfc hba data structure. | |
13118 | * | |
13119 | * This function read region 23 and parse TLV for port status to | |
13120 | * decide if the user disaled the port. If the TLV indicates the | |
13121 | * port is disabled, the hba_flag is set accordingly. | |
13122 | **/ | |
13123 | void | |
13124 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
13125 | { | |
13126 | LPFC_MBOXQ_t *pmb = NULL; | |
13127 | MAILBOX_t *mb; | |
13128 | uint8_t *rgn23_data = NULL; | |
13129 | uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset; | |
13130 | int rc; | |
13131 | ||
13132 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13133 | if (!pmb) { | |
13134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13135 | "2600 lpfc_sli_read_serdes_param failed to" | |
13136 | " allocate mailbox memory\n"); | |
13137 | goto out; | |
13138 | } | |
13139 | mb = &pmb->u.mb; | |
13140 | ||
13141 | /* Get adapter Region 23 data */ | |
13142 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
13143 | if (!rgn23_data) | |
13144 | goto out; | |
13145 | ||
13146 | do { | |
13147 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
13148 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
13149 | ||
13150 | if (rc != MBX_SUCCESS) { | |
13151 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13152 | "2601 lpfc_sli_read_link_ste failed to" | |
13153 | " read config region 23 rc 0x%x Status 0x%x\n", | |
13154 | rc, mb->mbxStatus); | |
13155 | mb->un.varDmp.word_cnt = 0; | |
13156 | } | |
13157 | /* | |
13158 | * dump mem may return a zero when finished or we got a | |
13159 | * mailbox error, either way we are done. | |
13160 | */ | |
13161 | if (mb->un.varDmp.word_cnt == 0) | |
13162 | break; | |
13163 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
13164 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
13165 | ||
13166 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
13167 | rgn23_data + offset, | |
13168 | mb->un.varDmp.word_cnt); | |
13169 | offset += mb->un.varDmp.word_cnt; | |
13170 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
13171 | ||
13172 | data_size = offset; | |
13173 | offset = 0; | |
13174 | ||
13175 | if (!data_size) | |
13176 | goto out; | |
13177 | ||
13178 | /* Check the region signature first */ | |
13179 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
13180 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13181 | "2619 Config region 23 has bad signature\n"); | |
13182 | goto out; | |
13183 | } | |
13184 | offset += 4; | |
13185 | ||
13186 | /* Check the data structure version */ | |
13187 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
13188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13189 | "2620 Config region 23 has bad version\n"); | |
13190 | goto out; | |
13191 | } | |
13192 | offset += 4; | |
13193 | ||
13194 | /* Parse TLV entries in the region */ | |
13195 | while (offset < data_size) { | |
13196 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
13197 | break; | |
13198 | /* | |
13199 | * If the TLV is not driver specific TLV or driver id is | |
13200 | * not linux driver id, skip the record. | |
13201 | */ | |
13202 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
13203 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
13204 | (rgn23_data[offset + 3] != 0)) { | |
13205 | offset += rgn23_data[offset + 1] * 4 + 4; | |
13206 | continue; | |
13207 | } | |
13208 | ||
13209 | /* Driver found a driver specific TLV in the config region */ | |
13210 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
13211 | offset += 4; | |
13212 | tlv_offset = 0; | |
13213 | ||
13214 | /* | |
13215 | * Search for configured port state sub-TLV. | |
13216 | */ | |
13217 | while ((offset < data_size) && | |
13218 | (tlv_offset < sub_tlv_len)) { | |
13219 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
13220 | offset += 4; | |
13221 | tlv_offset += 4; | |
13222 | break; | |
13223 | } | |
13224 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
13225 | offset += rgn23_data[offset + 1] * 4 + 4; | |
13226 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
13227 | continue; | |
13228 | } | |
13229 | ||
13230 | /* This HBA contains PORT_STE configured */ | |
13231 | if (!rgn23_data[offset + 2]) | |
13232 | phba->hba_flag |= LINK_DISABLED; | |
13233 | ||
13234 | goto out; | |
13235 | } | |
13236 | } | |
13237 | out: | |
13238 | if (pmb) | |
13239 | mempool_free(pmb, phba->mbox_mem_pool); | |
13240 | kfree(rgn23_data); | |
13241 | return; | |
13242 | } | |
695a814e JS |
13243 | |
13244 | /** | |
13245 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
13246 | * @vport: pointer to vport data structure. | |
13247 | * | |
13248 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
13249 | * and REG_VPI mailbox commands associated with the vport. This function | |
13250 | * is called when driver want to restart discovery of the vport due to | |
13251 | * a Clear Virtual Link event. | |
13252 | **/ | |
13253 | void | |
13254 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
13255 | { | |
13256 | struct lpfc_hba *phba = vport->phba; | |
13257 | LPFC_MBOXQ_t *mb, *nextmb; | |
13258 | struct lpfc_dmabuf *mp; | |
78730cfe | 13259 | struct lpfc_nodelist *ndlp; |
d439d286 | 13260 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 13261 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 13262 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 13263 | uint8_t restart_loop; |
695a814e | 13264 | |
d439d286 | 13265 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
13266 | spin_lock_irq(&phba->hbalock); |
13267 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
13268 | if (mb->vport != vport) | |
13269 | continue; | |
13270 | ||
13271 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
13272 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
13273 | continue; | |
13274 | ||
d439d286 JS |
13275 | list_del(&mb->list); |
13276 | list_add_tail(&mb->list, &mbox_cmd_list); | |
13277 | } | |
13278 | /* Clean up active mailbox command with the vport */ | |
13279 | mb = phba->sli.mbox_active; | |
13280 | if (mb && (mb->vport == vport)) { | |
13281 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
13282 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
13283 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13284 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
13285 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
13286 | /* Put reference count for delayed processing */ | |
13287 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
13288 | /* Unregister the RPI when mailbox complete */ | |
13289 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
13290 | } | |
13291 | } | |
63e801ce JS |
13292 | /* Cleanup any mailbox completions which are not yet processed */ |
13293 | do { | |
13294 | restart_loop = 0; | |
13295 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
13296 | /* | |
13297 | * If this mailox is already processed or it is | |
13298 | * for another vport ignore it. | |
13299 | */ | |
13300 | if ((mb->vport != vport) || | |
13301 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
13302 | continue; | |
13303 | ||
13304 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
13305 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
13306 | continue; | |
13307 | ||
13308 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13309 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
13310 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
13311 | /* Unregister the RPI when mailbox complete */ | |
13312 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
13313 | restart_loop = 1; | |
13314 | spin_unlock_irq(&phba->hbalock); | |
13315 | spin_lock(shost->host_lock); | |
13316 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
13317 | spin_unlock(shost->host_lock); | |
13318 | spin_lock_irq(&phba->hbalock); | |
13319 | break; | |
13320 | } | |
13321 | } | |
13322 | } while (restart_loop); | |
13323 | ||
d439d286 JS |
13324 | spin_unlock_irq(&phba->hbalock); |
13325 | ||
13326 | /* Release the cleaned-up mailbox commands */ | |
13327 | while (!list_empty(&mbox_cmd_list)) { | |
13328 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e | 13329 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
d7c47992 JS |
13330 | if (phba->sli_rev == LPFC_SLI_REV4) |
13331 | __lpfc_sli4_free_rpi(phba, | |
13332 | mb->u.mb.un.varRegLogin.rpi); | |
695a814e JS |
13333 | mp = (struct lpfc_dmabuf *) (mb->context1); |
13334 | if (mp) { | |
13335 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
13336 | kfree(mp); | |
13337 | } | |
78730cfe | 13338 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 13339 | mb->context2 = NULL; |
78730cfe | 13340 | if (ndlp) { |
ec21b3b0 | 13341 | spin_lock(shost->host_lock); |
589a52d6 | 13342 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 13343 | spin_unlock(shost->host_lock); |
78730cfe | 13344 | lpfc_nlp_put(ndlp); |
78730cfe | 13345 | } |
695a814e | 13346 | } |
695a814e JS |
13347 | mempool_free(mb, phba->mbox_mem_pool); |
13348 | } | |
d439d286 JS |
13349 | |
13350 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
13351 | if (act_mbx_ndlp) { | |
13352 | spin_lock(shost->host_lock); | |
13353 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
13354 | spin_unlock(shost->host_lock); | |
13355 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 13356 | } |
695a814e JS |
13357 | } |
13358 | ||
2a9bf3d0 JS |
13359 | /** |
13360 | * lpfc_drain_txq - Drain the txq | |
13361 | * @phba: Pointer to HBA context object. | |
13362 | * | |
13363 | * This function attempt to submit IOCBs on the txq | |
13364 | * to the adapter. For SLI4 adapters, the txq contains | |
13365 | * ELS IOCBs that have been deferred because the there | |
13366 | * are no SGLs. This congestion can occur with large | |
13367 | * vport counts during node discovery. | |
13368 | **/ | |
13369 | ||
13370 | uint32_t | |
13371 | lpfc_drain_txq(struct lpfc_hba *phba) | |
13372 | { | |
13373 | LIST_HEAD(completions); | |
13374 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
13375 | struct lpfc_iocbq *piocbq = 0; | |
13376 | unsigned long iflags = 0; | |
13377 | char *fail_msg = NULL; | |
13378 | struct lpfc_sglq *sglq; | |
13379 | union lpfc_wqe wqe; | |
13380 | ||
13381 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13382 | if (pring->txq_cnt > pring->txq_max) | |
13383 | pring->txq_max = pring->txq_cnt; | |
13384 | ||
13385 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13386 | ||
13387 | while (pring->txq_cnt) { | |
13388 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13389 | ||
19ca7609 JS |
13390 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
13391 | sglq = __lpfc_sli_get_sglq(phba, piocbq); | |
2a9bf3d0 | 13392 | if (!sglq) { |
19ca7609 | 13393 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
13394 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
13395 | break; | |
13396 | } else { | |
2a9bf3d0 JS |
13397 | if (!piocbq) { |
13398 | /* The txq_cnt out of sync. This should | |
13399 | * never happen | |
13400 | */ | |
13401 | sglq = __lpfc_clear_active_sglq(phba, | |
13402 | sglq->sli4_xritag); | |
13403 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13404 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13405 | "2823 txq empty and txq_cnt is %d\n ", | |
13406 | pring->txq_cnt); | |
13407 | break; | |
13408 | } | |
13409 | } | |
13410 | ||
13411 | /* The xri and iocb resources secured, | |
13412 | * attempt to issue request | |
13413 | */ | |
13414 | piocbq->sli4_xritag = sglq->sli4_xritag; | |
13415 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
13416 | fail_msg = "to convert bpl to sgl"; | |
13417 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
13418 | fail_msg = "to convert iocb to wqe"; | |
13419 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
13420 | fail_msg = " - Wq is full"; | |
13421 | else | |
13422 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
13423 | ||
13424 | if (fail_msg) { | |
13425 | /* Failed means we can't issue and need to cancel */ | |
13426 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13427 | "2822 IOCB failed %s iotag 0x%x " | |
13428 | "xri 0x%x\n", | |
13429 | fail_msg, | |
13430 | piocbq->iotag, piocbq->sli4_xritag); | |
13431 | list_add_tail(&piocbq->list, &completions); | |
13432 | } | |
13433 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13434 | } | |
13435 | ||
2a9bf3d0 JS |
13436 | /* Cancel all the IOCBs that cannot be issued */ |
13437 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
13438 | IOERR_SLI_ABORTED); | |
13439 | ||
13440 | return pring->txq_cnt; | |
13441 | } |