]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
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 JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/pci.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
5a0e3ad6 | 26 | #include <linux/slab.h> |
dea3101e | 27 | |
91886523 | 28 | #include <scsi/scsi.h> |
dea3101e JB |
29 | #include <scsi/scsi_cmnd.h> |
30 | #include <scsi/scsi_device.h> | |
31 | #include <scsi/scsi_host.h> | |
f888ba3c | 32 | #include <scsi/scsi_transport_fc.h> |
da0436e9 | 33 | #include <scsi/fc/fc_fs.h> |
0d878419 | 34 | #include <linux/aer.h> |
dea3101e | 35 | |
da0436e9 | 36 | #include "lpfc_hw4.h" |
dea3101e JB |
37 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | |
da0436e9 | 39 | #include "lpfc_sli4.h" |
ea2151b4 | 40 | #include "lpfc_nl.h" |
dea3101e JB |
41 | #include "lpfc_disc.h" |
42 | #include "lpfc_scsi.h" | |
43 | #include "lpfc.h" | |
44 | #include "lpfc_crtn.h" | |
45 | #include "lpfc_logmsg.h" | |
46 | #include "lpfc_compat.h" | |
858c9f6c | 47 | #include "lpfc_debugfs.h" |
04c68496 | 48 | #include "lpfc_vport.h" |
dea3101e JB |
49 | |
50 | /* There are only four IOCB completion types. */ | |
51 | typedef enum _lpfc_iocb_type { | |
52 | LPFC_UNKNOWN_IOCB, | |
53 | LPFC_UNSOL_IOCB, | |
54 | LPFC_SOL_IOCB, | |
55 | LPFC_ABORT_IOCB | |
56 | } lpfc_iocb_type; | |
57 | ||
4f774513 JS |
58 | |
59 | /* Provide function prototypes local to this module. */ | |
60 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
61 | uint32_t); | |
62 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | |
45ed1190 JS |
63 | uint8_t *, uint32_t *); |
64 | static struct lpfc_iocbq *lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *, | |
65 | struct lpfc_iocbq *); | |
6669f9bb JS |
66 | static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *, |
67 | struct hbq_dmabuf *); | |
4f774513 JS |
68 | static IOCB_t * |
69 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | |
70 | { | |
71 | return &iocbq->iocb; | |
72 | } | |
73 | ||
74 | /** | |
75 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | |
76 | * @q: The Work Queue to operate on. | |
77 | * @wqe: The work Queue Entry to put on the Work queue. | |
78 | * | |
79 | * This routine will copy the contents of @wqe to the next available entry on | |
80 | * the @q. This function will then ring the Work Queue Doorbell to signal the | |
81 | * HBA to start processing the Work Queue Entry. This function returns 0 if | |
82 | * successful. If no entries are available on @q then this function will return | |
83 | * -ENOMEM. | |
84 | * The caller is expected to hold the hbalock when calling this routine. | |
85 | **/ | |
86 | static uint32_t | |
87 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | |
88 | { | |
89 | union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe; | |
90 | struct lpfc_register doorbell; | |
91 | uint32_t host_index; | |
92 | ||
93 | /* If the host has not yet processed the next entry then we are done */ | |
94 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | |
95 | return -ENOMEM; | |
96 | /* set consumption flag every once in a while */ | |
97 | if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL)) | |
f0d9bccc | 98 | bf_set(wqe_wqec, &wqe->generic.wqe_com, 1); |
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; | |
874 | } else if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) | |
875 | ndlp = piocbq->context_un.ndlp; | |
876 | else if (piocbq->iocb.ulpCommand == CMD_XMIT_BLS_RSP64_CX) | |
877 | ndlp = lpfc_findnode_did(piocbq->vport, | |
878 | piocbq->iocb.ulpContext); | |
879 | else | |
880 | ndlp = piocbq->context1; | |
881 | ||
da0436e9 | 882 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); |
19ca7609 JS |
883 | start_sglq = sglq; |
884 | while (!found) { | |
885 | if (!sglq) | |
886 | return NULL; | |
887 | adj_xri = sglq->sli4_xritag - | |
888 | phba->sli4_hba.max_cfg_param.xri_base; | |
889 | if (__lpfc_test_rrq_active(phba, ndlp, sglq->sli4_xritag)) { | |
890 | /* This xri has an rrq outstanding for this DID. | |
891 | * put it back in the list and get another xri. | |
892 | */ | |
893 | list_add_tail(&sglq->list, lpfc_sgl_list); | |
894 | sglq = NULL; | |
895 | list_remove_head(lpfc_sgl_list, sglq, | |
896 | struct lpfc_sglq, list); | |
897 | if (sglq == start_sglq) { | |
898 | sglq = NULL; | |
899 | break; | |
900 | } else | |
901 | continue; | |
902 | } | |
903 | sglq->ndlp = ndlp; | |
904 | found = 1; | |
905 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq; | |
906 | sglq->state = SGL_ALLOCATED; | |
907 | } | |
da0436e9 JS |
908 | return sglq; |
909 | } | |
910 | ||
e59058c4 | 911 | /** |
3621a710 | 912 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
913 | * @phba: Pointer to HBA context object. |
914 | * | |
915 | * This function is called with no lock held. This function | |
916 | * allocates a new driver iocb object from the iocb pool. If the | |
917 | * allocation is successful, it returns pointer to the newly | |
918 | * allocated iocb object else it returns NULL. | |
919 | **/ | |
2e0fef85 JS |
920 | struct lpfc_iocbq * |
921 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
922 | { | |
923 | struct lpfc_iocbq * iocbq = NULL; | |
924 | unsigned long iflags; | |
925 | ||
926 | spin_lock_irqsave(&phba->hbalock, iflags); | |
927 | iocbq = __lpfc_sli_get_iocbq(phba); | |
928 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
929 | return iocbq; | |
930 | } | |
931 | ||
4f774513 JS |
932 | /** |
933 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
934 | * @phba: Pointer to HBA context object. | |
935 | * @iocbq: Pointer to driver iocb object. | |
936 | * | |
937 | * This function is called with hbalock held to release driver | |
938 | * iocb object to the iocb pool. The iotag in the iocb object | |
939 | * does not change for each use of the iocb object. This function | |
940 | * clears all other fields of the iocb object when it is freed. | |
941 | * The sqlq structure that holds the xritag and phys and virtual | |
942 | * mappings for the scatter gather list is retrieved from the | |
943 | * active array of sglq. The get of the sglq pointer also clears | |
944 | * the entry in the array. If the status of the IO indiactes that | |
945 | * this IO was aborted then the sglq entry it put on the | |
946 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
947 | * IO has good status or fails for any other reason then the sglq | |
948 | * entry is added to the free list (lpfc_sgl_list). | |
949 | **/ | |
950 | static void | |
951 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
952 | { | |
953 | struct lpfc_sglq *sglq; | |
954 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
955 | unsigned long iflag = 0; |
956 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
957 | |
958 | if (iocbq->sli4_xritag == NO_XRI) | |
959 | sglq = NULL; | |
960 | else | |
961 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag); | |
962 | if (sglq) { | |
0f65ff68 JS |
963 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
964 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
965 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
966 | iflag); | |
967 | list_add(&sglq->list, | |
968 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
969 | spin_unlock_irqrestore( | |
970 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
971 | } else { |
972 | sglq->state = SGL_FREED; | |
19ca7609 | 973 | sglq->ndlp = NULL; |
4f774513 | 974 | list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list); |
2a9bf3d0 JS |
975 | |
976 | /* Check if TXQ queue needs to be serviced */ | |
589a52d6 | 977 | if (pring->txq_cnt) |
2a9bf3d0 | 978 | lpfc_worker_wake_up(phba); |
0f65ff68 | 979 | } |
4f774513 JS |
980 | } |
981 | ||
982 | ||
983 | /* | |
984 | * Clean all volatile data fields, preserve iotag and node struct. | |
985 | */ | |
986 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
987 | iocbq->sli4_xritag = NO_XRI; | |
988 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
989 | } | |
990 | ||
2a9bf3d0 | 991 | |
e59058c4 | 992 | /** |
3772a991 | 993 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
994 | * @phba: Pointer to HBA context object. |
995 | * @iocbq: Pointer to driver iocb object. | |
996 | * | |
997 | * This function is called with hbalock held to release driver | |
998 | * iocb object to the iocb pool. The iotag in the iocb object | |
999 | * does not change for each use of the iocb object. This function | |
1000 | * clears all other fields of the iocb object when it is freed. | |
1001 | **/ | |
a6ababd2 | 1002 | static void |
3772a991 | 1003 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 1004 | { |
2e0fef85 | 1005 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
1006 | |
1007 | /* | |
1008 | * Clean all volatile data fields, preserve iotag and node struct. | |
1009 | */ | |
1010 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 1011 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
1012 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
1013 | } | |
1014 | ||
3772a991 JS |
1015 | /** |
1016 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
1017 | * @phba: Pointer to HBA context object. | |
1018 | * @iocbq: Pointer to driver iocb object. | |
1019 | * | |
1020 | * This function is called with hbalock held to release driver | |
1021 | * iocb object to the iocb pool. The iotag in the iocb object | |
1022 | * does not change for each use of the iocb object. This function | |
1023 | * clears all other fields of the iocb object when it is freed. | |
1024 | **/ | |
1025 | static void | |
1026 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1027 | { | |
1028 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 1029 | phba->iocb_cnt--; |
3772a991 JS |
1030 | } |
1031 | ||
e59058c4 | 1032 | /** |
3621a710 | 1033 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
1034 | * @phba: Pointer to HBA context object. |
1035 | * @iocbq: Pointer to driver iocb object. | |
1036 | * | |
1037 | * This function is called with no lock held to release the iocb to | |
1038 | * iocb pool. | |
1039 | **/ | |
2e0fef85 JS |
1040 | void |
1041 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
1042 | { | |
1043 | unsigned long iflags; | |
1044 | ||
1045 | /* | |
1046 | * Clean all volatile data fields, preserve iotag and node struct. | |
1047 | */ | |
1048 | spin_lock_irqsave(&phba->hbalock, iflags); | |
1049 | __lpfc_sli_release_iocbq(phba, iocbq); | |
1050 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
1051 | } | |
1052 | ||
a257bf90 JS |
1053 | /** |
1054 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
1055 | * @phba: Pointer to HBA context object. | |
1056 | * @iocblist: List of IOCBs. | |
1057 | * @ulpstatus: ULP status in IOCB command field. | |
1058 | * @ulpWord4: ULP word-4 in IOCB command field. | |
1059 | * | |
1060 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
1061 | * on the list by invoking the complete callback function associated with the | |
1062 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
1063 | * fields. | |
1064 | **/ | |
1065 | void | |
1066 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
1067 | uint32_t ulpstatus, uint32_t ulpWord4) | |
1068 | { | |
1069 | struct lpfc_iocbq *piocb; | |
1070 | ||
1071 | while (!list_empty(iocblist)) { | |
1072 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
1073 | ||
1074 | if (!piocb->iocb_cmpl) | |
1075 | lpfc_sli_release_iocbq(phba, piocb); | |
1076 | else { | |
1077 | piocb->iocb.ulpStatus = ulpstatus; | |
1078 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
1079 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
1080 | } | |
1081 | } | |
1082 | return; | |
1083 | } | |
1084 | ||
e59058c4 | 1085 | /** |
3621a710 JS |
1086 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
1087 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
1088 | * |
1089 | * This function is called by ring event handler function to get the iocb type. | |
1090 | * This function translates the iocb command to an iocb command type used to | |
1091 | * decide the final disposition of each completed IOCB. | |
1092 | * The function returns | |
1093 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
1094 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
1095 | * LPFC_ABORT_IOCB if it is an abort iocb | |
1096 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
1097 | * | |
1098 | * The caller is not required to hold any lock. | |
1099 | **/ | |
dea3101e JB |
1100 | static lpfc_iocb_type |
1101 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
1102 | { | |
1103 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
1104 | ||
1105 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
1106 | return 0; | |
1107 | ||
1108 | switch (iocb_cmnd) { | |
1109 | case CMD_XMIT_SEQUENCE_CR: | |
1110 | case CMD_XMIT_SEQUENCE_CX: | |
1111 | case CMD_XMIT_BCAST_CN: | |
1112 | case CMD_XMIT_BCAST_CX: | |
1113 | case CMD_ELS_REQUEST_CR: | |
1114 | case CMD_ELS_REQUEST_CX: | |
1115 | case CMD_CREATE_XRI_CR: | |
1116 | case CMD_CREATE_XRI_CX: | |
1117 | case CMD_GET_RPI_CN: | |
1118 | case CMD_XMIT_ELS_RSP_CX: | |
1119 | case CMD_GET_RPI_CR: | |
1120 | case CMD_FCP_IWRITE_CR: | |
1121 | case CMD_FCP_IWRITE_CX: | |
1122 | case CMD_FCP_IREAD_CR: | |
1123 | case CMD_FCP_IREAD_CX: | |
1124 | case CMD_FCP_ICMND_CR: | |
1125 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
1126 | case CMD_FCP_TSEND_CX: |
1127 | case CMD_FCP_TRSP_CX: | |
1128 | case CMD_FCP_TRECEIVE_CX: | |
1129 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
1130 | case CMD_ADAPTER_MSG: |
1131 | case CMD_ADAPTER_DUMP: | |
1132 | case CMD_XMIT_SEQUENCE64_CR: | |
1133 | case CMD_XMIT_SEQUENCE64_CX: | |
1134 | case CMD_XMIT_BCAST64_CN: | |
1135 | case CMD_XMIT_BCAST64_CX: | |
1136 | case CMD_ELS_REQUEST64_CR: | |
1137 | case CMD_ELS_REQUEST64_CX: | |
1138 | case CMD_FCP_IWRITE64_CR: | |
1139 | case CMD_FCP_IWRITE64_CX: | |
1140 | case CMD_FCP_IREAD64_CR: | |
1141 | case CMD_FCP_IREAD64_CX: | |
1142 | case CMD_FCP_ICMND64_CR: | |
1143 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
1144 | case CMD_FCP_TSEND64_CX: |
1145 | case CMD_FCP_TRSP64_CX: | |
1146 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
1147 | case CMD_GEN_REQUEST64_CR: |
1148 | case CMD_GEN_REQUEST64_CX: | |
1149 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
1150 | case DSSCMD_IWRITE64_CR: |
1151 | case DSSCMD_IWRITE64_CX: | |
1152 | case DSSCMD_IREAD64_CR: | |
1153 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
1154 | type = LPFC_SOL_IOCB; |
1155 | break; | |
1156 | case CMD_ABORT_XRI_CN: | |
1157 | case CMD_ABORT_XRI_CX: | |
1158 | case CMD_CLOSE_XRI_CN: | |
1159 | case CMD_CLOSE_XRI_CX: | |
1160 | case CMD_XRI_ABORTED_CX: | |
1161 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 1162 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
1163 | type = LPFC_ABORT_IOCB; |
1164 | break; | |
1165 | case CMD_RCV_SEQUENCE_CX: | |
1166 | case CMD_RCV_ELS_REQ_CX: | |
1167 | case CMD_RCV_SEQUENCE64_CX: | |
1168 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 1169 | case CMD_ASYNC_STATUS: |
ed957684 JS |
1170 | case CMD_IOCB_RCV_SEQ64_CX: |
1171 | case CMD_IOCB_RCV_ELS64_CX: | |
1172 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 1173 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
1174 | type = LPFC_UNSOL_IOCB; |
1175 | break; | |
3163f725 JS |
1176 | case CMD_IOCB_XMIT_MSEQ64_CR: |
1177 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
1178 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
1179 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
1180 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
1181 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
1182 | case CMD_IOCB_RET_HBQE64_CN: | |
1183 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
1184 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
1185 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
1186 | case CMD_IOCB_LOGENTRY_CN: | |
1187 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
1188 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 1189 | __func__, iocb_cmnd); |
3163f725 JS |
1190 | type = LPFC_UNKNOWN_IOCB; |
1191 | break; | |
dea3101e JB |
1192 | default: |
1193 | type = LPFC_UNKNOWN_IOCB; | |
1194 | break; | |
1195 | } | |
1196 | ||
1197 | return type; | |
1198 | } | |
1199 | ||
e59058c4 | 1200 | /** |
3621a710 | 1201 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
1202 | * @phba: Pointer to HBA context object. |
1203 | * | |
1204 | * This function is called from SLI initialization code | |
1205 | * to configure every ring of the HBA's SLI interface. The | |
1206 | * caller is not required to hold any lock. This function issues | |
1207 | * a config_ring mailbox command for each ring. | |
1208 | * This function returns zero if successful else returns a negative | |
1209 | * error code. | |
1210 | **/ | |
dea3101e | 1211 | static int |
ed957684 | 1212 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
1213 | { |
1214 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
1215 | LPFC_MBOXQ_t *pmb; |
1216 | MAILBOX_t *pmbox; | |
1217 | int i, rc, ret = 0; | |
dea3101e | 1218 | |
ed957684 JS |
1219 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
1220 | if (!pmb) | |
1221 | return -ENOMEM; | |
04c68496 | 1222 | pmbox = &pmb->u.mb; |
ed957684 | 1223 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 1224 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
1225 | lpfc_config_ring(phba, i, pmb); |
1226 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
1227 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 1228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 1229 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
1230 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
1231 | "ring %d\n", | |
e8b62011 JS |
1232 | rc, pmbox->mbxCommand, |
1233 | pmbox->mbxStatus, i); | |
2e0fef85 | 1234 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
1235 | ret = -ENXIO; |
1236 | break; | |
dea3101e JB |
1237 | } |
1238 | } | |
ed957684 JS |
1239 | mempool_free(pmb, phba->mbox_mem_pool); |
1240 | return ret; | |
dea3101e JB |
1241 | } |
1242 | ||
e59058c4 | 1243 | /** |
3621a710 | 1244 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
1245 | * @phba: Pointer to HBA context object. |
1246 | * @pring: Pointer to driver SLI ring object. | |
1247 | * @piocb: Pointer to the driver iocb object. | |
1248 | * | |
1249 | * This function is called with hbalock held. The function adds the | |
1250 | * new iocb to txcmplq of the given ring. This function always returns | |
1251 | * 0. If this function is called for ELS ring, this function checks if | |
1252 | * there is a vport associated with the ELS command. This function also | |
1253 | * starts els_tmofunc timer if this is an ELS command. | |
1254 | **/ | |
dea3101e | 1255 | static int |
2e0fef85 JS |
1256 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
1257 | struct lpfc_iocbq *piocb) | |
dea3101e | 1258 | { |
dea3101e | 1259 | list_add_tail(&piocb->list, &pring->txcmplq); |
2a9bf3d0 | 1260 | piocb->iocb_flag |= LPFC_IO_ON_Q; |
dea3101e | 1261 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
1262 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
1263 | pring->txcmplq_max = pring->txcmplq_cnt; | |
1264 | ||
92d7f7b0 JS |
1265 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
1266 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
1267 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
1268 | if (!piocb->vport) | |
1269 | BUG(); | |
1270 | else | |
1271 | mod_timer(&piocb->vport->els_tmofunc, | |
1272 | jiffies + HZ * (phba->fc_ratov << 1)); | |
1273 | } | |
1274 | ||
dea3101e | 1275 | |
2e0fef85 | 1276 | return 0; |
dea3101e JB |
1277 | } |
1278 | ||
e59058c4 | 1279 | /** |
3621a710 | 1280 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
1281 | * @phba: Pointer to HBA context object. |
1282 | * @pring: Pointer to driver SLI ring object. | |
1283 | * | |
1284 | * This function is called with hbalock held to get next | |
1285 | * iocb in txq of the given ring. If there is any iocb in | |
1286 | * the txq, the function returns first iocb in the list after | |
1287 | * removing the iocb from the list, else it returns NULL. | |
1288 | **/ | |
2a9bf3d0 | 1289 | struct lpfc_iocbq * |
2e0fef85 | 1290 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 1291 | { |
dea3101e JB |
1292 | struct lpfc_iocbq *cmd_iocb; |
1293 | ||
858c9f6c JS |
1294 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
1295 | if (cmd_iocb != NULL) | |
dea3101e | 1296 | pring->txq_cnt--; |
2e0fef85 | 1297 | return cmd_iocb; |
dea3101e JB |
1298 | } |
1299 | ||
e59058c4 | 1300 | /** |
3621a710 | 1301 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
1302 | * @phba: Pointer to HBA context object. |
1303 | * @pring: Pointer to driver SLI ring object. | |
1304 | * | |
1305 | * This function is called with hbalock held and the caller must post the | |
1306 | * iocb without releasing the lock. If the caller releases the lock, | |
1307 | * iocb slot returned by the function is not guaranteed to be available. | |
1308 | * The function returns pointer to the next available iocb slot if there | |
1309 | * is available slot in the ring, else it returns NULL. | |
1310 | * If the get index of the ring is ahead of the put index, the function | |
1311 | * will post an error attention event to the worker thread to take the | |
1312 | * HBA to offline state. | |
1313 | **/ | |
dea3101e JB |
1314 | static IOCB_t * |
1315 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
1316 | { | |
34b02dcd | 1317 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 1318 | uint32_t max_cmd_idx = pring->numCiocb; |
dea3101e JB |
1319 | if ((pring->next_cmdidx == pring->cmdidx) && |
1320 | (++pring->next_cmdidx >= max_cmd_idx)) | |
1321 | pring->next_cmdidx = 0; | |
1322 | ||
1323 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { | |
1324 | ||
1325 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
1326 | ||
1327 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { | |
1328 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 1329 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 1330 | "is bigger than cmd ring %d\n", |
e8b62011 | 1331 | pring->ringno, |
dea3101e JB |
1332 | pring->local_getidx, max_cmd_idx); |
1333 | ||
2e0fef85 | 1334 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1335 | /* |
1336 | * All error attention handlers are posted to | |
1337 | * worker thread | |
1338 | */ | |
1339 | phba->work_ha |= HA_ERATT; | |
1340 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 1341 | |
5e9d9b82 | 1342 | lpfc_worker_wake_up(phba); |
dea3101e JB |
1343 | |
1344 | return NULL; | |
1345 | } | |
1346 | ||
1347 | if (pring->local_getidx == pring->next_cmdidx) | |
1348 | return NULL; | |
1349 | } | |
1350 | ||
ed957684 | 1351 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
1352 | } |
1353 | ||
e59058c4 | 1354 | /** |
3621a710 | 1355 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
1356 | * @phba: Pointer to HBA context object. |
1357 | * @iocbq: Pointer to driver iocb object. | |
1358 | * | |
1359 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
1360 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
1361 | * array and assigns a new iotag. | |
1362 | * The function returns the allocated iotag if successful, else returns zero. | |
1363 | * Zero is not a valid iotag. | |
1364 | * The caller is not required to hold any lock. | |
1365 | **/ | |
604a3e30 | 1366 | uint16_t |
2e0fef85 | 1367 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1368 | { |
2e0fef85 JS |
1369 | struct lpfc_iocbq **new_arr; |
1370 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1371 | size_t new_len; |
1372 | struct lpfc_sli *psli = &phba->sli; | |
1373 | uint16_t iotag; | |
dea3101e | 1374 | |
2e0fef85 | 1375 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1376 | iotag = psli->last_iotag; |
1377 | if(++iotag < psli->iocbq_lookup_len) { | |
1378 | psli->last_iotag = iotag; | |
1379 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1380 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1381 | iocbq->iotag = iotag; |
1382 | return iotag; | |
2e0fef85 | 1383 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1384 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1385 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1386 | spin_unlock_irq(&phba->hbalock); |
1387 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1388 | GFP_KERNEL); |
1389 | if (new_arr) { | |
2e0fef85 | 1390 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1391 | old_arr = psli->iocbq_lookup; |
1392 | if (new_len <= psli->iocbq_lookup_len) { | |
1393 | /* highly unprobable case */ | |
1394 | kfree(new_arr); | |
1395 | iotag = psli->last_iotag; | |
1396 | if(++iotag < psli->iocbq_lookup_len) { | |
1397 | psli->last_iotag = iotag; | |
1398 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1399 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1400 | iocbq->iotag = iotag; |
1401 | return iotag; | |
1402 | } | |
2e0fef85 | 1403 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1404 | return 0; |
1405 | } | |
1406 | if (psli->iocbq_lookup) | |
1407 | memcpy(new_arr, old_arr, | |
1408 | ((psli->last_iotag + 1) * | |
311464ec | 1409 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1410 | psli->iocbq_lookup = new_arr; |
1411 | psli->iocbq_lookup_len = new_len; | |
1412 | psli->last_iotag = iotag; | |
1413 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1414 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1415 | iocbq->iotag = iotag; |
1416 | kfree(old_arr); | |
1417 | return iotag; | |
1418 | } | |
8f6d98d2 | 1419 | } else |
2e0fef85 | 1420 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1421 | |
bc73905a | 1422 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
1423 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1424 | psli->last_iotag); | |
dea3101e | 1425 | |
604a3e30 | 1426 | return 0; |
dea3101e JB |
1427 | } |
1428 | ||
e59058c4 | 1429 | /** |
3621a710 | 1430 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1431 | * @phba: Pointer to HBA context object. |
1432 | * @pring: Pointer to driver SLI ring object. | |
1433 | * @iocb: Pointer to iocb slot in the ring. | |
1434 | * @nextiocb: Pointer to driver iocb object which need to be | |
1435 | * posted to firmware. | |
1436 | * | |
1437 | * This function is called with hbalock held to post a new iocb to | |
1438 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1439 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1440 | * a completion call back for this iocb else the function will free the | |
1441 | * iocb object. | |
1442 | **/ | |
dea3101e JB |
1443 | static void |
1444 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1445 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1446 | { | |
1447 | /* | |
604a3e30 | 1448 | * Set up an iotag |
dea3101e | 1449 | */ |
604a3e30 | 1450 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1451 | |
e2a0a9d6 | 1452 | |
a58cbd52 JS |
1453 | if (pring->ringno == LPFC_ELS_RING) { |
1454 | lpfc_debugfs_slow_ring_trc(phba, | |
1455 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1456 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1457 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1458 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1459 | } | |
1460 | ||
dea3101e JB |
1461 | /* |
1462 | * Issue iocb command to adapter | |
1463 | */ | |
92d7f7b0 | 1464 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1465 | wmb(); |
1466 | pring->stats.iocb_cmd++; | |
1467 | ||
1468 | /* | |
1469 | * If there is no completion routine to call, we can release the | |
1470 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1471 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1472 | */ | |
1473 | if (nextiocb->iocb_cmpl) | |
1474 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1475 | else |
2e0fef85 | 1476 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1477 | |
1478 | /* | |
1479 | * Let the HBA know what IOCB slot will be the next one the | |
1480 | * driver will put a command into. | |
1481 | */ | |
1482 | pring->cmdidx = pring->next_cmdidx; | |
ed957684 | 1483 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
dea3101e JB |
1484 | } |
1485 | ||
e59058c4 | 1486 | /** |
3621a710 | 1487 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1488 | * @phba: Pointer to HBA context object. |
1489 | * @pring: Pointer to driver SLI ring object. | |
1490 | * | |
1491 | * The caller is not required to hold any lock for calling this function. | |
1492 | * This function updates the chip attention bits for the ring to inform firmware | |
1493 | * that there are pending work to be done for this ring and requests an | |
1494 | * interrupt when there is space available in the ring. This function is | |
1495 | * called when the driver is unable to post more iocbs to the ring due | |
1496 | * to unavailability of space in the ring. | |
1497 | **/ | |
dea3101e | 1498 | static void |
2e0fef85 | 1499 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1500 | { |
1501 | int ringno = pring->ringno; | |
1502 | ||
1503 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1504 | ||
1505 | wmb(); | |
1506 | ||
1507 | /* | |
1508 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1509 | * The HBA will tell us when an IOCB entry is available. | |
1510 | */ | |
1511 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1512 | readl(phba->CAregaddr); /* flush */ | |
1513 | ||
1514 | pring->stats.iocb_cmd_full++; | |
1515 | } | |
1516 | ||
e59058c4 | 1517 | /** |
3621a710 | 1518 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1519 | * @phba: Pointer to HBA context object. |
1520 | * @pring: Pointer to driver SLI ring object. | |
1521 | * | |
1522 | * This function updates the chip attention register bit for the | |
1523 | * given ring to inform HBA that there is more work to be done | |
1524 | * in this ring. The caller is not required to hold any lock. | |
1525 | **/ | |
dea3101e | 1526 | static void |
2e0fef85 | 1527 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1528 | { |
1529 | int ringno = pring->ringno; | |
1530 | ||
1531 | /* | |
1532 | * Tell the HBA that there is work to do in this ring. | |
1533 | */ | |
34b02dcd JS |
1534 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1535 | wmb(); | |
1536 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1537 | readl(phba->CAregaddr); /* flush */ | |
1538 | } | |
dea3101e JB |
1539 | } |
1540 | ||
e59058c4 | 1541 | /** |
3621a710 | 1542 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1543 | * @phba: Pointer to HBA context object. |
1544 | * @pring: Pointer to driver SLI ring object. | |
1545 | * | |
1546 | * This function is called with hbalock held to post pending iocbs | |
1547 | * in the txq to the firmware. This function is called when driver | |
1548 | * detects space available in the ring. | |
1549 | **/ | |
dea3101e | 1550 | static void |
2e0fef85 | 1551 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1552 | { |
1553 | IOCB_t *iocb; | |
1554 | struct lpfc_iocbq *nextiocb; | |
1555 | ||
1556 | /* | |
1557 | * Check to see if: | |
1558 | * (a) there is anything on the txq to send | |
1559 | * (b) link is up | |
1560 | * (c) link attention events can be processed (fcp ring only) | |
1561 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1562 | */ | |
1563 | if (pring->txq_cnt && | |
2e0fef85 | 1564 | lpfc_is_link_up(phba) && |
dea3101e | 1565 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1566 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1567 | |
1568 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1569 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1570 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1571 | ||
1572 | if (iocb) | |
1573 | lpfc_sli_update_ring(phba, pring); | |
1574 | else | |
1575 | lpfc_sli_update_full_ring(phba, pring); | |
1576 | } | |
1577 | ||
1578 | return; | |
1579 | } | |
1580 | ||
e59058c4 | 1581 | /** |
3621a710 | 1582 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1583 | * @phba: Pointer to HBA context object. |
1584 | * @hbqno: HBQ number. | |
1585 | * | |
1586 | * This function is called with hbalock held to get the next | |
1587 | * available slot for the given HBQ. If there is free slot | |
1588 | * available for the HBQ it will return pointer to the next available | |
1589 | * HBQ entry else it will return NULL. | |
1590 | **/ | |
a6ababd2 | 1591 | static struct lpfc_hbq_entry * |
ed957684 JS |
1592 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1593 | { | |
1594 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1595 | ||
1596 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1597 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1598 | hbqp->next_hbqPutIdx = 0; | |
1599 | ||
1600 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1601 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1602 | uint32_t getidx = le32_to_cpu(raw_index); |
1603 | ||
1604 | hbqp->local_hbqGetIdx = getidx; | |
1605 | ||
1606 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1607 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1608 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1609 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1610 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1611 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1612 | hbqp->entry_count); |
1613 | ||
1614 | phba->link_state = LPFC_HBA_ERROR; | |
1615 | return NULL; | |
1616 | } | |
1617 | ||
1618 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1619 | return NULL; | |
1620 | } | |
1621 | ||
51ef4c26 JS |
1622 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1623 | hbqp->hbqPutIdx; | |
ed957684 JS |
1624 | } |
1625 | ||
e59058c4 | 1626 | /** |
3621a710 | 1627 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1628 | * @phba: Pointer to HBA context object. |
1629 | * | |
1630 | * This function is called with no lock held to free all the | |
1631 | * hbq buffers while uninitializing the SLI interface. It also | |
1632 | * frees the HBQ buffers returned by the firmware but not yet | |
1633 | * processed by the upper layers. | |
1634 | **/ | |
ed957684 JS |
1635 | void |
1636 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1637 | { | |
92d7f7b0 JS |
1638 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1639 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1640 | unsigned long flags; |
51ef4c26 | 1641 | int i, hbq_count; |
3163f725 | 1642 | uint32_t hbqno; |
ed957684 | 1643 | |
51ef4c26 | 1644 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1645 | /* Return all memory used by all HBQs */ |
3163f725 | 1646 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1647 | for (i = 0; i < hbq_count; ++i) { |
1648 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1649 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1650 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1651 | list_del(&hbq_buf->dbuf.list); | |
1652 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1653 | } | |
a8adb832 | 1654 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1655 | } |
3163f725 | 1656 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1657 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1658 | list) { | |
3163f725 JS |
1659 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1660 | list_del(&hbq_buf->dbuf.list); | |
1661 | if (hbq_buf->tag == -1) { | |
1662 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1663 | (phba, hbq_buf); | |
1664 | } else { | |
1665 | hbqno = hbq_buf->tag >> 16; | |
1666 | if (hbqno >= LPFC_MAX_HBQS) | |
1667 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1668 | (phba, hbq_buf); | |
1669 | else | |
1670 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1671 | hbq_buf); | |
1672 | } | |
1673 | } | |
1674 | ||
1675 | /* Mark the HBQs not in use */ | |
1676 | phba->hbq_in_use = 0; | |
1677 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1678 | } |
1679 | ||
e59058c4 | 1680 | /** |
3621a710 | 1681 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1682 | * @phba: Pointer to HBA context object. |
1683 | * @hbqno: HBQ number. | |
1684 | * @hbq_buf: Pointer to HBQ buffer. | |
1685 | * | |
1686 | * This function is called with the hbalock held to post a | |
1687 | * hbq buffer to the firmware. If the function finds an empty | |
1688 | * slot in the HBQ, it will post the buffer. The function will return | |
1689 | * pointer to the hbq entry if it successfully post the buffer | |
1690 | * else it will return NULL. | |
1691 | **/ | |
3772a991 | 1692 | static int |
ed957684 | 1693 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1694 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1695 | { |
1696 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1697 | } | |
1698 | ||
1699 | /** | |
1700 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1701 | * @phba: Pointer to HBA context object. | |
1702 | * @hbqno: HBQ number. | |
1703 | * @hbq_buf: Pointer to HBQ buffer. | |
1704 | * | |
1705 | * This function is called with the hbalock held to post a hbq buffer to the | |
1706 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1707 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1708 | * it successfully post the buffer else it will return an error. | |
1709 | **/ | |
1710 | static int | |
1711 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1712 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1713 | { |
1714 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1715 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1716 | |
1717 | /* Get next HBQ entry slot to use */ | |
1718 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1719 | if (hbqe) { | |
1720 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1721 | ||
92d7f7b0 JS |
1722 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1723 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1724 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1725 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1726 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1727 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1728 | /* Sync SLIM */ | |
ed957684 JS |
1729 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1730 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1731 | /* flush */ |
ed957684 | 1732 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1733 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1734 | return 0; |
1735 | } else | |
1736 | return -ENOMEM; | |
ed957684 JS |
1737 | } |
1738 | ||
4f774513 JS |
1739 | /** |
1740 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1741 | * @phba: Pointer to HBA context object. | |
1742 | * @hbqno: HBQ number. | |
1743 | * @hbq_buf: Pointer to HBQ buffer. | |
1744 | * | |
1745 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1746 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1747 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1748 | **/ | |
1749 | static int | |
1750 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1751 | struct hbq_dmabuf *hbq_buf) | |
1752 | { | |
1753 | int rc; | |
1754 | struct lpfc_rqe hrqe; | |
1755 | struct lpfc_rqe drqe; | |
1756 | ||
1757 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1758 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1759 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1760 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1761 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1762 | &hrqe, &drqe); | |
1763 | if (rc < 0) | |
1764 | return rc; | |
1765 | hbq_buf->tag = rc; | |
1766 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1767 | return 0; | |
1768 | } | |
1769 | ||
e59058c4 | 1770 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1771 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1772 | .rn = 1, | |
def9c7a9 | 1773 | .entry_count = 256, |
92d7f7b0 JS |
1774 | .mask_count = 0, |
1775 | .profile = 0, | |
51ef4c26 | 1776 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1777 | .buffer_count = 0, |
a257bf90 JS |
1778 | .init_count = 40, |
1779 | .add_count = 40, | |
92d7f7b0 | 1780 | }; |
ed957684 | 1781 | |
e59058c4 | 1782 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1783 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1784 | .rn = 1, | |
1785 | .entry_count = 200, | |
1786 | .mask_count = 0, | |
1787 | .profile = 0, | |
1788 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1789 | .buffer_count = 0, | |
1790 | .init_count = 0, | |
1791 | .add_count = 5, | |
1792 | }; | |
1793 | ||
e59058c4 | 1794 | /* Array of HBQs */ |
78b2d852 | 1795 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1796 | &lpfc_els_hbq, |
51ef4c26 | 1797 | &lpfc_extra_hbq, |
92d7f7b0 | 1798 | }; |
ed957684 | 1799 | |
e59058c4 | 1800 | /** |
3621a710 | 1801 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1802 | * @phba: Pointer to HBA context object. |
1803 | * @hbqno: HBQ number. | |
1804 | * @count: Number of HBQ buffers to be posted. | |
1805 | * | |
d7c255b2 JS |
1806 | * This function is called with no lock held to post more hbq buffers to the |
1807 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1808 | * posted. | |
e59058c4 | 1809 | **/ |
311464ec | 1810 | static int |
92d7f7b0 | 1811 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1812 | { |
d7c255b2 | 1813 | uint32_t i, posted = 0; |
3163f725 | 1814 | unsigned long flags; |
92d7f7b0 | 1815 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1816 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1817 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1818 | return 0; |
51ef4c26 | 1819 | |
d7c255b2 JS |
1820 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1821 | lpfc_hbq_defs[hbqno]->entry_count) | |
1822 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1823 | phba->hbqs[hbqno].buffer_count; | |
1824 | if (!count) | |
1825 | return 0; | |
1826 | /* Allocate HBQ entries */ | |
1827 | for (i = 0; i < count; i++) { | |
1828 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1829 | if (!hbq_buffer) | |
1830 | break; | |
1831 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1832 | } | |
3163f725 JS |
1833 | /* Check whether HBQ is still in use */ |
1834 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1835 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1836 | goto err; |
1837 | while (!list_empty(&hbq_buf_list)) { | |
1838 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1839 | dbuf.list); | |
1840 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1841 | (hbqno << 16)); | |
3772a991 | 1842 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1843 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1844 | posted++; |
1845 | } else | |
51ef4c26 | 1846 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1847 | } |
3163f725 | 1848 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1849 | return posted; |
1850 | err: | |
eafe1df9 | 1851 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1852 | while (!list_empty(&hbq_buf_list)) { |
1853 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1854 | dbuf.list); | |
1855 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1856 | } | |
1857 | return 0; | |
ed957684 JS |
1858 | } |
1859 | ||
e59058c4 | 1860 | /** |
3621a710 | 1861 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1862 | * @phba: Pointer to HBA context object. |
1863 | * @qno: HBQ number. | |
1864 | * | |
1865 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1866 | * is called with no lock held. The function returns the number of HBQ entries |
1867 | * successfully allocated. | |
e59058c4 | 1868 | **/ |
92d7f7b0 JS |
1869 | int |
1870 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1871 | { |
def9c7a9 JS |
1872 | if (phba->sli_rev == LPFC_SLI_REV4) |
1873 | return 0; | |
1874 | else | |
1875 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1876 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1877 | } |
ed957684 | 1878 | |
e59058c4 | 1879 | /** |
3621a710 | 1880 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1881 | * @phba: Pointer to HBA context object. |
1882 | * @qno: HBQ queue number. | |
1883 | * | |
1884 | * This function is called from SLI initialization code path with | |
1885 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1886 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1887 | **/ |
a6ababd2 | 1888 | static int |
92d7f7b0 JS |
1889 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1890 | { | |
def9c7a9 JS |
1891 | if (phba->sli_rev == LPFC_SLI_REV4) |
1892 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1893 | lpfc_hbq_defs[qno]->entry_count); | |
1894 | else | |
1895 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1896 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1897 | } |
1898 | ||
3772a991 JS |
1899 | /** |
1900 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1901 | * @phba: Pointer to HBA context object. | |
1902 | * @hbqno: HBQ number. | |
1903 | * | |
1904 | * This function removes the first hbq buffer on an hbq list and returns a | |
1905 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1906 | **/ | |
1907 | static struct hbq_dmabuf * | |
1908 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1909 | { | |
1910 | struct lpfc_dmabuf *d_buf; | |
1911 | ||
1912 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1913 | if (!d_buf) | |
1914 | return NULL; | |
1915 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1916 | } | |
1917 | ||
e59058c4 | 1918 | /** |
3621a710 | 1919 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1920 | * @phba: Pointer to HBA context object. |
1921 | * @tag: Tag of the hbq buffer. | |
1922 | * | |
1923 | * This function is called with hbalock held. This function searches | |
1924 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1925 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1926 | * it returns NULL. | |
1927 | **/ | |
a6ababd2 | 1928 | static struct hbq_dmabuf * |
92d7f7b0 | 1929 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1930 | { |
92d7f7b0 JS |
1931 | struct lpfc_dmabuf *d_buf; |
1932 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1933 | uint32_t hbqno; |
1934 | ||
1935 | hbqno = tag >> 16; | |
a0a74e45 | 1936 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1937 | return NULL; |
ed957684 | 1938 | |
3772a991 | 1939 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1940 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1941 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1942 | if (hbq_buf->tag == tag) { |
3772a991 | 1943 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1944 | return hbq_buf; |
ed957684 JS |
1945 | } |
1946 | } | |
3772a991 | 1947 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1948 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1949 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1950 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1951 | return NULL; |
ed957684 JS |
1952 | } |
1953 | ||
e59058c4 | 1954 | /** |
3621a710 | 1955 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1956 | * @phba: Pointer to HBA context object. |
1957 | * @hbq_buffer: Pointer to HBQ buffer. | |
1958 | * | |
1959 | * This function is called with hbalock. This function gives back | |
1960 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1961 | * post the buffer, it will free the buffer. | |
1962 | **/ | |
ed957684 | 1963 | void |
51ef4c26 | 1964 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
1965 | { |
1966 | uint32_t hbqno; | |
1967 | ||
51ef4c26 JS |
1968 | if (hbq_buffer) { |
1969 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 1970 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 1971 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
1972 | } |
1973 | } | |
1974 | ||
e59058c4 | 1975 | /** |
3621a710 | 1976 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
1977 | * @mbxCommand: mailbox command code. |
1978 | * | |
1979 | * This function is called by the mailbox event handler function to verify | |
1980 | * that the completed mailbox command is a legitimate mailbox command. If the | |
1981 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
1982 | * and the mailbox event handler will take the HBA offline. | |
1983 | **/ | |
dea3101e JB |
1984 | static int |
1985 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
1986 | { | |
1987 | uint8_t ret; | |
1988 | ||
1989 | switch (mbxCommand) { | |
1990 | case MBX_LOAD_SM: | |
1991 | case MBX_READ_NV: | |
1992 | case MBX_WRITE_NV: | |
a8adb832 | 1993 | case MBX_WRITE_VPARMS: |
dea3101e JB |
1994 | case MBX_RUN_BIU_DIAG: |
1995 | case MBX_INIT_LINK: | |
1996 | case MBX_DOWN_LINK: | |
1997 | case MBX_CONFIG_LINK: | |
1998 | case MBX_CONFIG_RING: | |
1999 | case MBX_RESET_RING: | |
2000 | case MBX_READ_CONFIG: | |
2001 | case MBX_READ_RCONFIG: | |
2002 | case MBX_READ_SPARM: | |
2003 | case MBX_READ_STATUS: | |
2004 | case MBX_READ_RPI: | |
2005 | case MBX_READ_XRI: | |
2006 | case MBX_READ_REV: | |
2007 | case MBX_READ_LNK_STAT: | |
2008 | case MBX_REG_LOGIN: | |
2009 | case MBX_UNREG_LOGIN: | |
dea3101e JB |
2010 | case MBX_CLEAR_LA: |
2011 | case MBX_DUMP_MEMORY: | |
2012 | case MBX_DUMP_CONTEXT: | |
2013 | case MBX_RUN_DIAGS: | |
2014 | case MBX_RESTART: | |
2015 | case MBX_UPDATE_CFG: | |
2016 | case MBX_DOWN_LOAD: | |
2017 | case MBX_DEL_LD_ENTRY: | |
2018 | case MBX_RUN_PROGRAM: | |
2019 | case MBX_SET_MASK: | |
09372820 | 2020 | case MBX_SET_VARIABLE: |
dea3101e | 2021 | case MBX_UNREG_D_ID: |
41415862 | 2022 | case MBX_KILL_BOARD: |
dea3101e | 2023 | case MBX_CONFIG_FARP: |
41415862 | 2024 | case MBX_BEACON: |
dea3101e JB |
2025 | case MBX_LOAD_AREA: |
2026 | case MBX_RUN_BIU_DIAG64: | |
2027 | case MBX_CONFIG_PORT: | |
2028 | case MBX_READ_SPARM64: | |
2029 | case MBX_READ_RPI64: | |
2030 | case MBX_REG_LOGIN64: | |
76a95d75 | 2031 | case MBX_READ_TOPOLOGY: |
09372820 | 2032 | case MBX_WRITE_WWN: |
dea3101e JB |
2033 | case MBX_SET_DEBUG: |
2034 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 2035 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
2036 | case MBX_REG_VPI: |
2037 | case MBX_UNREG_VPI: | |
858c9f6c | 2038 | case MBX_HEARTBEAT: |
84774a4d JS |
2039 | case MBX_PORT_CAPABILITIES: |
2040 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
2041 | case MBX_SLI4_CONFIG: |
2042 | case MBX_SLI4_REQ_FTRS: | |
2043 | case MBX_REG_FCFI: | |
2044 | case MBX_UNREG_FCFI: | |
2045 | case MBX_REG_VFI: | |
2046 | case MBX_UNREG_VFI: | |
2047 | case MBX_INIT_VPI: | |
2048 | case MBX_INIT_VFI: | |
2049 | case MBX_RESUME_RPI: | |
c7495937 JS |
2050 | case MBX_READ_EVENT_LOG_STATUS: |
2051 | case MBX_READ_EVENT_LOG: | |
dcf2a4e0 JS |
2052 | case MBX_SECURITY_MGMT: |
2053 | case MBX_AUTH_PORT: | |
dea3101e JB |
2054 | ret = mbxCommand; |
2055 | break; | |
2056 | default: | |
2057 | ret = MBX_SHUTDOWN; | |
2058 | break; | |
2059 | } | |
2e0fef85 | 2060 | return ret; |
dea3101e | 2061 | } |
e59058c4 JS |
2062 | |
2063 | /** | |
3621a710 | 2064 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
2065 | * @phba: Pointer to HBA context object. |
2066 | * @pmboxq: Pointer to mailbox command. | |
2067 | * | |
2068 | * This is completion handler function for mailbox commands issued from | |
2069 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
2070 | * mailbox event handler function with no lock held. This function | |
2071 | * will wake up thread waiting on the wait queue pointed by context1 | |
2072 | * of the mailbox. | |
2073 | **/ | |
04c68496 | 2074 | void |
2e0fef85 | 2075 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
2076 | { |
2077 | wait_queue_head_t *pdone_q; | |
858c9f6c | 2078 | unsigned long drvr_flag; |
dea3101e JB |
2079 | |
2080 | /* | |
2081 | * If pdone_q is empty, the driver thread gave up waiting and | |
2082 | * continued running. | |
2083 | */ | |
7054a606 | 2084 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 2085 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
2086 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
2087 | if (pdone_q) | |
2088 | wake_up_interruptible(pdone_q); | |
858c9f6c | 2089 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
2090 | return; |
2091 | } | |
2092 | ||
e59058c4 JS |
2093 | |
2094 | /** | |
3621a710 | 2095 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
2096 | * @phba: Pointer to HBA context object. |
2097 | * @pmb: Pointer to mailbox object. | |
2098 | * | |
2099 | * This function is the default mailbox completion handler. It | |
2100 | * frees the memory resources associated with the completed mailbox | |
2101 | * command. If the completed command is a REG_LOGIN mailbox command, | |
2102 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
2103 | **/ | |
dea3101e | 2104 | void |
2e0fef85 | 2105 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e | 2106 | { |
d439d286 | 2107 | struct lpfc_vport *vport = pmb->vport; |
dea3101e | 2108 | struct lpfc_dmabuf *mp; |
d439d286 | 2109 | struct lpfc_nodelist *ndlp; |
5af5eee7 | 2110 | struct Scsi_Host *shost; |
04c68496 | 2111 | uint16_t rpi, vpi; |
7054a606 JS |
2112 | int rc; |
2113 | ||
dea3101e | 2114 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 2115 | |
dea3101e JB |
2116 | if (mp) { |
2117 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
2118 | kfree(mp); | |
2119 | } | |
7054a606 | 2120 | |
04c68496 | 2121 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
5af5eee7 JS |
2122 | (phba->sli_rev == LPFC_SLI_REV4) && |
2123 | (pmb->u.mb.un.varUnregLogin.rsvd1 == 0x0)) | |
04c68496 JS |
2124 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); |
2125 | ||
7054a606 JS |
2126 | /* |
2127 | * If a REG_LOGIN succeeded after node is destroyed or node | |
2128 | * is in re-discovery driver need to cleanup the RPI. | |
2129 | */ | |
2e0fef85 | 2130 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
2131 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
2132 | !pmb->u.mb.mbxStatus) { | |
2133 | rpi = pmb->u.mb.un.varWords[0]; | |
2134 | vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base; | |
2135 | lpfc_unreg_login(phba, vpi, rpi, pmb); | |
92d7f7b0 | 2136 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
2137 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
2138 | if (rc != MBX_NOT_FINISHED) | |
2139 | return; | |
2140 | } | |
2141 | ||
695a814e JS |
2142 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && |
2143 | !(phba->pport->load_flag & FC_UNLOADING) && | |
2144 | !pmb->u.mb.mbxStatus) { | |
5af5eee7 JS |
2145 | shost = lpfc_shost_from_vport(vport); |
2146 | spin_lock_irq(shost->host_lock); | |
2147 | vport->vpi_state |= LPFC_VPI_REGISTERED; | |
2148 | vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; | |
2149 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
2150 | } |
2151 | ||
d439d286 JS |
2152 | if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
2153 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
2154 | lpfc_nlp_put(ndlp); | |
2155 | pmb->context2 = NULL; | |
2156 | } | |
2157 | ||
dcf2a4e0 JS |
2158 | /* Check security permission status on INIT_LINK mailbox command */ |
2159 | if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) && | |
2160 | (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
2161 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
2162 | "2860 SLI authentication is required " | |
2163 | "for INIT_LINK but has not done yet\n"); | |
2164 | ||
04c68496 JS |
2165 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
2166 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
2167 | else | |
2168 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e JB |
2169 | } |
2170 | ||
e59058c4 | 2171 | /** |
3621a710 | 2172 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
2173 | * @phba: Pointer to HBA context object. |
2174 | * | |
2175 | * This function is called with no lock held. This function processes all | |
2176 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
2177 | * service routine processes mailbox completion interrupt and adds completed | |
2178 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
2179 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
2180 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
2181 | * function returns the mailbox commands to the upper layer by calling the | |
2182 | * completion handler function of each mailbox. | |
2183 | **/ | |
dea3101e | 2184 | int |
2e0fef85 | 2185 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 2186 | { |
92d7f7b0 | 2187 | MAILBOX_t *pmbox; |
dea3101e | 2188 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
2189 | int rc; |
2190 | LIST_HEAD(cmplq); | |
dea3101e JB |
2191 | |
2192 | phba->sli.slistat.mbox_event++; | |
2193 | ||
92d7f7b0 JS |
2194 | /* Get all completed mailboxe buffers into the cmplq */ |
2195 | spin_lock_irq(&phba->hbalock); | |
2196 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
2197 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 2198 | |
92d7f7b0 JS |
2199 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
2200 | do { | |
2201 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
2202 | if (pmb == NULL) | |
2203 | break; | |
2e0fef85 | 2204 | |
04c68496 | 2205 | pmbox = &pmb->u.mb; |
dea3101e | 2206 | |
858c9f6c JS |
2207 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
2208 | if (pmb->vport) { | |
2209 | lpfc_debugfs_disc_trc(pmb->vport, | |
2210 | LPFC_DISC_TRC_MBOX_VPORT, | |
2211 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
2212 | (uint32_t)pmbox->mbxCommand, | |
2213 | pmbox->un.varWords[0], | |
2214 | pmbox->un.varWords[1]); | |
2215 | } | |
2216 | else { | |
2217 | lpfc_debugfs_disc_trc(phba->pport, | |
2218 | LPFC_DISC_TRC_MBOX, | |
2219 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
2220 | (uint32_t)pmbox->mbxCommand, | |
2221 | pmbox->un.varWords[0], | |
2222 | pmbox->un.varWords[1]); | |
2223 | } | |
2224 | } | |
2225 | ||
dea3101e JB |
2226 | /* |
2227 | * It is a fatal error if unknown mbox command completion. | |
2228 | */ | |
2229 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
2230 | MBX_SHUTDOWN) { | |
af901ca1 | 2231 | /* Unknown mailbox command compl */ |
92d7f7b0 | 2232 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 2233 | "(%d):0323 Unknown Mailbox command " |
04c68496 | 2234 | "x%x (x%x) Cmpl\n", |
92d7f7b0 | 2235 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 JS |
2236 | pmbox->mbxCommand, |
2237 | lpfc_sli4_mbox_opcode_get(phba, pmb)); | |
2e0fef85 | 2238 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
2239 | phba->work_hs = HS_FFER3; |
2240 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 2241 | continue; |
dea3101e JB |
2242 | } |
2243 | ||
dea3101e JB |
2244 | if (pmbox->mbxStatus) { |
2245 | phba->sli.slistat.mbox_stat_err++; | |
2246 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
2247 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 JS |
2248 | lpfc_printf_log(phba, KERN_INFO, |
2249 | LOG_MBOX | LOG_SLI, | |
e8b62011 | 2250 | "(%d):0305 Mbox cmd cmpl " |
92d7f7b0 | 2251 | "error - RETRYing Data: x%x " |
04c68496 | 2252 | "(x%x) x%x x%x x%x\n", |
92d7f7b0 JS |
2253 | pmb->vport ? pmb->vport->vpi :0, |
2254 | pmbox->mbxCommand, | |
04c68496 JS |
2255 | lpfc_sli4_mbox_opcode_get(phba, |
2256 | pmb), | |
92d7f7b0 JS |
2257 | pmbox->mbxStatus, |
2258 | pmbox->un.varWords[0], | |
2259 | pmb->vport->port_state); | |
dea3101e JB |
2260 | pmbox->mbxStatus = 0; |
2261 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 2262 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 2263 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 2264 | continue; |
dea3101e JB |
2265 | } |
2266 | } | |
2267 | ||
2268 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 2269 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
04c68496 | 2270 | "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p " |
dea3101e | 2271 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 2272 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 2273 | pmbox->mbxCommand, |
04c68496 | 2274 | lpfc_sli4_mbox_opcode_get(phba, pmb), |
dea3101e JB |
2275 | pmb->mbox_cmpl, |
2276 | *((uint32_t *) pmbox), | |
2277 | pmbox->un.varWords[0], | |
2278 | pmbox->un.varWords[1], | |
2279 | pmbox->un.varWords[2], | |
2280 | pmbox->un.varWords[3], | |
2281 | pmbox->un.varWords[4], | |
2282 | pmbox->un.varWords[5], | |
2283 | pmbox->un.varWords[6], | |
2284 | pmbox->un.varWords[7]); | |
2285 | ||
92d7f7b0 | 2286 | if (pmb->mbox_cmpl) |
dea3101e | 2287 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
2288 | } while (1); |
2289 | return 0; | |
2290 | } | |
dea3101e | 2291 | |
e59058c4 | 2292 | /** |
3621a710 | 2293 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
2294 | * @phba: Pointer to HBA context object. |
2295 | * @pring: Pointer to driver SLI ring object. | |
2296 | * @tag: buffer tag. | |
2297 | * | |
2298 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
2299 | * is set in the tag the buffer is posted for a particular exchange, | |
2300 | * the function will return the buffer without replacing the buffer. | |
2301 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
2302 | * returns the buffer and also posts another buffer to the firmware. | |
2303 | **/ | |
76bb24ef JS |
2304 | static struct lpfc_dmabuf * |
2305 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
2306 | struct lpfc_sli_ring *pring, |
2307 | uint32_t tag) | |
76bb24ef | 2308 | { |
9f1e1b50 JS |
2309 | struct hbq_dmabuf *hbq_entry; |
2310 | ||
76bb24ef JS |
2311 | if (tag & QUE_BUFTAG_BIT) |
2312 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
2313 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
2314 | if (!hbq_entry) | |
2315 | return NULL; | |
2316 | return &hbq_entry->dbuf; | |
76bb24ef | 2317 | } |
57127f15 | 2318 | |
3772a991 JS |
2319 | /** |
2320 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
2321 | * @phba: Pointer to HBA context object. | |
2322 | * @pring: Pointer to driver SLI ring object. | |
2323 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
2324 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
2325 | * @fch_type: the type for the first frame of the sequence. | |
2326 | * | |
2327 | * This function is called with no lock held. This function uses the r_ctl and | |
2328 | * type of the received sequence to find the correct callback function to call | |
2329 | * to process the sequence. | |
2330 | **/ | |
2331 | static int | |
2332 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2333 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
2334 | uint32_t fch_type) | |
2335 | { | |
2336 | int i; | |
2337 | ||
2338 | /* unSolicited Responses */ | |
2339 | if (pring->prt[0].profile) { | |
2340 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
2341 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
2342 | saveq); | |
2343 | return 1; | |
2344 | } | |
2345 | /* We must search, based on rctl / type | |
2346 | for the right routine */ | |
2347 | for (i = 0; i < pring->num_mask; i++) { | |
2348 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
2349 | (pring->prt[i].type == fch_type)) { | |
2350 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2351 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
2352 | (phba, pring, saveq); | |
2353 | return 1; | |
2354 | } | |
2355 | } | |
2356 | return 0; | |
2357 | } | |
e59058c4 JS |
2358 | |
2359 | /** | |
3621a710 | 2360 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
2361 | * @phba: Pointer to HBA context object. |
2362 | * @pring: Pointer to driver SLI ring object. | |
2363 | * @saveq: Pointer to the unsolicited iocb. | |
2364 | * | |
2365 | * This function is called with no lock held by the ring event handler | |
2366 | * when there is an unsolicited iocb posted to the response ring by the | |
2367 | * firmware. This function gets the buffer associated with the iocbs | |
2368 | * and calls the event handler for the ring. This function handles both | |
2369 | * qring buffers and hbq buffers. | |
2370 | * When the function returns 1 the caller can free the iocb object otherwise | |
2371 | * upper layer functions will free the iocb objects. | |
2372 | **/ | |
dea3101e JB |
2373 | static int |
2374 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2375 | struct lpfc_iocbq *saveq) | |
2376 | { | |
2377 | IOCB_t * irsp; | |
2378 | WORD5 * w5p; | |
2379 | uint32_t Rctl, Type; | |
3772a991 | 2380 | uint32_t match; |
76bb24ef | 2381 | struct lpfc_iocbq *iocbq; |
3163f725 | 2382 | struct lpfc_dmabuf *dmzbuf; |
dea3101e JB |
2383 | |
2384 | match = 0; | |
2385 | irsp = &(saveq->iocb); | |
57127f15 JS |
2386 | |
2387 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2388 | if (pring->lpfc_sli_rcv_async_status) | |
2389 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2390 | else | |
2391 | lpfc_printf_log(phba, | |
2392 | KERN_WARNING, | |
2393 | LOG_SLI, | |
2394 | "0316 Ring %d handler: unexpected " | |
2395 | "ASYNC_STATUS iocb received evt_code " | |
2396 | "0x%x\n", | |
2397 | pring->ringno, | |
2398 | irsp->un.asyncstat.evt_code); | |
2399 | return 1; | |
2400 | } | |
2401 | ||
3163f725 JS |
2402 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2403 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2404 | if (irsp->ulpBdeCount > 0) { | |
2405 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2406 | irsp->un.ulpWord[3]); | |
2407 | lpfc_in_buf_free(phba, dmzbuf); | |
2408 | } | |
2409 | ||
2410 | if (irsp->ulpBdeCount > 1) { | |
2411 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2412 | irsp->unsli3.sli3Words[3]); | |
2413 | lpfc_in_buf_free(phba, dmzbuf); | |
2414 | } | |
2415 | ||
2416 | if (irsp->ulpBdeCount > 2) { | |
2417 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2418 | irsp->unsli3.sli3Words[7]); | |
2419 | lpfc_in_buf_free(phba, dmzbuf); | |
2420 | } | |
2421 | ||
2422 | return 1; | |
2423 | } | |
2424 | ||
92d7f7b0 | 2425 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2426 | if (irsp->ulpBdeCount != 0) { |
2427 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2428 | irsp->un.ulpWord[3]); | |
2429 | if (!saveq->context2) | |
2430 | lpfc_printf_log(phba, | |
2431 | KERN_ERR, | |
2432 | LOG_SLI, | |
2433 | "0341 Ring %d Cannot find buffer for " | |
2434 | "an unsolicited iocb. tag 0x%x\n", | |
2435 | pring->ringno, | |
2436 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2437 | } |
2438 | if (irsp->ulpBdeCount == 2) { | |
2439 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2440 | irsp->unsli3.sli3Words[7]); | |
2441 | if (!saveq->context3) | |
2442 | lpfc_printf_log(phba, | |
2443 | KERN_ERR, | |
2444 | LOG_SLI, | |
2445 | "0342 Ring %d Cannot find buffer for an" | |
2446 | " unsolicited iocb. tag 0x%x\n", | |
2447 | pring->ringno, | |
2448 | irsp->unsli3.sli3Words[7]); | |
2449 | } | |
2450 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2451 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2452 | if (irsp->ulpBdeCount != 0) { |
2453 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2454 | irsp->un.ulpWord[3]); | |
9c2face6 | 2455 | if (!iocbq->context2) |
76bb24ef JS |
2456 | lpfc_printf_log(phba, |
2457 | KERN_ERR, | |
2458 | LOG_SLI, | |
2459 | "0343 Ring %d Cannot find " | |
2460 | "buffer for an unsolicited iocb" | |
2461 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2462 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2463 | } |
2464 | if (irsp->ulpBdeCount == 2) { | |
2465 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2466 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2467 | if (!iocbq->context3) |
76bb24ef JS |
2468 | lpfc_printf_log(phba, |
2469 | KERN_ERR, | |
2470 | LOG_SLI, | |
2471 | "0344 Ring %d Cannot find " | |
2472 | "buffer for an unsolicited " | |
2473 | "iocb. tag 0x%x\n", | |
2474 | pring->ringno, | |
2475 | irsp->unsli3.sli3Words[7]); | |
2476 | } | |
2477 | } | |
92d7f7b0 | 2478 | } |
9c2face6 JS |
2479 | if (irsp->ulpBdeCount != 0 && |
2480 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2481 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2482 | int found = 0; | |
2483 | ||
2484 | /* search continue save q for same XRI */ | |
2485 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
2486 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { | |
2487 | list_add_tail(&saveq->list, &iocbq->list); | |
2488 | found = 1; | |
2489 | break; | |
2490 | } | |
2491 | } | |
2492 | if (!found) | |
2493 | list_add_tail(&saveq->clist, | |
2494 | &pring->iocb_continue_saveq); | |
2495 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2496 | list_del_init(&iocbq->clist); | |
2497 | saveq = iocbq; | |
2498 | irsp = &(saveq->iocb); | |
2499 | } else | |
2500 | return 0; | |
2501 | } | |
2502 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2503 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2504 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2505 | Rctl = FC_RCTL_ELS_REQ; |
2506 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2507 | } else { |
2508 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2509 | Rctl = w5p->hcsw.Rctl; | |
2510 | Type = w5p->hcsw.Type; | |
2511 | ||
2512 | /* Firmware Workaround */ | |
2513 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2514 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2515 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2516 | Rctl = FC_RCTL_ELS_REQ; |
2517 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2518 | w5p->hcsw.Rctl = Rctl; |
2519 | w5p->hcsw.Type = Type; | |
2520 | } | |
2521 | } | |
92d7f7b0 | 2522 | |
3772a991 | 2523 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2524 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2525 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2526 | "Type x%x received\n", |
e8b62011 | 2527 | pring->ringno, Rctl, Type); |
3772a991 | 2528 | |
92d7f7b0 | 2529 | return 1; |
dea3101e JB |
2530 | } |
2531 | ||
e59058c4 | 2532 | /** |
3621a710 | 2533 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2534 | * @phba: Pointer to HBA context object. |
2535 | * @pring: Pointer to driver SLI ring object. | |
2536 | * @prspiocb: Pointer to response iocb object. | |
2537 | * | |
2538 | * This function looks up the iocb_lookup table to get the command iocb | |
2539 | * corresponding to the given response iocb using the iotag of the | |
2540 | * response iocb. This function is called with the hbalock held. | |
2541 | * This function returns the command iocb object if it finds the command | |
2542 | * iocb else returns NULL. | |
2543 | **/ | |
dea3101e | 2544 | static struct lpfc_iocbq * |
2e0fef85 JS |
2545 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2546 | struct lpfc_sli_ring *pring, | |
2547 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2548 | { |
dea3101e JB |
2549 | struct lpfc_iocbq *cmd_iocb = NULL; |
2550 | uint16_t iotag; | |
2551 | ||
604a3e30 JB |
2552 | iotag = prspiocb->iocb.ulpIoTag; |
2553 | ||
2554 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2555 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2556 | list_del_init(&cmd_iocb->list); |
2a9bf3d0 JS |
2557 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2558 | pring->txcmplq_cnt--; | |
2559 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2560 | } | |
604a3e30 | 2561 | return cmd_iocb; |
dea3101e JB |
2562 | } |
2563 | ||
dea3101e | 2564 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2565 | "0317 iotag x%x is out off " |
604a3e30 | 2566 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2567 | iotag, phba->sli.last_iotag, |
604a3e30 | 2568 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
2569 | return NULL; |
2570 | } | |
2571 | ||
3772a991 JS |
2572 | /** |
2573 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2574 | * @phba: Pointer to HBA context object. | |
2575 | * @pring: Pointer to driver SLI ring object. | |
2576 | * @iotag: IOCB tag. | |
2577 | * | |
2578 | * This function looks up the iocb_lookup table to get the command iocb | |
2579 | * corresponding to the given iotag. This function is called with the | |
2580 | * hbalock held. | |
2581 | * This function returns the command iocb object if it finds the command | |
2582 | * iocb else returns NULL. | |
2583 | **/ | |
2584 | static struct lpfc_iocbq * | |
2585 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2586 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2587 | { | |
2588 | struct lpfc_iocbq *cmd_iocb; | |
2589 | ||
2590 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2591 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
2592 | list_del_init(&cmd_iocb->list); | |
2a9bf3d0 JS |
2593 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2594 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2595 | pring->txcmplq_cnt--; | |
2596 | } | |
3772a991 JS |
2597 | return cmd_iocb; |
2598 | } | |
2599 | ||
2600 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2601 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2602 | iotag, phba->sli.last_iotag); | |
2603 | return NULL; | |
2604 | } | |
2605 | ||
e59058c4 | 2606 | /** |
3621a710 | 2607 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2608 | * @phba: Pointer to HBA context object. |
2609 | * @pring: Pointer to driver SLI ring object. | |
2610 | * @saveq: Pointer to the response iocb to be processed. | |
2611 | * | |
2612 | * This function is called by the ring event handler for non-fcp | |
2613 | * rings when there is a new response iocb in the response ring. | |
2614 | * The caller is not required to hold any locks. This function | |
2615 | * gets the command iocb associated with the response iocb and | |
2616 | * calls the completion handler for the command iocb. If there | |
2617 | * is no completion handler, the function will free the resources | |
2618 | * associated with command iocb. If the response iocb is for | |
2619 | * an already aborted command iocb, the status of the completion | |
2620 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2621 | * This function always returns 1. | |
2622 | **/ | |
dea3101e | 2623 | static int |
2e0fef85 | 2624 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
2625 | struct lpfc_iocbq *saveq) |
2626 | { | |
2e0fef85 | 2627 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
2628 | int rc = 1; |
2629 | unsigned long iflag; | |
2630 | ||
2631 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2632 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2633 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2634 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2635 | ||
dea3101e JB |
2636 | if (cmdiocbp) { |
2637 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2638 | /* |
2639 | * If an ELS command failed send an event to mgmt | |
2640 | * application. | |
2641 | */ | |
2642 | if (saveq->iocb.ulpStatus && | |
2643 | (pring->ringno == LPFC_ELS_RING) && | |
2644 | (cmdiocbp->iocb.ulpCommand == | |
2645 | CMD_ELS_REQUEST64_CR)) | |
2646 | lpfc_send_els_failure_event(phba, | |
2647 | cmdiocbp, saveq); | |
2648 | ||
dea3101e JB |
2649 | /* |
2650 | * Post all ELS completions to the worker thread. | |
2651 | * All other are passed to the completion callback. | |
2652 | */ | |
2653 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2654 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2655 | (cmdiocbp->iocb_flag & | |
2656 | LPFC_DRIVER_ABORTED)) { | |
2657 | spin_lock_irqsave(&phba->hbalock, | |
2658 | iflag); | |
07951076 JS |
2659 | cmdiocbp->iocb_flag &= |
2660 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2661 | spin_unlock_irqrestore(&phba->hbalock, |
2662 | iflag); | |
07951076 JS |
2663 | saveq->iocb.ulpStatus = |
2664 | IOSTAT_LOCAL_REJECT; | |
2665 | saveq->iocb.un.ulpWord[4] = | |
2666 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2667 | |
2668 | /* Firmware could still be in progress | |
2669 | * of DMAing payload, so don't free data | |
2670 | * buffer till after a hbeat. | |
2671 | */ | |
341af102 JS |
2672 | spin_lock_irqsave(&phba->hbalock, |
2673 | iflag); | |
0ff10d46 | 2674 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2675 | spin_unlock_irqrestore(&phba->hbalock, |
2676 | iflag); | |
2677 | } | |
0f65ff68 JS |
2678 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2679 | if (saveq->iocb_flag & | |
2680 | LPFC_EXCHANGE_BUSY) { | |
2681 | /* Set cmdiocb flag for the | |
2682 | * exchange busy so sgl (xri) | |
2683 | * will not be released until | |
2684 | * the abort xri is received | |
2685 | * from hba. | |
2686 | */ | |
2687 | spin_lock_irqsave( | |
2688 | &phba->hbalock, iflag); | |
2689 | cmdiocbp->iocb_flag |= | |
2690 | LPFC_EXCHANGE_BUSY; | |
2691 | spin_unlock_irqrestore( | |
2692 | &phba->hbalock, iflag); | |
2693 | } | |
2694 | if (cmdiocbp->iocb_flag & | |
2695 | LPFC_DRIVER_ABORTED) { | |
2696 | /* | |
2697 | * Clear LPFC_DRIVER_ABORTED | |
2698 | * bit in case it was driver | |
2699 | * initiated abort. | |
2700 | */ | |
2701 | spin_lock_irqsave( | |
2702 | &phba->hbalock, iflag); | |
2703 | cmdiocbp->iocb_flag &= | |
2704 | ~LPFC_DRIVER_ABORTED; | |
2705 | spin_unlock_irqrestore( | |
2706 | &phba->hbalock, iflag); | |
2707 | cmdiocbp->iocb.ulpStatus = | |
2708 | IOSTAT_LOCAL_REJECT; | |
2709 | cmdiocbp->iocb.un.ulpWord[4] = | |
2710 | IOERR_ABORT_REQUESTED; | |
2711 | /* | |
2712 | * For SLI4, irsiocb contains | |
2713 | * NO_XRI in sli_xritag, it | |
2714 | * shall not affect releasing | |
2715 | * sgl (xri) process. | |
2716 | */ | |
2717 | saveq->iocb.ulpStatus = | |
2718 | IOSTAT_LOCAL_REJECT; | |
2719 | saveq->iocb.un.ulpWord[4] = | |
2720 | IOERR_SLI_ABORTED; | |
2721 | spin_lock_irqsave( | |
2722 | &phba->hbalock, iflag); | |
2723 | saveq->iocb_flag |= | |
2724 | LPFC_DELAY_MEM_FREE; | |
2725 | spin_unlock_irqrestore( | |
2726 | &phba->hbalock, iflag); | |
2727 | } | |
07951076 | 2728 | } |
dea3101e | 2729 | } |
2e0fef85 | 2730 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2731 | } else |
2732 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
2733 | } else { |
2734 | /* | |
2735 | * Unknown initiating command based on the response iotag. | |
2736 | * This could be the case on the ELS ring because of | |
2737 | * lpfc_els_abort(). | |
2738 | */ | |
2739 | if (pring->ringno != LPFC_ELS_RING) { | |
2740 | /* | |
2741 | * Ring <ringno> handler: unexpected completion IoTag | |
2742 | * <IoTag> | |
2743 | */ | |
a257bf90 | 2744 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2745 | "0322 Ring %d handler: " |
2746 | "unexpected completion IoTag x%x " | |
2747 | "Data: x%x x%x x%x x%x\n", | |
2748 | pring->ringno, | |
2749 | saveq->iocb.ulpIoTag, | |
2750 | saveq->iocb.ulpStatus, | |
2751 | saveq->iocb.un.ulpWord[4], | |
2752 | saveq->iocb.ulpCommand, | |
2753 | saveq->iocb.ulpContext); | |
dea3101e JB |
2754 | } |
2755 | } | |
68876920 | 2756 | |
dea3101e JB |
2757 | return rc; |
2758 | } | |
2759 | ||
e59058c4 | 2760 | /** |
3621a710 | 2761 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2762 | * @phba: Pointer to HBA context object. |
2763 | * @pring: Pointer to driver SLI ring object. | |
2764 | * | |
2765 | * This function is called from the iocb ring event handlers when | |
2766 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2767 | * an error attention condition to the worker thread and the worker | |
2768 | * thread will transition the HBA to offline state. | |
2769 | **/ | |
2e0fef85 JS |
2770 | static void |
2771 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2772 | { |
34b02dcd | 2773 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2774 | /* |
025dfdaf | 2775 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2776 | * rsp ring <portRspMax> |
2777 | */ | |
2778 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2779 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2780 | "is bigger than rsp ring %d\n", |
e8b62011 | 2781 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
2782 | pring->numRiocb); |
2783 | ||
2e0fef85 | 2784 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2785 | |
2786 | /* | |
2787 | * All error attention handlers are posted to | |
2788 | * worker thread | |
2789 | */ | |
2790 | phba->work_ha |= HA_ERATT; | |
2791 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2792 | |
5e9d9b82 | 2793 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2794 | |
2795 | return; | |
2796 | } | |
2797 | ||
9399627f | 2798 | /** |
3621a710 | 2799 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2800 | * @ptr: Pointer to address of HBA context object. |
2801 | * | |
2802 | * This function is invoked by the Error Attention polling timer when the | |
2803 | * timer times out. It will check the SLI Error Attention register for | |
2804 | * possible attention events. If so, it will post an Error Attention event | |
2805 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2806 | * Error Attention polling timer for the next poll. | |
2807 | **/ | |
2808 | void lpfc_poll_eratt(unsigned long ptr) | |
2809 | { | |
2810 | struct lpfc_hba *phba; | |
2811 | uint32_t eratt = 0; | |
2812 | ||
2813 | phba = (struct lpfc_hba *)ptr; | |
2814 | ||
2815 | /* Check chip HA register for error event */ | |
2816 | eratt = lpfc_sli_check_eratt(phba); | |
2817 | ||
2818 | if (eratt) | |
2819 | /* Tell the worker thread there is work to do */ | |
2820 | lpfc_worker_wake_up(phba); | |
2821 | else | |
2822 | /* Restart the timer for next eratt poll */ | |
2823 | mod_timer(&phba->eratt_poll, jiffies + | |
2824 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2825 | return; | |
2826 | } | |
2827 | ||
875fbdfe | 2828 | |
e59058c4 | 2829 | /** |
3621a710 | 2830 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2831 | * @phba: Pointer to HBA context object. |
2832 | * @pring: Pointer to driver SLI ring object. | |
2833 | * @mask: Host attention register mask for this ring. | |
2834 | * | |
2835 | * This function is called from the interrupt context when there is a ring | |
2836 | * event for the fcp ring. The caller does not hold any lock. | |
2837 | * The function processes each response iocb in the response ring until it | |
2838 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | |
2839 | * LE bit set. The function will call the completion handler of the command iocb | |
2840 | * if the response iocb indicates a completion for a command iocb or it is | |
2841 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2842 | * function if this is an unsolicited iocb. | |
dea3101e | 2843 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2844 | * to check it explicitly. |
2845 | */ | |
2846 | int | |
2e0fef85 JS |
2847 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2848 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2849 | { |
34b02dcd | 2850 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2851 | IOCB_t *irsp = NULL; |
87f6eaff | 2852 | IOCB_t *entry = NULL; |
dea3101e JB |
2853 | struct lpfc_iocbq *cmdiocbq = NULL; |
2854 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
2855 | uint32_t status; |
2856 | uint32_t portRspPut, portRspMax; | |
2857 | int rc = 1; | |
2858 | lpfc_iocb_type type; | |
2859 | unsigned long iflag; | |
2860 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2861 | |
2e0fef85 | 2862 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2863 | pring->stats.iocb_event++; |
2864 | ||
dea3101e JB |
2865 | /* |
2866 | * The next available response entry should never exceed the maximum | |
2867 | * entries. If it does, treat it as an adapter hardware error. | |
2868 | */ | |
2869 | portRspMax = pring->numRiocb; | |
2870 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2871 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2872 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2873 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2874 | return 1; |
2875 | } | |
45ed1190 JS |
2876 | if (phba->fcp_ring_in_use) { |
2877 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2878 | return 1; | |
2879 | } else | |
2880 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
2881 | |
2882 | rmb(); | |
2883 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
2884 | /* |
2885 | * Fetch an entry off the ring and copy it into a local data | |
2886 | * structure. The copy involves a byte-swap since the | |
2887 | * network byte order and pci byte orders are different. | |
2888 | */ | |
ed957684 | 2889 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2890 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
2891 | |
2892 | if (++pring->rspidx >= portRspMax) | |
2893 | pring->rspidx = 0; | |
2894 | ||
87f6eaff JSEC |
2895 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2896 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2897 | phba->iocb_rsp_size); |
a4bc3379 | 2898 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2899 | irsp = &rspiocbq.iocb; |
2900 | ||
dea3101e JB |
2901 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2902 | pring->stats.iocb_rsp++; | |
2903 | rsp_cmpl++; | |
2904 | ||
2905 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2906 | /* |
2907 | * If resource errors reported from HBA, reduce | |
2908 | * queuedepths of the SCSI device. | |
2909 | */ | |
2910 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2911 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2912 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2913 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2914 | spin_lock_irqsave(&phba->hbalock, iflag); |
2915 | } | |
2916 | ||
dea3101e JB |
2917 | /* Rsp ring <ringno> error: IOCB */ |
2918 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2919 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2920 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2921 | pring->ringno, |
92d7f7b0 JS |
2922 | irsp->un.ulpWord[0], |
2923 | irsp->un.ulpWord[1], | |
2924 | irsp->un.ulpWord[2], | |
2925 | irsp->un.ulpWord[3], | |
2926 | irsp->un.ulpWord[4], | |
2927 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2928 | *(uint32_t *)&irsp->un1, |
2929 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
2930 | } |
2931 | ||
2932 | switch (type) { | |
2933 | case LPFC_ABORT_IOCB: | |
2934 | case LPFC_SOL_IOCB: | |
2935 | /* | |
2936 | * Idle exchange closed via ABTS from port. No iocb | |
2937 | * resources need to be recovered. | |
2938 | */ | |
2939 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2940 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2941 | "0333 IOCB cmd 0x%x" |
dca9479b | 2942 | " processed. Skipping" |
92d7f7b0 | 2943 | " completion\n", |
dca9479b | 2944 | irsp->ulpCommand); |
dea3101e JB |
2945 | break; |
2946 | } | |
2947 | ||
604a3e30 JB |
2948 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2949 | &rspiocbq); | |
0f65ff68 JS |
2950 | if (unlikely(!cmdiocbq)) |
2951 | break; | |
2952 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2953 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2954 | if (cmdiocbq->iocb_cmpl) { | |
2955 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2956 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2957 | &rspiocbq); | |
2958 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2959 | } | |
dea3101e | 2960 | break; |
a4bc3379 | 2961 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2962 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2963 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2964 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2965 | break; |
dea3101e JB |
2966 | default: |
2967 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2968 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2969 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2970 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2971 | MAX_MSG_DATA); | |
898eb71c JP |
2972 | dev_warn(&((phba->pcidev)->dev), |
2973 | "lpfc%d: %s\n", | |
dea3101e JB |
2974 | phba->brd_no, adaptermsg); |
2975 | } else { | |
2976 | /* Unknown IOCB command */ | |
2977 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2978 | "0334 Unknown IOCB command " |
92d7f7b0 | 2979 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2980 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2981 | irsp->ulpStatus, |
2982 | irsp->ulpIoTag, | |
2983 | irsp->ulpContext); | |
dea3101e JB |
2984 | } |
2985 | break; | |
2986 | } | |
2987 | ||
2988 | /* | |
2989 | * The response IOCB has been processed. Update the ring | |
2990 | * pointer in SLIM. If the port response put pointer has not | |
2991 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2992 | * response put pointer. | |
2993 | */ | |
ed957684 | 2994 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e JB |
2995 | |
2996 | if (pring->rspidx == portRspPut) | |
2997 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2998 | } | |
2999 | ||
3000 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
3001 | pring->stats.iocb_rsp_full++; | |
3002 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3003 | writel(status, phba->CAregaddr); | |
3004 | readl(phba->CAregaddr); | |
3005 | } | |
3006 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3007 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3008 | pring->stats.iocb_cmd_empty++; | |
3009 | ||
3010 | /* Force update of the local copy of cmdGetInx */ | |
3011 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3012 | lpfc_sli_resume_iocb(phba, pring); | |
3013 | ||
3014 | if ((pring->lpfc_sli_cmd_available)) | |
3015 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3016 | ||
3017 | } | |
3018 | ||
45ed1190 | 3019 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 3020 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
3021 | return rc; |
3022 | } | |
3023 | ||
e59058c4 | 3024 | /** |
3772a991 JS |
3025 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
3026 | * @phba: Pointer to HBA context object. | |
3027 | * @pring: Pointer to driver SLI ring object. | |
3028 | * @rspiocbp: Pointer to driver response IOCB object. | |
3029 | * | |
3030 | * This function is called from the worker thread when there is a slow-path | |
3031 | * response IOCB to process. This function chains all the response iocbs until | |
3032 | * seeing the iocb with the LE bit set. The function will call | |
3033 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
3034 | * completion of a command iocb. The function will call the | |
3035 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
3036 | * The function frees the resources or calls the completion handler if this | |
3037 | * iocb is an abort completion. The function returns NULL when the response | |
3038 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
3039 | * this function shall chain the iocb on to the iocb_continueq and return the | |
3040 | * response iocb passed in. | |
3041 | **/ | |
3042 | static struct lpfc_iocbq * | |
3043 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
3044 | struct lpfc_iocbq *rspiocbp) | |
3045 | { | |
3046 | struct lpfc_iocbq *saveq; | |
3047 | struct lpfc_iocbq *cmdiocbp; | |
3048 | struct lpfc_iocbq *next_iocb; | |
3049 | IOCB_t *irsp = NULL; | |
3050 | uint32_t free_saveq; | |
3051 | uint8_t iocb_cmd_type; | |
3052 | lpfc_iocb_type type; | |
3053 | unsigned long iflag; | |
3054 | int rc; | |
3055 | ||
3056 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3057 | /* First add the response iocb to the countinueq list */ | |
3058 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
3059 | pring->iocb_continueq_cnt++; | |
3060 | ||
3061 | /* Now, determine whetehr the list is completed for processing */ | |
3062 | irsp = &rspiocbp->iocb; | |
3063 | if (irsp->ulpLe) { | |
3064 | /* | |
3065 | * By default, the driver expects to free all resources | |
3066 | * associated with this iocb completion. | |
3067 | */ | |
3068 | free_saveq = 1; | |
3069 | saveq = list_get_first(&pring->iocb_continueq, | |
3070 | struct lpfc_iocbq, list); | |
3071 | irsp = &(saveq->iocb); | |
3072 | list_del_init(&pring->iocb_continueq); | |
3073 | pring->iocb_continueq_cnt = 0; | |
3074 | ||
3075 | pring->stats.iocb_rsp++; | |
3076 | ||
3077 | /* | |
3078 | * If resource errors reported from HBA, reduce | |
3079 | * queuedepths of the SCSI device. | |
3080 | */ | |
3081 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
3082 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
3083 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3084 | phba->lpfc_rampdown_queue_depth(phba); | |
3085 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3086 | } | |
3087 | ||
3088 | if (irsp->ulpStatus) { | |
3089 | /* Rsp ring <ringno> error: IOCB */ | |
3090 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
3091 | "0328 Rsp Ring %d error: " | |
3092 | "IOCB Data: " | |
3093 | "x%x x%x x%x x%x " | |
3094 | "x%x x%x x%x x%x " | |
3095 | "x%x x%x x%x x%x " | |
3096 | "x%x x%x x%x x%x\n", | |
3097 | pring->ringno, | |
3098 | irsp->un.ulpWord[0], | |
3099 | irsp->un.ulpWord[1], | |
3100 | irsp->un.ulpWord[2], | |
3101 | irsp->un.ulpWord[3], | |
3102 | irsp->un.ulpWord[4], | |
3103 | irsp->un.ulpWord[5], | |
3104 | *(((uint32_t *) irsp) + 6), | |
3105 | *(((uint32_t *) irsp) + 7), | |
3106 | *(((uint32_t *) irsp) + 8), | |
3107 | *(((uint32_t *) irsp) + 9), | |
3108 | *(((uint32_t *) irsp) + 10), | |
3109 | *(((uint32_t *) irsp) + 11), | |
3110 | *(((uint32_t *) irsp) + 12), | |
3111 | *(((uint32_t *) irsp) + 13), | |
3112 | *(((uint32_t *) irsp) + 14), | |
3113 | *(((uint32_t *) irsp) + 15)); | |
3114 | } | |
3115 | ||
3116 | /* | |
3117 | * Fetch the IOCB command type and call the correct completion | |
3118 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
3119 | * get freed back to the lpfc_iocb_list by the discovery | |
3120 | * kernel thread. | |
3121 | */ | |
3122 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
3123 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
3124 | switch (type) { | |
3125 | case LPFC_SOL_IOCB: | |
3126 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3127 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
3128 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3129 | break; | |
3130 | ||
3131 | case LPFC_UNSOL_IOCB: | |
3132 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3133 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
3134 | spin_lock_irqsave(&phba->hbalock, iflag); | |
3135 | if (!rc) | |
3136 | free_saveq = 0; | |
3137 | break; | |
3138 | ||
3139 | case LPFC_ABORT_IOCB: | |
3140 | cmdiocbp = NULL; | |
3141 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
3142 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
3143 | saveq); | |
3144 | if (cmdiocbp) { | |
3145 | /* Call the specified completion routine */ | |
3146 | if (cmdiocbp->iocb_cmpl) { | |
3147 | spin_unlock_irqrestore(&phba->hbalock, | |
3148 | iflag); | |
3149 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
3150 | saveq); | |
3151 | spin_lock_irqsave(&phba->hbalock, | |
3152 | iflag); | |
3153 | } else | |
3154 | __lpfc_sli_release_iocbq(phba, | |
3155 | cmdiocbp); | |
3156 | } | |
3157 | break; | |
3158 | ||
3159 | case LPFC_UNKNOWN_IOCB: | |
3160 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
3161 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
3162 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
3163 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
3164 | MAX_MSG_DATA); | |
3165 | dev_warn(&((phba->pcidev)->dev), | |
3166 | "lpfc%d: %s\n", | |
3167 | phba->brd_no, adaptermsg); | |
3168 | } else { | |
3169 | /* Unknown IOCB command */ | |
3170 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3171 | "0335 Unknown IOCB " | |
3172 | "command Data: x%x " | |
3173 | "x%x x%x x%x\n", | |
3174 | irsp->ulpCommand, | |
3175 | irsp->ulpStatus, | |
3176 | irsp->ulpIoTag, | |
3177 | irsp->ulpContext); | |
3178 | } | |
3179 | break; | |
3180 | } | |
3181 | ||
3182 | if (free_saveq) { | |
3183 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
3184 | &saveq->list, list) { | |
3185 | list_del(&rspiocbp->list); | |
3186 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
3187 | } | |
3188 | __lpfc_sli_release_iocbq(phba, saveq); | |
3189 | } | |
3190 | rspiocbp = NULL; | |
3191 | } | |
3192 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3193 | return rspiocbp; | |
3194 | } | |
3195 | ||
3196 | /** | |
3197 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
3198 | * @phba: Pointer to HBA context object. |
3199 | * @pring: Pointer to driver SLI ring object. | |
3200 | * @mask: Host attention register mask for this ring. | |
3201 | * | |
3772a991 JS |
3202 | * This routine wraps the actual slow_ring event process routine from the |
3203 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 3204 | **/ |
3772a991 | 3205 | void |
2e0fef85 JS |
3206 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
3207 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
3208 | { |
3209 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
3210 | } | |
3211 | ||
3212 | /** | |
3213 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
3214 | * @phba: Pointer to HBA context object. | |
3215 | * @pring: Pointer to driver SLI ring object. | |
3216 | * @mask: Host attention register mask for this ring. | |
3217 | * | |
3218 | * This function is called from the worker thread when there is a ring event | |
3219 | * for non-fcp rings. The caller does not hold any lock. The function will | |
3220 | * remove each response iocb in the response ring and calls the handle | |
3221 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3222 | **/ | |
3223 | static void | |
3224 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
3225 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 3226 | { |
34b02dcd | 3227 | struct lpfc_pgp *pgp; |
dea3101e JB |
3228 | IOCB_t *entry; |
3229 | IOCB_t *irsp = NULL; | |
3230 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 3231 | uint32_t portRspPut, portRspMax; |
dea3101e | 3232 | unsigned long iflag; |
3772a991 | 3233 | uint32_t status; |
dea3101e | 3234 | |
34b02dcd | 3235 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 3236 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
3237 | pring->stats.iocb_event++; |
3238 | ||
dea3101e JB |
3239 | /* |
3240 | * The next available response entry should never exceed the maximum | |
3241 | * entries. If it does, treat it as an adapter hardware error. | |
3242 | */ | |
3243 | portRspMax = pring->numRiocb; | |
3244 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3245 | if (portRspPut >= portRspMax) { | |
3246 | /* | |
025dfdaf | 3247 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
3248 | * rsp ring <portRspMax> |
3249 | */ | |
ed957684 | 3250 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 3251 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 3252 | "is bigger than rsp ring %d\n", |
e8b62011 | 3253 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 3254 | |
2e0fef85 JS |
3255 | phba->link_state = LPFC_HBA_ERROR; |
3256 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
3257 | |
3258 | phba->work_hs = HS_FFER3; | |
3259 | lpfc_handle_eratt(phba); | |
3260 | ||
3772a991 | 3261 | return; |
dea3101e JB |
3262 | } |
3263 | ||
3264 | rmb(); | |
dea3101e JB |
3265 | while (pring->rspidx != portRspPut) { |
3266 | /* | |
3267 | * Build a completion list and call the appropriate handler. | |
3268 | * The process is to get the next available response iocb, get | |
3269 | * a free iocb from the list, copy the response data into the | |
3270 | * free iocb, insert to the continuation list, and update the | |
3271 | * next response index to slim. This process makes response | |
3272 | * iocb's in the ring available to DMA as fast as possible but | |
3273 | * pays a penalty for a copy operation. Since the iocb is | |
3274 | * only 32 bytes, this penalty is considered small relative to | |
3275 | * the PCI reads for register values and a slim write. When | |
3276 | * the ulpLe field is set, the entire Command has been | |
3277 | * received. | |
3278 | */ | |
ed957684 JS |
3279 | entry = lpfc_resp_iocb(phba, pring); |
3280 | ||
858c9f6c | 3281 | phba->last_completion_time = jiffies; |
2e0fef85 | 3282 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
3283 | if (rspiocbp == NULL) { |
3284 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 3285 | "completion.\n", __func__); |
dea3101e JB |
3286 | break; |
3287 | } | |
3288 | ||
ed957684 JS |
3289 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
3290 | phba->iocb_rsp_size); | |
dea3101e JB |
3291 | irsp = &rspiocbp->iocb; |
3292 | ||
3293 | if (++pring->rspidx >= portRspMax) | |
3294 | pring->rspidx = 0; | |
3295 | ||
a58cbd52 JS |
3296 | if (pring->ringno == LPFC_ELS_RING) { |
3297 | lpfc_debugfs_slow_ring_trc(phba, | |
3298 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
3299 | *(((uint32_t *) irsp) + 4), | |
3300 | *(((uint32_t *) irsp) + 6), | |
3301 | *(((uint32_t *) irsp) + 7)); | |
3302 | } | |
3303 | ||
ed957684 | 3304 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 3305 | |
3772a991 JS |
3306 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3307 | /* Handle the response IOCB */ | |
3308 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
3309 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
3310 | |
3311 | /* | |
3312 | * If the port response put pointer has not been updated, sync | |
3313 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
3314 | * response put pointer. | |
3315 | */ | |
3316 | if (pring->rspidx == portRspPut) { | |
3317 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
3318 | } | |
3319 | } /* while (pring->rspidx != portRspPut) */ | |
3320 | ||
92d7f7b0 | 3321 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
3322 | /* At least one response entry has been freed */ |
3323 | pring->stats.iocb_rsp_full++; | |
3324 | /* SET RxRE_RSP in Chip Att register */ | |
3325 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
3326 | writel(status, phba->CAregaddr); | |
3327 | readl(phba->CAregaddr); /* flush */ | |
3328 | } | |
3329 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
3330 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
3331 | pring->stats.iocb_cmd_empty++; | |
3332 | ||
3333 | /* Force update of the local copy of cmdGetInx */ | |
3334 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
3335 | lpfc_sli_resume_iocb(phba, pring); | |
3336 | ||
3337 | if ((pring->lpfc_sli_cmd_available)) | |
3338 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
3339 | ||
3340 | } | |
3341 | ||
2e0fef85 | 3342 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 3343 | return; |
dea3101e JB |
3344 | } |
3345 | ||
4f774513 JS |
3346 | /** |
3347 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
3348 | * @phba: Pointer to HBA context object. | |
3349 | * @pring: Pointer to driver SLI ring object. | |
3350 | * @mask: Host attention register mask for this ring. | |
3351 | * | |
3352 | * This function is called from the worker thread when there is a pending | |
3353 | * ELS response iocb on the driver internal slow-path response iocb worker | |
3354 | * queue. The caller does not hold any lock. The function will remove each | |
3355 | * response iocb from the response worker queue and calls the handle | |
3356 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
3357 | **/ | |
3358 | static void | |
3359 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
3360 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3361 | { | |
3362 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
3363 | struct hbq_dmabuf *dmabuf; |
3364 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
3365 | unsigned long iflag; |
3366 | ||
45ed1190 JS |
3367 | spin_lock_irqsave(&phba->hbalock, iflag); |
3368 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
3369 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3370 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
3371 | /* Get the response iocb from the head of work queue */ |
3372 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 3373 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 3374 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 3375 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
3376 | |
3377 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
3378 | case CQE_CODE_COMPL_WQE: | |
3379 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
3380 | cq_event); | |
45ed1190 JS |
3381 | /* Translate ELS WCQE to response IOCBQ */ |
3382 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3383 | irspiocbq); | |
3384 | if (irspiocbq) | |
3385 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3386 | irspiocbq); | |
4d9ab994 JS |
3387 | break; |
3388 | case CQE_CODE_RECEIVE: | |
3389 | dmabuf = container_of(cq_event, struct hbq_dmabuf, | |
3390 | cq_event); | |
3391 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3392 | break; | |
3393 | default: | |
3394 | break; | |
3395 | } | |
4f774513 JS |
3396 | } |
3397 | } | |
3398 | ||
e59058c4 | 3399 | /** |
3621a710 | 3400 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3401 | * @phba: Pointer to HBA context object. |
3402 | * @pring: Pointer to driver SLI ring object. | |
3403 | * | |
3404 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3405 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3406 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3407 | * the return of this function. The caller is not required to hold any locks. | |
3408 | **/ | |
2e0fef85 | 3409 | void |
dea3101e JB |
3410 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3411 | { | |
2534ba75 | 3412 | LIST_HEAD(completions); |
dea3101e | 3413 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3414 | |
92d7f7b0 JS |
3415 | if (pring->ringno == LPFC_ELS_RING) { |
3416 | lpfc_fabric_abort_hba(phba); | |
3417 | } | |
3418 | ||
dea3101e JB |
3419 | /* Error everything on txq and txcmplq |
3420 | * First do the txq. | |
3421 | */ | |
2e0fef85 | 3422 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3423 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3424 | pring->txq_cnt = 0; |
dea3101e JB |
3425 | |
3426 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3427 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3428 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3429 | |
2e0fef85 | 3430 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3431 | |
a257bf90 JS |
3432 | /* Cancel all the IOCBs from the completions list */ |
3433 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3434 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3435 | } |
3436 | ||
a8e497d5 | 3437 | /** |
3621a710 | 3438 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3439 | * @phba: Pointer to HBA context object. |
3440 | * | |
3441 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3442 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3443 | * for all the iocb commands in txcmplq, they will just be returned with | |
3444 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3445 | * slot has been permanently disabled. | |
3446 | **/ | |
3447 | void | |
3448 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3449 | { | |
3450 | LIST_HEAD(txq); | |
3451 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3452 | struct lpfc_sli *psli = &phba->sli; |
3453 | struct lpfc_sli_ring *pring; | |
3454 | ||
3455 | /* Currently, only one fcp ring */ | |
3456 | pring = &psli->ring[psli->fcp_ring]; | |
3457 | ||
3458 | spin_lock_irq(&phba->hbalock); | |
3459 | /* Retrieve everything on txq */ | |
3460 | list_splice_init(&pring->txq, &txq); | |
3461 | pring->txq_cnt = 0; | |
3462 | ||
3463 | /* Retrieve everything on the txcmplq */ | |
3464 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3465 | pring->txcmplq_cnt = 0; | |
3466 | spin_unlock_irq(&phba->hbalock); | |
3467 | ||
3468 | /* Flush the txq */ | |
a257bf90 JS |
3469 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3470 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3471 | |
3472 | /* Flush the txcmpq */ | |
a257bf90 JS |
3473 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3474 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3475 | } |
3476 | ||
e59058c4 | 3477 | /** |
3772a991 | 3478 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3479 | * @phba: Pointer to HBA context object. |
3480 | * @mask: Bit mask to be checked. | |
3481 | * | |
3482 | * This function reads the host status register and compares | |
3483 | * with the provided bit mask to check if HBA completed | |
3484 | * the restart. This function will wait in a loop for the | |
3485 | * HBA to complete restart. If the HBA does not restart within | |
3486 | * 15 iterations, the function will reset the HBA again. The | |
3487 | * function returns 1 when HBA fail to restart otherwise returns | |
3488 | * zero. | |
3489 | **/ | |
3772a991 JS |
3490 | static int |
3491 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3492 | { |
41415862 JW |
3493 | uint32_t status; |
3494 | int i = 0; | |
3495 | int retval = 0; | |
dea3101e | 3496 | |
41415862 JW |
3497 | /* Read the HBA Host Status Register */ |
3498 | status = readl(phba->HSregaddr); | |
dea3101e | 3499 | |
41415862 JW |
3500 | /* |
3501 | * Check status register every 100ms for 5 retries, then every | |
3502 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3503 | * every 2.5 sec for 4. | |
3504 | * Break our of the loop if errors occurred during init. | |
3505 | */ | |
3506 | while (((status & mask) != mask) && | |
3507 | !(status & HS_FFERM) && | |
3508 | i++ < 20) { | |
dea3101e | 3509 | |
41415862 JW |
3510 | if (i <= 5) |
3511 | msleep(10); | |
3512 | else if (i <= 10) | |
3513 | msleep(500); | |
3514 | else | |
3515 | msleep(2500); | |
dea3101e | 3516 | |
41415862 | 3517 | if (i == 15) { |
2e0fef85 | 3518 | /* Do post */ |
92d7f7b0 | 3519 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3520 | lpfc_sli_brdrestart(phba); |
3521 | } | |
3522 | /* Read the HBA Host Status Register */ | |
3523 | status = readl(phba->HSregaddr); | |
3524 | } | |
dea3101e | 3525 | |
41415862 JW |
3526 | /* Check to see if any errors occurred during init */ |
3527 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3528 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3529 | "2751 Adapter failed to restart, " | |
3530 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3531 | status, | |
3532 | readl(phba->MBslimaddr + 0xa8), | |
3533 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3534 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3535 | retval = 1; |
dea3101e | 3536 | } |
dea3101e | 3537 | |
41415862 JW |
3538 | return retval; |
3539 | } | |
dea3101e | 3540 | |
da0436e9 JS |
3541 | /** |
3542 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3543 | * @phba: Pointer to HBA context object. | |
3544 | * @mask: Bit mask to be checked. | |
3545 | * | |
3546 | * This function checks the host status register to check if HBA is | |
3547 | * ready. This function will wait in a loop for the HBA to be ready | |
3548 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3549 | * function again. The function returns 1 when HBA fail to be ready | |
3550 | * otherwise returns zero. | |
3551 | **/ | |
3552 | static int | |
3553 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3554 | { | |
3555 | uint32_t status; | |
3556 | int retval = 0; | |
3557 | ||
3558 | /* Read the HBA Host Status Register */ | |
3559 | status = lpfc_sli4_post_status_check(phba); | |
3560 | ||
3561 | if (status) { | |
3562 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3563 | lpfc_sli_brdrestart(phba); | |
3564 | status = lpfc_sli4_post_status_check(phba); | |
3565 | } | |
3566 | ||
3567 | /* Check to see if any errors occurred during init */ | |
3568 | if (status) { | |
3569 | phba->link_state = LPFC_HBA_ERROR; | |
3570 | retval = 1; | |
3571 | } else | |
3572 | phba->sli4_hba.intr_enable = 0; | |
3573 | ||
3574 | return retval; | |
3575 | } | |
3576 | ||
3577 | /** | |
3578 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3579 | * @phba: Pointer to HBA context object. | |
3580 | * @mask: Bit mask to be checked. | |
3581 | * | |
3582 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3583 | * from the API jump table function pointer from the lpfc_hba struct. | |
3584 | **/ | |
3585 | int | |
3586 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3587 | { | |
3588 | return phba->lpfc_sli_brdready(phba, mask); | |
3589 | } | |
3590 | ||
9290831f JS |
3591 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3592 | ||
e59058c4 | 3593 | /** |
3621a710 | 3594 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3595 | * @phba: Pointer to HBA context object. |
3596 | * | |
3597 | * This function is called before resetting an HBA. This | |
3598 | * function requests HBA to quiesce DMAs before a reset. | |
3599 | **/ | |
2e0fef85 | 3600 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3601 | { |
65a29c16 JS |
3602 | uint32_t __iomem *resp_buf; |
3603 | uint32_t __iomem *mbox_buf; | |
9290831f JS |
3604 | volatile uint32_t mbox; |
3605 | uint32_t hc_copy; | |
3606 | int i; | |
3607 | uint8_t hdrtype; | |
3608 | ||
3609 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3610 | if (hdrtype != 0x80 || | |
3611 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3612 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3613 | return; | |
3614 | ||
3615 | /* | |
3616 | * Tell the other part of the chip to suspend temporarily all | |
3617 | * its DMA activity. | |
3618 | */ | |
65a29c16 | 3619 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3620 | |
3621 | /* Disable the error attention */ | |
3622 | hc_copy = readl(phba->HCregaddr); | |
3623 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); | |
3624 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3625 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f JS |
3626 | |
3627 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3628 | /* Clear Chip error bit */ | |
3629 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3630 | phba->pport->stopped = 1; |
9290831f JS |
3631 | } |
3632 | ||
3633 | mbox = 0; | |
3634 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3635 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3636 | ||
3637 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3638 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3639 | writel(mbox, mbox_buf); |
3640 | ||
3641 | for (i = 0; | |
3642 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) | |
3643 | mdelay(1); | |
3644 | ||
3645 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3646 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3647 | phba->pport->stopped) |
9290831f JS |
3648 | goto restore_hc; |
3649 | else | |
3650 | goto clear_errat; | |
3651 | } | |
3652 | ||
3653 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
3654 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) | |
3655 | mdelay(1); | |
3656 | ||
3657 | clear_errat: | |
3658 | ||
3659 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) | |
3660 | mdelay(1); | |
3661 | ||
3662 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3663 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3664 | phba->pport->stopped = 1; |
9290831f JS |
3665 | } |
3666 | ||
3667 | restore_hc: | |
2e0fef85 | 3668 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3669 | writel(hc_copy, phba->HCregaddr); |
3670 | readl(phba->HCregaddr); /* flush */ | |
3671 | } | |
3672 | ||
e59058c4 | 3673 | /** |
3621a710 | 3674 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3675 | * @phba: Pointer to HBA context object. |
3676 | * | |
3677 | * This function issues a kill_board mailbox command and waits for | |
3678 | * the error attention interrupt. This function is called for stopping | |
3679 | * the firmware processing. The caller is not required to hold any | |
3680 | * locks. This function calls lpfc_hba_down_post function to free | |
3681 | * any pending commands after the kill. The function will return 1 when it | |
3682 | * fails to kill the board else will return 0. | |
3683 | **/ | |
41415862 | 3684 | int |
2e0fef85 | 3685 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3686 | { |
3687 | struct lpfc_sli *psli; | |
3688 | LPFC_MBOXQ_t *pmb; | |
3689 | uint32_t status; | |
3690 | uint32_t ha_copy; | |
3691 | int retval; | |
3692 | int i = 0; | |
dea3101e | 3693 | |
41415862 | 3694 | psli = &phba->sli; |
dea3101e | 3695 | |
41415862 | 3696 | /* Kill HBA */ |
ed957684 | 3697 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3698 | "0329 Kill HBA Data: x%x x%x\n", |
3699 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3700 | |
98c9ea5c JS |
3701 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3702 | if (!pmb) | |
41415862 | 3703 | return 1; |
41415862 JW |
3704 | |
3705 | /* Disable the error attention */ | |
2e0fef85 | 3706 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
3707 | status = readl(phba->HCregaddr); |
3708 | status &= ~HC_ERINT_ENA; | |
3709 | writel(status, phba->HCregaddr); | |
3710 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3711 | phba->link_flag |= LS_IGNORE_ERATT; |
3712 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3713 | |
3714 | lpfc_kill_board(phba, pmb); | |
3715 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3716 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3717 | ||
3718 | if (retval != MBX_SUCCESS) { | |
3719 | if (retval != MBX_BUSY) | |
3720 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3721 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3722 | "2752 KILL_BOARD command failed retval %d\n", | |
3723 | retval); | |
2e0fef85 JS |
3724 | spin_lock_irq(&phba->hbalock); |
3725 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3726 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3727 | return 1; |
3728 | } | |
3729 | ||
f4b4c68f JS |
3730 | spin_lock_irq(&phba->hbalock); |
3731 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3732 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3733 | |
41415862 JW |
3734 | mempool_free(pmb, phba->mbox_mem_pool); |
3735 | ||
3736 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3737 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3738 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3739 | * board is now undefined. | |
3740 | */ | |
3741 | ha_copy = readl(phba->HAregaddr); | |
3742 | ||
3743 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { | |
3744 | mdelay(100); | |
3745 | ha_copy = readl(phba->HAregaddr); | |
3746 | } | |
3747 | ||
3748 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3749 | if (ha_copy & HA_ERATT) { |
3750 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3751 | phba->pport->stopped = 1; |
9290831f | 3752 | } |
2e0fef85 | 3753 | spin_lock_irq(&phba->hbalock); |
41415862 | 3754 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3755 | psli->mbox_active = NULL; |
2e0fef85 JS |
3756 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3757 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3758 | |
41415862 | 3759 | lpfc_hba_down_post(phba); |
2e0fef85 | 3760 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3761 | |
2e0fef85 | 3762 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
3763 | } |
3764 | ||
e59058c4 | 3765 | /** |
3772a991 | 3766 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3767 | * @phba: Pointer to HBA context object. |
3768 | * | |
3769 | * This function resets the HBA by writing HC_INITFF to the control | |
3770 | * register. After the HBA resets, this function resets all the iocb ring | |
3771 | * indices. This function disables PCI layer parity checking during | |
3772 | * the reset. | |
3773 | * This function returns 0 always. | |
3774 | * The caller is not required to hold any locks. | |
3775 | **/ | |
41415862 | 3776 | int |
2e0fef85 | 3777 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3778 | { |
41415862 | 3779 | struct lpfc_sli *psli; |
dea3101e | 3780 | struct lpfc_sli_ring *pring; |
41415862 | 3781 | uint16_t cfg_value; |
dea3101e | 3782 | int i; |
dea3101e | 3783 | |
41415862 | 3784 | psli = &phba->sli; |
dea3101e | 3785 | |
41415862 JW |
3786 | /* Reset HBA */ |
3787 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3788 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3789 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
3790 | |
3791 | /* perform board reset */ | |
3792 | phba->fc_eventTag = 0; | |
4d9ab994 | 3793 | phba->link_events = 0; |
2e0fef85 JS |
3794 | phba->pport->fc_myDID = 0; |
3795 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3796 | |
41415862 JW |
3797 | /* Turn off parity checking and serr during the physical reset */ |
3798 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3799 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3800 | (cfg_value & | |
3801 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3802 | ||
3772a991 JS |
3803 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3804 | ||
41415862 JW |
3805 | /* Now toggle INITFF bit in the Host Control Register */ |
3806 | writel(HC_INITFF, phba->HCregaddr); | |
3807 | mdelay(1); | |
3808 | readl(phba->HCregaddr); /* flush */ | |
3809 | writel(0, phba->HCregaddr); | |
3810 | readl(phba->HCregaddr); /* flush */ | |
3811 | ||
3812 | /* Restore PCI cmd register */ | |
3813 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
3814 | |
3815 | /* Initialize relevant SLI info */ | |
41415862 JW |
3816 | for (i = 0; i < psli->num_rings; i++) { |
3817 | pring = &psli->ring[i]; | |
dea3101e JB |
3818 | pring->flag = 0; |
3819 | pring->rspidx = 0; | |
3820 | pring->next_cmdidx = 0; | |
3821 | pring->local_getidx = 0; | |
3822 | pring->cmdidx = 0; | |
3823 | pring->missbufcnt = 0; | |
3824 | } | |
dea3101e | 3825 | |
2e0fef85 | 3826 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3827 | return 0; |
3828 | } | |
3829 | ||
e59058c4 | 3830 | /** |
da0436e9 JS |
3831 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3832 | * @phba: Pointer to HBA context object. | |
3833 | * | |
3834 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3835 | * checking during resets the device. The caller is not required to hold | |
3836 | * any locks. | |
3837 | * | |
3838 | * This function returns 0 always. | |
3839 | **/ | |
3840 | int | |
3841 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3842 | { | |
3843 | struct lpfc_sli *psli = &phba->sli; | |
3844 | uint16_t cfg_value; | |
3845 | uint8_t qindx; | |
3846 | ||
3847 | /* Reset HBA */ | |
3848 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3849 | "0295 Reset HBA Data: x%x x%x\n", | |
3850 | phba->pport->port_state, psli->sli_flag); | |
3851 | ||
3852 | /* perform board reset */ | |
3853 | phba->fc_eventTag = 0; | |
4d9ab994 | 3854 | phba->link_events = 0; |
da0436e9 JS |
3855 | phba->pport->fc_myDID = 0; |
3856 | phba->pport->fc_prevDID = 0; | |
3857 | ||
3858 | /* Turn off parity checking and serr during the physical reset */ | |
3859 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3860 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3861 | (cfg_value & | |
3862 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3863 | ||
3864 | spin_lock_irq(&phba->hbalock); | |
3865 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3866 | phba->fcf.fcf_flag = 0; | |
3867 | /* Clean up the child queue list for the CQs */ | |
3868 | list_del_init(&phba->sli4_hba.mbx_wq->list); | |
3869 | list_del_init(&phba->sli4_hba.els_wq->list); | |
3870 | list_del_init(&phba->sli4_hba.hdr_rq->list); | |
3871 | list_del_init(&phba->sli4_hba.dat_rq->list); | |
3872 | list_del_init(&phba->sli4_hba.mbx_cq->list); | |
3873 | list_del_init(&phba->sli4_hba.els_cq->list); | |
da0436e9 JS |
3874 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
3875 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | |
3876 | for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++) | |
3877 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); | |
3878 | spin_unlock_irq(&phba->hbalock); | |
3879 | ||
3880 | /* Now physically reset the device */ | |
3881 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3882 | "0389 Performing PCI function reset!\n"); | |
3883 | /* Perform FCoE PCI function reset */ | |
3884 | lpfc_pci_function_reset(phba); | |
3885 | ||
3886 | return 0; | |
3887 | } | |
3888 | ||
3889 | /** | |
3890 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3891 | * @phba: Pointer to HBA context object. |
3892 | * | |
3893 | * This function is called in the SLI initialization code path to | |
3894 | * restart the HBA. The caller is not required to hold any lock. | |
3895 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3896 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3897 | * function to free any pending commands. The function enables | |
3898 | * POST only during the first initialization. The function returns zero. | |
3899 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3900 | * command before the return of this function. | |
3901 | **/ | |
da0436e9 JS |
3902 | static int |
3903 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3904 | { |
3905 | MAILBOX_t *mb; | |
3906 | struct lpfc_sli *psli; | |
41415862 JW |
3907 | volatile uint32_t word0; |
3908 | void __iomem *to_slim; | |
0d878419 | 3909 | uint32_t hba_aer_enabled; |
41415862 | 3910 | |
2e0fef85 | 3911 | spin_lock_irq(&phba->hbalock); |
41415862 | 3912 | |
0d878419 JS |
3913 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3914 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3915 | ||
41415862 JW |
3916 | psli = &phba->sli; |
3917 | ||
3918 | /* Restart HBA */ | |
3919 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3920 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3921 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3922 | |
3923 | word0 = 0; | |
3924 | mb = (MAILBOX_t *) &word0; | |
3925 | mb->mbxCommand = MBX_RESTART; | |
3926 | mb->mbxHc = 1; | |
3927 | ||
9290831f JS |
3928 | lpfc_reset_barrier(phba); |
3929 | ||
41415862 JW |
3930 | to_slim = phba->MBslimaddr; |
3931 | writel(*(uint32_t *) mb, to_slim); | |
3932 | readl(to_slim); /* flush */ | |
3933 | ||
3934 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3935 | if (phba->pport->port_state) |
41415862 | 3936 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 3937 | else |
41415862 | 3938 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 3939 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
3940 | writel(*(uint32_t *) mb, to_slim); |
3941 | readl(to_slim); /* flush */ | |
dea3101e | 3942 | |
41415862 | 3943 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
3944 | phba->pport->stopped = 0; |
3945 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 3946 | phba->hba_flag = 0; |
2e0fef85 | 3947 | spin_unlock_irq(&phba->hbalock); |
41415862 | 3948 | |
64ba8818 JS |
3949 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
3950 | psli->stats_start = get_seconds(); | |
3951 | ||
eaf15d5b JS |
3952 | /* Give the INITFF and Post time to settle. */ |
3953 | mdelay(100); | |
41415862 | 3954 | |
0d878419 JS |
3955 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3956 | if (hba_aer_enabled) | |
3957 | pci_disable_pcie_error_reporting(phba->pcidev); | |
3958 | ||
41415862 | 3959 | lpfc_hba_down_post(phba); |
dea3101e JB |
3960 | |
3961 | return 0; | |
3962 | } | |
3963 | ||
da0436e9 JS |
3964 | /** |
3965 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
3966 | * @phba: Pointer to HBA context object. | |
3967 | * | |
3968 | * This function is called in the SLI initialization code path to restart | |
3969 | * a SLI4 HBA. The caller is not required to hold any lock. | |
3970 | * At the end of the function, it calls lpfc_hba_down_post function to | |
3971 | * free any pending commands. | |
3972 | **/ | |
3973 | static int | |
3974 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
3975 | { | |
3976 | struct lpfc_sli *psli = &phba->sli; | |
75baf696 | 3977 | uint32_t hba_aer_enabled; |
da0436e9 JS |
3978 | |
3979 | /* Restart HBA */ | |
3980 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3981 | "0296 Restart HBA Data: x%x x%x\n", | |
3982 | phba->pport->port_state, psli->sli_flag); | |
3983 | ||
75baf696 JS |
3984 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3985 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3986 | ||
da0436e9 JS |
3987 | lpfc_sli4_brdreset(phba); |
3988 | ||
3989 | spin_lock_irq(&phba->hbalock); | |
3990 | phba->pport->stopped = 0; | |
3991 | phba->link_state = LPFC_INIT_START; | |
3992 | phba->hba_flag = 0; | |
3993 | spin_unlock_irq(&phba->hbalock); | |
3994 | ||
3995 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
3996 | psli->stats_start = get_seconds(); | |
3997 | ||
75baf696 JS |
3998 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3999 | if (hba_aer_enabled) | |
4000 | pci_disable_pcie_error_reporting(phba->pcidev); | |
4001 | ||
da0436e9 JS |
4002 | lpfc_hba_down_post(phba); |
4003 | ||
4004 | return 0; | |
4005 | } | |
4006 | ||
4007 | /** | |
4008 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
4009 | * @phba: Pointer to HBA context object. | |
4010 | * | |
4011 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
4012 | * API jump table function pointer from the lpfc_hba struct. | |
4013 | **/ | |
4014 | int | |
4015 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
4016 | { | |
4017 | return phba->lpfc_sli_brdrestart(phba); | |
4018 | } | |
4019 | ||
e59058c4 | 4020 | /** |
3621a710 | 4021 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
4022 | * @phba: Pointer to HBA context object. |
4023 | * | |
4024 | * This function is called after a HBA restart to wait for successful | |
4025 | * restart of the HBA. Successful restart of the HBA is indicated by | |
4026 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
4027 | * iteration, the function will restart the HBA again. The function returns | |
4028 | * zero if HBA successfully restarted else returns negative error code. | |
4029 | **/ | |
dea3101e JB |
4030 | static int |
4031 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
4032 | { | |
4033 | uint32_t status, i = 0; | |
4034 | ||
4035 | /* Read the HBA Host Status Register */ | |
4036 | status = readl(phba->HSregaddr); | |
4037 | ||
4038 | /* Check status register to see what current state is */ | |
4039 | i = 0; | |
4040 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
4041 | ||
dcf2a4e0 JS |
4042 | /* Check every 10ms for 10 retries, then every 100ms for 90 |
4043 | * retries, then every 1 sec for 50 retires for a total of | |
4044 | * ~60 seconds before reset the board again and check every | |
4045 | * 1 sec for 50 retries. The up to 60 seconds before the | |
4046 | * board ready is required by the Falcon FIPS zeroization | |
4047 | * complete, and any reset the board in between shall cause | |
4048 | * restart of zeroization, further delay the board ready. | |
dea3101e | 4049 | */ |
dcf2a4e0 | 4050 | if (i++ >= 200) { |
dea3101e JB |
4051 | /* Adapter failed to init, timeout, status reg |
4052 | <status> */ | |
ed957684 | 4053 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4054 | "0436 Adapter failed to init, " |
09372820 JS |
4055 | "timeout, status reg x%x, " |
4056 | "FW Data: A8 x%x AC x%x\n", status, | |
4057 | readl(phba->MBslimaddr + 0xa8), | |
4058 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4059 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4060 | return -ETIMEDOUT; |
4061 | } | |
4062 | ||
4063 | /* Check to see if any errors occurred during init */ | |
4064 | if (status & HS_FFERM) { | |
4065 | /* ERROR: During chipset initialization */ | |
4066 | /* Adapter failed to init, chipset, status reg | |
4067 | <status> */ | |
ed957684 | 4068 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4069 | "0437 Adapter failed to init, " |
09372820 JS |
4070 | "chipset, status reg x%x, " |
4071 | "FW Data: A8 x%x AC x%x\n", status, | |
4072 | readl(phba->MBslimaddr + 0xa8), | |
4073 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4074 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4075 | return -EIO; |
4076 | } | |
4077 | ||
dcf2a4e0 | 4078 | if (i <= 10) |
dea3101e | 4079 | msleep(10); |
dcf2a4e0 JS |
4080 | else if (i <= 100) |
4081 | msleep(100); | |
4082 | else | |
4083 | msleep(1000); | |
dea3101e | 4084 | |
dcf2a4e0 JS |
4085 | if (i == 150) { |
4086 | /* Do post */ | |
92d7f7b0 | 4087 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4088 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4089 | } |
4090 | /* Read the HBA Host Status Register */ | |
4091 | status = readl(phba->HSregaddr); | |
4092 | } | |
4093 | ||
4094 | /* Check to see if any errors occurred during init */ | |
4095 | if (status & HS_FFERM) { | |
4096 | /* ERROR: During chipset initialization */ | |
4097 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 4098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4099 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
4100 | "status reg x%x, " |
4101 | "FW Data: A8 x%x AC x%x\n", status, | |
4102 | readl(phba->MBslimaddr + 0xa8), | |
4103 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 4104 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4105 | return -EIO; |
4106 | } | |
4107 | ||
4108 | /* Clear all interrupt enable conditions */ | |
4109 | writel(0, phba->HCregaddr); | |
4110 | readl(phba->HCregaddr); /* flush */ | |
4111 | ||
4112 | /* setup host attn register */ | |
4113 | writel(0xffffffff, phba->HAregaddr); | |
4114 | readl(phba->HAregaddr); /* flush */ | |
4115 | return 0; | |
4116 | } | |
4117 | ||
e59058c4 | 4118 | /** |
3621a710 | 4119 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
4120 | * |
4121 | * This function calculates and returns the number of HBQs required to be | |
4122 | * configured. | |
4123 | **/ | |
78b2d852 | 4124 | int |
ed957684 JS |
4125 | lpfc_sli_hbq_count(void) |
4126 | { | |
92d7f7b0 | 4127 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
4128 | } |
4129 | ||
e59058c4 | 4130 | /** |
3621a710 | 4131 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
4132 | * |
4133 | * This function adds the number of hbq entries in every HBQ to get | |
4134 | * the total number of hbq entries required for the HBA and returns | |
4135 | * the total count. | |
4136 | **/ | |
ed957684 JS |
4137 | static int |
4138 | lpfc_sli_hbq_entry_count(void) | |
4139 | { | |
4140 | int hbq_count = lpfc_sli_hbq_count(); | |
4141 | int count = 0; | |
4142 | int i; | |
4143 | ||
4144 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 4145 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
4146 | return count; |
4147 | } | |
4148 | ||
e59058c4 | 4149 | /** |
3621a710 | 4150 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
4151 | * |
4152 | * This function calculates amount of memory required for all hbq entries | |
4153 | * to be configured and returns the total memory required. | |
4154 | **/ | |
dea3101e | 4155 | int |
ed957684 JS |
4156 | lpfc_sli_hbq_size(void) |
4157 | { | |
4158 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
4159 | } | |
4160 | ||
e59058c4 | 4161 | /** |
3621a710 | 4162 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
4163 | * @phba: Pointer to HBA context object. |
4164 | * | |
4165 | * This function is called during the SLI initialization to configure | |
4166 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4167 | * required to hold any locks. This function will return zero if successful | |
4168 | * else it will return negative error code. | |
4169 | **/ | |
ed957684 JS |
4170 | static int |
4171 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
4172 | { | |
4173 | int hbq_count = lpfc_sli_hbq_count(); | |
4174 | LPFC_MBOXQ_t *pmb; | |
4175 | MAILBOX_t *pmbox; | |
4176 | uint32_t hbqno; | |
4177 | uint32_t hbq_entry_index; | |
ed957684 | 4178 | |
92d7f7b0 JS |
4179 | /* Get a Mailbox buffer to setup mailbox |
4180 | * commands for HBA initialization | |
4181 | */ | |
ed957684 JS |
4182 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4183 | ||
4184 | if (!pmb) | |
4185 | return -ENOMEM; | |
4186 | ||
04c68496 | 4187 | pmbox = &pmb->u.mb; |
ed957684 JS |
4188 | |
4189 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
4190 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 4191 | phba->hbq_in_use = 1; |
ed957684 JS |
4192 | |
4193 | hbq_entry_index = 0; | |
4194 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
4195 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
4196 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
4197 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
4198 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 4199 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
4200 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
4201 | hbq_entry_index, pmb); | |
ed957684 JS |
4202 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
4203 | ||
4204 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
4205 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
4206 | mbxStatus <status>, ring <num> */ | |
4207 | ||
4208 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 4209 | LOG_SLI | LOG_VPORT, |
e8b62011 | 4210 | "1805 Adapter failed to init. " |
ed957684 | 4211 | "Data: x%x x%x x%x\n", |
e8b62011 | 4212 | pmbox->mbxCommand, |
ed957684 JS |
4213 | pmbox->mbxStatus, hbqno); |
4214 | ||
4215 | phba->link_state = LPFC_HBA_ERROR; | |
4216 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 4217 | return -ENXIO; |
ed957684 JS |
4218 | } |
4219 | } | |
4220 | phba->hbq_count = hbq_count; | |
4221 | ||
ed957684 JS |
4222 | mempool_free(pmb, phba->mbox_mem_pool); |
4223 | ||
92d7f7b0 | 4224 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
4225 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
4226 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
4227 | return 0; |
4228 | } | |
4229 | ||
4f774513 JS |
4230 | /** |
4231 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
4232 | * @phba: Pointer to HBA context object. | |
4233 | * | |
4234 | * This function is called during the SLI initialization to configure | |
4235 | * all the HBQs and post buffers to the HBQ. The caller is not | |
4236 | * required to hold any locks. This function will return zero if successful | |
4237 | * else it will return negative error code. | |
4238 | **/ | |
4239 | static int | |
4240 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
4241 | { | |
4242 | phba->hbq_in_use = 1; | |
4243 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
4244 | phba->hbq_count = 1; | |
4245 | /* Initially populate or replenish the HBQs */ | |
4246 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
4247 | return 0; | |
4248 | } | |
4249 | ||
e59058c4 | 4250 | /** |
3621a710 | 4251 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
4252 | * @phba: Pointer to HBA context object. |
4253 | * @sli_mode: sli mode - 2/3 | |
4254 | * | |
4255 | * This function is called by the sli intialization code path | |
4256 | * to issue config_port mailbox command. This function restarts the | |
4257 | * HBA firmware and issues a config_port mailbox command to configure | |
4258 | * the SLI interface in the sli mode specified by sli_mode | |
4259 | * variable. The caller is not required to hold any locks. | |
4260 | * The function returns 0 if successful, else returns negative error | |
4261 | * code. | |
4262 | **/ | |
9399627f JS |
4263 | int |
4264 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
4265 | { |
4266 | LPFC_MBOXQ_t *pmb; | |
4267 | uint32_t resetcount = 0, rc = 0, done = 0; | |
4268 | ||
4269 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4270 | if (!pmb) { | |
2e0fef85 | 4271 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
4272 | return -ENOMEM; |
4273 | } | |
4274 | ||
ed957684 | 4275 | phba->sli_rev = sli_mode; |
dea3101e | 4276 | while (resetcount < 2 && !done) { |
2e0fef85 | 4277 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4278 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4279 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 4280 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 4281 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
4282 | rc = lpfc_sli_chipset_init(phba); |
4283 | if (rc) | |
4284 | break; | |
4285 | ||
2e0fef85 | 4286 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 4287 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4288 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4289 | resetcount++; |
4290 | ||
ed957684 JS |
4291 | /* Call pre CONFIG_PORT mailbox command initialization. A |
4292 | * value of 0 means the call was successful. Any other | |
4293 | * nonzero value is a failure, but if ERESTART is returned, | |
4294 | * the driver may reset the HBA and try again. | |
4295 | */ | |
dea3101e JB |
4296 | rc = lpfc_config_port_prep(phba); |
4297 | if (rc == -ERESTART) { | |
ed957684 | 4298 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 4299 | continue; |
34b02dcd | 4300 | } else if (rc) |
dea3101e | 4301 | break; |
2e0fef85 | 4302 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
4303 | lpfc_config_port(phba, pmb); |
4304 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
4305 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
4306 | LPFC_SLI3_HBQ_ENABLED | | |
4307 | LPFC_SLI3_CRP_ENABLED | | |
bc73905a JS |
4308 | LPFC_SLI3_BG_ENABLED | |
4309 | LPFC_SLI3_DSS_ENABLED); | |
ed957684 | 4310 | if (rc != MBX_SUCCESS) { |
dea3101e | 4311 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4312 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 4313 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 4314 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 4315 | spin_lock_irq(&phba->hbalock); |
04c68496 | 4316 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
4317 | spin_unlock_irq(&phba->hbalock); |
4318 | rc = -ENXIO; | |
04c68496 JS |
4319 | } else { |
4320 | /* Allow asynchronous mailbox command to go through */ | |
4321 | spin_lock_irq(&phba->hbalock); | |
4322 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4323 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 4324 | done = 1; |
04c68496 | 4325 | } |
dea3101e | 4326 | } |
ed957684 JS |
4327 | if (!done) { |
4328 | rc = -EINVAL; | |
4329 | goto do_prep_failed; | |
4330 | } | |
04c68496 JS |
4331 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
4332 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
4333 | rc = -ENXIO; |
4334 | goto do_prep_failed; | |
4335 | } | |
04c68496 | 4336 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 4337 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
4338 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
4339 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
4340 | phba->max_vpi : phba->max_vports; | |
4341 | ||
34b02dcd JS |
4342 | } else |
4343 | phba->max_vpi = 0; | |
bc73905a JS |
4344 | phba->fips_level = 0; |
4345 | phba->fips_spec_rev = 0; | |
4346 | if (pmb->u.mb.un.varCfgPort.gdss) { | |
04c68496 | 4347 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; |
bc73905a JS |
4348 | phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level; |
4349 | phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev; | |
4350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4351 | "2850 Security Crypto Active. FIPS x%d " | |
4352 | "(Spec Rev: x%d)", | |
4353 | phba->fips_level, phba->fips_spec_rev); | |
4354 | } | |
4355 | if (pmb->u.mb.un.varCfgPort.sec_err) { | |
4356 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4357 | "2856 Config Port Security Crypto " | |
4358 | "Error: x%x ", | |
4359 | pmb->u.mb.un.varCfgPort.sec_err); | |
4360 | } | |
04c68496 | 4361 | if (pmb->u.mb.un.varCfgPort.gerbm) |
34b02dcd | 4362 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 4363 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 4364 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
4365 | |
4366 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
4367 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
4368 | |
4369 | if (phba->cfg_enable_bg) { | |
04c68496 | 4370 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
4371 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
4372 | else | |
4373 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4374 | "0443 Adapter did not grant " | |
4375 | "BlockGuard\n"); | |
4376 | } | |
34b02dcd | 4377 | } else { |
8f34f4ce | 4378 | phba->hbq_get = NULL; |
34b02dcd | 4379 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 4380 | phba->max_vpi = 0; |
ed957684 | 4381 | } |
92d7f7b0 | 4382 | do_prep_failed: |
ed957684 JS |
4383 | mempool_free(pmb, phba->mbox_mem_pool); |
4384 | return rc; | |
4385 | } | |
4386 | ||
e59058c4 JS |
4387 | |
4388 | /** | |
3621a710 | 4389 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
4390 | * @phba: Pointer to HBA context object. |
4391 | * | |
4392 | * This function is the main SLI intialization function. This function | |
4393 | * is called by the HBA intialization code, HBA reset code and HBA | |
4394 | * error attention handler code. Caller is not required to hold any | |
4395 | * locks. This function issues config_port mailbox command to configure | |
4396 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
4397 | * calls the config_port_post function to issue init_link mailbox | |
4398 | * command and to start the discovery. The function will return zero | |
4399 | * if successful, else it will return negative error code. | |
4400 | **/ | |
ed957684 JS |
4401 | int |
4402 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
4403 | { | |
4404 | uint32_t rc; | |
92d7f7b0 | 4405 | int mode = 3; |
ed957684 JS |
4406 | |
4407 | switch (lpfc_sli_mode) { | |
4408 | case 2: | |
78b2d852 | 4409 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4410 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4411 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4412 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4413 | lpfc_sli_mode); |
92d7f7b0 JS |
4414 | break; |
4415 | } | |
ed957684 JS |
4416 | mode = 2; |
4417 | break; | |
4418 | case 0: | |
4419 | case 3: | |
4420 | break; | |
4421 | default: | |
92d7f7b0 | 4422 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4423 | "1819 Unrecognized lpfc_sli_mode " |
4424 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4425 | |
4426 | break; | |
4427 | } | |
4428 | ||
9399627f JS |
4429 | rc = lpfc_sli_config_port(phba, mode); |
4430 | ||
ed957684 | 4431 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4432 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4433 | "1820 Unable to select SLI-3. " |
4434 | "Not supported by adapter.\n"); | |
ed957684 | 4435 | if (rc && mode != 2) |
9399627f | 4436 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4437 | if (rc) |
dea3101e JB |
4438 | goto lpfc_sli_hba_setup_error; |
4439 | ||
0d878419 JS |
4440 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4441 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4442 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4443 | if (!rc) { | |
4444 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4445 | "2709 This device supports " | |
4446 | "Advanced Error Reporting (AER)\n"); | |
4447 | spin_lock_irq(&phba->hbalock); | |
4448 | phba->hba_flag |= HBA_AER_ENABLED; | |
4449 | spin_unlock_irq(&phba->hbalock); | |
4450 | } else { | |
4451 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4452 | "2708 This device does not support " | |
4453 | "Advanced Error Reporting (AER)\n"); | |
4454 | phba->cfg_aer_support = 0; | |
4455 | } | |
4456 | } | |
4457 | ||
ed957684 JS |
4458 | if (phba->sli_rev == 3) { |
4459 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4460 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4461 | } else { |
4462 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4463 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4464 | phba->sli3_options = 0; |
ed957684 JS |
4465 | } |
4466 | ||
4467 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4468 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4469 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4470 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
4471 | |
4472 | if (rc) | |
4473 | goto lpfc_sli_hba_setup_error; | |
4474 | ||
9399627f | 4475 | /* Init HBQs */ |
ed957684 JS |
4476 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4477 | rc = lpfc_sli_hbq_setup(phba); | |
4478 | if (rc) | |
4479 | goto lpfc_sli_hba_setup_error; | |
4480 | } | |
04c68496 | 4481 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4482 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4483 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4484 | |
4485 | rc = lpfc_config_port_post(phba); | |
4486 | if (rc) | |
4487 | goto lpfc_sli_hba_setup_error; | |
4488 | ||
ed957684 JS |
4489 | return rc; |
4490 | ||
92d7f7b0 | 4491 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4492 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4493 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4494 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
4495 | return rc; |
4496 | } | |
4497 | ||
e59058c4 | 4498 | /** |
da0436e9 JS |
4499 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4500 | * @phba: Pointer to HBA context object. | |
4501 | * @mboxq: mailbox pointer. | |
4502 | * This function issue a dump mailbox command to read config region | |
4503 | * 23 and parse the records in the region and populate driver | |
4504 | * data structure. | |
e59058c4 | 4505 | **/ |
da0436e9 JS |
4506 | static int |
4507 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, | |
4508 | LPFC_MBOXQ_t *mboxq) | |
dea3101e | 4509 | { |
da0436e9 JS |
4510 | struct lpfc_dmabuf *mp; |
4511 | struct lpfc_mqe *mqe; | |
4512 | uint32_t data_length; | |
4513 | int rc; | |
dea3101e | 4514 | |
da0436e9 JS |
4515 | /* Program the default value of vlan_id and fc_map */ |
4516 | phba->valid_vlan = 0; | |
4517 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4518 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4519 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4520 | |
da0436e9 JS |
4521 | mqe = &mboxq->u.mqe; |
4522 | if (lpfc_dump_fcoe_param(phba, mboxq)) | |
4523 | return -ENOMEM; | |
4524 | ||
4525 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4526 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4527 | ||
4528 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4529 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4530 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4531 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4532 | "CQ: x%x x%x x%x x%x\n", | |
4533 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4534 | bf_get(lpfc_mqe_command, mqe), | |
4535 | bf_get(lpfc_mqe_status, mqe), | |
4536 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4537 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4538 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4539 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4540 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4541 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4542 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4543 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4544 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4545 | mboxq->mcqe.word0, | |
4546 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4547 | mboxq->mcqe.trailer); | |
4548 | ||
4549 | if (rc) { | |
4550 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4551 | kfree(mp); | |
4552 | return -EIO; | |
4553 | } | |
4554 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4555 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4556 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4557 | kfree(mp); | |
da0436e9 | 4558 | return -EIO; |
d11e31dd | 4559 | } |
dea3101e | 4560 | |
da0436e9 JS |
4561 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4562 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4563 | kfree(mp); | |
4564 | return 0; | |
4565 | } | |
e59058c4 JS |
4566 | |
4567 | /** | |
da0436e9 JS |
4568 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4569 | * @phba: pointer to lpfc hba data structure. | |
4570 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4571 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4572 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4573 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4574 | * |
da0436e9 JS |
4575 | * This routine executes a READ_REV SLI4 mailbox command. In |
4576 | * addition, this routine gets the port vpd data. | |
4577 | * | |
4578 | * Return codes | |
af901ca1 | 4579 | * 0 - successful |
d439d286 | 4580 | * -ENOMEM - could not allocated memory. |
e59058c4 | 4581 | **/ |
da0436e9 JS |
4582 | static int |
4583 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4584 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4585 | { |
da0436e9 JS |
4586 | int rc = 0; |
4587 | uint32_t dma_size; | |
4588 | struct lpfc_dmabuf *dmabuf; | |
4589 | struct lpfc_mqe *mqe; | |
dea3101e | 4590 | |
da0436e9 JS |
4591 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4592 | if (!dmabuf) | |
4593 | return -ENOMEM; | |
4594 | ||
4595 | /* | |
4596 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4597 | * mailbox command. | |
a257bf90 | 4598 | */ |
da0436e9 JS |
4599 | dma_size = *vpd_size; |
4600 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4601 | dma_size, | |
4602 | &dmabuf->phys, | |
4603 | GFP_KERNEL); | |
4604 | if (!dmabuf->virt) { | |
4605 | kfree(dmabuf); | |
4606 | return -ENOMEM; | |
a257bf90 | 4607 | } |
da0436e9 | 4608 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4609 | |
da0436e9 JS |
4610 | /* |
4611 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4612 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4613 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4614 | */ |
da0436e9 JS |
4615 | lpfc_read_rev(phba, mboxq); |
4616 | mqe = &mboxq->u.mqe; | |
4617 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4618 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4619 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4620 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4621 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4622 | ||
4623 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4624 | if (rc) { | |
4625 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4626 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4627 | kfree(dmabuf); |
da0436e9 JS |
4628 | return -EIO; |
4629 | } | |
1dcb58e5 | 4630 | |
da0436e9 JS |
4631 | /* |
4632 | * The available vpd length cannot be bigger than the | |
4633 | * DMA buffer passed to the port. Catch the less than | |
4634 | * case and update the caller's size. | |
4635 | */ | |
4636 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4637 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4638 | |
d7c47992 JS |
4639 | memcpy(vpd, dmabuf->virt, *vpd_size); |
4640 | ||
da0436e9 JS |
4641 | dma_free_coherent(&phba->pcidev->dev, dma_size, |
4642 | dmabuf->virt, dmabuf->phys); | |
4643 | kfree(dmabuf); | |
4644 | return 0; | |
dea3101e JB |
4645 | } |
4646 | ||
e59058c4 | 4647 | /** |
da0436e9 JS |
4648 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4649 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4650 | * |
da0436e9 JS |
4651 | * This routine is called to explicitly arm the SLI4 device's completion and |
4652 | * event queues | |
4653 | **/ | |
4654 | static void | |
4655 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4656 | { | |
4657 | uint8_t fcp_eqidx; | |
4658 | ||
4659 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4660 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
da0436e9 JS |
4661 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) |
4662 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], | |
4663 | LPFC_QUEUE_REARM); | |
4664 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); | |
4665 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | |
4666 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | |
4667 | LPFC_QUEUE_REARM); | |
4668 | } | |
4669 | ||
4670 | /** | |
4671 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
4672 | * @phba: Pointer to HBA context object. | |
4673 | * | |
4674 | * This function is the main SLI4 device intialization PCI function. This | |
4675 | * function is called by the HBA intialization code, HBA reset code and | |
4676 | * HBA error attention handler code. Caller is not required to hold any | |
4677 | * locks. | |
4678 | **/ | |
4679 | int | |
4680 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
4681 | { | |
4682 | int rc; | |
4683 | LPFC_MBOXQ_t *mboxq; | |
4684 | struct lpfc_mqe *mqe; | |
4685 | uint8_t *vpd; | |
4686 | uint32_t vpd_size; | |
4687 | uint32_t ftr_rsp = 0; | |
4688 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
4689 | struct lpfc_vport *vport = phba->pport; | |
4690 | struct lpfc_dmabuf *mp; | |
4691 | ||
4692 | /* Perform a PCI function reset to start from clean */ | |
4693 | rc = lpfc_pci_function_reset(phba); | |
4694 | if (unlikely(rc)) | |
4695 | return -ENODEV; | |
4696 | ||
4697 | /* Check the HBA Host Status Register for readyness */ | |
4698 | rc = lpfc_sli4_post_status_check(phba); | |
4699 | if (unlikely(rc)) | |
4700 | return -ENODEV; | |
4701 | else { | |
4702 | spin_lock_irq(&phba->hbalock); | |
4703 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
4704 | spin_unlock_irq(&phba->hbalock); | |
4705 | } | |
4706 | ||
4707 | /* | |
4708 | * Allocate a single mailbox container for initializing the | |
4709 | * port. | |
4710 | */ | |
4711 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4712 | if (!mboxq) | |
4713 | return -ENOMEM; | |
4714 | ||
4715 | /* | |
4716 | * Continue initialization with default values even if driver failed | |
4717 | * to read FCoE param config regions | |
4718 | */ | |
4719 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) | |
4720 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
e4e74273 | 4721 | "2570 Failed to read FCoE parameters\n"); |
da0436e9 JS |
4722 | |
4723 | /* Issue READ_REV to collect vpd and FW information. */ | |
49198b37 | 4724 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
4725 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
4726 | if (!vpd) { | |
4727 | rc = -ENOMEM; | |
4728 | goto out_free_mbox; | |
4729 | } | |
4730 | ||
4731 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
76a95d75 JS |
4732 | if (unlikely(rc)) { |
4733 | kfree(vpd); | |
4734 | goto out_free_mbox; | |
4735 | } | |
da0436e9 | 4736 | mqe = &mboxq->u.mqe; |
f1126688 JS |
4737 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
4738 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
76a95d75 JS |
4739 | phba->hba_flag |= HBA_FCOE_MODE; |
4740 | else | |
4741 | phba->hba_flag &= ~HBA_FCOE_MODE; | |
45ed1190 JS |
4742 | |
4743 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
4744 | LPFC_DCBX_CEE_MODE) | |
4745 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
4746 | else | |
4747 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
4748 | ||
f1126688 | 4749 | if (phba->sli_rev != LPFC_SLI_REV4 || |
76a95d75 | 4750 | !(phba->hba_flag & HBA_FCOE_MODE)) { |
da0436e9 JS |
4751 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4752 | "0376 READ_REV Error. SLI Level %d " | |
4753 | "FCoE enabled %d\n", | |
76a95d75 | 4754 | phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE); |
da0436e9 | 4755 | rc = -EIO; |
76a95d75 JS |
4756 | kfree(vpd); |
4757 | goto out_free_mbox; | |
da0436e9 | 4758 | } |
da0436e9 JS |
4759 | /* |
4760 | * Evaluate the read rev and vpd data. Populate the driver | |
4761 | * state with the results. If this routine fails, the failure | |
4762 | * is not fatal as the driver will use generic values. | |
4763 | */ | |
4764 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
4765 | if (unlikely(!rc)) { | |
4766 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4767 | "0377 Error %d parsing vpd. " | |
4768 | "Using defaults.\n", rc); | |
4769 | rc = 0; | |
4770 | } | |
76a95d75 | 4771 | kfree(vpd); |
da0436e9 | 4772 | |
f1126688 JS |
4773 | /* Save information as VPD data */ |
4774 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
4775 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
4776 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
4777 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
4778 | &mqe->un.read_rev); | |
4779 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
4780 | &mqe->un.read_rev); | |
4781 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
4782 | &mqe->un.read_rev); | |
4783 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
4784 | &mqe->un.read_rev); | |
4785 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
4786 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
4787 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
4788 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
4789 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
4790 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
4791 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4792 | "(%d):0380 READ_REV Status x%x " | |
4793 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
4794 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4795 | bf_get(lpfc_mqe_status, mqe), | |
4796 | phba->vpd.rev.opFwName, | |
4797 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
4798 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
4799 | |
4800 | /* | |
4801 | * Discover the port's supported feature set and match it against the | |
4802 | * hosts requests. | |
4803 | */ | |
4804 | lpfc_request_features(phba, mboxq); | |
4805 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4806 | if (unlikely(rc)) { | |
4807 | rc = -EIO; | |
76a95d75 | 4808 | goto out_free_mbox; |
da0436e9 JS |
4809 | } |
4810 | ||
4811 | /* | |
4812 | * The port must support FCP initiator mode as this is the | |
4813 | * only mode running in the host. | |
4814 | */ | |
4815 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
4816 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4817 | "0378 No support for fcpi mode.\n"); | |
4818 | ftr_rsp++; | |
4819 | } | |
4820 | ||
4821 | /* | |
4822 | * If the port cannot support the host's requested features | |
4823 | * then turn off the global config parameters to disable the | |
4824 | * feature in the driver. This is not a fatal error. | |
4825 | */ | |
4826 | if ((phba->cfg_enable_bg) && | |
4827 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4828 | ftr_rsp++; | |
4829 | ||
4830 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
4831 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4832 | ftr_rsp++; | |
4833 | ||
4834 | if (ftr_rsp) { | |
4835 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4836 | "0379 Feature Mismatch Data: x%08x %08x " | |
4837 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
4838 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
4839 | phba->cfg_enable_npiv, phba->max_vpi); | |
4840 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4841 | phba->cfg_enable_bg = 0; | |
4842 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4843 | phba->cfg_enable_npiv = 0; | |
4844 | } | |
4845 | ||
4846 | /* These SLI3 features are assumed in SLI4 */ | |
4847 | spin_lock_irq(&phba->hbalock); | |
4848 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
4849 | spin_unlock_irq(&phba->hbalock); | |
4850 | ||
4851 | /* Read the port's service parameters. */ | |
9f1177a3 JS |
4852 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
4853 | if (rc) { | |
4854 | phba->link_state = LPFC_HBA_ERROR; | |
4855 | rc = -ENOMEM; | |
76a95d75 | 4856 | goto out_free_mbox; |
9f1177a3 JS |
4857 | } |
4858 | ||
da0436e9 JS |
4859 | mboxq->vport = vport; |
4860 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4861 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4862 | if (rc == MBX_SUCCESS) { | |
4863 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
4864 | rc = 0; | |
4865 | } | |
4866 | ||
4867 | /* | |
4868 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
4869 | * it to the mbuf pool. | |
4870 | */ | |
4871 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4872 | kfree(mp); | |
4873 | mboxq->context1 = NULL; | |
4874 | if (unlikely(rc)) { | |
4875 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4876 | "0382 READ_SPARAM command failed " | |
4877 | "status %d, mbxStatus x%x\n", | |
4878 | rc, bf_get(lpfc_mqe_status, mqe)); | |
4879 | phba->link_state = LPFC_HBA_ERROR; | |
4880 | rc = -EIO; | |
76a95d75 | 4881 | goto out_free_mbox; |
da0436e9 JS |
4882 | } |
4883 | ||
4884 | if (phba->cfg_soft_wwnn) | |
4885 | u64_to_wwn(phba->cfg_soft_wwnn, | |
4886 | vport->fc_sparam.nodeName.u.wwn); | |
4887 | if (phba->cfg_soft_wwpn) | |
4888 | u64_to_wwn(phba->cfg_soft_wwpn, | |
4889 | vport->fc_sparam.portName.u.wwn); | |
4890 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
4891 | sizeof(struct lpfc_name)); | |
4892 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
4893 | sizeof(struct lpfc_name)); | |
4894 | ||
4895 | /* Update the fc_host data structures with new wwn. */ | |
4896 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
4897 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
4898 | ||
4899 | /* Register SGL pool to the device using non-embedded mailbox command */ | |
4900 | rc = lpfc_sli4_post_sgl_list(phba); | |
4901 | if (unlikely(rc)) { | |
4902 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4903 | "0582 Error %d during sgl post operation\n", |
4904 | rc); | |
da0436e9 | 4905 | rc = -ENODEV; |
76a95d75 | 4906 | goto out_free_mbox; |
da0436e9 JS |
4907 | } |
4908 | ||
4909 | /* Register SCSI SGL pool to the device */ | |
4910 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
4911 | if (unlikely(rc)) { | |
4912 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4913 | "0383 Error %d during scsi sgl post " |
4914 | "operation\n", rc); | |
da0436e9 JS |
4915 | /* Some Scsi buffers were moved to the abort scsi list */ |
4916 | /* A pci function reset will repost them */ | |
4917 | rc = -ENODEV; | |
76a95d75 | 4918 | goto out_free_mbox; |
da0436e9 JS |
4919 | } |
4920 | ||
4921 | /* Post the rpi header region to the device. */ | |
4922 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
4923 | if (unlikely(rc)) { | |
4924 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4925 | "0393 Error %d during rpi post operation\n", | |
4926 | rc); | |
4927 | rc = -ENODEV; | |
76a95d75 | 4928 | goto out_free_mbox; |
da0436e9 | 4929 | } |
da0436e9 JS |
4930 | |
4931 | /* Set up all the queues to the device */ | |
4932 | rc = lpfc_sli4_queue_setup(phba); | |
4933 | if (unlikely(rc)) { | |
4934 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4935 | "0381 Error %d during queue setup.\n ", rc); | |
4936 | goto out_stop_timers; | |
4937 | } | |
4938 | ||
4939 | /* Arm the CQs and then EQs on device */ | |
4940 | lpfc_sli4_arm_cqeq_intr(phba); | |
4941 | ||
4942 | /* Indicate device interrupt mode */ | |
4943 | phba->sli4_hba.intr_enable = 1; | |
4944 | ||
4945 | /* Allow asynchronous mailbox command to go through */ | |
4946 | spin_lock_irq(&phba->hbalock); | |
4947 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4948 | spin_unlock_irq(&phba->hbalock); | |
4949 | ||
4950 | /* Post receive buffers to the device */ | |
4951 | lpfc_sli4_rb_setup(phba); | |
4952 | ||
fc2b989b JS |
4953 | /* Reset HBA FCF states after HBA reset */ |
4954 | phba->fcf.fcf_flag = 0; | |
4955 | phba->fcf.current_rec.flag = 0; | |
4956 | ||
da0436e9 | 4957 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
4958 | mod_timer(&vport->els_tmofunc, |
4959 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
4960 | |
4961 | /* Start heart beat timer */ | |
4962 | mod_timer(&phba->hb_tmofunc, | |
4963 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
4964 | phba->hb_outstanding = 0; | |
4965 | phba->last_completion_time = jiffies; | |
4966 | ||
4967 | /* Start error attention (ERATT) polling timer */ | |
4968 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
4969 | ||
75baf696 JS |
4970 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4971 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4972 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4973 | if (!rc) { | |
4974 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4975 | "2829 This device supports " | |
4976 | "Advanced Error Reporting (AER)\n"); | |
4977 | spin_lock_irq(&phba->hbalock); | |
4978 | phba->hba_flag |= HBA_AER_ENABLED; | |
4979 | spin_unlock_irq(&phba->hbalock); | |
4980 | } else { | |
4981 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4982 | "2830 This device does not support " | |
4983 | "Advanced Error Reporting (AER)\n"); | |
4984 | phba->cfg_aer_support = 0; | |
4985 | } | |
4986 | } | |
4987 | ||
76a95d75 JS |
4988 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
4989 | /* | |
4990 | * The FC Port needs to register FCFI (index 0) | |
4991 | */ | |
4992 | lpfc_reg_fcfi(phba, mboxq); | |
4993 | mboxq->vport = phba->pport; | |
4994 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4995 | if (rc == MBX_SUCCESS) | |
4996 | rc = 0; | |
4997 | else | |
4998 | goto out_unset_queue; | |
4999 | } | |
da0436e9 JS |
5000 | /* |
5001 | * The port is ready, set the host's link state to LINK_DOWN | |
5002 | * in preparation for link interrupts. | |
5003 | */ | |
da0436e9 JS |
5004 | spin_lock_irq(&phba->hbalock); |
5005 | phba->link_state = LPFC_LINK_DOWN; | |
5006 | spin_unlock_irq(&phba->hbalock); | |
76a95d75 JS |
5007 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
5008 | out_unset_queue: | |
da0436e9 JS |
5009 | /* Unset all the queues set up in this routine when error out */ |
5010 | if (rc) | |
5011 | lpfc_sli4_queue_unset(phba); | |
da0436e9 JS |
5012 | out_stop_timers: |
5013 | if (rc) | |
5014 | lpfc_stop_hba_timers(phba); | |
da0436e9 JS |
5015 | out_free_mbox: |
5016 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5017 | return rc; | |
5018 | } | |
5019 | ||
5020 | /** | |
5021 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
5022 | * @ptr: context object - pointer to hba structure. | |
5023 | * | |
5024 | * This is the callback function for mailbox timer. The mailbox | |
5025 | * timer is armed when a new mailbox command is issued and the timer | |
5026 | * is deleted when the mailbox complete. The function is called by | |
5027 | * the kernel timer code when a mailbox does not complete within | |
5028 | * expected time. This function wakes up the worker thread to | |
5029 | * process the mailbox timeout and returns. All the processing is | |
5030 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
5031 | **/ | |
5032 | void | |
5033 | lpfc_mbox_timeout(unsigned long ptr) | |
5034 | { | |
5035 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
5036 | unsigned long iflag; | |
5037 | uint32_t tmo_posted; | |
5038 | ||
5039 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
5040 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
5041 | if (!tmo_posted) | |
5042 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
5043 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
5044 | ||
5045 | if (!tmo_posted) | |
5046 | lpfc_worker_wake_up(phba); | |
5047 | return; | |
5048 | } | |
5049 | ||
5050 | ||
5051 | /** | |
5052 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
5053 | * @phba: Pointer to HBA context object. | |
5054 | * | |
5055 | * This function is called from worker thread when a mailbox command times out. | |
5056 | * The caller is not required to hold any locks. This function will reset the | |
5057 | * HBA and recover all the pending commands. | |
5058 | **/ | |
5059 | void | |
5060 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
5061 | { | |
5062 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 5063 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
5064 | struct lpfc_sli *psli = &phba->sli; |
5065 | struct lpfc_sli_ring *pring; | |
5066 | ||
5067 | /* Check the pmbox pointer first. There is a race condition | |
5068 | * between the mbox timeout handler getting executed in the | |
5069 | * worklist and the mailbox actually completing. When this | |
5070 | * race condition occurs, the mbox_active will be NULL. | |
5071 | */ | |
5072 | spin_lock_irq(&phba->hbalock); | |
5073 | if (pmbox == NULL) { | |
5074 | lpfc_printf_log(phba, KERN_WARNING, | |
5075 | LOG_MBOX | LOG_SLI, | |
5076 | "0353 Active Mailbox cleared - mailbox timeout " | |
5077 | "exiting\n"); | |
5078 | spin_unlock_irq(&phba->hbalock); | |
5079 | return; | |
5080 | } | |
5081 | ||
5082 | /* Mbox cmd <mbxCommand> timeout */ | |
5083 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5084 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
5085 | mb->mbxCommand, | |
5086 | phba->pport->port_state, | |
5087 | phba->sli.sli_flag, | |
5088 | phba->sli.mbox_active); | |
5089 | spin_unlock_irq(&phba->hbalock); | |
5090 | ||
5091 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
5092 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
5093 | * it to fail all oustanding SCSI IO. | |
5094 | */ | |
5095 | spin_lock_irq(&phba->pport->work_port_lock); | |
5096 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
5097 | spin_unlock_irq(&phba->pport->work_port_lock); | |
5098 | spin_lock_irq(&phba->hbalock); | |
5099 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 5100 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
5101 | spin_unlock_irq(&phba->hbalock); |
5102 | ||
5103 | pring = &psli->ring[psli->fcp_ring]; | |
5104 | lpfc_sli_abort_iocb_ring(phba, pring); | |
5105 | ||
5106 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5107 | "0345 Resetting board due to mailbox timeout\n"); | |
5108 | ||
5109 | /* Reset the HBA device */ | |
5110 | lpfc_reset_hba(phba); | |
5111 | } | |
5112 | ||
5113 | /** | |
5114 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
5115 | * @phba: Pointer to HBA context object. | |
5116 | * @pmbox: Pointer to mailbox object. | |
5117 | * @flag: Flag indicating how the mailbox need to be processed. | |
5118 | * | |
5119 | * This function is called by discovery code and HBA management code | |
5120 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
5121 | * function gets the hbalock to protect the data structures. | |
5122 | * The mailbox command can be submitted in polling mode, in which case | |
5123 | * this function will wait in a polling loop for the completion of the | |
5124 | * mailbox. | |
5125 | * If the mailbox is submitted in no_wait mode (not polling) the | |
5126 | * function will submit the command and returns immediately without waiting | |
5127 | * for the mailbox completion. The no_wait is supported only when HBA | |
5128 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
5129 | * The SLI interface allows only one mailbox pending at a time. If the | |
5130 | * mailbox is issued in polling mode and there is already a mailbox | |
5131 | * pending, then the function will return an error. If the mailbox is issued | |
5132 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
5133 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
5134 | * The sli layer owns the mailbox object until the completion of mailbox | |
5135 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
5136 | * return codes the caller owns the mailbox command after the return of | |
5137 | * the function. | |
e59058c4 | 5138 | **/ |
3772a991 JS |
5139 | static int |
5140 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
5141 | uint32_t flag) | |
dea3101e | 5142 | { |
dea3101e | 5143 | MAILBOX_t *mb; |
2e0fef85 | 5144 | struct lpfc_sli *psli = &phba->sli; |
dea3101e JB |
5145 | uint32_t status, evtctr; |
5146 | uint32_t ha_copy; | |
5147 | int i; | |
09372820 | 5148 | unsigned long timeout; |
dea3101e | 5149 | unsigned long drvr_flag = 0; |
34b02dcd | 5150 | uint32_t word0, ldata; |
dea3101e | 5151 | void __iomem *to_slim; |
58da1ffb JS |
5152 | int processing_queue = 0; |
5153 | ||
5154 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5155 | if (!pmbox) { | |
8568a4d2 | 5156 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 5157 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
5158 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
5159 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5160 | return MBX_SUCCESS; | |
5161 | } | |
58da1ffb | 5162 | processing_queue = 1; |
58da1ffb JS |
5163 | pmbox = lpfc_mbox_get(phba); |
5164 | if (!pmbox) { | |
5165 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5166 | return MBX_SUCCESS; | |
5167 | } | |
5168 | } | |
dea3101e | 5169 | |
ed957684 | 5170 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 5171 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 5172 | if(!pmbox->vport) { |
58da1ffb | 5173 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 5174 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 5175 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 5176 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 5177 | pmbox->u.mb.mbxCommand); |
ed957684 | 5178 | dump_stack(); |
58da1ffb | 5179 | goto out_not_finished; |
ed957684 JS |
5180 | } |
5181 | } | |
5182 | ||
8d63f375 | 5183 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
5184 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
5185 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5186 | goto out_not_finished; | |
5187 | } | |
8d63f375 | 5188 | |
a257bf90 JS |
5189 | /* If HBA has a deferred error attention, fail the iocb. */ |
5190 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
5191 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
5192 | goto out_not_finished; | |
5193 | } | |
5194 | ||
dea3101e | 5195 | psli = &phba->sli; |
92d7f7b0 | 5196 | |
3772a991 | 5197 | mb = &pmbox->u.mb; |
dea3101e JB |
5198 | status = MBX_SUCCESS; |
5199 | ||
2e0fef85 JS |
5200 | if (phba->link_state == LPFC_HBA_ERROR) { |
5201 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
5202 | |
5203 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
5204 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5205 | "(%d):0311 Mailbox command x%x cannot " | |
5206 | "issue Data: x%x x%x\n", | |
5207 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5208 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 5209 | goto out_not_finished; |
41415862 JW |
5210 | } |
5211 | ||
9290831f JS |
5212 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
5213 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { | |
2e0fef85 | 5214 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3772a991 JS |
5215 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5216 | "(%d):2528 Mailbox command x%x cannot " | |
5217 | "issue Data: x%x x%x\n", | |
5218 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5219 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 5220 | goto out_not_finished; |
9290831f JS |
5221 | } |
5222 | ||
dea3101e JB |
5223 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
5224 | /* Polling for a mbox command when another one is already active | |
5225 | * is not allowed in SLI. Also, the driver must have established | |
5226 | * SLI2 mode to queue and process multiple mbox commands. | |
5227 | */ | |
5228 | ||
5229 | if (flag & MBX_POLL) { | |
2e0fef85 | 5230 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
5231 | |
5232 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
5233 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5234 | "(%d):2529 Mailbox command x%x " | |
5235 | "cannot issue Data: x%x x%x\n", | |
5236 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5237 | pmbox->u.mb.mbxCommand, | |
5238 | psli->sli_flag, flag); | |
58da1ffb | 5239 | goto out_not_finished; |
dea3101e JB |
5240 | } |
5241 | ||
3772a991 | 5242 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 5243 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5244 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
5245 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5246 | "(%d):2530 Mailbox command x%x " | |
5247 | "cannot issue Data: x%x x%x\n", | |
5248 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5249 | pmbox->u.mb.mbxCommand, | |
5250 | psli->sli_flag, flag); | |
58da1ffb | 5251 | goto out_not_finished; |
dea3101e JB |
5252 | } |
5253 | ||
dea3101e JB |
5254 | /* Another mailbox command is still being processed, queue this |
5255 | * command to be processed later. | |
5256 | */ | |
5257 | lpfc_mbox_put(phba, pmbox); | |
5258 | ||
5259 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 5260 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 5261 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 5262 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
5263 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
5264 | mb->mbxCommand, phba->pport->port_state, | |
5265 | psli->sli_flag, flag); | |
dea3101e JB |
5266 | |
5267 | psli->slistat.mbox_busy++; | |
2e0fef85 | 5268 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5269 | |
858c9f6c JS |
5270 | if (pmbox->vport) { |
5271 | lpfc_debugfs_disc_trc(pmbox->vport, | |
5272 | LPFC_DISC_TRC_MBOX_VPORT, | |
5273 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
5274 | (uint32_t)mb->mbxCommand, | |
5275 | mb->un.varWords[0], mb->un.varWords[1]); | |
5276 | } | |
5277 | else { | |
5278 | lpfc_debugfs_disc_trc(phba->pport, | |
5279 | LPFC_DISC_TRC_MBOX, | |
5280 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
5281 | (uint32_t)mb->mbxCommand, | |
5282 | mb->un.varWords[0], mb->un.varWords[1]); | |
5283 | } | |
5284 | ||
2e0fef85 | 5285 | return MBX_BUSY; |
dea3101e JB |
5286 | } |
5287 | ||
dea3101e JB |
5288 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
5289 | ||
5290 | /* If we are not polling, we MUST be in SLI2 mode */ | |
5291 | if (flag != MBX_POLL) { | |
3772a991 | 5292 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 5293 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 5294 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5295 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 5296 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
5297 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
5298 | "(%d):2531 Mailbox command x%x " | |
5299 | "cannot issue Data: x%x x%x\n", | |
5300 | pmbox->vport ? pmbox->vport->vpi : 0, | |
5301 | pmbox->u.mb.mbxCommand, | |
5302 | psli->sli_flag, flag); | |
58da1ffb | 5303 | goto out_not_finished; |
dea3101e JB |
5304 | } |
5305 | /* timeout active mbox command */ | |
a309a6b6 JS |
5306 | mod_timer(&psli->mbox_tmo, (jiffies + |
5307 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | |
dea3101e JB |
5308 | } |
5309 | ||
5310 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 5311 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 5312 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 5313 | "x%x\n", |
e8b62011 | 5314 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
5315 | mb->mbxCommand, phba->pport->port_state, |
5316 | psli->sli_flag, flag); | |
dea3101e | 5317 | |
858c9f6c JS |
5318 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
5319 | if (pmbox->vport) { | |
5320 | lpfc_debugfs_disc_trc(pmbox->vport, | |
5321 | LPFC_DISC_TRC_MBOX_VPORT, | |
5322 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5323 | (uint32_t)mb->mbxCommand, | |
5324 | mb->un.varWords[0], mb->un.varWords[1]); | |
5325 | } | |
5326 | else { | |
5327 | lpfc_debugfs_disc_trc(phba->pport, | |
5328 | LPFC_DISC_TRC_MBOX, | |
5329 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5330 | (uint32_t)mb->mbxCommand, | |
5331 | mb->un.varWords[0], mb->un.varWords[1]); | |
5332 | } | |
5333 | } | |
5334 | ||
dea3101e JB |
5335 | psli->slistat.mbox_cmd++; |
5336 | evtctr = psli->slistat.mbox_event; | |
5337 | ||
5338 | /* next set own bit for the adapter and copy over command word */ | |
5339 | mb->mbxOwner = OWN_CHIP; | |
5340 | ||
3772a991 | 5341 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
5342 | /* Populate mbox extension offset word. */ |
5343 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
5344 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
5345 | = (uint8_t *)phba->mbox_ext | |
5346 | - (uint8_t *)phba->mbox; | |
5347 | } | |
5348 | ||
5349 | /* Copy the mailbox extension data */ | |
5350 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
5351 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
5352 | (uint8_t *)phba->mbox_ext, | |
5353 | pmbox->in_ext_byte_len); | |
5354 | } | |
5355 | /* Copy command data to host SLIM area */ | |
34b02dcd | 5356 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 5357 | } else { |
7a470277 JS |
5358 | /* Populate mbox extension offset word. */ |
5359 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
5360 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
5361 | = MAILBOX_HBA_EXT_OFFSET; | |
5362 | ||
5363 | /* Copy the mailbox extension data */ | |
5364 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
5365 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
5366 | MAILBOX_HBA_EXT_OFFSET, | |
5367 | pmbox->context2, pmbox->in_ext_byte_len); | |
5368 | ||
5369 | } | |
9290831f | 5370 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 5371 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 5372 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e JB |
5373 | } |
5374 | ||
5375 | /* First copy mbox command data to HBA SLIM, skip past first | |
5376 | word */ | |
5377 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
5378 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
5379 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
5380 | ||
5381 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 5382 | ldata = *((uint32_t *)mb); |
dea3101e JB |
5383 | to_slim = phba->MBslimaddr; |
5384 | writel(ldata, to_slim); | |
5385 | readl(to_slim); /* flush */ | |
5386 | ||
5387 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5388 | /* switch over to host mailbox */ | |
3772a991 | 5389 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
5390 | } |
5391 | } | |
5392 | ||
5393 | wmb(); | |
dea3101e JB |
5394 | |
5395 | switch (flag) { | |
5396 | case MBX_NOWAIT: | |
09372820 | 5397 | /* Set up reference to mailbox command */ |
dea3101e | 5398 | psli->mbox_active = pmbox; |
09372820 JS |
5399 | /* Interrupt board to do it */ |
5400 | writel(CA_MBATT, phba->CAregaddr); | |
5401 | readl(phba->CAregaddr); /* flush */ | |
5402 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
5403 | break; |
5404 | ||
5405 | case MBX_POLL: | |
09372820 | 5406 | /* Set up null reference to mailbox command */ |
dea3101e | 5407 | psli->mbox_active = NULL; |
09372820 JS |
5408 | /* Interrupt board to do it */ |
5409 | writel(CA_MBATT, phba->CAregaddr); | |
5410 | readl(phba->CAregaddr); /* flush */ | |
5411 | ||
3772a991 | 5412 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5413 | /* First read mbox status word */ |
34b02dcd | 5414 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
5415 | word0 = le32_to_cpu(word0); |
5416 | } else { | |
5417 | /* First read mbox status word */ | |
5418 | word0 = readl(phba->MBslimaddr); | |
5419 | } | |
5420 | ||
5421 | /* Read the HBA Host Attention Register */ | |
5422 | ha_copy = readl(phba->HAregaddr); | |
09372820 JS |
5423 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
5424 | mb->mbxCommand) * | |
5425 | 1000) + jiffies; | |
5426 | i = 0; | |
dea3101e | 5427 | /* Wait for command to complete */ |
41415862 JW |
5428 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
5429 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 5430 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 5431 | if (time_after(jiffies, timeout)) { |
dea3101e | 5432 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5433 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 5434 | drvr_flag); |
58da1ffb | 5435 | goto out_not_finished; |
dea3101e JB |
5436 | } |
5437 | ||
5438 | /* Check if we took a mbox interrupt while we were | |
5439 | polling */ | |
5440 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
5441 | && (evtctr != psli->slistat.mbox_event)) | |
5442 | break; | |
5443 | ||
09372820 JS |
5444 | if (i++ > 10) { |
5445 | spin_unlock_irqrestore(&phba->hbalock, | |
5446 | drvr_flag); | |
5447 | msleep(1); | |
5448 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5449 | } | |
dea3101e | 5450 | |
3772a991 | 5451 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5452 | /* First copy command data */ |
34b02dcd | 5453 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
5454 | word0 = le32_to_cpu(word0); |
5455 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5456 | MAILBOX_t *slimmb; | |
34b02dcd | 5457 | uint32_t slimword0; |
dea3101e JB |
5458 | /* Check real SLIM for any errors */ |
5459 | slimword0 = readl(phba->MBslimaddr); | |
5460 | slimmb = (MAILBOX_t *) & slimword0; | |
5461 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
5462 | && slimmb->mbxStatus) { | |
5463 | psli->sli_flag &= | |
3772a991 | 5464 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
5465 | word0 = slimword0; |
5466 | } | |
5467 | } | |
5468 | } else { | |
5469 | /* First copy command data */ | |
5470 | word0 = readl(phba->MBslimaddr); | |
5471 | } | |
5472 | /* Read the HBA Host Attention Register */ | |
5473 | ha_copy = readl(phba->HAregaddr); | |
5474 | } | |
5475 | ||
3772a991 | 5476 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5477 | /* copy results back to user */ |
34b02dcd | 5478 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
5479 | /* Copy the mailbox extension data */ |
5480 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5481 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
5482 | pmbox->context2, | |
5483 | pmbox->out_ext_byte_len); | |
5484 | } | |
dea3101e JB |
5485 | } else { |
5486 | /* First copy command data */ | |
5487 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
5488 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
5489 | /* Copy the mailbox extension data */ |
5490 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5491 | lpfc_memcpy_from_slim(pmbox->context2, | |
5492 | phba->MBslimaddr + | |
5493 | MAILBOX_HBA_EXT_OFFSET, | |
5494 | pmbox->out_ext_byte_len); | |
dea3101e JB |
5495 | } |
5496 | } | |
5497 | ||
5498 | writel(HA_MBATT, phba->HAregaddr); | |
5499 | readl(phba->HAregaddr); /* flush */ | |
5500 | ||
5501 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5502 | status = mb->mbxStatus; | |
5503 | } | |
5504 | ||
2e0fef85 JS |
5505 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
5506 | return status; | |
58da1ffb JS |
5507 | |
5508 | out_not_finished: | |
5509 | if (processing_queue) { | |
da0436e9 | 5510 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
5511 | lpfc_mbox_cmpl_put(phba, pmbox); |
5512 | } | |
5513 | return MBX_NOT_FINISHED; | |
dea3101e JB |
5514 | } |
5515 | ||
f1126688 JS |
5516 | /** |
5517 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
5518 | * @phba: Pointer to HBA context object. | |
5519 | * | |
5520 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
5521 | * the driver internal pending mailbox queue. It will then try to wait out the | |
5522 | * possible outstanding mailbox command before return. | |
5523 | * | |
5524 | * Returns: | |
5525 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
5526 | * the outstanding mailbox command timed out. | |
5527 | **/ | |
5528 | static int | |
5529 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
5530 | { | |
5531 | struct lpfc_sli *psli = &phba->sli; | |
5532 | uint8_t actcmd = MBX_HEARTBEAT; | |
5533 | int rc = 0; | |
5534 | unsigned long timeout; | |
5535 | ||
5536 | /* Mark the asynchronous mailbox command posting as blocked */ | |
5537 | spin_lock_irq(&phba->hbalock); | |
5538 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
5539 | if (phba->sli.mbox_active) | |
5540 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
5541 | spin_unlock_irq(&phba->hbalock); | |
5542 | /* Determine how long we might wait for the active mailbox | |
5543 | * command to be gracefully completed by firmware. | |
5544 | */ | |
5545 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
5546 | jiffies; | |
5547 | /* Wait for the outstnading mailbox command to complete */ | |
5548 | while (phba->sli.mbox_active) { | |
5549 | /* Check active mailbox complete status every 2ms */ | |
5550 | msleep(2); | |
5551 | if (time_after(jiffies, timeout)) { | |
5552 | /* Timeout, marked the outstanding cmd not complete */ | |
5553 | rc = 1; | |
5554 | break; | |
5555 | } | |
5556 | } | |
5557 | ||
5558 | /* Can not cleanly block async mailbox command, fails it */ | |
5559 | if (rc) { | |
5560 | spin_lock_irq(&phba->hbalock); | |
5561 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5562 | spin_unlock_irq(&phba->hbalock); | |
5563 | } | |
5564 | return rc; | |
5565 | } | |
5566 | ||
5567 | /** | |
5568 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
5569 | * @phba: Pointer to HBA context object. | |
5570 | * | |
5571 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
5572 | * commands from the driver internal pending mailbox queue. It makes sure | |
5573 | * that there is no outstanding mailbox command before resuming posting | |
5574 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
5575 | * mailbox command, it will try to wait it out before resuming asynchronous | |
5576 | * mailbox command posting. | |
5577 | **/ | |
5578 | static void | |
5579 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
5580 | { | |
5581 | struct lpfc_sli *psli = &phba->sli; | |
5582 | ||
5583 | spin_lock_irq(&phba->hbalock); | |
5584 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5585 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
5586 | spin_unlock_irq(&phba->hbalock); | |
5587 | return; | |
5588 | } | |
5589 | ||
5590 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
5591 | * successful or timeout, after timing-out the outstanding mailbox | |
5592 | * command shall always be removed, so just unblock posting async | |
5593 | * mailbox command and resume | |
5594 | */ | |
5595 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5596 | spin_unlock_irq(&phba->hbalock); | |
5597 | ||
5598 | /* wake up worker thread to post asynchronlous mailbox command */ | |
5599 | lpfc_worker_wake_up(phba); | |
5600 | } | |
5601 | ||
da0436e9 JS |
5602 | /** |
5603 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
5604 | * @phba: Pointer to HBA context object. | |
5605 | * @mboxq: Pointer to mailbox object. | |
5606 | * | |
5607 | * The function posts a mailbox to the port. The mailbox is expected | |
5608 | * to be comletely filled in and ready for the port to operate on it. | |
5609 | * This routine executes a synchronous completion operation on the | |
5610 | * mailbox by polling for its completion. | |
5611 | * | |
5612 | * The caller must not be holding any locks when calling this routine. | |
5613 | * | |
5614 | * Returns: | |
5615 | * MBX_SUCCESS - mailbox posted successfully | |
5616 | * Any of the MBX error values. | |
5617 | **/ | |
5618 | static int | |
5619 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
5620 | { | |
5621 | int rc = MBX_SUCCESS; | |
5622 | unsigned long iflag; | |
5623 | uint32_t db_ready; | |
5624 | uint32_t mcqe_status; | |
5625 | uint32_t mbx_cmnd; | |
5626 | unsigned long timeout; | |
5627 | struct lpfc_sli *psli = &phba->sli; | |
5628 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
5629 | struct lpfc_bmbx_create *mbox_rgn; | |
5630 | struct dma_address *dma_address; | |
5631 | struct lpfc_register bmbx_reg; | |
5632 | ||
5633 | /* | |
5634 | * Only one mailbox can be active to the bootstrap mailbox region | |
5635 | * at a time and there is no queueing provided. | |
5636 | */ | |
5637 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5638 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5639 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5640 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5641 | "(%d):2532 Mailbox command x%x (x%x) " | |
5642 | "cannot issue Data: x%x x%x\n", | |
5643 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5644 | mboxq->u.mb.mbxCommand, | |
5645 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5646 | psli->sli_flag, MBX_POLL); | |
5647 | return MBXERR_ERROR; | |
5648 | } | |
5649 | /* The server grabs the token and owns it until release */ | |
5650 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5651 | phba->sli.mbox_active = mboxq; | |
5652 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5653 | ||
5654 | /* | |
5655 | * Initialize the bootstrap memory region to avoid stale data areas | |
5656 | * in the mailbox post. Then copy the caller's mailbox contents to | |
5657 | * the bmbx mailbox region. | |
5658 | */ | |
5659 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
5660 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
5661 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
5662 | sizeof(struct lpfc_mqe)); | |
5663 | ||
5664 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
5665 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5666 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
5667 | ||
5668 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5669 | * 1000) + jiffies; | |
5670 | do { | |
5671 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5672 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5673 | if (!db_ready) | |
5674 | msleep(2); | |
5675 | ||
5676 | if (time_after(jiffies, timeout)) { | |
5677 | rc = MBXERR_ERROR; | |
5678 | goto exit; | |
5679 | } | |
5680 | } while (!db_ready); | |
5681 | ||
5682 | /* Post the low mailbox dma address to the port. */ | |
5683 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
5684 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5685 | * 1000) + jiffies; | |
5686 | do { | |
5687 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5688 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5689 | if (!db_ready) | |
5690 | msleep(2); | |
5691 | ||
5692 | if (time_after(jiffies, timeout)) { | |
5693 | rc = MBXERR_ERROR; | |
5694 | goto exit; | |
5695 | } | |
5696 | } while (!db_ready); | |
5697 | ||
5698 | /* | |
5699 | * Read the CQ to ensure the mailbox has completed. | |
5700 | * If so, update the mailbox status so that the upper layers | |
5701 | * can complete the request normally. | |
5702 | */ | |
5703 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
5704 | sizeof(struct lpfc_mqe)); | |
5705 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
5706 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
5707 | sizeof(struct lpfc_mcqe)); | |
5708 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
5709 | ||
5710 | /* Prefix the mailbox status with range x4000 to note SLI4 status. */ | |
5711 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
5712 | bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status); | |
5713 | rc = MBXERR_ERROR; | |
d7c47992 JS |
5714 | } else |
5715 | lpfc_sli4_swap_str(phba, mboxq); | |
da0436e9 JS |
5716 | |
5717 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5718 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " | |
5719 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" | |
5720 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
5721 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5722 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5723 | bf_get(lpfc_mqe_status, mb), | |
5724 | mb->un.mb_words[0], mb->un.mb_words[1], | |
5725 | mb->un.mb_words[2], mb->un.mb_words[3], | |
5726 | mb->un.mb_words[4], mb->un.mb_words[5], | |
5727 | mb->un.mb_words[6], mb->un.mb_words[7], | |
5728 | mb->un.mb_words[8], mb->un.mb_words[9], | |
5729 | mb->un.mb_words[10], mb->un.mb_words[11], | |
5730 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
5731 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
5732 | mboxq->mcqe.trailer); | |
5733 | exit: | |
5734 | /* We are holding the token, no needed for lock when release */ | |
5735 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5736 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5737 | phba->sli.mbox_active = NULL; | |
5738 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5739 | return rc; | |
5740 | } | |
5741 | ||
5742 | /** | |
5743 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
5744 | * @phba: Pointer to HBA context object. | |
5745 | * @pmbox: Pointer to mailbox object. | |
5746 | * @flag: Flag indicating how the mailbox need to be processed. | |
5747 | * | |
5748 | * This function is called by discovery code and HBA management code to submit | |
5749 | * a mailbox command to firmware with SLI-4 interface spec. | |
5750 | * | |
5751 | * Return codes the caller owns the mailbox command after the return of the | |
5752 | * function. | |
5753 | **/ | |
5754 | static int | |
5755 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
5756 | uint32_t flag) | |
5757 | { | |
5758 | struct lpfc_sli *psli = &phba->sli; | |
5759 | unsigned long iflags; | |
5760 | int rc; | |
5761 | ||
8fa38513 JS |
5762 | rc = lpfc_mbox_dev_check(phba); |
5763 | if (unlikely(rc)) { | |
5764 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5765 | "(%d):2544 Mailbox command x%x (x%x) " | |
5766 | "cannot issue Data: x%x x%x\n", | |
5767 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5768 | mboxq->u.mb.mbxCommand, | |
5769 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5770 | psli->sli_flag, flag); | |
5771 | goto out_not_finished; | |
5772 | } | |
5773 | ||
da0436e9 JS |
5774 | /* Detect polling mode and jump to a handler */ |
5775 | if (!phba->sli4_hba.intr_enable) { | |
5776 | if (flag == MBX_POLL) | |
5777 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5778 | else | |
5779 | rc = -EIO; | |
5780 | if (rc != MBX_SUCCESS) | |
5781 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5782 | "(%d):2541 Mailbox command x%x " | |
5783 | "(x%x) cannot issue Data: x%x x%x\n", | |
5784 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5785 | mboxq->u.mb.mbxCommand, | |
5786 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5787 | psli->sli_flag, flag); | |
5788 | return rc; | |
5789 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
5790 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
5791 | "(%d):2542 Try to issue mailbox command " | |
5792 | "x%x (x%x) synchronously ahead of async" | |
5793 | "mailbox command queue: x%x x%x\n", | |
da0436e9 JS |
5794 | mboxq->vport ? mboxq->vport->vpi : 0, |
5795 | mboxq->u.mb.mbxCommand, | |
5796 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5797 | psli->sli_flag, flag); | |
f1126688 JS |
5798 | /* Try to block the asynchronous mailbox posting */ |
5799 | rc = lpfc_sli4_async_mbox_block(phba); | |
5800 | if (!rc) { | |
5801 | /* Successfully blocked, now issue sync mbox cmd */ | |
5802 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5803 | if (rc != MBX_SUCCESS) | |
5804 | lpfc_printf_log(phba, KERN_ERR, | |
5805 | LOG_MBOX | LOG_SLI, | |
5806 | "(%d):2597 Mailbox command " | |
5807 | "x%x (x%x) cannot issue " | |
5808 | "Data: x%x x%x\n", | |
5809 | mboxq->vport ? | |
5810 | mboxq->vport->vpi : 0, | |
5811 | mboxq->u.mb.mbxCommand, | |
5812 | lpfc_sli4_mbox_opcode_get(phba, | |
5813 | mboxq), | |
5814 | psli->sli_flag, flag); | |
5815 | /* Unblock the async mailbox posting afterward */ | |
5816 | lpfc_sli4_async_mbox_unblock(phba); | |
5817 | } | |
5818 | return rc; | |
da0436e9 JS |
5819 | } |
5820 | ||
5821 | /* Now, interrupt mode asynchrous mailbox command */ | |
5822 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
5823 | if (rc) { | |
5824 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5825 | "(%d):2543 Mailbox command x%x (x%x) " | |
5826 | "cannot issue Data: x%x x%x\n", | |
5827 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5828 | mboxq->u.mb.mbxCommand, | |
5829 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5830 | psli->sli_flag, flag); | |
5831 | goto out_not_finished; | |
5832 | } | |
da0436e9 JS |
5833 | |
5834 | /* Put the mailbox command to the driver internal FIFO */ | |
5835 | psli->slistat.mbox_busy++; | |
5836 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5837 | lpfc_mbox_put(phba, mboxq); | |
5838 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5839 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5840 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
5841 | "x%x (x%x) x%x x%x x%x\n", | |
5842 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, | |
5843 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5844 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5845 | phba->pport->port_state, | |
5846 | psli->sli_flag, MBX_NOWAIT); | |
5847 | /* Wake up worker thread to transport mailbox command from head */ | |
5848 | lpfc_worker_wake_up(phba); | |
5849 | ||
5850 | return MBX_BUSY; | |
5851 | ||
5852 | out_not_finished: | |
5853 | return MBX_NOT_FINISHED; | |
5854 | } | |
5855 | ||
5856 | /** | |
5857 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
5858 | * @phba: Pointer to HBA context object. | |
5859 | * | |
5860 | * This function is called by worker thread to send a mailbox command to | |
5861 | * SLI4 HBA firmware. | |
5862 | * | |
5863 | **/ | |
5864 | int | |
5865 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
5866 | { | |
5867 | struct lpfc_sli *psli = &phba->sli; | |
5868 | LPFC_MBOXQ_t *mboxq; | |
5869 | int rc = MBX_SUCCESS; | |
5870 | unsigned long iflags; | |
5871 | struct lpfc_mqe *mqe; | |
5872 | uint32_t mbx_cmnd; | |
5873 | ||
5874 | /* Check interrupt mode before post async mailbox command */ | |
5875 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
5876 | return MBX_NOT_FINISHED; | |
5877 | ||
5878 | /* Check for mailbox command service token */ | |
5879 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5880 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5881 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5882 | return MBX_NOT_FINISHED; | |
5883 | } | |
5884 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5885 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5886 | return MBX_NOT_FINISHED; | |
5887 | } | |
5888 | if (unlikely(phba->sli.mbox_active)) { | |
5889 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5890 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5891 | "0384 There is pending active mailbox cmd\n"); | |
5892 | return MBX_NOT_FINISHED; | |
5893 | } | |
5894 | /* Take the mailbox command service token */ | |
5895 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5896 | ||
5897 | /* Get the next mailbox command from head of queue */ | |
5898 | mboxq = lpfc_mbox_get(phba); | |
5899 | ||
5900 | /* If no more mailbox command waiting for post, we're done */ | |
5901 | if (!mboxq) { | |
5902 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5903 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5904 | return MBX_SUCCESS; | |
5905 | } | |
5906 | phba->sli.mbox_active = mboxq; | |
5907 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5908 | ||
5909 | /* Check device readiness for posting mailbox command */ | |
5910 | rc = lpfc_mbox_dev_check(phba); | |
5911 | if (unlikely(rc)) | |
5912 | /* Driver clean routine will clean up pending mailbox */ | |
5913 | goto out_not_finished; | |
5914 | ||
5915 | /* Prepare the mbox command to be posted */ | |
5916 | mqe = &mboxq->u.mqe; | |
5917 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
5918 | ||
5919 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
5920 | mod_timer(&psli->mbox_tmo, (jiffies + | |
5921 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); | |
5922 | ||
5923 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5924 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " | |
5925 | "x%x x%x\n", | |
5926 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
5927 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5928 | phba->pport->port_state, psli->sli_flag); | |
5929 | ||
5930 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
5931 | if (mboxq->vport) { | |
5932 | lpfc_debugfs_disc_trc(mboxq->vport, | |
5933 | LPFC_DISC_TRC_MBOX_VPORT, | |
5934 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5935 | mbx_cmnd, mqe->un.mb_words[0], | |
5936 | mqe->un.mb_words[1]); | |
5937 | } else { | |
5938 | lpfc_debugfs_disc_trc(phba->pport, | |
5939 | LPFC_DISC_TRC_MBOX, | |
5940 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5941 | mbx_cmnd, mqe->un.mb_words[0], | |
5942 | mqe->un.mb_words[1]); | |
5943 | } | |
5944 | } | |
5945 | psli->slistat.mbox_cmd++; | |
5946 | ||
5947 | /* Post the mailbox command to the port */ | |
5948 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
5949 | if (rc != MBX_SUCCESS) { | |
5950 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5951 | "(%d):2533 Mailbox command x%x (x%x) " | |
5952 | "cannot issue Data: x%x x%x\n", | |
5953 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5954 | mboxq->u.mb.mbxCommand, | |
5955 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5956 | psli->sli_flag, MBX_NOWAIT); | |
5957 | goto out_not_finished; | |
5958 | } | |
5959 | ||
5960 | return rc; | |
5961 | ||
5962 | out_not_finished: | |
5963 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5964 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
5965 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
5966 | /* Release the token */ | |
5967 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5968 | phba->sli.mbox_active = NULL; | |
5969 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5970 | ||
5971 | return MBX_NOT_FINISHED; | |
5972 | } | |
5973 | ||
5974 | /** | |
5975 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
5976 | * @phba: Pointer to HBA context object. | |
5977 | * @pmbox: Pointer to mailbox object. | |
5978 | * @flag: Flag indicating how the mailbox need to be processed. | |
5979 | * | |
5980 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
5981 | * the API jump table function pointer from the lpfc_hba struct. | |
5982 | * | |
5983 | * Return codes the caller owns the mailbox command after the return of the | |
5984 | * function. | |
5985 | **/ | |
5986 | int | |
5987 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
5988 | { | |
5989 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
5990 | } | |
5991 | ||
5992 | /** | |
5993 | * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table | |
5994 | * @phba: The hba struct for which this call is being executed. | |
5995 | * @dev_grp: The HBA PCI-Device group number. | |
5996 | * | |
5997 | * This routine sets up the mbox interface API function jump table in @phba | |
5998 | * struct. | |
5999 | * Returns: 0 - success, -ENODEV - failure. | |
6000 | **/ | |
6001 | int | |
6002 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6003 | { | |
6004 | ||
6005 | switch (dev_grp) { | |
6006 | case LPFC_PCI_DEV_LP: | |
6007 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
6008 | phba->lpfc_sli_handle_slow_ring_event = | |
6009 | lpfc_sli_handle_slow_ring_event_s3; | |
6010 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
6011 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
6012 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
6013 | break; | |
6014 | case LPFC_PCI_DEV_OC: | |
6015 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
6016 | phba->lpfc_sli_handle_slow_ring_event = | |
6017 | lpfc_sli_handle_slow_ring_event_s4; | |
6018 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
6019 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
6020 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
6021 | break; | |
6022 | default: | |
6023 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6024 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
6025 | dev_grp); | |
6026 | return -ENODEV; | |
6027 | break; | |
6028 | } | |
6029 | return 0; | |
6030 | } | |
6031 | ||
e59058c4 | 6032 | /** |
3621a710 | 6033 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
6034 | * @phba: Pointer to HBA context object. |
6035 | * @pring: Pointer to driver SLI ring object. | |
6036 | * @piocb: Pointer to address of newly added command iocb. | |
6037 | * | |
6038 | * This function is called with hbalock held to add a command | |
6039 | * iocb to the txq when SLI layer cannot submit the command iocb | |
6040 | * to the ring. | |
6041 | **/ | |
2a9bf3d0 | 6042 | void |
92d7f7b0 | 6043 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 6044 | struct lpfc_iocbq *piocb) |
dea3101e JB |
6045 | { |
6046 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
6047 | list_add_tail(&piocb->list, &pring->txq); | |
6048 | pring->txq_cnt++; | |
dea3101e JB |
6049 | } |
6050 | ||
e59058c4 | 6051 | /** |
3621a710 | 6052 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
6053 | * @phba: Pointer to HBA context object. |
6054 | * @pring: Pointer to driver SLI ring object. | |
6055 | * @piocb: Pointer to address of newly added command iocb. | |
6056 | * | |
6057 | * This function is called with hbalock held before a new | |
6058 | * iocb is submitted to the firmware. This function checks | |
6059 | * txq to flush the iocbs in txq to Firmware before | |
6060 | * submitting new iocbs to the Firmware. | |
6061 | * If there are iocbs in the txq which need to be submitted | |
6062 | * to firmware, lpfc_sli_next_iocb returns the first element | |
6063 | * of the txq after dequeuing it from txq. | |
6064 | * If there is no iocb in the txq then the function will return | |
6065 | * *piocb and *piocb is set to NULL. Caller needs to check | |
6066 | * *piocb to find if there are more commands in the txq. | |
6067 | **/ | |
dea3101e JB |
6068 | static struct lpfc_iocbq * |
6069 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 6070 | struct lpfc_iocbq **piocb) |
dea3101e JB |
6071 | { |
6072 | struct lpfc_iocbq * nextiocb; | |
6073 | ||
6074 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
6075 | if (!nextiocb) { | |
6076 | nextiocb = *piocb; | |
6077 | *piocb = NULL; | |
6078 | } | |
6079 | ||
6080 | return nextiocb; | |
6081 | } | |
6082 | ||
e59058c4 | 6083 | /** |
3772a991 | 6084 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 6085 | * @phba: Pointer to HBA context object. |
3772a991 | 6086 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
6087 | * @piocb: Pointer to command iocb. |
6088 | * @flag: Flag indicating if this command can be put into txq. | |
6089 | * | |
3772a991 JS |
6090 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
6091 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
6092 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
6093 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
6094 | * this function allows only iocbs for posting buffers. This function finds | |
6095 | * next available slot in the command ring and posts the command to the | |
6096 | * available slot and writes the port attention register to request HBA start | |
6097 | * processing new iocb. If there is no slot available in the ring and | |
6098 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
6099 | * the function returns IOCB_BUSY. | |
e59058c4 | 6100 | * |
3772a991 JS |
6101 | * This function is called with hbalock held. The function will return success |
6102 | * after it successfully submit the iocb to firmware or after adding to the | |
6103 | * txq. | |
e59058c4 | 6104 | **/ |
98c9ea5c | 6105 | static int |
3772a991 | 6106 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
6107 | struct lpfc_iocbq *piocb, uint32_t flag) |
6108 | { | |
6109 | struct lpfc_iocbq *nextiocb; | |
6110 | IOCB_t *iocb; | |
3772a991 | 6111 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 6112 | |
92d7f7b0 JS |
6113 | if (piocb->iocb_cmpl && (!piocb->vport) && |
6114 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
6115 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
6116 | lpfc_printf_log(phba, KERN_ERR, | |
6117 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 6118 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
6119 | piocb->iocb.ulpCommand); |
6120 | dump_stack(); | |
6121 | return IOCB_ERROR; | |
6122 | } | |
6123 | ||
6124 | ||
8d63f375 LV |
6125 | /* If the PCI channel is in offline state, do not post iocbs. */ |
6126 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
6127 | return IOCB_ERROR; | |
6128 | ||
a257bf90 JS |
6129 | /* If HBA has a deferred error attention, fail the iocb. */ |
6130 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
6131 | return IOCB_ERROR; | |
6132 | ||
dea3101e JB |
6133 | /* |
6134 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
6135 | */ | |
2e0fef85 | 6136 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
6137 | return IOCB_ERROR; |
6138 | ||
6139 | /* | |
6140 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 6141 | * outstanding event. |
dea3101e | 6142 | */ |
0b727fea | 6143 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
6144 | goto iocb_busy; |
6145 | ||
2e0fef85 | 6146 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 6147 | /* |
2680eeaa | 6148 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
6149 | * can be issued if the link is not up. |
6150 | */ | |
6151 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
6152 | case CMD_GEN_REQUEST64_CR: |
6153 | case CMD_GEN_REQUEST64_CX: | |
6154 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
6155 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 6156 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
6157 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
6158 | MENLO_TRANSPORT_TYPE)) | |
6159 | ||
6160 | goto iocb_busy; | |
6161 | break; | |
dea3101e JB |
6162 | case CMD_QUE_RING_BUF_CN: |
6163 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
6164 | /* |
6165 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
6166 | * completion, iocb_cmpl MUST be 0. | |
6167 | */ | |
6168 | if (piocb->iocb_cmpl) | |
6169 | piocb->iocb_cmpl = NULL; | |
6170 | /*FALLTHROUGH*/ | |
6171 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
6172 | case CMD_CLOSE_XRI_CN: |
6173 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
6174 | break; |
6175 | default: | |
6176 | goto iocb_busy; | |
6177 | } | |
6178 | ||
6179 | /* | |
6180 | * For FCP commands, we must be in a state where we can process link | |
6181 | * attention events. | |
6182 | */ | |
6183 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 6184 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 6185 | goto iocb_busy; |
92d7f7b0 | 6186 | } |
dea3101e | 6187 | |
dea3101e JB |
6188 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
6189 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
6190 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
6191 | ||
6192 | if (iocb) | |
6193 | lpfc_sli_update_ring(phba, pring); | |
6194 | else | |
6195 | lpfc_sli_update_full_ring(phba, pring); | |
6196 | ||
6197 | if (!piocb) | |
6198 | return IOCB_SUCCESS; | |
6199 | ||
6200 | goto out_busy; | |
6201 | ||
6202 | iocb_busy: | |
6203 | pring->stats.iocb_cmd_delay++; | |
6204 | ||
6205 | out_busy: | |
6206 | ||
6207 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 6208 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
6209 | return IOCB_SUCCESS; |
6210 | } | |
6211 | ||
6212 | return IOCB_BUSY; | |
6213 | } | |
6214 | ||
3772a991 | 6215 | /** |
4f774513 JS |
6216 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
6217 | * @phba: Pointer to HBA context object. | |
6218 | * @piocb: Pointer to command iocb. | |
6219 | * @sglq: Pointer to the scatter gather queue object. | |
6220 | * | |
6221 | * This routine converts the bpl or bde that is in the IOCB | |
6222 | * to a sgl list for the sli4 hardware. The physical address | |
6223 | * of the bpl/bde is converted back to a virtual address. | |
6224 | * If the IOCB contains a BPL then the list of BDE's is | |
6225 | * converted to sli4_sge's. If the IOCB contains a single | |
6226 | * BDE then it is converted to a single sli_sge. | |
6227 | * The IOCB is still in cpu endianess so the contents of | |
6228 | * the bpl can be used without byte swapping. | |
6229 | * | |
6230 | * Returns valid XRI = Success, NO_XRI = Failure. | |
6231 | **/ | |
6232 | static uint16_t | |
6233 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
6234 | struct lpfc_sglq *sglq) | |
3772a991 | 6235 | { |
4f774513 JS |
6236 | uint16_t xritag = NO_XRI; |
6237 | struct ulp_bde64 *bpl = NULL; | |
6238 | struct ulp_bde64 bde; | |
6239 | struct sli4_sge *sgl = NULL; | |
6240 | IOCB_t *icmd; | |
6241 | int numBdes = 0; | |
6242 | int i = 0; | |
63e801ce JS |
6243 | uint32_t offset = 0; /* accumulated offset in the sg request list */ |
6244 | int inbound = 0; /* number of sg reply entries inbound from firmware */ | |
3772a991 | 6245 | |
4f774513 JS |
6246 | if (!piocbq || !sglq) |
6247 | return xritag; | |
6248 | ||
6249 | sgl = (struct sli4_sge *)sglq->sgl; | |
6250 | icmd = &piocbq->iocb; | |
6251 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
6252 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
6253 | sizeof(struct ulp_bde64); | |
6254 | /* The addrHigh and addrLow fields within the IOCB | |
6255 | * have not been byteswapped yet so there is no | |
6256 | * need to swap them back. | |
6257 | */ | |
6258 | bpl = (struct ulp_bde64 *) | |
6259 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | |
6260 | ||
6261 | if (!bpl) | |
6262 | return xritag; | |
6263 | ||
6264 | for (i = 0; i < numBdes; i++) { | |
6265 | /* Should already be byte swapped. */ | |
28baac74 JS |
6266 | sgl->addr_hi = bpl->addrHigh; |
6267 | sgl->addr_lo = bpl->addrLow; | |
6268 | ||
4f774513 JS |
6269 | if ((i+1) == numBdes) |
6270 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
6271 | else | |
6272 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
6273 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
6274 | /* swap the size field back to the cpu so we |
6275 | * can assign it to the sgl. | |
6276 | */ | |
6277 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
6278 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
63e801ce JS |
6279 | /* The offsets in the sgl need to be accumulated |
6280 | * separately for the request and reply lists. | |
6281 | * The request is always first, the reply follows. | |
6282 | */ | |
6283 | if (piocbq->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) { | |
6284 | /* add up the reply sg entries */ | |
6285 | if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I) | |
6286 | inbound++; | |
6287 | /* first inbound? reset the offset */ | |
6288 | if (inbound == 1) | |
6289 | offset = 0; | |
6290 | bf_set(lpfc_sli4_sge_offset, sgl, offset); | |
6291 | offset += bde.tus.f.bdeSize; | |
6292 | } | |
4f774513 JS |
6293 | bpl++; |
6294 | sgl++; | |
6295 | } | |
6296 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
6297 | /* The addrHigh and addrLow fields of the BDE have not | |
6298 | * been byteswapped yet so they need to be swapped | |
6299 | * before putting them in the sgl. | |
6300 | */ | |
6301 | sgl->addr_hi = | |
6302 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
6303 | sgl->addr_lo = | |
6304 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
4f774513 JS |
6305 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
6306 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
6307 | sgl->sge_len = |
6308 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
6309 | } |
6310 | return sglq->sli4_xritag; | |
3772a991 | 6311 | } |
92d7f7b0 | 6312 | |
e59058c4 | 6313 | /** |
4f774513 | 6314 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 6315 | * @phba: Pointer to HBA context object. |
e59058c4 | 6316 | * |
a93ff37a | 6317 | * This routine performs a roundrobin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
6318 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
6319 | * held. | |
4f774513 JS |
6320 | * |
6321 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 6322 | **/ |
4f774513 | 6323 | static uint32_t |
8fa38513 | 6324 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 6325 | { |
8fa38513 JS |
6326 | ++phba->fcp_qidx; |
6327 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) | |
6328 | phba->fcp_qidx = 0; | |
92d7f7b0 | 6329 | |
8fa38513 | 6330 | return phba->fcp_qidx; |
92d7f7b0 JS |
6331 | } |
6332 | ||
e59058c4 | 6333 | /** |
4f774513 | 6334 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 6335 | * @phba: Pointer to HBA context object. |
4f774513 JS |
6336 | * @piocb: Pointer to command iocb. |
6337 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 6338 | * |
4f774513 JS |
6339 | * This routine converts the iocb command to its Work Queue Entry |
6340 | * equivalent. The wqe pointer should not have any fields set when | |
6341 | * this routine is called because it will memcpy over them. | |
6342 | * This routine does not set the CQ_ID or the WQEC bits in the | |
6343 | * wqe. | |
e59058c4 | 6344 | * |
4f774513 | 6345 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 6346 | **/ |
cf5bf97e | 6347 | static int |
4f774513 JS |
6348 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
6349 | union lpfc_wqe *wqe) | |
cf5bf97e | 6350 | { |
5ffc266e | 6351 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
6352 | uint8_t ct = 0; |
6353 | uint32_t fip; | |
6354 | uint32_t abort_tag; | |
6355 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
6356 | uint8_t cmnd; | |
6357 | uint16_t xritag; | |
dcf2a4e0 JS |
6358 | uint16_t abrt_iotag; |
6359 | struct lpfc_iocbq *abrtiocbq; | |
4f774513 | 6360 | struct ulp_bde64 *bpl = NULL; |
f0d9bccc | 6361 | uint32_t els_id = LPFC_ELS_ID_DEFAULT; |
5ffc266e JS |
6362 | int numBdes, i; |
6363 | struct ulp_bde64 bde; | |
4f774513 | 6364 | |
45ed1190 | 6365 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 6366 | /* The fcp commands will set command type */ |
0c287589 | 6367 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 6368 | command_type = FCP_COMMAND; |
c868595d | 6369 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
6370 | command_type = ELS_COMMAND_FIP; |
6371 | else | |
6372 | command_type = ELS_COMMAND_NON_FIP; | |
6373 | ||
4f774513 JS |
6374 | /* Some of the fields are in the right position already */ |
6375 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
6376 | abort_tag = (uint32_t) iocbq->iotag; | |
6377 | xritag = iocbq->sli4_xritag; | |
f0d9bccc | 6378 | wqe->generic.wqe_com.word7 = 0; /* The ct field has moved so reset */ |
4f774513 JS |
6379 | /* words0-2 bpl convert bde */ |
6380 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
6381 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
6382 | sizeof(struct ulp_bde64); | |
4f774513 JS |
6383 | bpl = (struct ulp_bde64 *) |
6384 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
6385 | if (!bpl) | |
6386 | return IOCB_ERROR; | |
cf5bf97e | 6387 | |
4f774513 JS |
6388 | /* Should already be byte swapped. */ |
6389 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
6390 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
6391 | /* swap the size field back to the cpu so we | |
6392 | * can assign it to the sgl. | |
6393 | */ | |
6394 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
6395 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
6396 | total_len = 0; | |
6397 | for (i = 0; i < numBdes; i++) { | |
6398 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
6399 | total_len += bde.tus.f.bdeSize; | |
6400 | } | |
4f774513 | 6401 | } else |
5ffc266e | 6402 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 6403 | |
4f774513 JS |
6404 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
6405 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 6406 | |
4f774513 JS |
6407 | switch (iocbq->iocb.ulpCommand) { |
6408 | case CMD_ELS_REQUEST64_CR: | |
6409 | if (!iocbq->iocb.ulpLe) { | |
6410 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6411 | "2007 Only Limited Edition cmd Format" | |
6412 | " supported 0x%x\n", | |
6413 | iocbq->iocb.ulpCommand); | |
6414 | return IOCB_ERROR; | |
6415 | } | |
5ffc266e | 6416 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
6417 | /* Els_reguest64 has a TMO */ |
6418 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
6419 | iocbq->iocb.ulpTimeout); | |
6420 | /* Need a VF for word 4 set the vf bit*/ | |
6421 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
6422 | /* And a VFID for word 12 */ | |
6423 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
6424 | /* | |
6425 | * Set ct field to 3, indicates that the context_tag field | |
6426 | * contains the FCFI and remote N_Port_ID is | |
6427 | * in word 5. | |
6428 | */ | |
4f774513 | 6429 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); |
f0d9bccc JS |
6430 | bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com, |
6431 | iocbq->iocb.ulpContext); | |
6432 | bf_set(wqe_ct, &wqe->els_req.wqe_com, ct); | |
6433 | bf_set(wqe_pu, &wqe->els_req.wqe_com, 0); | |
4f774513 | 6434 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ |
c868595d JS |
6435 | if (command_type == ELS_COMMAND_FIP) { |
6436 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) | |
6437 | >> LPFC_FIP_ELS_ID_SHIFT); | |
6438 | } | |
f0d9bccc JS |
6439 | bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id); |
6440 | bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1); | |
6441 | bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ); | |
6442 | bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1); | |
6443 | bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
6444 | bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0); | |
4f774513 | 6445 | break; |
5ffc266e | 6446 | case CMD_XMIT_SEQUENCE64_CX: |
f0d9bccc JS |
6447 | bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, |
6448 | iocbq->iocb.un.ulpWord[3]); | |
6449 | bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, | |
6450 | iocbq->iocb.ulpContext); | |
5ffc266e JS |
6451 | /* The entire sequence is transmitted for this IOCB */ |
6452 | xmit_len = total_len; | |
6453 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
4f774513 | 6454 | case CMD_XMIT_SEQUENCE64_CR: |
f0d9bccc JS |
6455 | /* word3 iocb=io_tag32 wqe=reserved */ |
6456 | wqe->xmit_sequence.rsvd3 = 0; | |
4f774513 JS |
6457 | /* word4 relative_offset memcpy */ |
6458 | /* word5 r_ctl/df_ctl memcpy */ | |
f0d9bccc JS |
6459 | bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0); |
6460 | bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1); | |
6461 | bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com, | |
6462 | LPFC_WQE_IOD_WRITE); | |
6463 | bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com, | |
6464 | LPFC_WQE_LENLOC_WORD12); | |
6465 | bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0); | |
5ffc266e JS |
6466 | wqe->xmit_sequence.xmit_len = xmit_len; |
6467 | command_type = OTHER_COMMAND; | |
4f774513 JS |
6468 | break; |
6469 | case CMD_XMIT_BCAST64_CN: | |
f0d9bccc JS |
6470 | /* word3 iocb=iotag32 wqe=seq_payload_len */ |
6471 | wqe->xmit_bcast64.seq_payload_len = xmit_len; | |
4f774513 JS |
6472 | /* word4 iocb=rsvd wqe=rsvd */ |
6473 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
6474 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
f0d9bccc | 6475 | bf_set(wqe_ct, &wqe->xmit_bcast64.wqe_com, |
4f774513 | 6476 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
f0d9bccc JS |
6477 | bf_set(wqe_dbde, &wqe->xmit_bcast64.wqe_com, 1); |
6478 | bf_set(wqe_iod, &wqe->xmit_bcast64.wqe_com, LPFC_WQE_IOD_WRITE); | |
6479 | bf_set(wqe_lenloc, &wqe->xmit_bcast64.wqe_com, | |
6480 | LPFC_WQE_LENLOC_WORD3); | |
6481 | bf_set(wqe_ebde_cnt, &wqe->xmit_bcast64.wqe_com, 0); | |
4f774513 JS |
6482 | break; |
6483 | case CMD_FCP_IWRITE64_CR: | |
6484 | command_type = FCP_COMMAND_DATA_OUT; | |
f0d9bccc JS |
6485 | /* word3 iocb=iotag wqe=payload_offset_len */ |
6486 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
6487 | wqe->fcp_iwrite.payload_offset_len = | |
6488 | xmit_len + sizeof(struct fcp_rsp); | |
6489 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ | |
6490 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
6491 | bf_set(wqe_erp, &wqe->fcp_iwrite.wqe_com, | |
6492 | iocbq->iocb.ulpFCP2Rcvy); | |
6493 | bf_set(wqe_lnk, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpXS); | |
6494 | /* Always open the exchange */ | |
6495 | bf_set(wqe_xc, &wqe->fcp_iwrite.wqe_com, 0); | |
6496 | bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 1); | |
6497 | bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE); | |
6498 | bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, | |
6499 | LPFC_WQE_LENLOC_WORD4); | |
6500 | bf_set(wqe_ebde_cnt, &wqe->fcp_iwrite.wqe_com, 0); | |
6501 | bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, iocbq->iocb.ulpPU); | |
6502 | break; | |
4f774513 | 6503 | case CMD_FCP_IREAD64_CR: |
f0d9bccc JS |
6504 | /* word3 iocb=iotag wqe=payload_offset_len */ |
6505 | /* Add the FCP_CMD and FCP_RSP sizes to get the offset */ | |
6506 | wqe->fcp_iread.payload_offset_len = | |
5ffc266e | 6507 | xmit_len + sizeof(struct fcp_rsp); |
f0d9bccc JS |
6508 | /* word4 iocb=parameter wqe=total_xfer_length memcpy */ |
6509 | /* word5 iocb=initial_xfer_len wqe=initial_xfer_len memcpy */ | |
6510 | bf_set(wqe_erp, &wqe->fcp_iread.wqe_com, | |
6511 | iocbq->iocb.ulpFCP2Rcvy); | |
6512 | bf_set(wqe_lnk, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpXS); | |
f1126688 JS |
6513 | /* Always open the exchange */ |
6514 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
f0d9bccc JS |
6515 | bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 1); |
6516 | bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ); | |
6517 | bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, | |
6518 | LPFC_WQE_LENLOC_WORD4); | |
6519 | bf_set(wqe_ebde_cnt, &wqe->fcp_iread.wqe_com, 0); | |
6520 | bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, iocbq->iocb.ulpPU); | |
6521 | break; | |
4f774513 | 6522 | case CMD_FCP_ICMND64_CR: |
f0d9bccc JS |
6523 | /* word3 iocb=IO_TAG wqe=reserved */ |
6524 | wqe->fcp_icmd.rsrvd3 = 0; | |
6525 | bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 | 6526 | /* Always open the exchange */ |
f0d9bccc JS |
6527 | bf_set(wqe_xc, &wqe->fcp_icmd.wqe_com, 0); |
6528 | bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 1); | |
6529 | bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_WRITE); | |
6530 | bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1); | |
6531 | bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, | |
6532 | LPFC_WQE_LENLOC_NONE); | |
6533 | bf_set(wqe_ebde_cnt, &wqe->fcp_icmd.wqe_com, 0); | |
4f774513 JS |
6534 | break; |
6535 | case CMD_GEN_REQUEST64_CR: | |
63e801ce JS |
6536 | /* For this command calculate the xmit length of the |
6537 | * request bde. | |
6538 | */ | |
6539 | xmit_len = 0; | |
6540 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / | |
6541 | sizeof(struct ulp_bde64); | |
6542 | for (i = 0; i < numBdes; i++) { | |
6543 | if (bpl[i].tus.f.bdeFlags != BUFF_TYPE_BDE_64) | |
6544 | break; | |
6545 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
6546 | xmit_len += bde.tus.f.bdeSize; | |
6547 | } | |
f0d9bccc JS |
6548 | /* word3 iocb=IO_TAG wqe=request_payload_len */ |
6549 | wqe->gen_req.request_payload_len = xmit_len; | |
6550 | /* word4 iocb=parameter wqe=relative_offset memcpy */ | |
6551 | /* word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
4f774513 JS |
6552 | /* word6 context tag copied in memcpy */ |
6553 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
6554 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
6555 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6556 | "2015 Invalid CT %x command 0x%x\n", | |
6557 | ct, iocbq->iocb.ulpCommand); | |
6558 | return IOCB_ERROR; | |
6559 | } | |
f0d9bccc JS |
6560 | bf_set(wqe_ct, &wqe->gen_req.wqe_com, 0); |
6561 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, iocbq->iocb.ulpTimeout); | |
6562 | bf_set(wqe_pu, &wqe->gen_req.wqe_com, iocbq->iocb.ulpPU); | |
6563 | bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1); | |
6564 | bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ); | |
6565 | bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1); | |
6566 | bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE); | |
6567 | bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0); | |
4f774513 JS |
6568 | command_type = OTHER_COMMAND; |
6569 | break; | |
6570 | case CMD_XMIT_ELS_RSP64_CX: | |
6571 | /* words0-2 BDE memcpy */ | |
f0d9bccc JS |
6572 | /* word3 iocb=iotag32 wqe=response_payload_len */ |
6573 | wqe->xmit_els_rsp.response_payload_len = xmit_len; | |
4f774513 | 6574 | /* word4 iocb=did wge=rsvd. */ |
f0d9bccc | 6575 | wqe->xmit_els_rsp.rsvd4 = 0; |
4f774513 JS |
6576 | /* word5 iocb=rsvd wge=did */ |
6577 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
6578 | iocbq->iocb.un.elsreq64.remoteID); | |
f0d9bccc JS |
6579 | bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, |
6580 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
6581 | bf_set(wqe_pu, &wqe->xmit_els_rsp.wqe_com, iocbq->iocb.ulpPU); | |
6582 | bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com, | |
6583 | iocbq->iocb.ulpContext); | |
4f774513 | 6584 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) |
f0d9bccc | 6585 | bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, |
4f774513 | 6586 | iocbq->vport->vpi + phba->vpi_base); |
f0d9bccc JS |
6587 | bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1); |
6588 | bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE); | |
6589 | bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1); | |
6590 | bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com, | |
6591 | LPFC_WQE_LENLOC_WORD3); | |
6592 | bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0); | |
4f774513 JS |
6593 | command_type = OTHER_COMMAND; |
6594 | break; | |
6595 | case CMD_CLOSE_XRI_CN: | |
6596 | case CMD_ABORT_XRI_CN: | |
6597 | case CMD_ABORT_XRI_CX: | |
6598 | /* words 0-2 memcpy should be 0 rserved */ | |
6599 | /* port will send abts */ | |
dcf2a4e0 JS |
6600 | abrt_iotag = iocbq->iocb.un.acxri.abortContextTag; |
6601 | if (abrt_iotag != 0 && abrt_iotag <= phba->sli.last_iotag) { | |
6602 | abrtiocbq = phba->sli.iocbq_lookup[abrt_iotag]; | |
6603 | fip = abrtiocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK; | |
6604 | } else | |
6605 | fip = 0; | |
6606 | ||
6607 | if ((iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) || fip) | |
4f774513 | 6608 | /* |
dcf2a4e0 JS |
6609 | * The link is down, or the command was ELS_FIP |
6610 | * so the fw does not need to send abts | |
4f774513 JS |
6611 | * on the wire. |
6612 | */ | |
6613 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
6614 | else | |
6615 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
6616 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
f0d9bccc JS |
6617 | /* word5 iocb=CONTEXT_TAG|IO_TAG wqe=reserved */ |
6618 | wqe->abort_cmd.rsrvd5 = 0; | |
6619 | bf_set(wqe_ct, &wqe->abort_cmd.wqe_com, | |
4f774513 JS |
6620 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); |
6621 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
6622 | /* |
6623 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
6624 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
6625 | */ | |
f0d9bccc JS |
6626 | bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX); |
6627 | bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1); | |
6628 | bf_set(wqe_lenloc, &wqe->abort_cmd.wqe_com, | |
6629 | LPFC_WQE_LENLOC_NONE); | |
4f774513 JS |
6630 | cmnd = CMD_ABORT_XRI_CX; |
6631 | command_type = OTHER_COMMAND; | |
6632 | xritag = 0; | |
6633 | break; | |
6669f9bb JS |
6634 | case CMD_XMIT_BLS_RSP64_CX: |
6635 | /* As BLS ABTS-ACC WQE is very different from other WQEs, | |
6636 | * we re-construct this WQE here based on information in | |
6637 | * iocbq from scratch. | |
6638 | */ | |
6639 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 6640 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 6641 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
5ffc266e JS |
6642 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc)); |
6643 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) == | |
6644 | LPFC_ABTS_UNSOL_INT) { | |
6645 | /* ABTS sent by initiator to CT exchange, the | |
6646 | * RX_ID field will be filled with the newly | |
6647 | * allocated responder XRI. | |
6648 | */ | |
6649 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6650 | iocbq->sli4_xritag); | |
6651 | } else { | |
6652 | /* ABTS sent by responder to CT exchange, the | |
6653 | * RX_ID field will be filled with the responder | |
6654 | * RX_ID from ABTS. | |
6655 | */ | |
6656 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6657 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc)); | |
6658 | } | |
6669f9bb JS |
6659 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
6660 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6661 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, | |
6662 | iocbq->iocb.ulpContext); | |
f0d9bccc JS |
6663 | bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1); |
6664 | bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com, | |
6665 | LPFC_WQE_LENLOC_NONE); | |
6669f9bb JS |
6666 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ |
6667 | command_type = OTHER_COMMAND; | |
6668 | break; | |
4f774513 JS |
6669 | case CMD_XRI_ABORTED_CX: |
6670 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
4f774513 JS |
6671 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ |
6672 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
6673 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
6674 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
6675 | default: | |
6676 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6677 | "2014 Invalid command 0x%x\n", | |
6678 | iocbq->iocb.ulpCommand); | |
6679 | return IOCB_ERROR; | |
6680 | break; | |
4f774513 | 6681 | } |
f0d9bccc JS |
6682 | bf_set(wqe_xri_tag, &wqe->generic.wqe_com, xritag); |
6683 | bf_set(wqe_reqtag, &wqe->generic.wqe_com, iocbq->iotag); | |
6684 | wqe->generic.wqe_com.abort_tag = abort_tag; | |
6685 | bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type); | |
6686 | bf_set(wqe_cmnd, &wqe->generic.wqe_com, cmnd); | |
6687 | bf_set(wqe_class, &wqe->generic.wqe_com, iocbq->iocb.ulpClass); | |
6688 | bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT); | |
4f774513 JS |
6689 | return 0; |
6690 | } | |
6691 | ||
6692 | /** | |
6693 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
6694 | * @phba: Pointer to HBA context object. | |
6695 | * @ring_number: SLI ring number to issue iocb on. | |
6696 | * @piocb: Pointer to command iocb. | |
6697 | * @flag: Flag indicating if this command can be put into txq. | |
6698 | * | |
6699 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
6700 | * an iocb command to an HBA with SLI-4 interface spec. | |
6701 | * | |
6702 | * This function is called with hbalock held. The function will return success | |
6703 | * after it successfully submit the iocb to firmware or after adding to the | |
6704 | * txq. | |
6705 | **/ | |
6706 | static int | |
6707 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
6708 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6709 | { | |
6710 | struct lpfc_sglq *sglq; | |
4f774513 JS |
6711 | union lpfc_wqe wqe; |
6712 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
6713 | |
6714 | if (piocb->sli4_xritag == NO_XRI) { | |
6715 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6669f9bb | 6716 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
6717 | sglq = NULL; |
6718 | else { | |
2a9bf3d0 JS |
6719 | if (pring->txq_cnt) { |
6720 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6721 | __lpfc_sli_ringtx_put(phba, | |
6722 | pring, piocb); | |
6723 | return IOCB_SUCCESS; | |
6724 | } else { | |
6725 | return IOCB_BUSY; | |
6726 | } | |
6727 | } else { | |
19ca7609 | 6728 | sglq = __lpfc_sli_get_sglq(phba, piocb); |
2a9bf3d0 JS |
6729 | if (!sglq) { |
6730 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6731 | __lpfc_sli_ringtx_put(phba, | |
6732 | pring, | |
6733 | piocb); | |
6734 | return IOCB_SUCCESS; | |
6735 | } else | |
6736 | return IOCB_BUSY; | |
6737 | } | |
6738 | } | |
4f774513 JS |
6739 | } |
6740 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6741 | sglq = NULL; /* These IO's already have an XRI and | |
6742 | * a mapped sgl. | |
6743 | */ | |
6744 | } else { | |
6745 | /* This is a continuation of a commandi,(CX) so this | |
6746 | * sglq is on the active list | |
6747 | */ | |
6748 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
6749 | if (!sglq) | |
6750 | return IOCB_ERROR; | |
6751 | } | |
6752 | ||
6753 | if (sglq) { | |
2a9bf3d0 JS |
6754 | piocb->sli4_xritag = sglq->sli4_xritag; |
6755 | ||
6756 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) | |
4f774513 JS |
6757 | return IOCB_ERROR; |
6758 | } | |
6759 | ||
6760 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
6761 | return IOCB_ERROR; | |
6762 | ||
341af102 JS |
6763 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
6764 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
6765 | /* |
6766 | * For FCP command IOCB, get a new WQ index to distribute | |
6767 | * WQE across the WQsr. On the other hand, for abort IOCB, | |
6768 | * it carries the same WQ index to the original command | |
6769 | * IOCB. | |
6770 | */ | |
341af102 | 6771 | if (piocb->iocb_flag & LPFC_IO_FCP) |
5ffc266e JS |
6772 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
6773 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], | |
6774 | &wqe)) | |
4f774513 JS |
6775 | return IOCB_ERROR; |
6776 | } else { | |
6777 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
6778 | return IOCB_ERROR; | |
6779 | } | |
6780 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
6781 | ||
6782 | return 0; | |
6783 | } | |
6784 | ||
6785 | /** | |
6786 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
6787 | * | |
6788 | * This routine wraps the actual lockless version for issusing IOCB function | |
6789 | * pointer from the lpfc_hba struct. | |
6790 | * | |
6791 | * Return codes: | |
6792 | * IOCB_ERROR - Error | |
6793 | * IOCB_SUCCESS - Success | |
6794 | * IOCB_BUSY - Busy | |
6795 | **/ | |
2a9bf3d0 | 6796 | int |
4f774513 JS |
6797 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
6798 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6799 | { | |
6800 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6801 | } | |
6802 | ||
6803 | /** | |
6804 | * lpfc_sli_api_table_setup - Set up sli api fucntion jump table | |
6805 | * @phba: The hba struct for which this call is being executed. | |
6806 | * @dev_grp: The HBA PCI-Device group number. | |
6807 | * | |
6808 | * This routine sets up the SLI interface API function jump table in @phba | |
6809 | * struct. | |
6810 | * Returns: 0 - success, -ENODEV - failure. | |
6811 | **/ | |
6812 | int | |
6813 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6814 | { | |
6815 | ||
6816 | switch (dev_grp) { | |
6817 | case LPFC_PCI_DEV_LP: | |
6818 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
6819 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
6820 | break; | |
6821 | case LPFC_PCI_DEV_OC: | |
6822 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
6823 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
6824 | break; | |
6825 | default: | |
6826 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6827 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
6828 | dev_grp); | |
6829 | return -ENODEV; | |
6830 | break; | |
6831 | } | |
6832 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
6833 | return 0; | |
6834 | } | |
6835 | ||
6836 | /** | |
6837 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
6838 | * @phba: Pointer to HBA context object. | |
6839 | * @pring: Pointer to driver SLI ring object. | |
6840 | * @piocb: Pointer to command iocb. | |
6841 | * @flag: Flag indicating if this command can be put into txq. | |
6842 | * | |
6843 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
6844 | * function. This function gets the hbalock and calls | |
6845 | * __lpfc_sli_issue_iocb function and will return the error returned | |
6846 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
6847 | * functions which do not hold hbalock. | |
6848 | **/ | |
6849 | int | |
6850 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
6851 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6852 | { | |
6853 | unsigned long iflags; | |
6854 | int rc; | |
6855 | ||
6856 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6857 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6858 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6859 | ||
6860 | return rc; | |
6861 | } | |
6862 | ||
6863 | /** | |
6864 | * lpfc_extra_ring_setup - Extra ring setup function | |
6865 | * @phba: Pointer to HBA context object. | |
6866 | * | |
6867 | * This function is called while driver attaches with the | |
6868 | * HBA to setup the extra ring. The extra ring is used | |
6869 | * only when driver needs to support target mode functionality | |
6870 | * or IP over FC functionalities. | |
6871 | * | |
6872 | * This function is called with no lock held. | |
6873 | **/ | |
6874 | static int | |
6875 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
6876 | { | |
6877 | struct lpfc_sli *psli; | |
6878 | struct lpfc_sli_ring *pring; | |
6879 | ||
6880 | psli = &phba->sli; | |
6881 | ||
6882 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
6883 | ||
6884 | /* Take some away from the FCP ring */ | |
6885 | pring = &psli->ring[psli->fcp_ring]; | |
6886 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
6887 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
cf5bf97e JW |
6888 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
6889 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6890 | ||
a4bc3379 JS |
6891 | /* and give them to the extra ring */ |
6892 | pring = &psli->ring[psli->extra_ring]; | |
6893 | ||
cf5bf97e JW |
6894 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
6895 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
6896 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
6897 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6898 | ||
6899 | /* Setup default profile for this ring */ | |
6900 | pring->iotag_max = 4096; | |
6901 | pring->num_mask = 1; | |
6902 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
6903 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
6904 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
6905 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
6906 | return 0; | |
6907 | } | |
6908 | ||
e59058c4 | 6909 | /** |
3621a710 | 6910 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
6911 | * @phba: Pointer to HBA context object. |
6912 | * @pring: Pointer to driver SLI ring object. | |
6913 | * @iocbq: Pointer to iocb object. | |
6914 | * | |
6915 | * This function is called by the slow ring event handler | |
6916 | * function when there is an ASYNC event iocb in the ring. | |
6917 | * This function is called with no lock held. | |
6918 | * Currently this function handles only temperature related | |
6919 | * ASYNC events. The function decodes the temperature sensor | |
6920 | * event message and posts events for the management applications. | |
6921 | **/ | |
98c9ea5c | 6922 | static void |
57127f15 JS |
6923 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
6924 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
6925 | { | |
6926 | IOCB_t *icmd; | |
6927 | uint16_t evt_code; | |
6928 | uint16_t temp; | |
6929 | struct temp_event temp_event_data; | |
6930 | struct Scsi_Host *shost; | |
a257bf90 | 6931 | uint32_t *iocb_w; |
57127f15 JS |
6932 | |
6933 | icmd = &iocbq->iocb; | |
6934 | evt_code = icmd->un.asyncstat.evt_code; | |
6935 | temp = icmd->ulpContext; | |
6936 | ||
6937 | if ((evt_code != ASYNC_TEMP_WARN) && | |
6938 | (evt_code != ASYNC_TEMP_SAFE)) { | |
a257bf90 | 6939 | iocb_w = (uint32_t *) icmd; |
57127f15 JS |
6940 | lpfc_printf_log(phba, |
6941 | KERN_ERR, | |
6942 | LOG_SLI, | |
76bb24ef | 6943 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 6944 | " evt_code 0x%x\n" |
a257bf90 JS |
6945 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
6946 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
6947 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
6948 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
57127f15 | 6949 | pring->ringno, |
a257bf90 JS |
6950 | icmd->un.asyncstat.evt_code, |
6951 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], | |
6952 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
6953 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
6954 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
6955 | ||
57127f15 JS |
6956 | return; |
6957 | } | |
6958 | temp_event_data.data = (uint32_t)temp; | |
6959 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
6960 | if (evt_code == ASYNC_TEMP_WARN) { | |
6961 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
6962 | lpfc_printf_log(phba, | |
09372820 | 6963 | KERN_ERR, |
57127f15 | 6964 | LOG_TEMP, |
76bb24ef | 6965 | "0347 Adapter is very hot, please take " |
57127f15 JS |
6966 | "corrective action. temperature : %d Celsius\n", |
6967 | temp); | |
6968 | } | |
6969 | if (evt_code == ASYNC_TEMP_SAFE) { | |
6970 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
6971 | lpfc_printf_log(phba, | |
09372820 | 6972 | KERN_ERR, |
57127f15 JS |
6973 | LOG_TEMP, |
6974 | "0340 Adapter temperature is OK now. " | |
6975 | "temperature : %d Celsius\n", | |
6976 | temp); | |
6977 | } | |
6978 | ||
6979 | /* Send temperature change event to applications */ | |
6980 | shost = lpfc_shost_from_vport(phba->pport); | |
6981 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
6982 | sizeof(temp_event_data), (char *) &temp_event_data, | |
ddcc50f0 | 6983 | LPFC_NL_VENDOR_ID); |
57127f15 JS |
6984 | |
6985 | } | |
6986 | ||
6987 | ||
e59058c4 | 6988 | /** |
3621a710 | 6989 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
6990 | * @phba: Pointer to HBA context object. |
6991 | * | |
6992 | * lpfc_sli_setup sets up rings of the SLI interface with | |
6993 | * number of iocbs per ring and iotags. This function is | |
6994 | * called while driver attach to the HBA and before the | |
6995 | * interrupts are enabled. So there is no need for locking. | |
6996 | * | |
6997 | * This function always returns 0. | |
6998 | **/ | |
dea3101e JB |
6999 | int |
7000 | lpfc_sli_setup(struct lpfc_hba *phba) | |
7001 | { | |
ed957684 | 7002 | int i, totiocbsize = 0; |
dea3101e JB |
7003 | struct lpfc_sli *psli = &phba->sli; |
7004 | struct lpfc_sli_ring *pring; | |
7005 | ||
7006 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
7007 | psli->sli_flag = 0; | |
7008 | psli->fcp_ring = LPFC_FCP_RING; | |
7009 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 7010 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 7011 | |
604a3e30 JB |
7012 | psli->iocbq_lookup = NULL; |
7013 | psli->iocbq_lookup_len = 0; | |
7014 | psli->last_iotag = 0; | |
7015 | ||
dea3101e JB |
7016 | for (i = 0; i < psli->num_rings; i++) { |
7017 | pring = &psli->ring[i]; | |
7018 | switch (i) { | |
7019 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
7020 | /* numCiocb and numRiocb are used in config_port */ | |
7021 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
7022 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
7023 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
7024 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
7025 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
7026 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 7027 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7028 | SLI3_IOCB_CMD_SIZE : |
7029 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7030 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7031 | SLI3_IOCB_RSP_SIZE : |
7032 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
7033 | pring->iotag_ctr = 0; |
7034 | pring->iotag_max = | |
92d7f7b0 | 7035 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
7036 | pring->fast_iotag = pring->iotag_max; |
7037 | pring->num_mask = 0; | |
7038 | break; | |
a4bc3379 | 7039 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e JB |
7040 | /* numCiocb and numRiocb are used in config_port */ |
7041 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
7042 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 7043 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7044 | SLI3_IOCB_CMD_SIZE : |
7045 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7046 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7047 | SLI3_IOCB_RSP_SIZE : |
7048 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 7049 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
7050 | pring->num_mask = 0; |
7051 | break; | |
7052 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
7053 | /* numCiocb and numRiocb are used in config_port */ | |
7054 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
7055 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 7056 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7057 | SLI3_IOCB_CMD_SIZE : |
7058 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 7059 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
7060 | SLI3_IOCB_RSP_SIZE : |
7061 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
7062 | pring->fast_iotag = 0; |
7063 | pring->iotag_ctr = 0; | |
7064 | pring->iotag_max = 4096; | |
57127f15 JS |
7065 | pring->lpfc_sli_rcv_async_status = |
7066 | lpfc_sli_async_event_handler; | |
6669f9bb | 7067 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 7068 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
7069 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
7070 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 7071 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7072 | lpfc_els_unsol_event; |
dea3101e | 7073 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
7074 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
7075 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 7076 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7077 | lpfc_els_unsol_event; |
dea3101e JB |
7078 | pring->prt[2].profile = 0; /* Mask 2 */ |
7079 | /* NameServer Inquiry */ | |
6a9c52cf | 7080 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 7081 | /* NameServer */ |
6a9c52cf | 7082 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 7083 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7084 | lpfc_ct_unsol_event; |
dea3101e JB |
7085 | pring->prt[3].profile = 0; /* Mask 3 */ |
7086 | /* NameServer response */ | |
6a9c52cf | 7087 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 7088 | /* NameServer */ |
6a9c52cf | 7089 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 7090 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 7091 | lpfc_ct_unsol_event; |
6669f9bb JS |
7092 | /* abort unsolicited sequence */ |
7093 | pring->prt[4].profile = 0; /* Mask 4 */ | |
7094 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
7095 | pring->prt[4].type = FC_TYPE_BLS; | |
7096 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
7097 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e JB |
7098 | break; |
7099 | } | |
ed957684 | 7100 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 7101 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 7102 | } |
ed957684 | 7103 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 7104 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
7105 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
7106 | "SLI2 SLIM Data: x%x x%lx\n", | |
7107 | phba->brd_no, totiocbsize, | |
7108 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 7109 | } |
cf5bf97e JW |
7110 | if (phba->cfg_multi_ring_support == 2) |
7111 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
7112 | |
7113 | return 0; | |
7114 | } | |
7115 | ||
e59058c4 | 7116 | /** |
3621a710 | 7117 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
7118 | * @phba: Pointer to HBA context object. |
7119 | * | |
7120 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
7121 | * ring. This function also initializes ring indices of each ring. | |
7122 | * This function is called during the initialization of the SLI | |
7123 | * interface of an HBA. | |
7124 | * This function is called with no lock held and always returns | |
7125 | * 1. | |
7126 | **/ | |
dea3101e | 7127 | int |
2e0fef85 | 7128 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
7129 | { |
7130 | struct lpfc_sli *psli; | |
7131 | struct lpfc_sli_ring *pring; | |
604a3e30 | 7132 | int i; |
dea3101e JB |
7133 | |
7134 | psli = &phba->sli; | |
2e0fef85 | 7135 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7136 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 7137 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
7138 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
7139 | for (i = 0; i < psli->num_rings; i++) { | |
7140 | pring = &psli->ring[i]; | |
7141 | pring->ringno = i; | |
7142 | pring->next_cmdidx = 0; | |
7143 | pring->local_getidx = 0; | |
7144 | pring->cmdidx = 0; | |
7145 | INIT_LIST_HEAD(&pring->txq); | |
7146 | INIT_LIST_HEAD(&pring->txcmplq); | |
7147 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 7148 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 7149 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 7150 | } |
2e0fef85 JS |
7151 | spin_unlock_irq(&phba->hbalock); |
7152 | return 1; | |
dea3101e JB |
7153 | } |
7154 | ||
04c68496 JS |
7155 | /** |
7156 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
7157 | * @phba: Pointer to HBA context object. | |
7158 | * | |
7159 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
7160 | * flush all the mailbox commands in the three possible stages in the mailbox | |
7161 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
7162 | * command; and completed mailbox command queue. It is caller's responsibility | |
7163 | * to make sure that the driver is in the proper state to flush the mailbox | |
7164 | * command sub-system. Namely, the posting of mailbox commands into the | |
7165 | * pending mailbox command queue from the various clients must be stopped; | |
7166 | * either the HBA is in a state that it will never works on the outstanding | |
7167 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
7168 | * mailbox command has been completed. | |
7169 | **/ | |
7170 | static void | |
7171 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
7172 | { | |
7173 | LIST_HEAD(completions); | |
7174 | struct lpfc_sli *psli = &phba->sli; | |
7175 | LPFC_MBOXQ_t *pmb; | |
7176 | unsigned long iflag; | |
7177 | ||
7178 | /* Flush all the mailbox commands in the mbox system */ | |
7179 | spin_lock_irqsave(&phba->hbalock, iflag); | |
7180 | /* The pending mailbox command queue */ | |
7181 | list_splice_init(&phba->sli.mboxq, &completions); | |
7182 | /* The outstanding active mailbox command */ | |
7183 | if (psli->mbox_active) { | |
7184 | list_add_tail(&psli->mbox_active->list, &completions); | |
7185 | psli->mbox_active = NULL; | |
7186 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7187 | } | |
7188 | /* The completed mailbox command queue */ | |
7189 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
7190 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
7191 | ||
7192 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
7193 | while (!list_empty(&completions)) { | |
7194 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
7195 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7196 | if (pmb->mbox_cmpl) | |
7197 | pmb->mbox_cmpl(phba, pmb); | |
7198 | } | |
7199 | } | |
7200 | ||
e59058c4 | 7201 | /** |
3621a710 | 7202 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
7203 | * @vport: Pointer to virtual port object. |
7204 | * | |
7205 | * lpfc_sli_host_down is called to clean up the resources | |
7206 | * associated with a vport before destroying virtual | |
7207 | * port data structures. | |
7208 | * This function does following operations: | |
7209 | * - Free discovery resources associated with this virtual | |
7210 | * port. | |
7211 | * - Free iocbs associated with this virtual port in | |
7212 | * the txq. | |
7213 | * - Send abort for all iocb commands associated with this | |
7214 | * vport in txcmplq. | |
7215 | * | |
7216 | * This function is called with no lock held and always returns 1. | |
7217 | **/ | |
92d7f7b0 JS |
7218 | int |
7219 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
7220 | { | |
858c9f6c | 7221 | LIST_HEAD(completions); |
92d7f7b0 JS |
7222 | struct lpfc_hba *phba = vport->phba; |
7223 | struct lpfc_sli *psli = &phba->sli; | |
7224 | struct lpfc_sli_ring *pring; | |
7225 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
7226 | int i; |
7227 | unsigned long flags = 0; | |
7228 | uint16_t prev_pring_flag; | |
7229 | ||
7230 | lpfc_cleanup_discovery_resources(vport); | |
7231 | ||
7232 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
7233 | for (i = 0; i < psli->num_rings; i++) { |
7234 | pring = &psli->ring[i]; | |
7235 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
7236 | /* Only slow rings */ |
7237 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 7238 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
7239 | /* Set the lpfc data pending flag */ |
7240 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
7241 | } | |
92d7f7b0 JS |
7242 | /* |
7243 | * Error everything on the txq since these iocbs have not been | |
7244 | * given to the FW yet. | |
7245 | */ | |
92d7f7b0 JS |
7246 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
7247 | if (iocb->vport != vport) | |
7248 | continue; | |
858c9f6c | 7249 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 7250 | pring->txq_cnt--; |
92d7f7b0 JS |
7251 | } |
7252 | ||
7253 | /* Next issue ABTS for everything on the txcmplq */ | |
7254 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
7255 | list) { | |
7256 | if (iocb->vport != vport) | |
7257 | continue; | |
7258 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
7259 | } | |
7260 | ||
7261 | pring->flag = prev_pring_flag; | |
7262 | } | |
7263 | ||
7264 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
7265 | ||
a257bf90 JS |
7266 | /* Cancel all the IOCBs from the completions list */ |
7267 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7268 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
7269 | return 1; |
7270 | } | |
7271 | ||
e59058c4 | 7272 | /** |
3621a710 | 7273 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
7274 | * @phba: Pointer to HBA context object. |
7275 | * | |
7276 | * This function cleans up all iocb, buffers, mailbox commands | |
7277 | * while shutting down the HBA. This function is called with no | |
7278 | * lock held and always returns 1. | |
7279 | * This function does the following to cleanup driver resources: | |
7280 | * - Free discovery resources for each virtual port | |
7281 | * - Cleanup any pending fabric iocbs | |
7282 | * - Iterate through the iocb txq and free each entry | |
7283 | * in the list. | |
7284 | * - Free up any buffer posted to the HBA | |
7285 | * - Free mailbox commands in the mailbox queue. | |
7286 | **/ | |
dea3101e | 7287 | int |
2e0fef85 | 7288 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 7289 | { |
2534ba75 | 7290 | LIST_HEAD(completions); |
2e0fef85 | 7291 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 7292 | struct lpfc_sli_ring *pring; |
0ff10d46 | 7293 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 7294 | unsigned long flags = 0; |
04c68496 JS |
7295 | int i; |
7296 | ||
7297 | /* Shutdown the mailbox command sub-system */ | |
7298 | lpfc_sli_mbox_sys_shutdown(phba); | |
dea3101e | 7299 | |
dea3101e JB |
7300 | lpfc_hba_down_prep(phba); |
7301 | ||
92d7f7b0 JS |
7302 | lpfc_fabric_abort_hba(phba); |
7303 | ||
2e0fef85 | 7304 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
7305 | for (i = 0; i < psli->num_rings; i++) { |
7306 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
7307 | /* Only slow rings */ |
7308 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 7309 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
7310 | /* Set the lpfc data pending flag */ |
7311 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
7312 | } | |
dea3101e JB |
7313 | |
7314 | /* | |
7315 | * Error everything on the txq since these iocbs have not been | |
7316 | * given to the FW yet. | |
7317 | */ | |
2534ba75 | 7318 | list_splice_init(&pring->txq, &completions); |
dea3101e JB |
7319 | pring->txq_cnt = 0; |
7320 | ||
2534ba75 | 7321 | } |
2e0fef85 | 7322 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 7323 | |
a257bf90 JS |
7324 | /* Cancel all the IOCBs from the completions list */ |
7325 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7326 | IOERR_SLI_DOWN); | |
dea3101e | 7327 | |
0ff10d46 JS |
7328 | spin_lock_irqsave(&phba->hbalock, flags); |
7329 | list_splice_init(&phba->elsbuf, &completions); | |
7330 | phba->elsbuf_cnt = 0; | |
7331 | phba->elsbuf_prev_cnt = 0; | |
7332 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
7333 | ||
7334 | while (!list_empty(&completions)) { | |
7335 | list_remove_head(&completions, buf_ptr, | |
7336 | struct lpfc_dmabuf, list); | |
7337 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
7338 | kfree(buf_ptr); | |
7339 | } | |
7340 | ||
dea3101e JB |
7341 | /* Return any active mbox cmds */ |
7342 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 7343 | |
da0436e9 | 7344 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 7345 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 7346 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 7347 | |
da0436e9 JS |
7348 | return 1; |
7349 | } | |
7350 | ||
e59058c4 | 7351 | /** |
3621a710 | 7352 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
7353 | * @srcp: Source memory pointer. |
7354 | * @destp: Destination memory pointer. | |
7355 | * @cnt: Number of words required to be copied. | |
7356 | * | |
7357 | * This function is used for copying data between driver memory | |
7358 | * and the SLI memory. This function also changes the endianness | |
7359 | * of each word if native endianness is different from SLI | |
7360 | * endianness. This function can be called with or without | |
7361 | * lock. | |
7362 | **/ | |
dea3101e JB |
7363 | void |
7364 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
7365 | { | |
7366 | uint32_t *src = srcp; | |
7367 | uint32_t *dest = destp; | |
7368 | uint32_t ldata; | |
7369 | int i; | |
7370 | ||
7371 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
7372 | ldata = *src; | |
7373 | ldata = le32_to_cpu(ldata); | |
7374 | *dest = ldata; | |
7375 | src++; | |
7376 | dest++; | |
7377 | } | |
7378 | } | |
7379 | ||
e59058c4 | 7380 | |
a0c87cbd JS |
7381 | /** |
7382 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
7383 | * @srcp: Source memory pointer. | |
7384 | * @destp: Destination memory pointer. | |
7385 | * @cnt: Number of words required to be copied. | |
7386 | * | |
7387 | * This function is used for copying data between a data structure | |
7388 | * with big endian representation to local endianness. | |
7389 | * This function can be called with or without lock. | |
7390 | **/ | |
7391 | void | |
7392 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
7393 | { | |
7394 | uint32_t *src = srcp; | |
7395 | uint32_t *dest = destp; | |
7396 | uint32_t ldata; | |
7397 | int i; | |
7398 | ||
7399 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
7400 | ldata = *src; | |
7401 | ldata = be32_to_cpu(ldata); | |
7402 | *dest = ldata; | |
7403 | src++; | |
7404 | dest++; | |
7405 | } | |
7406 | } | |
7407 | ||
e59058c4 | 7408 | /** |
3621a710 | 7409 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
7410 | * @phba: Pointer to HBA context object. |
7411 | * @pring: Pointer to driver SLI ring object. | |
7412 | * @mp: Pointer to driver buffer object. | |
7413 | * | |
7414 | * This function is called with no lock held. | |
7415 | * It always return zero after adding the buffer to the postbufq | |
7416 | * buffer list. | |
7417 | **/ | |
dea3101e | 7418 | int |
2e0fef85 JS |
7419 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
7420 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
7421 | { |
7422 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
7423 | later */ | |
2e0fef85 | 7424 | spin_lock_irq(&phba->hbalock); |
dea3101e | 7425 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 7426 | pring->postbufq_cnt++; |
2e0fef85 | 7427 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
7428 | return 0; |
7429 | } | |
7430 | ||
e59058c4 | 7431 | /** |
3621a710 | 7432 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
7433 | * @phba: Pointer to HBA context object. |
7434 | * | |
7435 | * When HBQ is enabled, buffers are searched based on tags. This function | |
7436 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
7437 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
7438 | * does not conflict with tags of buffer posted for unsolicited events. | |
7439 | * The function returns the allocated tag. The function is called with | |
7440 | * no locks held. | |
7441 | **/ | |
76bb24ef JS |
7442 | uint32_t |
7443 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
7444 | { | |
7445 | spin_lock_irq(&phba->hbalock); | |
7446 | phba->buffer_tag_count++; | |
7447 | /* | |
7448 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
7449 | * a tag assigned by HBQ. | |
7450 | */ | |
7451 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
7452 | spin_unlock_irq(&phba->hbalock); | |
7453 | return phba->buffer_tag_count; | |
7454 | } | |
7455 | ||
e59058c4 | 7456 | /** |
3621a710 | 7457 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
7458 | * @phba: Pointer to HBA context object. |
7459 | * @pring: Pointer to driver SLI ring object. | |
7460 | * @tag: Buffer tag. | |
7461 | * | |
7462 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
7463 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
7464 | * iocb is posted to the response ring with the tag of the buffer. | |
7465 | * This function searches the pring->postbufq list using the tag | |
7466 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
7467 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
7468 | * buffer is returned to the caller else NULL is returned. | |
7469 | * This function is called with no lock held. | |
7470 | **/ | |
76bb24ef JS |
7471 | struct lpfc_dmabuf * |
7472 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7473 | uint32_t tag) | |
7474 | { | |
7475 | struct lpfc_dmabuf *mp, *next_mp; | |
7476 | struct list_head *slp = &pring->postbufq; | |
7477 | ||
7478 | /* Search postbufq, from the begining, looking for a match on tag */ | |
7479 | spin_lock_irq(&phba->hbalock); | |
7480 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
7481 | if (mp->buffer_tag == tag) { | |
7482 | list_del_init(&mp->list); | |
7483 | pring->postbufq_cnt--; | |
7484 | spin_unlock_irq(&phba->hbalock); | |
7485 | return mp; | |
7486 | } | |
7487 | } | |
7488 | ||
7489 | spin_unlock_irq(&phba->hbalock); | |
7490 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 7491 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
7492 | "ring %d Data x%lx x%p x%p x%x\n", |
7493 | pring->ringno, (unsigned long) tag, | |
7494 | slp->next, slp->prev, pring->postbufq_cnt); | |
7495 | ||
7496 | return NULL; | |
7497 | } | |
dea3101e | 7498 | |
e59058c4 | 7499 | /** |
3621a710 | 7500 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
7501 | * @phba: Pointer to HBA context object. |
7502 | * @pring: Pointer to driver SLI ring object. | |
7503 | * @phys: DMA address of the buffer. | |
7504 | * | |
7505 | * This function searches the buffer list using the dma_address | |
7506 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
7507 | * corresponding to the dma_address. The function returns the | |
7508 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
7509 | * This function is called by the ct and els unsolicited event | |
7510 | * handlers to get the buffer associated with the unsolicited | |
7511 | * event. | |
7512 | * | |
7513 | * This function is called with no lock held. | |
7514 | **/ | |
dea3101e JB |
7515 | struct lpfc_dmabuf * |
7516 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7517 | dma_addr_t phys) | |
7518 | { | |
7519 | struct lpfc_dmabuf *mp, *next_mp; | |
7520 | struct list_head *slp = &pring->postbufq; | |
7521 | ||
7522 | /* Search postbufq, from the begining, looking for a match on phys */ | |
2e0fef85 | 7523 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
7524 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
7525 | if (mp->phys == phys) { | |
7526 | list_del_init(&mp->list); | |
7527 | pring->postbufq_cnt--; | |
2e0fef85 | 7528 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
7529 | return mp; |
7530 | } | |
7531 | } | |
7532 | ||
2e0fef85 | 7533 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7534 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 7535 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 7536 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 7537 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
7538 | slp->next, slp->prev, pring->postbufq_cnt); |
7539 | return NULL; | |
7540 | } | |
7541 | ||
e59058c4 | 7542 | /** |
3621a710 | 7543 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
7544 | * @phba: Pointer to HBA context object. |
7545 | * @cmdiocb: Pointer to driver command iocb object. | |
7546 | * @rspiocb: Pointer to driver response iocb object. | |
7547 | * | |
7548 | * This function is the completion handler for the abort iocbs for | |
7549 | * ELS commands. This function is called from the ELS ring event | |
7550 | * handler with no lock held. This function frees memory resources | |
7551 | * associated with the abort iocb. | |
7552 | **/ | |
dea3101e | 7553 | static void |
2e0fef85 JS |
7554 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7555 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 7556 | { |
2e0fef85 | 7557 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 7558 | uint16_t abort_iotag, abort_context; |
92d7f7b0 | 7559 | struct lpfc_iocbq *abort_iocb; |
2680eeaa JS |
7560 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
7561 | ||
7562 | abort_iocb = NULL; | |
2680eeaa JS |
7563 | |
7564 | if (irsp->ulpStatus) { | |
7565 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | |
7566 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
7567 | ||
2e0fef85 | 7568 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
7569 | if (phba->sli_rev < LPFC_SLI_REV4) { |
7570 | if (abort_iotag != 0 && | |
7571 | abort_iotag <= phba->sli.last_iotag) | |
7572 | abort_iocb = | |
7573 | phba->sli.iocbq_lookup[abort_iotag]; | |
7574 | } else | |
7575 | /* For sli4 the abort_tag is the XRI, | |
7576 | * so the abort routine puts the iotag of the iocb | |
7577 | * being aborted in the context field of the abort | |
7578 | * IOCB. | |
7579 | */ | |
7580 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 7581 | |
58da1ffb JS |
7582 | /* |
7583 | * If the iocb is not found in Firmware queue the iocb | |
7584 | * might have completed already. Do not free it again. | |
7585 | */ | |
9b379605 | 7586 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
45ed1190 JS |
7587 | if (irsp->un.ulpWord[4] != IOERR_NO_XRI) { |
7588 | spin_unlock_irq(&phba->hbalock); | |
7589 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
7590 | return; | |
7591 | } | |
7592 | /* For SLI4 the ulpContext field for abort IOCB | |
7593 | * holds the iotag of the IOCB being aborted so | |
7594 | * the local abort_context needs to be reset to | |
7595 | * match the aborted IOCBs ulpContext. | |
7596 | */ | |
7597 | if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4) | |
7598 | abort_context = abort_iocb->iocb.ulpContext; | |
58da1ffb | 7599 | } |
2a9bf3d0 JS |
7600 | |
7601 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, | |
7602 | "0327 Cannot abort els iocb %p " | |
7603 | "with tag %x context %x, abort status %x, " | |
7604 | "abort code %x\n", | |
7605 | abort_iocb, abort_iotag, abort_context, | |
7606 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
2680eeaa JS |
7607 | /* |
7608 | * make sure we have the right iocbq before taking it | |
7609 | * off the txcmplq and try to call completion routine. | |
7610 | */ | |
2e0fef85 JS |
7611 | if (!abort_iocb || |
7612 | abort_iocb->iocb.ulpContext != abort_context || | |
7613 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | |
7614 | spin_unlock_irq(&phba->hbalock); | |
341af102 JS |
7615 | else if (phba->sli_rev < LPFC_SLI_REV4) { |
7616 | /* | |
7617 | * leave the SLI4 aborted command on the txcmplq | |
7618 | * list and the command complete WCQE's XB bit | |
7619 | * will tell whether the SGL (XRI) can be released | |
7620 | * immediately or to the aborted SGL list for the | |
7621 | * following abort XRI from the HBA. | |
7622 | */ | |
92d7f7b0 | 7623 | list_del_init(&abort_iocb->list); |
2a9bf3d0 JS |
7624 | if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) { |
7625 | abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
7626 | pring->txcmplq_cnt--; | |
7627 | } | |
2680eeaa | 7628 | |
0ff10d46 JS |
7629 | /* Firmware could still be in progress of DMAing |
7630 | * payload, so don't free data buffer till after | |
7631 | * a hbeat. | |
7632 | */ | |
7633 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
92d7f7b0 | 7634 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
341af102 JS |
7635 | spin_unlock_irq(&phba->hbalock); |
7636 | ||
92d7f7b0 | 7637 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
341af102 | 7638 | abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED; |
92d7f7b0 | 7639 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
49198b37 JS |
7640 | } else |
7641 | spin_unlock_irq(&phba->hbalock); | |
2680eeaa JS |
7642 | } |
7643 | ||
604a3e30 | 7644 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
7645 | return; |
7646 | } | |
7647 | ||
e59058c4 | 7648 | /** |
3621a710 | 7649 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
7650 | * @phba: Pointer to HBA context object. |
7651 | * @cmdiocb: Pointer to driver command iocb object. | |
7652 | * @rspiocb: Pointer to driver response iocb object. | |
7653 | * | |
7654 | * The function is called from SLI ring event handler with no | |
7655 | * lock held. This function is the completion handler for ELS commands | |
7656 | * which are aborted. The function frees memory resources used for | |
7657 | * the aborted ELS commands. | |
7658 | **/ | |
92d7f7b0 JS |
7659 | static void |
7660 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
7661 | struct lpfc_iocbq *rspiocb) | |
7662 | { | |
7663 | IOCB_t *irsp = &rspiocb->iocb; | |
7664 | ||
7665 | /* ELS cmd tag <ulpIoTag> completes */ | |
7666 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 7667 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 7668 | "x%x x%x x%x\n", |
e8b62011 | 7669 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 7670 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
7671 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
7672 | lpfc_ct_free_iocb(phba, cmdiocb); | |
7673 | else | |
7674 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
7675 | return; |
7676 | } | |
7677 | ||
e59058c4 | 7678 | /** |
5af5eee7 | 7679 | * lpfc_sli_abort_iotag_issue - Issue abort for a command iocb |
e59058c4 JS |
7680 | * @phba: Pointer to HBA context object. |
7681 | * @pring: Pointer to driver SLI ring object. | |
7682 | * @cmdiocb: Pointer to driver command iocb object. | |
7683 | * | |
5af5eee7 JS |
7684 | * This function issues an abort iocb for the provided command iocb down to |
7685 | * the port. Other than the case the outstanding command iocb is an abort | |
7686 | * request, this function issues abort out unconditionally. This function is | |
7687 | * called with hbalock held. The function returns 0 when it fails due to | |
7688 | * memory allocation failure or when the command iocb is an abort request. | |
e59058c4 | 7689 | **/ |
5af5eee7 JS |
7690 | static int |
7691 | lpfc_sli_abort_iotag_issue(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 7692 | struct lpfc_iocbq *cmdiocb) |
dea3101e | 7693 | { |
2e0fef85 | 7694 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 7695 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
7696 | IOCB_t *icmd = NULL; |
7697 | IOCB_t *iabt = NULL; | |
5af5eee7 | 7698 | int retval; |
07951076 | 7699 | |
92d7f7b0 JS |
7700 | /* |
7701 | * There are certain command types we don't want to abort. And we | |
7702 | * don't want to abort commands that are already in the process of | |
7703 | * being aborted. | |
07951076 JS |
7704 | */ |
7705 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 7706 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
7707 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
7708 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
7709 | return 0; |
7710 | ||
dea3101e | 7711 | /* issue ABTS for this IOCB based on iotag */ |
92d7f7b0 | 7712 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
7713 | if (abtsiocbp == NULL) |
7714 | return 0; | |
dea3101e | 7715 | |
07951076 | 7716 | /* This signals the response to set the correct status |
341af102 | 7717 | * before calling the completion handler |
07951076 JS |
7718 | */ |
7719 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
7720 | ||
dea3101e | 7721 | iabt = &abtsiocbp->iocb; |
07951076 JS |
7722 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
7723 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 7724 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 7725 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
7726 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
7727 | } | |
da0436e9 JS |
7728 | else |
7729 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
7730 | iabt->ulpLe = 1; |
7731 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 7732 | |
5ffc266e JS |
7733 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
7734 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
7735 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
7736 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 7737 | |
2e0fef85 | 7738 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
7739 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
7740 | else | |
7741 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 7742 | |
07951076 | 7743 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 7744 | |
e8b62011 JS |
7745 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
7746 | "0339 Abort xri x%x, original iotag x%x, " | |
7747 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 7748 | iabt->un.acxri.abortIoTag, |
e8b62011 | 7749 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 7750 | abtsiocbp->iotag); |
da0436e9 | 7751 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
dea3101e | 7752 | |
d7c255b2 JS |
7753 | if (retval) |
7754 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
5af5eee7 JS |
7755 | |
7756 | /* | |
7757 | * Caller to this routine should check for IOCB_ERROR | |
7758 | * and handle it properly. This routine no longer removes | |
7759 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
7760 | */ | |
7761 | return retval; | |
7762 | } | |
7763 | ||
7764 | /** | |
7765 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb | |
7766 | * @phba: Pointer to HBA context object. | |
7767 | * @pring: Pointer to driver SLI ring object. | |
7768 | * @cmdiocb: Pointer to driver command iocb object. | |
7769 | * | |
7770 | * This function issues an abort iocb for the provided command iocb. In case | |
7771 | * of unloading, the abort iocb will not be issued to commands on the ELS | |
7772 | * ring. Instead, the callback function shall be changed to those commands | |
7773 | * so that nothing happens when them finishes. This function is called with | |
7774 | * hbalock held. The function returns 0 when the command iocb is an abort | |
7775 | * request. | |
7776 | **/ | |
7777 | int | |
7778 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7779 | struct lpfc_iocbq *cmdiocb) | |
7780 | { | |
7781 | struct lpfc_vport *vport = cmdiocb->vport; | |
7782 | int retval = IOCB_ERROR; | |
7783 | IOCB_t *icmd = NULL; | |
7784 | ||
7785 | /* | |
7786 | * There are certain command types we don't want to abort. And we | |
7787 | * don't want to abort commands that are already in the process of | |
7788 | * being aborted. | |
7789 | */ | |
7790 | icmd = &cmdiocb->iocb; | |
7791 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || | |
7792 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || | |
7793 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
7794 | return 0; | |
7795 | ||
7796 | /* | |
7797 | * If we're unloading, don't abort iocb on the ELS ring, but change | |
7798 | * the callback so that nothing happens when it finishes. | |
7799 | */ | |
7800 | if ((vport->load_flag & FC_UNLOADING) && | |
7801 | (pring->ringno == LPFC_ELS_RING)) { | |
7802 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) | |
7803 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
7804 | else | |
7805 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
7806 | goto abort_iotag_exit; | |
7807 | } | |
7808 | ||
7809 | /* Now, we try to issue the abort to the cmdiocb out */ | |
7810 | retval = lpfc_sli_abort_iotag_issue(phba, pring, cmdiocb); | |
7811 | ||
07951076 | 7812 | abort_iotag_exit: |
2e0fef85 JS |
7813 | /* |
7814 | * Caller to this routine should check for IOCB_ERROR | |
7815 | * and handle it properly. This routine no longer removes | |
7816 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 7817 | */ |
2e0fef85 | 7818 | return retval; |
dea3101e JB |
7819 | } |
7820 | ||
5af5eee7 JS |
7821 | /** |
7822 | * lpfc_sli_iocb_ring_abort - Unconditionally abort all iocbs on an iocb ring | |
7823 | * @phba: Pointer to HBA context object. | |
7824 | * @pring: Pointer to driver SLI ring object. | |
7825 | * | |
7826 | * This function aborts all iocbs in the given ring and frees all the iocb | |
7827 | * objects in txq. This function issues abort iocbs unconditionally for all | |
7828 | * the iocb commands in txcmplq. The iocbs in the txcmplq is not guaranteed | |
7829 | * to complete before the return of this function. The caller is not required | |
7830 | * to hold any locks. | |
7831 | **/ | |
7832 | static void | |
7833 | lpfc_sli_iocb_ring_abort(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
7834 | { | |
7835 | LIST_HEAD(completions); | |
7836 | struct lpfc_iocbq *iocb, *next_iocb; | |
7837 | ||
7838 | if (pring->ringno == LPFC_ELS_RING) | |
7839 | lpfc_fabric_abort_hba(phba); | |
7840 | ||
7841 | spin_lock_irq(&phba->hbalock); | |
7842 | ||
7843 | /* Take off all the iocbs on txq for cancelling */ | |
7844 | list_splice_init(&pring->txq, &completions); | |
7845 | pring->txq_cnt = 0; | |
7846 | ||
7847 | /* Next issue ABTS for everything on the txcmplq */ | |
7848 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) | |
7849 | lpfc_sli_abort_iotag_issue(phba, pring, iocb); | |
7850 | ||
7851 | spin_unlock_irq(&phba->hbalock); | |
7852 | ||
7853 | /* Cancel all the IOCBs from the completions list */ | |
7854 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
7855 | IOERR_SLI_ABORTED); | |
7856 | } | |
7857 | ||
7858 | /** | |
7859 | * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba. | |
7860 | * @phba: pointer to lpfc HBA data structure. | |
7861 | * | |
7862 | * This routine will abort all pending and outstanding iocbs to an HBA. | |
7863 | **/ | |
7864 | void | |
7865 | lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba) | |
7866 | { | |
7867 | struct lpfc_sli *psli = &phba->sli; | |
7868 | struct lpfc_sli_ring *pring; | |
7869 | int i; | |
7870 | ||
7871 | for (i = 0; i < psli->num_rings; i++) { | |
7872 | pring = &psli->ring[i]; | |
7873 | lpfc_sli_iocb_ring_abort(phba, pring); | |
7874 | } | |
7875 | } | |
7876 | ||
e59058c4 | 7877 | /** |
3621a710 | 7878 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
7879 | * @iocbq: Pointer to driver iocb object. |
7880 | * @vport: Pointer to driver virtual port object. | |
7881 | * @tgt_id: SCSI ID of the target. | |
7882 | * @lun_id: LUN ID of the scsi device. | |
7883 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
7884 | * | |
3621a710 | 7885 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
7886 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
7887 | * 0 if the filtering criteria is met for the given iocb and will return | |
7888 | * 1 if the filtering criteria is not met. | |
7889 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
7890 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
7891 | * lun_id parameter. | |
7892 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
7893 | * given iocb is for the SCSI target specified by vport and tgt_id | |
7894 | * parameters. | |
7895 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
7896 | * given iocb is for the SCSI host associated with the given vport. | |
7897 | * This function is called with no locks held. | |
7898 | **/ | |
dea3101e | 7899 | static int |
51ef4c26 JS |
7900 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
7901 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 7902 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 7903 | { |
0bd4ca25 | 7904 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
7905 | int rc = 1; |
7906 | ||
0bd4ca25 JSEC |
7907 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
7908 | return rc; | |
7909 | ||
51ef4c26 JS |
7910 | if (iocbq->vport != vport) |
7911 | return rc; | |
7912 | ||
0bd4ca25 | 7913 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 7914 | |
495a714c | 7915 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
7916 | return rc; |
7917 | ||
7918 | switch (ctx_cmd) { | |
7919 | case LPFC_CTX_LUN: | |
495a714c JS |
7920 | if ((lpfc_cmd->rdata->pnode) && |
7921 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
7922 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
7923 | rc = 0; |
7924 | break; | |
7925 | case LPFC_CTX_TGT: | |
495a714c JS |
7926 | if ((lpfc_cmd->rdata->pnode) && |
7927 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
7928 | rc = 0; |
7929 | break; | |
dea3101e JB |
7930 | case LPFC_CTX_HOST: |
7931 | rc = 0; | |
7932 | break; | |
7933 | default: | |
7934 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 7935 | __func__, ctx_cmd); |
dea3101e JB |
7936 | break; |
7937 | } | |
7938 | ||
7939 | return rc; | |
7940 | } | |
7941 | ||
e59058c4 | 7942 | /** |
3621a710 | 7943 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
7944 | * @vport: Pointer to virtual port. |
7945 | * @tgt_id: SCSI ID of the target. | |
7946 | * @lun_id: LUN ID of the scsi device. | |
7947 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
7948 | * | |
7949 | * This function returns number of FCP commands pending for the vport. | |
7950 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
7951 | * commands pending on the vport associated with SCSI device specified | |
7952 | * by tgt_id and lun_id parameters. | |
7953 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
7954 | * commands pending on the vport associated with SCSI target specified | |
7955 | * by tgt_id parameter. | |
7956 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
7957 | * commands pending on the vport. | |
7958 | * This function returns the number of iocbs which satisfy the filter. | |
7959 | * This function is called without any lock held. | |
7960 | **/ | |
dea3101e | 7961 | int |
51ef4c26 JS |
7962 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
7963 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 7964 | { |
51ef4c26 | 7965 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
7966 | struct lpfc_iocbq *iocbq; |
7967 | int sum, i; | |
dea3101e | 7968 | |
0bd4ca25 JSEC |
7969 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
7970 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 7971 | |
51ef4c26 JS |
7972 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
7973 | ctx_cmd) == 0) | |
0bd4ca25 | 7974 | sum++; |
dea3101e | 7975 | } |
0bd4ca25 | 7976 | |
dea3101e JB |
7977 | return sum; |
7978 | } | |
7979 | ||
e59058c4 | 7980 | /** |
3621a710 | 7981 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
7982 | * @phba: Pointer to HBA context object |
7983 | * @cmdiocb: Pointer to command iocb object. | |
7984 | * @rspiocb: Pointer to response iocb object. | |
7985 | * | |
7986 | * This function is called when an aborted FCP iocb completes. This | |
7987 | * function is called by the ring event handler with no lock held. | |
7988 | * This function frees the iocb. | |
7989 | **/ | |
5eb95af0 | 7990 | void |
2e0fef85 JS |
7991 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7992 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 7993 | { |
604a3e30 | 7994 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
7995 | return; |
7996 | } | |
7997 | ||
e59058c4 | 7998 | /** |
3621a710 | 7999 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
8000 | * @vport: Pointer to virtual port. |
8001 | * @pring: Pointer to driver SLI ring object. | |
8002 | * @tgt_id: SCSI ID of the target. | |
8003 | * @lun_id: LUN ID of the scsi device. | |
8004 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
8005 | * | |
8006 | * This function sends an abort command for every SCSI command | |
8007 | * associated with the given virtual port pending on the ring | |
8008 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
8009 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
8010 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
8011 | * parameters | |
8012 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
8013 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
8014 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
8015 | * FCP iocbs associated with virtual port. | |
8016 | * This function returns number of iocbs it failed to abort. | |
8017 | * This function is called with no locks held. | |
8018 | **/ | |
dea3101e | 8019 | int |
51ef4c26 JS |
8020 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
8021 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 8022 | { |
51ef4c26 | 8023 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
8024 | struct lpfc_iocbq *iocbq; |
8025 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 8026 | IOCB_t *cmd = NULL; |
dea3101e | 8027 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 8028 | int i; |
dea3101e | 8029 | |
0bd4ca25 JSEC |
8030 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
8031 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 8032 | |
51ef4c26 | 8033 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 8034 | abort_cmd) != 0) |
dea3101e JB |
8035 | continue; |
8036 | ||
8037 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 8038 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
8039 | if (abtsiocb == NULL) { |
8040 | errcnt++; | |
8041 | continue; | |
8042 | } | |
dea3101e | 8043 | |
0bd4ca25 | 8044 | cmd = &iocbq->iocb; |
dea3101e JB |
8045 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
8046 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
8047 | if (phba->sli_rev == LPFC_SLI_REV4) |
8048 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
8049 | else | |
8050 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
8051 | abtsiocb->iocb.ulpLe = 1; |
8052 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 8053 | abtsiocb->vport = phba->pport; |
dea3101e | 8054 | |
5ffc266e JS |
8055 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
8056 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
8057 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
8058 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 8059 | |
2e0fef85 | 8060 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
8061 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
8062 | else | |
8063 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
8064 | ||
5eb95af0 JSEC |
8065 | /* Setup callback routine and issue the command. */ |
8066 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
8067 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
8068 | abtsiocb, 0); | |
dea3101e | 8069 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 8070 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
8071 | errcnt++; |
8072 | continue; | |
8073 | } | |
8074 | } | |
8075 | ||
8076 | return errcnt; | |
8077 | } | |
8078 | ||
e59058c4 | 8079 | /** |
3621a710 | 8080 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
8081 | * @phba: Pointer to HBA context object. |
8082 | * @cmdiocbq: Pointer to command iocb. | |
8083 | * @rspiocbq: Pointer to response iocb. | |
8084 | * | |
8085 | * This function is the completion handler for iocbs issued using | |
8086 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
8087 | * ring event handler function without any lock held. This function | |
8088 | * can be called from both worker thread context and interrupt | |
8089 | * context. This function also can be called from other thread which | |
8090 | * cleans up the SLI layer objects. | |
8091 | * This function copy the contents of the response iocb to the | |
8092 | * response iocb memory object provided by the caller of | |
8093 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
8094 | * sleeps for the iocb completion. | |
8095 | **/ | |
68876920 JSEC |
8096 | static void |
8097 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
8098 | struct lpfc_iocbq *cmdiocbq, | |
8099 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 8100 | { |
68876920 JSEC |
8101 | wait_queue_head_t *pdone_q; |
8102 | unsigned long iflags; | |
0f65ff68 | 8103 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 8104 | |
2e0fef85 | 8105 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
8106 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
8107 | if (cmdiocbq->context2 && rspiocbq) | |
8108 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
8109 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
8110 | ||
0f65ff68 JS |
8111 | /* Set the exchange busy flag for task management commands */ |
8112 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
8113 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
8114 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
8115 | cur_iocbq); | |
8116 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
8117 | } | |
8118 | ||
68876920 | 8119 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
8120 | if (pdone_q) |
8121 | wake_up(pdone_q); | |
858c9f6c | 8122 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
8123 | return; |
8124 | } | |
8125 | ||
d11e31dd JS |
8126 | /** |
8127 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
8128 | * @phba: Pointer to HBA context object.. | |
8129 | * @piocbq: Pointer to command iocb. | |
8130 | * @flag: Flag to test. | |
8131 | * | |
8132 | * This routine grabs the hbalock and then test the iocb_flag to | |
8133 | * see if the passed in flag is set. | |
8134 | * Returns: | |
8135 | * 1 if flag is set. | |
8136 | * 0 if flag is not set. | |
8137 | **/ | |
8138 | static int | |
8139 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
8140 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
8141 | { | |
8142 | unsigned long iflags; | |
8143 | int ret; | |
8144 | ||
8145 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8146 | ret = piocbq->iocb_flag & flag; | |
8147 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8148 | return ret; | |
8149 | ||
8150 | } | |
8151 | ||
e59058c4 | 8152 | /** |
3621a710 | 8153 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
8154 | * @phba: Pointer to HBA context object.. |
8155 | * @pring: Pointer to sli ring. | |
8156 | * @piocb: Pointer to command iocb. | |
8157 | * @prspiocbq: Pointer to response iocb. | |
8158 | * @timeout: Timeout in number of seconds. | |
8159 | * | |
8160 | * This function issues the iocb to firmware and waits for the | |
8161 | * iocb to complete. If the iocb command is not | |
8162 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
8163 | * Caller should not free the iocb resources if this function | |
8164 | * returns IOCB_TIMEDOUT. | |
8165 | * The function waits for the iocb completion using an | |
8166 | * non-interruptible wait. | |
8167 | * This function will sleep while waiting for iocb completion. | |
8168 | * So, this function should not be called from any context which | |
8169 | * does not allow sleeping. Due to the same reason, this function | |
8170 | * cannot be called with interrupt disabled. | |
8171 | * This function assumes that the iocb completions occur while | |
8172 | * this function sleep. So, this function cannot be called from | |
8173 | * the thread which process iocb completion for this ring. | |
8174 | * This function clears the iocb_flag of the iocb object before | |
8175 | * issuing the iocb and the iocb completion handler sets this | |
8176 | * flag and wakes this thread when the iocb completes. | |
8177 | * The contents of the response iocb will be copied to prspiocbq | |
8178 | * by the completion handler when the command completes. | |
8179 | * This function returns IOCB_SUCCESS when success. | |
8180 | * This function is called with no lock held. | |
8181 | **/ | |
dea3101e | 8182 | int |
2e0fef85 | 8183 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 8184 | uint32_t ring_number, |
2e0fef85 JS |
8185 | struct lpfc_iocbq *piocb, |
8186 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 8187 | uint32_t timeout) |
dea3101e | 8188 | { |
7259f0d0 | 8189 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
8190 | long timeleft, timeout_req = 0; |
8191 | int retval = IOCB_SUCCESS; | |
875fbdfe | 8192 | uint32_t creg_val; |
2a9bf3d0 | 8193 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 8194 | /* |
68876920 JSEC |
8195 | * If the caller has provided a response iocbq buffer, then context2 |
8196 | * is NULL or its an error. | |
dea3101e | 8197 | */ |
68876920 JSEC |
8198 | if (prspiocbq) { |
8199 | if (piocb->context2) | |
8200 | return IOCB_ERROR; | |
8201 | piocb->context2 = prspiocbq; | |
dea3101e JB |
8202 | } |
8203 | ||
68876920 JSEC |
8204 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
8205 | piocb->context_un.wait_queue = &done_q; | |
8206 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 8207 | |
875fbdfe JSEC |
8208 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
8209 | creg_val = readl(phba->HCregaddr); | |
8210 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
8211 | writel(creg_val, phba->HCregaddr); | |
8212 | readl(phba->HCregaddr); /* flush */ | |
8213 | } | |
8214 | ||
2a9bf3d0 JS |
8215 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
8216 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
8217 | if (retval == IOCB_SUCCESS) { |
8218 | timeout_req = timeout * HZ; | |
68876920 | 8219 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 8220 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 8221 | timeout_req); |
dea3101e | 8222 | |
7054a606 JS |
8223 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
8224 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 8225 | "0331 IOCB wake signaled\n"); |
7054a606 | 8226 | } else if (timeleft == 0) { |
68876920 | 8227 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
8228 | "0338 IOCB wait timeout error - no " |
8229 | "wake response Data x%x\n", timeout); | |
68876920 | 8230 | retval = IOCB_TIMEDOUT; |
7054a606 | 8231 | } else { |
68876920 | 8232 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
8233 | "0330 IOCB wake NOT set, " |
8234 | "Data x%x x%lx\n", | |
68876920 JSEC |
8235 | timeout, (timeleft / jiffies)); |
8236 | retval = IOCB_TIMEDOUT; | |
dea3101e | 8237 | } |
2a9bf3d0 JS |
8238 | } else if (retval == IOCB_BUSY) { |
8239 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8240 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
8241 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
8242 | return retval; | |
68876920 JSEC |
8243 | } else { |
8244 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 8245 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 8246 | retval); |
68876920 | 8247 | retval = IOCB_ERROR; |
dea3101e JB |
8248 | } |
8249 | ||
875fbdfe JSEC |
8250 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
8251 | creg_val = readl(phba->HCregaddr); | |
8252 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | |
8253 | writel(creg_val, phba->HCregaddr); | |
8254 | readl(phba->HCregaddr); /* flush */ | |
8255 | } | |
8256 | ||
68876920 JSEC |
8257 | if (prspiocbq) |
8258 | piocb->context2 = NULL; | |
8259 | ||
8260 | piocb->context_un.wait_queue = NULL; | |
8261 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
8262 | return retval; |
8263 | } | |
68876920 | 8264 | |
e59058c4 | 8265 | /** |
3621a710 | 8266 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
8267 | * @phba: Pointer to HBA context object. |
8268 | * @pmboxq: Pointer to driver mailbox object. | |
8269 | * @timeout: Timeout in number of seconds. | |
8270 | * | |
8271 | * This function issues the mailbox to firmware and waits for the | |
8272 | * mailbox command to complete. If the mailbox command is not | |
8273 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
8274 | * The function waits for the mailbox completion using an | |
8275 | * interruptible wait. If the thread is woken up due to a | |
8276 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
8277 | * should not free the mailbox resources, if this function returns | |
8278 | * MBX_TIMEOUT. | |
8279 | * This function will sleep while waiting for mailbox completion. | |
8280 | * So, this function should not be called from any context which | |
8281 | * does not allow sleeping. Due to the same reason, this function | |
8282 | * cannot be called with interrupt disabled. | |
8283 | * This function assumes that the mailbox completion occurs while | |
8284 | * this function sleep. So, this function cannot be called from | |
8285 | * the worker thread which processes mailbox completion. | |
8286 | * This function is called in the context of HBA management | |
8287 | * applications. | |
8288 | * This function returns MBX_SUCCESS when successful. | |
8289 | * This function is called with no lock held. | |
8290 | **/ | |
dea3101e | 8291 | int |
2e0fef85 | 8292 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
8293 | uint32_t timeout) |
8294 | { | |
7259f0d0 | 8295 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 8296 | int retval; |
858c9f6c | 8297 | unsigned long flag; |
dea3101e JB |
8298 | |
8299 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 8300 | if (pmboxq->context1) |
2e0fef85 | 8301 | return MBX_NOT_FINISHED; |
dea3101e | 8302 | |
495a714c | 8303 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
8304 | /* setup wake call as IOCB callback */ |
8305 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
8306 | /* setup context field to pass wait_queue pointer to wake function */ | |
8307 | pmboxq->context1 = &done_q; | |
8308 | ||
dea3101e JB |
8309 | /* now issue the command */ |
8310 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
8311 | ||
8312 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | |
7054a606 JS |
8313 | wait_event_interruptible_timeout(done_q, |
8314 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
8315 | timeout * HZ); | |
8316 | ||
858c9f6c | 8317 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 8318 | pmboxq->context1 = NULL; |
7054a606 JS |
8319 | /* |
8320 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
8321 | * else do not free the resources. | |
8322 | */ | |
d7c47992 | 8323 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) { |
dea3101e | 8324 | retval = MBX_SUCCESS; |
d7c47992 JS |
8325 | lpfc_sli4_swap_str(phba, pmboxq); |
8326 | } else { | |
7054a606 | 8327 | retval = MBX_TIMEOUT; |
858c9f6c JS |
8328 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
8329 | } | |
8330 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e JB |
8331 | } |
8332 | ||
dea3101e JB |
8333 | return retval; |
8334 | } | |
8335 | ||
e59058c4 | 8336 | /** |
3772a991 | 8337 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
8338 | * @phba: Pointer to HBA context. |
8339 | * | |
3772a991 JS |
8340 | * This function is called to shutdown the driver's mailbox sub-system. |
8341 | * It first marks the mailbox sub-system is in a block state to prevent | |
8342 | * the asynchronous mailbox command from issued off the pending mailbox | |
8343 | * command queue. If the mailbox command sub-system shutdown is due to | |
8344 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
8345 | * the mailbox sub-system flush routine to forcefully bring down the | |
8346 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
8347 | * as with offline or HBA function reset), this routine will wait for the | |
8348 | * outstanding mailbox command to complete before invoking the mailbox | |
8349 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 8350 | **/ |
3772a991 JS |
8351 | void |
8352 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) | |
b4c02652 | 8353 | { |
3772a991 JS |
8354 | struct lpfc_sli *psli = &phba->sli; |
8355 | uint8_t actcmd = MBX_HEARTBEAT; | |
8356 | unsigned long timeout; | |
b4c02652 | 8357 | |
3772a991 JS |
8358 | spin_lock_irq(&phba->hbalock); |
8359 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
8360 | spin_unlock_irq(&phba->hbalock); | |
b4c02652 | 8361 | |
3772a991 | 8362 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
ed957684 | 8363 | spin_lock_irq(&phba->hbalock); |
3772a991 JS |
8364 | if (phba->sli.mbox_active) |
8365 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
ed957684 | 8366 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
8367 | /* Determine how long we might wait for the active mailbox |
8368 | * command to be gracefully completed by firmware. | |
8369 | */ | |
8370 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * | |
8371 | 1000) + jiffies; | |
8372 | while (phba->sli.mbox_active) { | |
8373 | /* Check active mailbox complete status every 2ms */ | |
8374 | msleep(2); | |
8375 | if (time_after(jiffies, timeout)) | |
8376 | /* Timeout, let the mailbox flush routine to | |
8377 | * forcefully release active mailbox command | |
8378 | */ | |
8379 | break; | |
8380 | } | |
8381 | } | |
8382 | lpfc_sli_mbox_sys_flush(phba); | |
8383 | } | |
ed957684 | 8384 | |
3772a991 JS |
8385 | /** |
8386 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
8387 | * @phba: Pointer to HBA context. | |
8388 | * | |
8389 | * This function is called to read the SLI3 device error attention registers | |
8390 | * for possible error attention events. The caller must hold the hostlock | |
8391 | * with spin_lock_irq(). | |
8392 | * | |
8393 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
8394 | * Register and returns 0 otherwise. | |
8395 | **/ | |
8396 | static int | |
8397 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
8398 | { | |
8399 | uint32_t ha_copy; | |
b4c02652 | 8400 | |
3772a991 JS |
8401 | /* Read chip Host Attention (HA) register */ |
8402 | ha_copy = readl(phba->HAregaddr); | |
8403 | if (ha_copy & HA_ERATT) { | |
8404 | /* Read host status register to retrieve error event */ | |
8405 | lpfc_sli_read_hs(phba); | |
b4c02652 | 8406 | |
3772a991 JS |
8407 | /* Check if there is a deferred error condition is active */ |
8408 | if ((HS_FFER1 & phba->work_hs) && | |
8409 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 | 8410 | HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) { |
3772a991 | 8411 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
8412 | /* Clear all interrupt enable conditions */ |
8413 | writel(0, phba->HCregaddr); | |
8414 | readl(phba->HCregaddr); | |
8415 | } | |
8416 | ||
8417 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
8418 | phba->work_ha |= HA_ERATT; |
8419 | /* Indicate polling handles this ERATT */ | |
8420 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
8421 | return 1; |
8422 | } | |
8423 | return 0; | |
b4c02652 JS |
8424 | } |
8425 | ||
da0436e9 JS |
8426 | /** |
8427 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
8428 | * @phba: Pointer to HBA context. | |
8429 | * | |
8430 | * This function is called to read the SLI4 device error attention registers | |
8431 | * for possible error attention events. The caller must hold the hostlock | |
8432 | * with spin_lock_irq(). | |
8433 | * | |
8434 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
8435 | * Register and returns 0 otherwise. | |
8436 | **/ | |
8437 | static int | |
8438 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
8439 | { | |
8440 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
da0436e9 JS |
8441 | |
8442 | /* For now, use the SLI4 device internal unrecoverable error | |
8443 | * registers for error attention. This can be changed later. | |
8444 | */ | |
a747c9ce JS |
8445 | uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr); |
8446 | uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr); | |
8447 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || | |
8448 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
8449 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8450 | "1423 HBA Unrecoverable error: " | |
8451 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
8452 | "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n", | |
8453 | uerr_sta_lo, uerr_sta_hi, | |
8454 | phba->sli4_hba.ue_mask_lo, | |
8455 | phba->sli4_hba.ue_mask_hi); | |
8456 | phba->work_status[0] = uerr_sta_lo; | |
8457 | phba->work_status[1] = uerr_sta_hi; | |
8458 | /* Set the driver HA work bitmap */ | |
8459 | phba->work_ha |= HA_ERATT; | |
8460 | /* Indicate polling handles this ERATT */ | |
8461 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8462 | return 1; | |
da0436e9 JS |
8463 | } |
8464 | return 0; | |
8465 | } | |
8466 | ||
e59058c4 | 8467 | /** |
3621a710 | 8468 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
8469 | * @phba: Pointer to HBA context. |
8470 | * | |
3772a991 | 8471 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
8472 | * error attention register bit for error attention events. |
8473 | * | |
8474 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
8475 | * Register and returns 0 otherwise. | |
8476 | **/ | |
8477 | int | |
8478 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
8479 | { | |
8480 | uint32_t ha_copy; | |
8481 | ||
8482 | /* If somebody is waiting to handle an eratt, don't process it | |
8483 | * here. The brdkill function will do this. | |
8484 | */ | |
8485 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8486 | return 0; | |
8487 | ||
8488 | /* Check if interrupt handler handles this ERATT */ | |
8489 | spin_lock_irq(&phba->hbalock); | |
8490 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
8491 | /* Interrupt handler has handled ERATT */ | |
8492 | spin_unlock_irq(&phba->hbalock); | |
8493 | return 0; | |
8494 | } | |
8495 | ||
a257bf90 JS |
8496 | /* |
8497 | * If there is deferred error attention, do not check for error | |
8498 | * attention | |
8499 | */ | |
8500 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
8501 | spin_unlock_irq(&phba->hbalock); | |
8502 | return 0; | |
8503 | } | |
8504 | ||
3772a991 JS |
8505 | /* If PCI channel is offline, don't process it */ |
8506 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 8507 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
8508 | return 0; |
8509 | } | |
8510 | ||
8511 | switch (phba->sli_rev) { | |
8512 | case LPFC_SLI_REV2: | |
8513 | case LPFC_SLI_REV3: | |
8514 | /* Read chip Host Attention (HA) register */ | |
8515 | ha_copy = lpfc_sli_eratt_read(phba); | |
8516 | break; | |
da0436e9 JS |
8517 | case LPFC_SLI_REV4: |
8518 | /* Read devcie Uncoverable Error (UERR) registers */ | |
8519 | ha_copy = lpfc_sli4_eratt_read(phba); | |
8520 | break; | |
3772a991 JS |
8521 | default: |
8522 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8523 | "0299 Invalid SLI revision (%d)\n", | |
8524 | phba->sli_rev); | |
8525 | ha_copy = 0; | |
8526 | break; | |
9399627f JS |
8527 | } |
8528 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
8529 | |
8530 | return ha_copy; | |
8531 | } | |
8532 | ||
8533 | /** | |
8534 | * lpfc_intr_state_check - Check device state for interrupt handling | |
8535 | * @phba: Pointer to HBA context. | |
8536 | * | |
8537 | * This inline routine checks whether a device or its PCI slot is in a state | |
8538 | * that the interrupt should be handled. | |
8539 | * | |
8540 | * This function returns 0 if the device or the PCI slot is in a state that | |
8541 | * interrupt should be handled, otherwise -EIO. | |
8542 | */ | |
8543 | static inline int | |
8544 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
8545 | { | |
8546 | /* If the pci channel is offline, ignore all the interrupts */ | |
8547 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
8548 | return -EIO; | |
8549 | ||
8550 | /* Update device level interrupt statistics */ | |
8551 | phba->sli.slistat.sli_intr++; | |
8552 | ||
8553 | /* Ignore all interrupts during initialization. */ | |
8554 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
8555 | return -EIO; | |
8556 | ||
9399627f JS |
8557 | return 0; |
8558 | } | |
8559 | ||
8560 | /** | |
3772a991 | 8561 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
8562 | * @irq: Interrupt number. |
8563 | * @dev_id: The device context pointer. | |
8564 | * | |
9399627f | 8565 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
8566 | * service routine when device with SLI-3 interface spec is enabled with |
8567 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
8568 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
8569 | * interrupt mode, this function is called as part of the device-level | |
8570 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
8571 | * is undergoing initialization, the interrupt handler will not process | |
8572 | * the interrupt. The link attention and ELS ring attention events are | |
8573 | * handled by the worker thread. The interrupt handler signals the worker | |
8574 | * thread and returns for these events. This function is called without | |
8575 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
8576 | * structures. |
8577 | * | |
8578 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8579 | * returns IRQ_NONE. | |
e59058c4 | 8580 | **/ |
dea3101e | 8581 | irqreturn_t |
3772a991 | 8582 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 8583 | { |
2e0fef85 | 8584 | struct lpfc_hba *phba; |
a747c9ce | 8585 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
8586 | uint32_t work_ha_copy; |
8587 | unsigned long status; | |
5b75da2f | 8588 | unsigned long iflag; |
dea3101e JB |
8589 | uint32_t control; |
8590 | ||
92d7f7b0 | 8591 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
8592 | struct lpfc_vport *vport; |
8593 | struct lpfc_nodelist *ndlp; | |
8594 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
8595 | LPFC_MBOXQ_t *pmb; |
8596 | int rc; | |
8597 | ||
dea3101e JB |
8598 | /* |
8599 | * Get the driver's phba structure from the dev_id and | |
8600 | * assume the HBA is not interrupting. | |
8601 | */ | |
9399627f | 8602 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
8603 | |
8604 | if (unlikely(!phba)) | |
8605 | return IRQ_NONE; | |
8606 | ||
dea3101e | 8607 | /* |
9399627f JS |
8608 | * Stuff needs to be attented to when this function is invoked as an |
8609 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 8610 | */ |
9399627f | 8611 | if (phba->intr_type == MSIX) { |
3772a991 JS |
8612 | /* Check device state for handling interrupt */ |
8613 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8614 | return IRQ_NONE; |
8615 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 8616 | spin_lock_irqsave(&phba->hbalock, iflag); |
34b02dcd | 8617 | ha_copy = readl(phba->HAregaddr); |
9399627f JS |
8618 | /* If somebody is waiting to handle an eratt don't process it |
8619 | * here. The brdkill function will do this. | |
8620 | */ | |
8621 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8622 | ha_copy &= ~HA_ERATT; | |
8623 | /* Check the need for handling ERATT in interrupt handler */ | |
8624 | if (ha_copy & HA_ERATT) { | |
8625 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8626 | /* ERATT polling has handled ERATT */ | |
8627 | ha_copy &= ~HA_ERATT; | |
8628 | else | |
8629 | /* Indicate interrupt handler handles ERATT */ | |
8630 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8631 | } | |
a257bf90 JS |
8632 | |
8633 | /* | |
8634 | * If there is deferred error attention, do not check for any | |
8635 | * interrupt. | |
8636 | */ | |
8637 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8638 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8639 | return IRQ_NONE; |
8640 | } | |
8641 | ||
9399627f | 8642 | /* Clear up only attention source related to slow-path */ |
a747c9ce JS |
8643 | hc_copy = readl(phba->HCregaddr); |
8644 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | | |
8645 | HC_LAINT_ENA | HC_ERINT_ENA), | |
8646 | phba->HCregaddr); | |
9399627f JS |
8647 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
8648 | phba->HAregaddr); | |
a747c9ce | 8649 | writel(hc_copy, phba->HCregaddr); |
9399627f | 8650 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 8651 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8652 | } else |
8653 | ha_copy = phba->ha_copy; | |
dea3101e | 8654 | |
dea3101e JB |
8655 | work_ha_copy = ha_copy & phba->work_ha_mask; |
8656 | ||
9399627f | 8657 | if (work_ha_copy) { |
dea3101e JB |
8658 | if (work_ha_copy & HA_LATT) { |
8659 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
8660 | /* | |
8661 | * Turn off Link Attention interrupts | |
8662 | * until CLEAR_LA done | |
8663 | */ | |
5b75da2f | 8664 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
8665 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
8666 | control = readl(phba->HCregaddr); | |
8667 | control &= ~HC_LAINT_ENA; | |
8668 | writel(control, phba->HCregaddr); | |
8669 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 8670 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
8671 | } |
8672 | else | |
8673 | work_ha_copy &= ~HA_LATT; | |
8674 | } | |
8675 | ||
9399627f | 8676 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
8677 | /* |
8678 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
8679 | * the only slow ring. | |
8680 | */ | |
8681 | status = (work_ha_copy & | |
8682 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
8683 | status >>= (4*LPFC_ELS_RING); | |
8684 | if (status & HA_RXMASK) { | |
5b75da2f | 8685 | spin_lock_irqsave(&phba->hbalock, iflag); |
858c9f6c | 8686 | control = readl(phba->HCregaddr); |
a58cbd52 JS |
8687 | |
8688 | lpfc_debugfs_slow_ring_trc(phba, | |
8689 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
8690 | control, status, | |
8691 | (uint32_t)phba->sli.slistat.sli_intr); | |
8692 | ||
858c9f6c | 8693 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
8694 | lpfc_debugfs_slow_ring_trc(phba, |
8695 | "ISR Disable ring:" | |
8696 | "pwork:x%x hawork:x%x wait:x%x", | |
8697 | phba->work_ha, work_ha_copy, | |
8698 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8699 | &phba->work_waitq)); |
a58cbd52 | 8700 | |
858c9f6c JS |
8701 | control &= |
8702 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
8703 | writel(control, phba->HCregaddr); |
8704 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 8705 | } |
a58cbd52 JS |
8706 | else { |
8707 | lpfc_debugfs_slow_ring_trc(phba, | |
8708 | "ISR slow ring: pwork:" | |
8709 | "x%x hawork:x%x wait:x%x", | |
8710 | phba->work_ha, work_ha_copy, | |
8711 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8712 | &phba->work_waitq)); |
a58cbd52 | 8713 | } |
5b75da2f | 8714 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
8715 | } |
8716 | } | |
5b75da2f | 8717 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 8718 | if (work_ha_copy & HA_ERATT) { |
9399627f | 8719 | lpfc_sli_read_hs(phba); |
a257bf90 JS |
8720 | /* |
8721 | * Check if there is a deferred error condition | |
8722 | * is active | |
8723 | */ | |
8724 | if ((HS_FFER1 & phba->work_hs) && | |
8725 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
dcf2a4e0 JS |
8726 | HS_FFER6 | HS_FFER7 | HS_FFER8) & |
8727 | phba->work_hs)) { | |
a257bf90 JS |
8728 | phba->hba_flag |= DEFER_ERATT; |
8729 | /* Clear all interrupt enable conditions */ | |
8730 | writel(0, phba->HCregaddr); | |
8731 | readl(phba->HCregaddr); | |
8732 | } | |
8733 | } | |
8734 | ||
9399627f | 8735 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 8736 | pmb = phba->sli.mbox_active; |
04c68496 | 8737 | pmbox = &pmb->u.mb; |
34b02dcd | 8738 | mbox = phba->mbox; |
858c9f6c | 8739 | vport = pmb->vport; |
92d7f7b0 JS |
8740 | |
8741 | /* First check out the status word */ | |
8742 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
8743 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 8744 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
8745 | /* |
8746 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
8747 | * mbxStatus <status> | |
8748 | */ | |
09372820 | 8749 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 8750 | LOG_SLI, |
e8b62011 | 8751 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
8752 | "Interrupt mbxCommand x%x " |
8753 | "mbxStatus x%x\n", | |
e8b62011 | 8754 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
8755 | pmbox->mbxCommand, |
8756 | pmbox->mbxStatus); | |
09372820 JS |
8757 | /* clear mailbox attention bit */ |
8758 | work_ha_copy &= ~HA_MBATT; | |
8759 | } else { | |
97eab634 | 8760 | phba->sli.mbox_active = NULL; |
5b75da2f | 8761 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
8762 | phba->last_completion_time = jiffies; |
8763 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
8764 | if (pmb->mbox_cmpl) { |
8765 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
8766 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
8767 | if (pmb->out_ext_byte_len && |
8768 | pmb->context2) | |
8769 | lpfc_sli_pcimem_bcopy( | |
8770 | phba->mbox_ext, | |
8771 | pmb->context2, | |
8772 | pmb->out_ext_byte_len); | |
09372820 JS |
8773 | } |
8774 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
8775 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
8776 | ||
8777 | lpfc_debugfs_disc_trc(vport, | |
8778 | LPFC_DISC_TRC_MBOX_VPORT, | |
8779 | "MBOX dflt rpi: : " | |
8780 | "status:x%x rpi:x%x", | |
8781 | (uint32_t)pmbox->mbxStatus, | |
8782 | pmbox->un.varWords[0], 0); | |
8783 | ||
8784 | if (!pmbox->mbxStatus) { | |
8785 | mp = (struct lpfc_dmabuf *) | |
8786 | (pmb->context1); | |
8787 | ndlp = (struct lpfc_nodelist *) | |
8788 | pmb->context2; | |
8789 | ||
8790 | /* Reg_LOGIN of dflt RPI was | |
8791 | * successful. new lets get | |
8792 | * rid of the RPI using the | |
8793 | * same mbox buffer. | |
8794 | */ | |
8795 | lpfc_unreg_login(phba, | |
8796 | vport->vpi, | |
8797 | pmbox->un.varWords[0], | |
8798 | pmb); | |
8799 | pmb->mbox_cmpl = | |
8800 | lpfc_mbx_cmpl_dflt_rpi; | |
8801 | pmb->context1 = mp; | |
8802 | pmb->context2 = ndlp; | |
8803 | pmb->vport = vport; | |
58da1ffb JS |
8804 | rc = lpfc_sli_issue_mbox(phba, |
8805 | pmb, | |
8806 | MBX_NOWAIT); | |
8807 | if (rc != MBX_BUSY) | |
8808 | lpfc_printf_log(phba, | |
8809 | KERN_ERR, | |
8810 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 8811 | "0350 rc should have" |
6a9c52cf | 8812 | "been MBX_BUSY\n"); |
3772a991 JS |
8813 | if (rc != MBX_NOT_FINISHED) |
8814 | goto send_current_mbox; | |
09372820 | 8815 | } |
858c9f6c | 8816 | } |
5b75da2f JS |
8817 | spin_lock_irqsave( |
8818 | &phba->pport->work_port_lock, | |
8819 | iflag); | |
09372820 JS |
8820 | phba->pport->work_port_events &= |
8821 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
8822 | spin_unlock_irqrestore( |
8823 | &phba->pport->work_port_lock, | |
8824 | iflag); | |
09372820 | 8825 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 8826 | } |
97eab634 | 8827 | } else |
5b75da2f | 8828 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 8829 | |
92d7f7b0 JS |
8830 | if ((work_ha_copy & HA_MBATT) && |
8831 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 8832 | send_current_mbox: |
92d7f7b0 | 8833 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
8834 | do { |
8835 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
8836 | MBX_NOWAIT); | |
8837 | } while (rc == MBX_NOT_FINISHED); | |
8838 | if (rc != MBX_SUCCESS) | |
8839 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
8840 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 8841 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
8842 | } |
8843 | ||
5b75da2f | 8844 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 8845 | phba->work_ha |= work_ha_copy; |
5b75da2f | 8846 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 8847 | lpfc_worker_wake_up(phba); |
dea3101e | 8848 | } |
9399627f | 8849 | return IRQ_HANDLED; |
dea3101e | 8850 | |
3772a991 | 8851 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
8852 | |
8853 | /** | |
3772a991 | 8854 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
8855 | * @irq: Interrupt number. |
8856 | * @dev_id: The device context pointer. | |
8857 | * | |
8858 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
8859 | * service routine when device with SLI-3 interface spec is enabled with |
8860 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
8861 | * ring event in the HBA. However, when the device is enabled with either | |
8862 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
8863 | * device-level interrupt handler. When the PCI slot is in error recovery | |
8864 | * or the HBA is undergoing initialization, the interrupt handler will not | |
8865 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
8866 | * the intrrupt context. This function is called without any lock held. | |
8867 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
8868 | * |
8869 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8870 | * returns IRQ_NONE. | |
8871 | **/ | |
8872 | irqreturn_t | |
3772a991 | 8873 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
8874 | { |
8875 | struct lpfc_hba *phba; | |
8876 | uint32_t ha_copy; | |
8877 | unsigned long status; | |
5b75da2f | 8878 | unsigned long iflag; |
9399627f JS |
8879 | |
8880 | /* Get the driver's phba structure from the dev_id and | |
8881 | * assume the HBA is not interrupting. | |
8882 | */ | |
8883 | phba = (struct lpfc_hba *) dev_id; | |
8884 | ||
8885 | if (unlikely(!phba)) | |
8886 | return IRQ_NONE; | |
8887 | ||
8888 | /* | |
8889 | * Stuff needs to be attented to when this function is invoked as an | |
8890 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
8891 | */ | |
8892 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
8893 | /* Check device state for handling interrupt */ |
8894 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8895 | return IRQ_NONE; |
8896 | /* Need to read HA REG for FCP ring and other ring events */ | |
8897 | ha_copy = readl(phba->HAregaddr); | |
8898 | /* Clear up only attention source related to fast-path */ | |
5b75da2f | 8899 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
8900 | /* |
8901 | * If there is deferred error attention, do not check for | |
8902 | * any interrupt. | |
8903 | */ | |
8904 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8905 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8906 | return IRQ_NONE; |
8907 | } | |
9399627f JS |
8908 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
8909 | phba->HAregaddr); | |
8910 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 8911 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8912 | } else |
8913 | ha_copy = phba->ha_copy; | |
dea3101e JB |
8914 | |
8915 | /* | |
9399627f | 8916 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 8917 | */ |
9399627f JS |
8918 | ha_copy &= ~(phba->work_ha_mask); |
8919 | ||
8920 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 8921 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 8922 | if (status & HA_RXMASK) |
dea3101e JB |
8923 | lpfc_sli_handle_fast_ring_event(phba, |
8924 | &phba->sli.ring[LPFC_FCP_RING], | |
8925 | status); | |
a4bc3379 JS |
8926 | |
8927 | if (phba->cfg_multi_ring_support == 2) { | |
8928 | /* | |
9399627f JS |
8929 | * Process all events on extra ring. Take the optimized path |
8930 | * for extra ring IO. | |
a4bc3379 | 8931 | */ |
9399627f | 8932 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 8933 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 8934 | if (status & HA_RXMASK) { |
a4bc3379 JS |
8935 | lpfc_sli_handle_fast_ring_event(phba, |
8936 | &phba->sli.ring[LPFC_EXTRA_RING], | |
8937 | status); | |
8938 | } | |
8939 | } | |
dea3101e | 8940 | return IRQ_HANDLED; |
3772a991 | 8941 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
8942 | |
8943 | /** | |
3772a991 | 8944 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
8945 | * @irq: Interrupt number. |
8946 | * @dev_id: The device context pointer. | |
8947 | * | |
3772a991 JS |
8948 | * This function is the HBA device-level interrupt handler to device with |
8949 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
8950 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
8951 | * requires driver attention. This function invokes the slow-path interrupt | |
8952 | * attention handling function and fast-path interrupt attention handling | |
8953 | * function in turn to process the relevant HBA attention events. This | |
8954 | * function is called without any lock held. It gets the hbalock to access | |
8955 | * and update SLI data structures. | |
9399627f JS |
8956 | * |
8957 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
8958 | * returns IRQ_NONE. | |
8959 | **/ | |
8960 | irqreturn_t | |
3772a991 | 8961 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
8962 | { |
8963 | struct lpfc_hba *phba; | |
8964 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
8965 | unsigned long status1, status2; | |
a747c9ce | 8966 | uint32_t hc_copy; |
9399627f JS |
8967 | |
8968 | /* | |
8969 | * Get the driver's phba structure from the dev_id and | |
8970 | * assume the HBA is not interrupting. | |
8971 | */ | |
8972 | phba = (struct lpfc_hba *) dev_id; | |
8973 | ||
8974 | if (unlikely(!phba)) | |
8975 | return IRQ_NONE; | |
8976 | ||
3772a991 JS |
8977 | /* Check device state for handling interrupt */ |
8978 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8979 | return IRQ_NONE; |
8980 | ||
8981 | spin_lock(&phba->hbalock); | |
8982 | phba->ha_copy = readl(phba->HAregaddr); | |
8983 | if (unlikely(!phba->ha_copy)) { | |
8984 | spin_unlock(&phba->hbalock); | |
8985 | return IRQ_NONE; | |
8986 | } else if (phba->ha_copy & HA_ERATT) { | |
8987 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8988 | /* ERATT polling has handled ERATT */ | |
8989 | phba->ha_copy &= ~HA_ERATT; | |
8990 | else | |
8991 | /* Indicate interrupt handler handles ERATT */ | |
8992 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8993 | } | |
8994 | ||
a257bf90 JS |
8995 | /* |
8996 | * If there is deferred error attention, do not check for any interrupt. | |
8997 | */ | |
8998 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
ec21b3b0 | 8999 | spin_unlock(&phba->hbalock); |
a257bf90 JS |
9000 | return IRQ_NONE; |
9001 | } | |
9002 | ||
9399627f | 9003 | /* Clear attention sources except link and error attentions */ |
a747c9ce JS |
9004 | hc_copy = readl(phba->HCregaddr); |
9005 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA | |
9006 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
9007 | phba->HCregaddr); | |
9399627f | 9008 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 9009 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
9010 | readl(phba->HAregaddr); /* flush */ |
9011 | spin_unlock(&phba->hbalock); | |
9012 | ||
9013 | /* | |
9014 | * Invokes slow-path host attention interrupt handling as appropriate. | |
9015 | */ | |
9016 | ||
9017 | /* status of events with mailbox and link attention */ | |
9018 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
9019 | ||
9020 | /* status of events with ELS ring */ | |
9021 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
9022 | status2 >>= (4*LPFC_ELS_RING); | |
9023 | ||
9024 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 9025 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
9026 | else |
9027 | sp_irq_rc = IRQ_NONE; | |
9028 | ||
9029 | /* | |
9030 | * Invoke fast-path host attention interrupt handling as appropriate. | |
9031 | */ | |
9032 | ||
9033 | /* status of events with FCP ring */ | |
9034 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
9035 | status1 >>= (4*LPFC_FCP_RING); | |
9036 | ||
9037 | /* status of events with extra ring */ | |
9038 | if (phba->cfg_multi_ring_support == 2) { | |
9039 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
9040 | status2 >>= (4*LPFC_EXTRA_RING); | |
9041 | } else | |
9042 | status2 = 0; | |
9043 | ||
9044 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 9045 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
9046 | else |
9047 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 9048 | |
9399627f JS |
9049 | /* Return device-level interrupt handling status */ |
9050 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 9051 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
9052 | |
9053 | /** | |
9054 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
9055 | * @phba: pointer to lpfc hba data structure. | |
9056 | * | |
9057 | * This routine is invoked by the worker thread to process all the pending | |
9058 | * SLI4 FCP abort XRI events. | |
9059 | **/ | |
9060 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
9061 | { | |
9062 | struct lpfc_cq_event *cq_event; | |
9063 | ||
9064 | /* First, declare the fcp xri abort event has been handled */ | |
9065 | spin_lock_irq(&phba->hbalock); | |
9066 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
9067 | spin_unlock_irq(&phba->hbalock); | |
9068 | /* Now, handle all the fcp xri abort events */ | |
9069 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
9070 | /* Get the first event from the head of the event queue */ | |
9071 | spin_lock_irq(&phba->hbalock); | |
9072 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
9073 | cq_event, struct lpfc_cq_event, list); | |
9074 | spin_unlock_irq(&phba->hbalock); | |
9075 | /* Notify aborted XRI for FCP work queue */ | |
9076 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
9077 | /* Free the event processed back to the free pool */ | |
9078 | lpfc_sli4_cq_event_release(phba, cq_event); | |
9079 | } | |
9080 | } | |
9081 | ||
9082 | /** | |
9083 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
9084 | * @phba: pointer to lpfc hba data structure. | |
9085 | * | |
9086 | * This routine is invoked by the worker thread to process all the pending | |
9087 | * SLI4 els abort xri events. | |
9088 | **/ | |
9089 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
9090 | { | |
9091 | struct lpfc_cq_event *cq_event; | |
9092 | ||
9093 | /* First, declare the els xri abort event has been handled */ | |
9094 | spin_lock_irq(&phba->hbalock); | |
9095 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
9096 | spin_unlock_irq(&phba->hbalock); | |
9097 | /* Now, handle all the els xri abort events */ | |
9098 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
9099 | /* Get the first event from the head of the event queue */ | |
9100 | spin_lock_irq(&phba->hbalock); | |
9101 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
9102 | cq_event, struct lpfc_cq_event, list); | |
9103 | spin_unlock_irq(&phba->hbalock); | |
9104 | /* Notify aborted XRI for ELS work queue */ | |
9105 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
9106 | /* Free the event processed back to the free pool */ | |
9107 | lpfc_sli4_cq_event_release(phba, cq_event); | |
9108 | } | |
9109 | } | |
9110 | ||
341af102 JS |
9111 | /** |
9112 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
9113 | * @phba: pointer to lpfc hba data structure | |
9114 | * @pIocbIn: pointer to the rspiocbq | |
9115 | * @pIocbOut: pointer to the cmdiocbq | |
9116 | * @wcqe: pointer to the complete wcqe | |
9117 | * | |
9118 | * This routine transfers the fields of a command iocbq to a response iocbq | |
9119 | * by copying all the IOCB fields from command iocbq and transferring the | |
9120 | * completion status information from the complete wcqe. | |
9121 | **/ | |
4f774513 | 9122 | static void |
341af102 JS |
9123 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
9124 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
9125 | struct lpfc_iocbq *pIocbOut, |
9126 | struct lpfc_wcqe_complete *wcqe) | |
9127 | { | |
341af102 | 9128 | unsigned long iflags; |
4f774513 JS |
9129 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
9130 | ||
9131 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
9132 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 JS |
9133 | /* Map WCQE parameters into irspiocb parameters */ |
9134 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | |
9135 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | |
9136 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
9137 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
9138 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
9139 | wcqe->total_data_placed; | |
9140 | else | |
9141 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 9142 | else { |
4f774513 | 9143 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
9144 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
9145 | } | |
341af102 JS |
9146 | |
9147 | /* Pick up HBA exchange busy condition */ | |
9148 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
9149 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9150 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
9151 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9152 | } | |
4f774513 JS |
9153 | } |
9154 | ||
45ed1190 JS |
9155 | /** |
9156 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
9157 | * @phba: Pointer to HBA context object. | |
9158 | * @wcqe: Pointer to work-queue completion queue entry. | |
9159 | * | |
9160 | * This routine handles an ELS work-queue completion event and construct | |
9161 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
9162 | * discovery engine to handle. | |
9163 | * | |
9164 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
9165 | **/ | |
9166 | static struct lpfc_iocbq * | |
9167 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
9168 | struct lpfc_iocbq *irspiocbq) | |
9169 | { | |
9170 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
9171 | struct lpfc_iocbq *cmdiocbq; | |
9172 | struct lpfc_wcqe_complete *wcqe; | |
9173 | unsigned long iflags; | |
9174 | ||
9175 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
9176 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9177 | pring->stats.iocb_event++; | |
9178 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
9179 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9180 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9181 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9182 | ||
9183 | if (unlikely(!cmdiocbq)) { | |
9184 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9185 | "0386 ELS complete with no corresponding " | |
9186 | "cmdiocb: iotag (%d)\n", | |
9187 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9188 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
9189 | return NULL; | |
9190 | } | |
9191 | ||
9192 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 9193 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
9194 | |
9195 | return irspiocbq; | |
9196 | } | |
9197 | ||
04c68496 JS |
9198 | /** |
9199 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
9200 | * @phba: Pointer to HBA context object. | |
9201 | * @cqe: Pointer to mailbox completion queue entry. | |
9202 | * | |
9203 | * This routine process a mailbox completion queue entry with asynchrous | |
9204 | * event. | |
9205 | * | |
9206 | * Return: true if work posted to worker thread, otherwise false. | |
9207 | **/ | |
9208 | static bool | |
9209 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
9210 | { | |
9211 | struct lpfc_cq_event *cq_event; | |
9212 | unsigned long iflags; | |
9213 | ||
9214 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
9215 | "0392 Async Event: word0:x%x, word1:x%x, " | |
9216 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
9217 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
9218 | ||
9219 | /* Allocate a new internal CQ_EVENT entry */ | |
9220 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
9221 | if (!cq_event) { | |
9222 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9223 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
9224 | return false; | |
9225 | } | |
9226 | ||
9227 | /* Move the CQE into an asynchronous event entry */ | |
9228 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
9229 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9230 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
9231 | /* Set the async event flag */ | |
9232 | phba->hba_flag |= ASYNC_EVENT; | |
9233 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9234 | ||
9235 | return true; | |
9236 | } | |
9237 | ||
9238 | /** | |
9239 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
9240 | * @phba: Pointer to HBA context object. | |
9241 | * @cqe: Pointer to mailbox completion queue entry. | |
9242 | * | |
9243 | * This routine process a mailbox completion queue entry with mailbox | |
9244 | * completion event. | |
9245 | * | |
9246 | * Return: true if work posted to worker thread, otherwise false. | |
9247 | **/ | |
9248 | static bool | |
9249 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
9250 | { | |
9251 | uint32_t mcqe_status; | |
9252 | MAILBOX_t *mbox, *pmbox; | |
9253 | struct lpfc_mqe *mqe; | |
9254 | struct lpfc_vport *vport; | |
9255 | struct lpfc_nodelist *ndlp; | |
9256 | struct lpfc_dmabuf *mp; | |
9257 | unsigned long iflags; | |
9258 | LPFC_MBOXQ_t *pmb; | |
9259 | bool workposted = false; | |
9260 | int rc; | |
9261 | ||
9262 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
9263 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
9264 | goto out_no_mqe_complete; | |
9265 | ||
9266 | /* Get the reference to the active mbox command */ | |
9267 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9268 | pmb = phba->sli.mbox_active; | |
9269 | if (unlikely(!pmb)) { | |
9270 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
9271 | "1832 No pending MBOX command to handle\n"); | |
9272 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9273 | goto out_no_mqe_complete; | |
9274 | } | |
9275 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9276 | mqe = &pmb->u.mqe; | |
9277 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
9278 | mbox = phba->mbox; | |
9279 | vport = pmb->vport; | |
9280 | ||
9281 | /* Reset heartbeat timer */ | |
9282 | phba->last_completion_time = jiffies; | |
9283 | del_timer(&phba->sli.mbox_tmo); | |
9284 | ||
9285 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
9286 | if (pmb->mbox_cmpl && mbox) | |
9287 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
9288 | /* Set the mailbox status with SLI4 range 0x4000 */ | |
9289 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
9290 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) | |
9291 | bf_set(lpfc_mqe_status, mqe, | |
9292 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
9293 | ||
9294 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
9295 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
9296 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
9297 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
9298 | mcqe_status, | |
9299 | pmbox->un.varWords[0], 0); | |
9300 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
9301 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
9302 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
9303 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
9304 | * RID of the PPI using the same mbox buffer. | |
9305 | */ | |
9306 | lpfc_unreg_login(phba, vport->vpi, | |
9307 | pmbox->un.varWords[0], pmb); | |
9308 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
9309 | pmb->context1 = mp; | |
9310 | pmb->context2 = ndlp; | |
9311 | pmb->vport = vport; | |
9312 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
9313 | if (rc != MBX_BUSY) | |
9314 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
9315 | LOG_SLI, "0385 rc should " | |
9316 | "have been MBX_BUSY\n"); | |
9317 | if (rc != MBX_NOT_FINISHED) | |
9318 | goto send_current_mbox; | |
9319 | } | |
9320 | } | |
9321 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
9322 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
9323 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
9324 | ||
9325 | /* There is mailbox completion work to do */ | |
9326 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9327 | __lpfc_mbox_cmpl_put(phba, pmb); | |
9328 | phba->work_ha |= HA_MBATT; | |
9329 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9330 | workposted = true; | |
9331 | ||
9332 | send_current_mbox: | |
9333 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9334 | /* Release the mailbox command posting token */ | |
9335 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9336 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
9337 | phba->sli.mbox_active = NULL; | |
9338 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9339 | /* Wake up worker thread to post the next pending mailbox command */ | |
9340 | lpfc_worker_wake_up(phba); | |
9341 | out_no_mqe_complete: | |
9342 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
9343 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
9344 | return workposted; | |
9345 | } | |
9346 | ||
9347 | /** | |
9348 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
9349 | * @phba: Pointer to HBA context object. | |
9350 | * @cqe: Pointer to mailbox completion queue entry. | |
9351 | * | |
9352 | * This routine process a mailbox completion queue entry, it invokes the | |
9353 | * proper mailbox complete handling or asynchrous event handling routine | |
9354 | * according to the MCQE's async bit. | |
9355 | * | |
9356 | * Return: true if work posted to worker thread, otherwise false. | |
9357 | **/ | |
9358 | static bool | |
9359 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
9360 | { | |
9361 | struct lpfc_mcqe mcqe; | |
9362 | bool workposted; | |
9363 | ||
9364 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
9365 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
9366 | ||
9367 | /* Invoke the proper event handling routine */ | |
9368 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
9369 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
9370 | else | |
9371 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
9372 | return workposted; | |
9373 | } | |
9374 | ||
4f774513 JS |
9375 | /** |
9376 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
9377 | * @phba: Pointer to HBA context object. | |
9378 | * @wcqe: Pointer to work-queue completion queue entry. | |
9379 | * | |
9380 | * This routine handles an ELS work-queue completion event. | |
9381 | * | |
9382 | * Return: true if work posted to worker thread, otherwise false. | |
9383 | **/ | |
9384 | static bool | |
9385 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | |
9386 | struct lpfc_wcqe_complete *wcqe) | |
9387 | { | |
4f774513 JS |
9388 | struct lpfc_iocbq *irspiocbq; |
9389 | unsigned long iflags; | |
2a9bf3d0 | 9390 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
4f774513 | 9391 | |
45ed1190 | 9392 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
9393 | irspiocbq = lpfc_sli_get_iocbq(phba); |
9394 | if (!irspiocbq) { | |
9395 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
9396 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
9397 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
9398 | pring->txq_cnt, phba->iocb_cnt, | |
9399 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
9400 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 9401 | return false; |
4f774513 | 9402 | } |
4f774513 | 9403 | |
45ed1190 JS |
9404 | /* Save off the slow-path queue event for work thread to process */ |
9405 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 9406 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 9407 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
9408 | &phba->sli4_hba.sp_queue_event); |
9409 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 9410 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 9411 | |
45ed1190 | 9412 | return true; |
4f774513 JS |
9413 | } |
9414 | ||
9415 | /** | |
9416 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
9417 | * @phba: Pointer to HBA context object. | |
9418 | * @wcqe: Pointer to work-queue completion queue entry. | |
9419 | * | |
9420 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
9421 | * proper WQ release routine to the slow-path WQ. | |
9422 | **/ | |
9423 | static void | |
9424 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
9425 | struct lpfc_wcqe_release *wcqe) | |
9426 | { | |
9427 | /* Check for the slow-path ELS work queue */ | |
9428 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
9429 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
9430 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9431 | else | |
9432 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9433 | "2579 Slow-path wqe consume event carries " | |
9434 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
9435 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
9436 | phba->sli4_hba.els_wq->queue_id); | |
9437 | } | |
9438 | ||
9439 | /** | |
9440 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
9441 | * @phba: Pointer to HBA context object. | |
9442 | * @cq: Pointer to a WQ completion queue. | |
9443 | * @wcqe: Pointer to work-queue completion queue entry. | |
9444 | * | |
9445 | * This routine handles an XRI abort event. | |
9446 | * | |
9447 | * Return: true if work posted to worker thread, otherwise false. | |
9448 | **/ | |
9449 | static bool | |
9450 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
9451 | struct lpfc_queue *cq, | |
9452 | struct sli4_wcqe_xri_aborted *wcqe) | |
9453 | { | |
9454 | bool workposted = false; | |
9455 | struct lpfc_cq_event *cq_event; | |
9456 | unsigned long iflags; | |
9457 | ||
9458 | /* Allocate a new internal CQ_EVENT entry */ | |
9459 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
9460 | if (!cq_event) { | |
9461 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9462 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
9463 | return false; | |
9464 | } | |
9465 | ||
9466 | /* Move the CQE into the proper xri abort event list */ | |
9467 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
9468 | switch (cq->subtype) { | |
9469 | case LPFC_FCP: | |
9470 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9471 | list_add_tail(&cq_event->list, | |
9472 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
9473 | /* Set the fcp xri abort event flag */ | |
9474 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
9475 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9476 | workposted = true; | |
9477 | break; | |
9478 | case LPFC_ELS: | |
9479 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9480 | list_add_tail(&cq_event->list, | |
9481 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
9482 | /* Set the els xri abort event flag */ | |
9483 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
9484 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9485 | workposted = true; | |
9486 | break; | |
9487 | default: | |
9488 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9489 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
9490 | cq->subtype); | |
9491 | workposted = false; | |
9492 | break; | |
9493 | } | |
9494 | return workposted; | |
9495 | } | |
9496 | ||
4f774513 JS |
9497 | /** |
9498 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
9499 | * @phba: Pointer to HBA context object. | |
9500 | * @rcqe: Pointer to receive-queue completion queue entry. | |
9501 | * | |
9502 | * This routine process a receive-queue completion queue entry. | |
9503 | * | |
9504 | * Return: true if work posted to worker thread, otherwise false. | |
9505 | **/ | |
9506 | static bool | |
4d9ab994 | 9507 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 9508 | { |
4f774513 JS |
9509 | bool workposted = false; |
9510 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
9511 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
9512 | struct hbq_dmabuf *dma_buf; | |
9513 | uint32_t status; | |
9514 | unsigned long iflags; | |
9515 | ||
4d9ab994 | 9516 | if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id) |
4f774513 JS |
9517 | goto out; |
9518 | ||
4d9ab994 | 9519 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
9520 | switch (status) { |
9521 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
9522 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9523 | "2537 Receive Frame Truncated!!\n"); | |
9524 | case FC_STATUS_RQ_SUCCESS: | |
5ffc266e | 9525 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
9526 | spin_lock_irqsave(&phba->hbalock, iflags); |
9527 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
9528 | if (!dma_buf) { | |
9529 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9530 | goto out; | |
9531 | } | |
4d9ab994 | 9532 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 9533 | /* save off the frame for the word thread to process */ |
4d9ab994 | 9534 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 9535 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 9536 | /* Frame received */ |
45ed1190 | 9537 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
9538 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
9539 | workposted = true; | |
9540 | break; | |
9541 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
9542 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
9543 | /* Post more buffers if possible */ | |
9544 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9545 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
9546 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9547 | workposted = true; | |
9548 | break; | |
9549 | } | |
9550 | out: | |
9551 | return workposted; | |
4f774513 JS |
9552 | } |
9553 | ||
4d9ab994 JS |
9554 | /** |
9555 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
9556 | * @phba: Pointer to HBA context object. | |
9557 | * @cq: Pointer to the completion queue. | |
9558 | * @wcqe: Pointer to a completion queue entry. | |
9559 | * | |
9560 | * This routine process a slow-path work-queue or recieve queue completion queue | |
9561 | * entry. | |
9562 | * | |
9563 | * Return: true if work posted to worker thread, otherwise false. | |
9564 | **/ | |
9565 | static bool | |
9566 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9567 | struct lpfc_cqe *cqe) | |
9568 | { | |
45ed1190 | 9569 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
9570 | bool workposted = false; |
9571 | ||
9572 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 9573 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
9574 | |
9575 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 9576 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 9577 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 9578 | /* Process the WQ/RQ complete event */ |
bc73905a | 9579 | phba->last_completion_time = jiffies; |
4d9ab994 | 9580 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
45ed1190 | 9581 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
9582 | break; |
9583 | case CQE_CODE_RELEASE_WQE: | |
9584 | /* Process the WQ release event */ | |
9585 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 9586 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
9587 | break; |
9588 | case CQE_CODE_XRI_ABORTED: | |
9589 | /* Process the WQ XRI abort event */ | |
bc73905a | 9590 | phba->last_completion_time = jiffies; |
4d9ab994 | 9591 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
45ed1190 | 9592 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
9593 | break; |
9594 | case CQE_CODE_RECEIVE: | |
9595 | /* Process the RQ event */ | |
bc73905a | 9596 | phba->last_completion_time = jiffies; |
4d9ab994 | 9597 | workposted = lpfc_sli4_sp_handle_rcqe(phba, |
45ed1190 | 9598 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
9599 | break; |
9600 | default: | |
9601 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9602 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 9603 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
9604 | break; |
9605 | } | |
9606 | return workposted; | |
9607 | } | |
9608 | ||
4f774513 JS |
9609 | /** |
9610 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
9611 | * @phba: Pointer to HBA context object. | |
9612 | * @eqe: Pointer to fast-path event queue entry. | |
9613 | * | |
9614 | * This routine process a event queue entry from the slow-path event queue. | |
9615 | * It will check the MajorCode and MinorCode to determine this is for a | |
9616 | * completion event on a completion queue, if not, an error shall be logged | |
9617 | * and just return. Otherwise, it will get to the corresponding completion | |
9618 | * queue and process all the entries on that completion queue, rearm the | |
9619 | * completion queue, and then return. | |
9620 | * | |
9621 | **/ | |
9622 | static void | |
9623 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
9624 | { | |
9625 | struct lpfc_queue *cq = NULL, *childq, *speq; | |
9626 | struct lpfc_cqe *cqe; | |
9627 | bool workposted = false; | |
9628 | int ecount = 0; | |
9629 | uint16_t cqid; | |
9630 | ||
cb5172ea | 9631 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
4f774513 JS |
9632 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9633 | "0359 Not a valid slow-path completion " | |
9634 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9635 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9636 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9637 | return; |
9638 | } | |
9639 | ||
9640 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9641 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9642 | |
9643 | /* Search for completion queue pointer matching this cqid */ | |
9644 | speq = phba->sli4_hba.sp_eq; | |
9645 | list_for_each_entry(childq, &speq->child_list, list) { | |
9646 | if (childq->queue_id == cqid) { | |
9647 | cq = childq; | |
9648 | break; | |
9649 | } | |
9650 | } | |
9651 | if (unlikely(!cq)) { | |
75baf696 JS |
9652 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
9653 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9654 | "0365 Slow-path CQ identifier " | |
9655 | "(%d) does not exist\n", cqid); | |
4f774513 JS |
9656 | return; |
9657 | } | |
9658 | ||
9659 | /* Process all the entries to the CQ */ | |
9660 | switch (cq->type) { | |
9661 | case LPFC_MCQ: | |
9662 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9663 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
9664 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9665 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9666 | } | |
9667 | break; | |
9668 | case LPFC_WCQ: | |
9669 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
4d9ab994 | 9670 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe); |
4f774513 JS |
9671 | if (!(++ecount % LPFC_GET_QE_REL_INT)) |
9672 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9673 | } | |
9674 | break; | |
9675 | default: | |
9676 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9677 | "0370 Invalid completion queue type (%d)\n", | |
9678 | cq->type); | |
9679 | return; | |
9680 | } | |
9681 | ||
9682 | /* Catch the no cq entry condition, log an error */ | |
9683 | if (unlikely(ecount == 0)) | |
9684 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9685 | "0371 No entry from the CQ: identifier " | |
9686 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
9687 | ||
9688 | /* In any case, flash and re-arm the RCQ */ | |
9689 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9690 | ||
9691 | /* wake up worker thread if there are works to be done */ | |
9692 | if (workposted) | |
9693 | lpfc_worker_wake_up(phba); | |
9694 | } | |
9695 | ||
9696 | /** | |
9697 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
9698 | * @eqe: Pointer to fast-path completion queue entry. | |
9699 | * | |
9700 | * This routine process a fast-path work queue completion entry from fast-path | |
9701 | * event queue for FCP command response completion. | |
9702 | **/ | |
9703 | static void | |
9704 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | |
9705 | struct lpfc_wcqe_complete *wcqe) | |
9706 | { | |
9707 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | |
9708 | struct lpfc_iocbq *cmdiocbq; | |
9709 | struct lpfc_iocbq irspiocbq; | |
9710 | unsigned long iflags; | |
9711 | ||
9712 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9713 | pring->stats.iocb_event++; | |
9714 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9715 | ||
9716 | /* Check for response status */ | |
9717 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
9718 | /* If resource errors reported from HBA, reduce queue | |
9719 | * depth of the SCSI device. | |
9720 | */ | |
9721 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
9722 | IOSTAT_LOCAL_REJECT) && | |
9723 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
9724 | phba->lpfc_rampdown_queue_depth(phba); | |
9725 | } | |
9726 | /* Log the error status */ | |
9727 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9728 | "0373 FCP complete error: status=x%x, " | |
9729 | "hw_status=x%x, total_data_specified=%d, " | |
9730 | "parameter=x%x, word3=x%x\n", | |
9731 | bf_get(lpfc_wcqe_c_status, wcqe), | |
9732 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
9733 | wcqe->total_data_placed, wcqe->parameter, | |
9734 | wcqe->word3); | |
9735 | } | |
9736 | ||
9737 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
9738 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9739 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9740 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9741 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9742 | if (unlikely(!cmdiocbq)) { | |
9743 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9744 | "0374 FCP complete with no corresponding " | |
9745 | "cmdiocb: iotag (%d)\n", | |
9746 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9747 | return; | |
9748 | } | |
9749 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
9750 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9751 | "0375 FCP cmdiocb not callback function " | |
9752 | "iotag: (%d)\n", | |
9753 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9754 | return; | |
9755 | } | |
9756 | ||
9757 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 9758 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 9759 | |
0f65ff68 JS |
9760 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
9761 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9762 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
9763 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9764 | } | |
9765 | ||
4f774513 JS |
9766 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
9767 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
9768 | } | |
9769 | ||
9770 | /** | |
9771 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
9772 | * @phba: Pointer to HBA context object. | |
9773 | * @cq: Pointer to completion queue. | |
9774 | * @wcqe: Pointer to work-queue completion queue entry. | |
9775 | * | |
9776 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
9777 | * proper WQ release routine to the slow-path WQ. | |
9778 | **/ | |
9779 | static void | |
9780 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9781 | struct lpfc_wcqe_release *wcqe) | |
9782 | { | |
9783 | struct lpfc_queue *childwq; | |
9784 | bool wqid_matched = false; | |
9785 | uint16_t fcp_wqid; | |
9786 | ||
9787 | /* Check for fast-path FCP work queue release */ | |
9788 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
9789 | list_for_each_entry(childwq, &cq->child_list, list) { | |
9790 | if (childwq->queue_id == fcp_wqid) { | |
9791 | lpfc_sli4_wq_release(childwq, | |
9792 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9793 | wqid_matched = true; | |
9794 | break; | |
9795 | } | |
9796 | } | |
9797 | /* Report warning log message if no match found */ | |
9798 | if (wqid_matched != true) | |
9799 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9800 | "2580 Fast-path wqe consume event carries " | |
9801 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
9802 | } | |
9803 | ||
9804 | /** | |
9805 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
9806 | * @cq: Pointer to the completion queue. | |
9807 | * @eqe: Pointer to fast-path completion queue entry. | |
9808 | * | |
9809 | * This routine process a fast-path work queue completion entry from fast-path | |
9810 | * event queue for FCP command response completion. | |
9811 | **/ | |
9812 | static int | |
9813 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9814 | struct lpfc_cqe *cqe) | |
9815 | { | |
9816 | struct lpfc_wcqe_release wcqe; | |
9817 | bool workposted = false; | |
9818 | ||
9819 | /* Copy the work queue CQE and convert endian order if needed */ | |
9820 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
9821 | ||
9822 | /* Check and process for different type of WCQE and dispatch */ | |
9823 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
9824 | case CQE_CODE_COMPL_WQE: | |
9825 | /* Process the WQ complete event */ | |
98fc5dd9 | 9826 | phba->last_completion_time = jiffies; |
4f774513 JS |
9827 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
9828 | (struct lpfc_wcqe_complete *)&wcqe); | |
9829 | break; | |
9830 | case CQE_CODE_RELEASE_WQE: | |
9831 | /* Process the WQ release event */ | |
9832 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
9833 | (struct lpfc_wcqe_release *)&wcqe); | |
9834 | break; | |
9835 | case CQE_CODE_XRI_ABORTED: | |
9836 | /* Process the WQ XRI abort event */ | |
bc73905a | 9837 | phba->last_completion_time = jiffies; |
4f774513 JS |
9838 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, |
9839 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
9840 | break; | |
9841 | default: | |
9842 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9843 | "0144 Not a valid WCQE code: x%x\n", | |
9844 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
9845 | break; | |
9846 | } | |
9847 | return workposted; | |
9848 | } | |
9849 | ||
9850 | /** | |
9851 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | |
9852 | * @phba: Pointer to HBA context object. | |
9853 | * @eqe: Pointer to fast-path event queue entry. | |
9854 | * | |
9855 | * This routine process a event queue entry from the fast-path event queue. | |
9856 | * It will check the MajorCode and MinorCode to determine this is for a | |
9857 | * completion event on a completion queue, if not, an error shall be logged | |
9858 | * and just return. Otherwise, it will get to the corresponding completion | |
9859 | * queue and process all the entries on the completion queue, rearm the | |
9860 | * completion queue, and then return. | |
9861 | **/ | |
9862 | static void | |
9863 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | |
9864 | uint32_t fcp_cqidx) | |
9865 | { | |
9866 | struct lpfc_queue *cq; | |
9867 | struct lpfc_cqe *cqe; | |
9868 | bool workposted = false; | |
9869 | uint16_t cqid; | |
9870 | int ecount = 0; | |
9871 | ||
cb5172ea | 9872 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 JS |
9873 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9874 | "0366 Not a valid fast-path completion " | |
9875 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9876 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9877 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9878 | return; |
9879 | } | |
9880 | ||
9881 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | |
9882 | if (unlikely(!cq)) { | |
75baf696 JS |
9883 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
9884 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9885 | "0367 Fast-path completion queue " | |
9886 | "does not exist\n"); | |
4f774513 JS |
9887 | return; |
9888 | } | |
9889 | ||
9890 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9891 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9892 | if (unlikely(cqid != cq->queue_id)) { |
9893 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9894 | "0368 Miss-matched fast-path completion " | |
9895 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
9896 | cqid, cq->queue_id); | |
9897 | return; | |
9898 | } | |
9899 | ||
9900 | /* Process all the entries to the CQ */ | |
9901 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9902 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
9903 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9904 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9905 | } | |
9906 | ||
9907 | /* Catch the no cq entry condition */ | |
9908 | if (unlikely(ecount == 0)) | |
9909 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9910 | "0369 No entry from fast-path completion " | |
9911 | "queue fcpcqid=%d\n", cq->queue_id); | |
9912 | ||
9913 | /* In any case, flash and re-arm the CQ */ | |
9914 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9915 | ||
9916 | /* wake up worker thread if there are works to be done */ | |
9917 | if (workposted) | |
9918 | lpfc_worker_wake_up(phba); | |
9919 | } | |
9920 | ||
9921 | static void | |
9922 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
9923 | { | |
9924 | struct lpfc_eqe *eqe; | |
9925 | ||
9926 | /* walk all the EQ entries and drop on the floor */ | |
9927 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
9928 | ; | |
9929 | ||
9930 | /* Clear and re-arm the EQ */ | |
9931 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
9932 | } | |
9933 | ||
9934 | /** | |
9935 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | |
9936 | * @irq: Interrupt number. | |
9937 | * @dev_id: The device context pointer. | |
9938 | * | |
9939 | * This function is directly called from the PCI layer as an interrupt | |
9940 | * service routine when device with SLI-4 interface spec is enabled with | |
9941 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
9942 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
9943 | * interrupt mode, this function is called as part of the device-level | |
9944 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | |
9945 | * undergoing initialization, the interrupt handler will not process the | |
9946 | * interrupt. The link attention and ELS ring attention events are handled | |
9947 | * by the worker thread. The interrupt handler signals the worker thread | |
9948 | * and returns for these events. This function is called without any lock | |
9949 | * held. It gets the hbalock to access and update SLI data structures. | |
9950 | * | |
9951 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
9952 | * returns IRQ_NONE. | |
9953 | **/ | |
9954 | irqreturn_t | |
9955 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | |
9956 | { | |
9957 | struct lpfc_hba *phba; | |
9958 | struct lpfc_queue *speq; | |
9959 | struct lpfc_eqe *eqe; | |
9960 | unsigned long iflag; | |
9961 | int ecount = 0; | |
9962 | ||
9963 | /* | |
9964 | * Get the driver's phba structure from the dev_id | |
9965 | */ | |
9966 | phba = (struct lpfc_hba *)dev_id; | |
9967 | ||
9968 | if (unlikely(!phba)) | |
9969 | return IRQ_NONE; | |
9970 | ||
9971 | /* Get to the EQ struct associated with this vector */ | |
9972 | speq = phba->sli4_hba.sp_eq; | |
9973 | ||
9974 | /* Check device state for handling interrupt */ | |
9975 | if (unlikely(lpfc_intr_state_check(phba))) { | |
9976 | /* Check again for link_state with lock held */ | |
9977 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9978 | if (phba->link_state < LPFC_LINK_DOWN) | |
9979 | /* Flush, clear interrupt, and rearm the EQ */ | |
9980 | lpfc_sli4_eq_flush(phba, speq); | |
9981 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9982 | return IRQ_NONE; | |
9983 | } | |
9984 | ||
9985 | /* | |
9986 | * Process all the event on FCP slow-path EQ | |
9987 | */ | |
9988 | while ((eqe = lpfc_sli4_eq_get(speq))) { | |
9989 | lpfc_sli4_sp_handle_eqe(phba, eqe); | |
9990 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9991 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); | |
9992 | } | |
9993 | ||
9994 | /* Always clear and re-arm the slow-path EQ */ | |
9995 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | |
9996 | ||
9997 | /* Catch the no cq entry condition */ | |
9998 | if (unlikely(ecount == 0)) { | |
9999 | if (phba->intr_type == MSIX) | |
10000 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10001 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10002 | "0357 MSI-X interrupt with no EQE\n"); | |
10003 | else | |
10004 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10005 | return IRQ_NONE; | |
10006 | } | |
10007 | ||
10008 | return IRQ_HANDLED; | |
10009 | } /* lpfc_sli4_sp_intr_handler */ | |
10010 | ||
10011 | /** | |
10012 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | |
10013 | * @irq: Interrupt number. | |
10014 | * @dev_id: The device context pointer. | |
10015 | * | |
10016 | * This function is directly called from the PCI layer as an interrupt | |
10017 | * service routine when device with SLI-4 interface spec is enabled with | |
10018 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
10019 | * ring event in the HBA. However, when the device is enabled with either | |
10020 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
10021 | * device-level interrupt handler. When the PCI slot is in error recovery | |
10022 | * or the HBA is undergoing initialization, the interrupt handler will not | |
10023 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
10024 | * the intrrupt context. This function is called without any lock held. | |
10025 | * It gets the hbalock to access and update SLI data structures. Note that, | |
10026 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
10027 | * equal to that of FCP CQ index. | |
10028 | * | |
10029 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
10030 | * returns IRQ_NONE. | |
10031 | **/ | |
10032 | irqreturn_t | |
10033 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | |
10034 | { | |
10035 | struct lpfc_hba *phba; | |
10036 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
10037 | struct lpfc_queue *fpeq; | |
10038 | struct lpfc_eqe *eqe; | |
10039 | unsigned long iflag; | |
10040 | int ecount = 0; | |
10041 | uint32_t fcp_eqidx; | |
10042 | ||
10043 | /* Get the driver's phba structure from the dev_id */ | |
10044 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
10045 | phba = fcp_eq_hdl->phba; | |
10046 | fcp_eqidx = fcp_eq_hdl->idx; | |
10047 | ||
10048 | if (unlikely(!phba)) | |
10049 | return IRQ_NONE; | |
10050 | ||
10051 | /* Get to the EQ struct associated with this vector */ | |
10052 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | |
10053 | ||
10054 | /* Check device state for handling interrupt */ | |
10055 | if (unlikely(lpfc_intr_state_check(phba))) { | |
10056 | /* Check again for link_state with lock held */ | |
10057 | spin_lock_irqsave(&phba->hbalock, iflag); | |
10058 | if (phba->link_state < LPFC_LINK_DOWN) | |
10059 | /* Flush, clear interrupt, and rearm the EQ */ | |
10060 | lpfc_sli4_eq_flush(phba, fpeq); | |
10061 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
10062 | return IRQ_NONE; | |
10063 | } | |
10064 | ||
10065 | /* | |
10066 | * Process all the event on FCP fast-path EQ | |
10067 | */ | |
10068 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
10069 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | |
10070 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
10071 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); | |
10072 | } | |
10073 | ||
10074 | /* Always clear and re-arm the fast-path EQ */ | |
10075 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
10076 | ||
10077 | if (unlikely(ecount == 0)) { | |
10078 | if (phba->intr_type == MSIX) | |
10079 | /* MSI-X treated interrupt served as no EQ share INT */ | |
10080 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
10081 | "0358 MSI-X interrupt with no EQE\n"); | |
10082 | else | |
10083 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
10084 | return IRQ_NONE; | |
10085 | } | |
10086 | ||
10087 | return IRQ_HANDLED; | |
10088 | } /* lpfc_sli4_fp_intr_handler */ | |
10089 | ||
10090 | /** | |
10091 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
10092 | * @irq: Interrupt number. | |
10093 | * @dev_id: The device context pointer. | |
10094 | * | |
10095 | * This function is the device-level interrupt handler to device with SLI-4 | |
10096 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
10097 | * interrupt mode is enabled and there is an event in the HBA which requires | |
10098 | * driver attention. This function invokes the slow-path interrupt attention | |
10099 | * handling function and fast-path interrupt attention handling function in | |
10100 | * turn to process the relevant HBA attention events. This function is called | |
10101 | * without any lock held. It gets the hbalock to access and update SLI data | |
10102 | * structures. | |
10103 | * | |
10104 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
10105 | * returns IRQ_NONE. | |
10106 | **/ | |
10107 | irqreturn_t | |
10108 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
10109 | { | |
10110 | struct lpfc_hba *phba; | |
10111 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
10112 | bool fp_handled = false; | |
10113 | uint32_t fcp_eqidx; | |
10114 | ||
10115 | /* Get the driver's phba structure from the dev_id */ | |
10116 | phba = (struct lpfc_hba *)dev_id; | |
10117 | ||
10118 | if (unlikely(!phba)) | |
10119 | return IRQ_NONE; | |
10120 | ||
10121 | /* | |
10122 | * Invokes slow-path host attention interrupt handling as appropriate. | |
10123 | */ | |
10124 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | |
10125 | ||
10126 | /* | |
10127 | * Invoke fast-path host attention interrupt handling as appropriate. | |
10128 | */ | |
10129 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
10130 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | |
10131 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | |
10132 | if (fp_irq_rc == IRQ_HANDLED) | |
10133 | fp_handled |= true; | |
10134 | } | |
10135 | ||
10136 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | |
10137 | } /* lpfc_sli4_intr_handler */ | |
10138 | ||
10139 | /** | |
10140 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
10141 | * @queue: The queue structure to free. | |
10142 | * | |
10143 | * This function frees a queue structure and the DMAable memeory used for | |
10144 | * the host resident queue. This function must be called after destroying the | |
10145 | * queue on the HBA. | |
10146 | **/ | |
10147 | void | |
10148 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
10149 | { | |
10150 | struct lpfc_dmabuf *dmabuf; | |
10151 | ||
10152 | if (!queue) | |
10153 | return; | |
10154 | ||
10155 | while (!list_empty(&queue->page_list)) { | |
10156 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
10157 | list); | |
49198b37 | 10158 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
10159 | dmabuf->virt, dmabuf->phys); |
10160 | kfree(dmabuf); | |
10161 | } | |
10162 | kfree(queue); | |
10163 | return; | |
10164 | } | |
10165 | ||
10166 | /** | |
10167 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
10168 | * @phba: The HBA that this queue is being created on. | |
10169 | * @entry_size: The size of each queue entry for this queue. | |
10170 | * @entry count: The number of entries that this queue will handle. | |
10171 | * | |
10172 | * This function allocates a queue structure and the DMAable memory used for | |
10173 | * the host resident queue. This function must be called before creating the | |
10174 | * queue on the HBA. | |
10175 | **/ | |
10176 | struct lpfc_queue * | |
10177 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
10178 | uint32_t entry_count) | |
10179 | { | |
10180 | struct lpfc_queue *queue; | |
10181 | struct lpfc_dmabuf *dmabuf; | |
10182 | int x, total_qe_count; | |
10183 | void *dma_pointer; | |
cb5172ea | 10184 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 10185 | |
cb5172ea JS |
10186 | if (!phba->sli4_hba.pc_sli4_params.supported) |
10187 | hw_page_size = SLI4_PAGE_SIZE; | |
10188 | ||
4f774513 JS |
10189 | queue = kzalloc(sizeof(struct lpfc_queue) + |
10190 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
10191 | if (!queue) | |
10192 | return NULL; | |
cb5172ea JS |
10193 | queue->page_count = (ALIGN(entry_size * entry_count, |
10194 | hw_page_size))/hw_page_size; | |
4f774513 JS |
10195 | INIT_LIST_HEAD(&queue->list); |
10196 | INIT_LIST_HEAD(&queue->page_list); | |
10197 | INIT_LIST_HEAD(&queue->child_list); | |
10198 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
10199 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
10200 | if (!dmabuf) | |
10201 | goto out_fail; | |
10202 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 10203 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
10204 | GFP_KERNEL); |
10205 | if (!dmabuf->virt) { | |
10206 | kfree(dmabuf); | |
10207 | goto out_fail; | |
10208 | } | |
cb5172ea | 10209 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10210 | dmabuf->buffer_tag = x; |
10211 | list_add_tail(&dmabuf->list, &queue->page_list); | |
10212 | /* initialize queue's entry array */ | |
10213 | dma_pointer = dmabuf->virt; | |
10214 | for (; total_qe_count < entry_count && | |
cb5172ea | 10215 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
10216 | total_qe_count++, dma_pointer += entry_size) { |
10217 | queue->qe[total_qe_count].address = dma_pointer; | |
10218 | } | |
10219 | } | |
10220 | queue->entry_size = entry_size; | |
10221 | queue->entry_count = entry_count; | |
10222 | queue->phba = phba; | |
10223 | ||
10224 | return queue; | |
10225 | out_fail: | |
10226 | lpfc_sli4_queue_free(queue); | |
10227 | return NULL; | |
10228 | } | |
10229 | ||
10230 | /** | |
10231 | * lpfc_eq_create - Create an Event Queue on the HBA | |
10232 | * @phba: HBA structure that indicates port to create a queue on. | |
10233 | * @eq: The queue structure to use to create the event queue. | |
10234 | * @imax: The maximum interrupt per second limit. | |
10235 | * | |
10236 | * This function creates an event queue, as detailed in @eq, on a port, | |
10237 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
10238 | * | |
10239 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
10240 | * is used to get the entry count and entry size that are necessary to | |
10241 | * determine the number of pages to allocate and use for this queue. This | |
10242 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
10243 | * event queue. This function is asynchronous and will wait for the mailbox | |
10244 | * command to finish before continuing. | |
10245 | * | |
10246 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10247 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10248 | * fails this function will return -ENXIO. | |
4f774513 JS |
10249 | **/ |
10250 | uint32_t | |
10251 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
10252 | { | |
10253 | struct lpfc_mbx_eq_create *eq_create; | |
10254 | LPFC_MBOXQ_t *mbox; | |
10255 | int rc, length, status = 0; | |
10256 | struct lpfc_dmabuf *dmabuf; | |
10257 | uint32_t shdr_status, shdr_add_status; | |
10258 | union lpfc_sli4_cfg_shdr *shdr; | |
10259 | uint16_t dmult; | |
49198b37 JS |
10260 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10261 | ||
10262 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10263 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10264 | |
10265 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10266 | if (!mbox) | |
10267 | return -ENOMEM; | |
10268 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
10269 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10270 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10271 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
10272 | length, LPFC_SLI4_MBX_EMBED); | |
10273 | eq_create = &mbox->u.mqe.un.eq_create; | |
10274 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
10275 | eq->page_count); | |
10276 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
10277 | LPFC_EQE_SIZE); | |
10278 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
10279 | /* Calculate delay multiper from maximum interrupt per second */ | |
10280 | dmult = LPFC_DMULT_CONST/imax - 1; | |
10281 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
10282 | dmult); | |
10283 | switch (eq->entry_count) { | |
10284 | default: | |
10285 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10286 | "0360 Unsupported EQ count. (%d)\n", | |
10287 | eq->entry_count); | |
10288 | if (eq->entry_count < 256) | |
10289 | return -EINVAL; | |
10290 | /* otherwise default to smallest count (drop through) */ | |
10291 | case 256: | |
10292 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10293 | LPFC_EQ_CNT_256); | |
10294 | break; | |
10295 | case 512: | |
10296 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10297 | LPFC_EQ_CNT_512); | |
10298 | break; | |
10299 | case 1024: | |
10300 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10301 | LPFC_EQ_CNT_1024); | |
10302 | break; | |
10303 | case 2048: | |
10304 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10305 | LPFC_EQ_CNT_2048); | |
10306 | break; | |
10307 | case 4096: | |
10308 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
10309 | LPFC_EQ_CNT_4096); | |
10310 | break; | |
10311 | } | |
10312 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 10313 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10314 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10315 | putPaddrLow(dmabuf->phys); | |
10316 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10317 | putPaddrHigh(dmabuf->phys); | |
10318 | } | |
10319 | mbox->vport = phba->pport; | |
10320 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10321 | mbox->context1 = NULL; | |
10322 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10323 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
10324 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10325 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10326 | if (shdr_status || shdr_add_status || rc) { | |
10327 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10328 | "2500 EQ_CREATE mailbox failed with " | |
10329 | "status x%x add_status x%x, mbx status x%x\n", | |
10330 | shdr_status, shdr_add_status, rc); | |
10331 | status = -ENXIO; | |
10332 | } | |
10333 | eq->type = LPFC_EQ; | |
10334 | eq->subtype = LPFC_NONE; | |
10335 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
10336 | if (eq->queue_id == 0xFFFF) | |
10337 | status = -ENXIO; | |
10338 | eq->host_index = 0; | |
10339 | eq->hba_index = 0; | |
10340 | ||
8fa38513 | 10341 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10342 | return status; |
10343 | } | |
10344 | ||
10345 | /** | |
10346 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
10347 | * @phba: HBA structure that indicates port to create a queue on. | |
10348 | * @cq: The queue structure to use to create the completion queue. | |
10349 | * @eq: The event queue to bind this completion queue to. | |
10350 | * | |
10351 | * This function creates a completion queue, as detailed in @wq, on a port, | |
10352 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
10353 | * | |
10354 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
10355 | * is used to get the entry count and entry size that are necessary to | |
10356 | * determine the number of pages to allocate and use for this queue. The @eq | |
10357 | * is used to indicate which event queue to bind this completion queue to. This | |
10358 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
10359 | * completion queue. This function is asynchronous and will wait for the mailbox | |
10360 | * command to finish before continuing. | |
10361 | * | |
10362 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10363 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10364 | * fails this function will return -ENXIO. | |
4f774513 JS |
10365 | **/ |
10366 | uint32_t | |
10367 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
10368 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
10369 | { | |
10370 | struct lpfc_mbx_cq_create *cq_create; | |
10371 | struct lpfc_dmabuf *dmabuf; | |
10372 | LPFC_MBOXQ_t *mbox; | |
10373 | int rc, length, status = 0; | |
10374 | uint32_t shdr_status, shdr_add_status; | |
10375 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10376 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10377 | ||
10378 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10379 | hw_page_size = SLI4_PAGE_SIZE; | |
10380 | ||
4f774513 JS |
10381 | |
10382 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10383 | if (!mbox) | |
10384 | return -ENOMEM; | |
10385 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
10386 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10387 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10388 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
10389 | length, LPFC_SLI4_MBX_EMBED); | |
10390 | cq_create = &mbox->u.mqe.un.cq_create; | |
10391 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, | |
10392 | cq->page_count); | |
10393 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
10394 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
10395 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id); | |
10396 | switch (cq->entry_count) { | |
10397 | default: | |
10398 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10399 | "0361 Unsupported CQ count. (%d)\n", | |
10400 | cq->entry_count); | |
10401 | if (cq->entry_count < 256) | |
10402 | return -EINVAL; | |
10403 | /* otherwise default to smallest count (drop through) */ | |
10404 | case 256: | |
10405 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10406 | LPFC_CQ_CNT_256); | |
10407 | break; | |
10408 | case 512: | |
10409 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10410 | LPFC_CQ_CNT_512); | |
10411 | break; | |
10412 | case 1024: | |
10413 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
10414 | LPFC_CQ_CNT_1024); | |
10415 | break; | |
10416 | } | |
10417 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 10418 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10419 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10420 | putPaddrLow(dmabuf->phys); | |
10421 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10422 | putPaddrHigh(dmabuf->phys); | |
10423 | } | |
10424 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10425 | ||
10426 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10427 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; | |
10428 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10429 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10430 | if (shdr_status || shdr_add_status || rc) { | |
10431 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10432 | "2501 CQ_CREATE mailbox failed with " | |
10433 | "status x%x add_status x%x, mbx status x%x\n", | |
10434 | shdr_status, shdr_add_status, rc); | |
10435 | status = -ENXIO; | |
10436 | goto out; | |
10437 | } | |
10438 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
10439 | if (cq->queue_id == 0xFFFF) { | |
10440 | status = -ENXIO; | |
10441 | goto out; | |
10442 | } | |
10443 | /* link the cq onto the parent eq child list */ | |
10444 | list_add_tail(&cq->list, &eq->child_list); | |
10445 | /* Set up completion queue's type and subtype */ | |
10446 | cq->type = type; | |
10447 | cq->subtype = subtype; | |
10448 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
10449 | cq->host_index = 0; | |
10450 | cq->hba_index = 0; | |
4f774513 | 10451 | |
8fa38513 JS |
10452 | out: |
10453 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
10454 | return status; |
10455 | } | |
10456 | ||
b19a061a JS |
10457 | /** |
10458 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
10459 | * @phba: HBA structure that indicates port to create a queue on. | |
10460 | * @mq: The queue structure to use to create the mailbox queue. | |
10461 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
10462 | * @cq: The completion queue to associate with this cq. | |
10463 | * | |
10464 | * This function provides failback (fb) functionality when the | |
10465 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
10466 | * to mq_create_ext otherwise. | |
10467 | * | |
10468 | * This routine cannot fail as all attributes were previously accessed and | |
10469 | * initialized in mq_create_ext. | |
10470 | **/ | |
10471 | static void | |
10472 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
10473 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
10474 | { | |
10475 | struct lpfc_mbx_mq_create *mq_create; | |
10476 | struct lpfc_dmabuf *dmabuf; | |
10477 | int length; | |
10478 | ||
10479 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
10480 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10481 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10482 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
10483 | length, LPFC_SLI4_MBX_EMBED); | |
10484 | mq_create = &mbox->u.mqe.un.mq_create; | |
10485 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
10486 | mq->page_count); | |
10487 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
10488 | cq->queue_id); | |
10489 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
10490 | switch (mq->entry_count) { | |
10491 | case 16: | |
10492 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10493 | LPFC_MQ_CNT_16); | |
10494 | break; | |
10495 | case 32: | |
10496 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10497 | LPFC_MQ_CNT_32); | |
10498 | break; | |
10499 | case 64: | |
10500 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10501 | LPFC_MQ_CNT_64); | |
10502 | break; | |
10503 | case 128: | |
10504 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
10505 | LPFC_MQ_CNT_128); | |
10506 | break; | |
10507 | } | |
10508 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
10509 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
10510 | putPaddrLow(dmabuf->phys); | |
10511 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10512 | putPaddrHigh(dmabuf->phys); | |
10513 | } | |
10514 | } | |
10515 | ||
04c68496 JS |
10516 | /** |
10517 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
10518 | * @phba: HBA structure that indicates port to create a queue on. | |
10519 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
10520 | * @cq: The completion queue to associate with this cq. |
10521 | * @subtype: The queue's subtype. | |
04c68496 JS |
10522 | * |
10523 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
10524 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
10525 | * | |
10526 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
10527 | * is used to get the entry count and entry size that are necessary to | |
10528 | * determine the number of pages to allocate and use for this queue. This | |
10529 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
10530 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
10531 | * command to finish before continuing. | |
10532 | * | |
10533 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10534 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10535 | * fails this function will return -ENXIO. | |
04c68496 | 10536 | **/ |
b19a061a | 10537 | int32_t |
04c68496 JS |
10538 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
10539 | struct lpfc_queue *cq, uint32_t subtype) | |
10540 | { | |
10541 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 10542 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
10543 | struct lpfc_dmabuf *dmabuf; |
10544 | LPFC_MBOXQ_t *mbox; | |
10545 | int rc, length, status = 0; | |
10546 | uint32_t shdr_status, shdr_add_status; | |
10547 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 10548 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 10549 | |
49198b37 JS |
10550 | if (!phba->sli4_hba.pc_sli4_params.supported) |
10551 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 10552 | |
04c68496 JS |
10553 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
10554 | if (!mbox) | |
10555 | return -ENOMEM; | |
b19a061a | 10556 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
10557 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
10558 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 10559 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 10560 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
10561 | |
10562 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
10563 | bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request, | |
04c68496 | 10564 | mq->page_count); |
b19a061a JS |
10565 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request, |
10566 | 1); | |
10567 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste, | |
10568 | &mq_create_ext->u.request, 1); | |
10569 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
10570 | &mq_create_ext->u.request, 1); | |
10571 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
10572 | cq->queue_id); | |
10573 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); | |
04c68496 JS |
10574 | switch (mq->entry_count) { |
10575 | default: | |
10576 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10577 | "0362 Unsupported MQ count. (%d)\n", | |
10578 | mq->entry_count); | |
10579 | if (mq->entry_count < 16) | |
10580 | return -EINVAL; | |
10581 | /* otherwise default to smallest count (drop through) */ | |
10582 | case 16: | |
b19a061a | 10583 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10584 | LPFC_MQ_CNT_16); |
10585 | break; | |
10586 | case 32: | |
b19a061a | 10587 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10588 | LPFC_MQ_CNT_32); |
10589 | break; | |
10590 | case 64: | |
b19a061a | 10591 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10592 | LPFC_MQ_CNT_64); |
10593 | break; | |
10594 | case 128: | |
b19a061a | 10595 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10596 | LPFC_MQ_CNT_128); |
10597 | break; | |
10598 | } | |
10599 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 10600 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 10601 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 10602 | putPaddrLow(dmabuf->phys); |
b19a061a | 10603 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
10604 | putPaddrHigh(dmabuf->phys); |
10605 | } | |
10606 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
10607 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
10608 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10609 | &mq_create_ext->u.response); | |
10610 | if (rc != MBX_SUCCESS) { | |
10611 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10612 | "2795 MQ_CREATE_EXT failed with " | |
10613 | "status x%x. Failback to MQ_CREATE.\n", | |
10614 | rc); | |
10615 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
10616 | mq_create = &mbox->u.mqe.un.mq_create; | |
10617 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10618 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
10619 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10620 | &mq_create->u.response); | |
10621 | } | |
10622 | ||
04c68496 | 10623 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
10624 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
10625 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10626 | if (shdr_status || shdr_add_status || rc) { | |
10627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10628 | "2502 MQ_CREATE mailbox failed with " | |
10629 | "status x%x add_status x%x, mbx status x%x\n", | |
10630 | shdr_status, shdr_add_status, rc); | |
10631 | status = -ENXIO; | |
10632 | goto out; | |
10633 | } | |
04c68496 JS |
10634 | if (mq->queue_id == 0xFFFF) { |
10635 | status = -ENXIO; | |
10636 | goto out; | |
10637 | } | |
10638 | mq->type = LPFC_MQ; | |
10639 | mq->subtype = subtype; | |
10640 | mq->host_index = 0; | |
10641 | mq->hba_index = 0; | |
10642 | ||
10643 | /* link the mq onto the parent cq child list */ | |
10644 | list_add_tail(&mq->list, &cq->child_list); | |
10645 | out: | |
8fa38513 | 10646 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
10647 | return status; |
10648 | } | |
10649 | ||
4f774513 JS |
10650 | /** |
10651 | * lpfc_wq_create - Create a Work Queue on the HBA | |
10652 | * @phba: HBA structure that indicates port to create a queue on. | |
10653 | * @wq: The queue structure to use to create the work queue. | |
10654 | * @cq: The completion queue to bind this work queue to. | |
10655 | * @subtype: The subtype of the work queue indicating its functionality. | |
10656 | * | |
10657 | * This function creates a work queue, as detailed in @wq, on a port, described | |
10658 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
10659 | * | |
10660 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
10661 | * is used to get the entry count and entry size that are necessary to | |
10662 | * determine the number of pages to allocate and use for this queue. The @cq | |
10663 | * is used to indicate which completion queue to bind this work queue to. This | |
10664 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
10665 | * work queue. This function is asynchronous and will wait for the mailbox | |
10666 | * command to finish before continuing. | |
10667 | * | |
10668 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10669 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10670 | * fails this function will return -ENXIO. | |
4f774513 JS |
10671 | **/ |
10672 | uint32_t | |
10673 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
10674 | struct lpfc_queue *cq, uint32_t subtype) | |
10675 | { | |
10676 | struct lpfc_mbx_wq_create *wq_create; | |
10677 | struct lpfc_dmabuf *dmabuf; | |
10678 | LPFC_MBOXQ_t *mbox; | |
10679 | int rc, length, status = 0; | |
10680 | uint32_t shdr_status, shdr_add_status; | |
10681 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10682 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10683 | ||
10684 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10685 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10686 | |
10687 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10688 | if (!mbox) | |
10689 | return -ENOMEM; | |
10690 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
10691 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10692 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10693 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
10694 | length, LPFC_SLI4_MBX_EMBED); | |
10695 | wq_create = &mbox->u.mqe.un.wq_create; | |
10696 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, | |
10697 | wq->page_count); | |
10698 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
10699 | cq->queue_id); | |
10700 | list_for_each_entry(dmabuf, &wq->page_list, list) { | |
49198b37 | 10701 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10702 | wq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10703 | putPaddrLow(dmabuf->phys); | |
10704 | wq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10705 | putPaddrHigh(dmabuf->phys); | |
10706 | } | |
10707 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10708 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10709 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; | |
10710 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10711 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10712 | if (shdr_status || shdr_add_status || rc) { | |
10713 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10714 | "2503 WQ_CREATE mailbox failed with " | |
10715 | "status x%x add_status x%x, mbx status x%x\n", | |
10716 | shdr_status, shdr_add_status, rc); | |
10717 | status = -ENXIO; | |
10718 | goto out; | |
10719 | } | |
10720 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
10721 | if (wq->queue_id == 0xFFFF) { | |
10722 | status = -ENXIO; | |
10723 | goto out; | |
10724 | } | |
10725 | wq->type = LPFC_WQ; | |
10726 | wq->subtype = subtype; | |
10727 | wq->host_index = 0; | |
10728 | wq->hba_index = 0; | |
10729 | ||
10730 | /* link the wq onto the parent cq child list */ | |
10731 | list_add_tail(&wq->list, &cq->child_list); | |
10732 | out: | |
8fa38513 | 10733 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10734 | return status; |
10735 | } | |
10736 | ||
10737 | /** | |
10738 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
10739 | * @phba: HBA structure that indicates port to create a queue on. | |
10740 | * @hrq: The queue structure to use to create the header receive queue. | |
10741 | * @drq: The queue structure to use to create the data receive queue. | |
10742 | * @cq: The completion queue to bind this work queue to. | |
10743 | * | |
10744 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
10745 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
10746 | * to the HBA. | |
10747 | * | |
10748 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
10749 | * struct is used to get the entry count that is necessary to determine the | |
10750 | * number of pages to use for this queue. The @cq is used to indicate which | |
10751 | * completion queue to bind received buffers that are posted to these queues to. | |
10752 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
10753 | * receive queue pair. This function is asynchronous and will wait for the | |
10754 | * mailbox command to finish before continuing. | |
10755 | * | |
10756 | * On success this function will return a zero. If unable to allocate enough | |
d439d286 JS |
10757 | * memory this function will return -ENOMEM. If the queue create mailbox command |
10758 | * fails this function will return -ENXIO. | |
4f774513 JS |
10759 | **/ |
10760 | uint32_t | |
10761 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
10762 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
10763 | { | |
10764 | struct lpfc_mbx_rq_create *rq_create; | |
10765 | struct lpfc_dmabuf *dmabuf; | |
10766 | LPFC_MBOXQ_t *mbox; | |
10767 | int rc, length, status = 0; | |
10768 | uint32_t shdr_status, shdr_add_status; | |
10769 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10770 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10771 | ||
10772 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10773 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10774 | |
10775 | if (hrq->entry_count != drq->entry_count) | |
10776 | return -EINVAL; | |
10777 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10778 | if (!mbox) | |
10779 | return -ENOMEM; | |
10780 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
10781 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10782 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10783 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10784 | length, LPFC_SLI4_MBX_EMBED); | |
10785 | rq_create = &mbox->u.mqe.un.rq_create; | |
10786 | switch (hrq->entry_count) { | |
10787 | default: | |
10788 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10789 | "2535 Unsupported RQ count. (%d)\n", | |
10790 | hrq->entry_count); | |
10791 | if (hrq->entry_count < 512) | |
10792 | return -EINVAL; | |
10793 | /* otherwise default to smallest count (drop through) */ | |
10794 | case 512: | |
10795 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10796 | LPFC_RQ_RING_SIZE_512); | |
10797 | break; | |
10798 | case 1024: | |
10799 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10800 | LPFC_RQ_RING_SIZE_1024); | |
10801 | break; | |
10802 | case 2048: | |
10803 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10804 | LPFC_RQ_RING_SIZE_2048); | |
10805 | break; | |
10806 | case 4096: | |
10807 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10808 | LPFC_RQ_RING_SIZE_4096); | |
10809 | break; | |
10810 | } | |
10811 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
10812 | cq->queue_id); | |
10813 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
10814 | hrq->page_count); | |
10815 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
10816 | LPFC_HDR_BUF_SIZE); | |
10817 | list_for_each_entry(dmabuf, &hrq->page_list, list) { | |
49198b37 | 10818 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10819 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10820 | putPaddrLow(dmabuf->phys); | |
10821 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10822 | putPaddrHigh(dmabuf->phys); | |
10823 | } | |
10824 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10825 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10826 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
10827 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10828 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10829 | if (shdr_status || shdr_add_status || rc) { | |
10830 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10831 | "2504 RQ_CREATE mailbox failed with " | |
10832 | "status x%x add_status x%x, mbx status x%x\n", | |
10833 | shdr_status, shdr_add_status, rc); | |
10834 | status = -ENXIO; | |
10835 | goto out; | |
10836 | } | |
10837 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
10838 | if (hrq->queue_id == 0xFFFF) { | |
10839 | status = -ENXIO; | |
10840 | goto out; | |
10841 | } | |
10842 | hrq->type = LPFC_HRQ; | |
10843 | hrq->subtype = subtype; | |
10844 | hrq->host_index = 0; | |
10845 | hrq->hba_index = 0; | |
10846 | ||
10847 | /* now create the data queue */ | |
10848 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10849 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10850 | length, LPFC_SLI4_MBX_EMBED); | |
10851 | switch (drq->entry_count) { | |
10852 | default: | |
10853 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10854 | "2536 Unsupported RQ count. (%d)\n", | |
10855 | drq->entry_count); | |
10856 | if (drq->entry_count < 512) | |
10857 | return -EINVAL; | |
10858 | /* otherwise default to smallest count (drop through) */ | |
10859 | case 512: | |
10860 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10861 | LPFC_RQ_RING_SIZE_512); | |
10862 | break; | |
10863 | case 1024: | |
10864 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10865 | LPFC_RQ_RING_SIZE_1024); | |
10866 | break; | |
10867 | case 2048: | |
10868 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10869 | LPFC_RQ_RING_SIZE_2048); | |
10870 | break; | |
10871 | case 4096: | |
10872 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10873 | LPFC_RQ_RING_SIZE_4096); | |
10874 | break; | |
10875 | } | |
10876 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
10877 | cq->queue_id); | |
10878 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
10879 | drq->page_count); | |
10880 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
10881 | LPFC_DATA_BUF_SIZE); | |
10882 | list_for_each_entry(dmabuf, &drq->page_list, list) { | |
10883 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
10884 | putPaddrLow(dmabuf->phys); | |
10885 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10886 | putPaddrHigh(dmabuf->phys); | |
10887 | } | |
10888 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10889 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10890 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
10891 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10892 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10893 | if (shdr_status || shdr_add_status || rc) { | |
10894 | status = -ENXIO; | |
10895 | goto out; | |
10896 | } | |
10897 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
10898 | if (drq->queue_id == 0xFFFF) { | |
10899 | status = -ENXIO; | |
10900 | goto out; | |
10901 | } | |
10902 | drq->type = LPFC_DRQ; | |
10903 | drq->subtype = subtype; | |
10904 | drq->host_index = 0; | |
10905 | drq->hba_index = 0; | |
10906 | ||
10907 | /* link the header and data RQs onto the parent cq child list */ | |
10908 | list_add_tail(&hrq->list, &cq->child_list); | |
10909 | list_add_tail(&drq->list, &cq->child_list); | |
10910 | ||
10911 | out: | |
8fa38513 | 10912 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10913 | return status; |
10914 | } | |
10915 | ||
10916 | /** | |
10917 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
10918 | * @eq: The queue structure associated with the queue to destroy. | |
10919 | * | |
10920 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
10921 | * command, specific to the type of queue, to the HBA. | |
10922 | * | |
10923 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
10924 | * | |
10925 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 10926 | * command fails this function will return -ENXIO. |
4f774513 JS |
10927 | **/ |
10928 | uint32_t | |
10929 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
10930 | { | |
10931 | LPFC_MBOXQ_t *mbox; | |
10932 | int rc, length, status = 0; | |
10933 | uint32_t shdr_status, shdr_add_status; | |
10934 | union lpfc_sli4_cfg_shdr *shdr; | |
10935 | ||
10936 | if (!eq) | |
10937 | return -ENODEV; | |
10938 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
10939 | if (!mbox) | |
10940 | return -ENOMEM; | |
10941 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
10942 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10943 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10944 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
10945 | length, LPFC_SLI4_MBX_EMBED); | |
10946 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
10947 | eq->queue_id); | |
10948 | mbox->vport = eq->phba->pport; | |
10949 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10950 | ||
10951 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
10952 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10953 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10954 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
10955 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10956 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10957 | if (shdr_status || shdr_add_status || rc) { | |
10958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10959 | "2505 EQ_DESTROY mailbox failed with " | |
10960 | "status x%x add_status x%x, mbx status x%x\n", | |
10961 | shdr_status, shdr_add_status, rc); | |
10962 | status = -ENXIO; | |
10963 | } | |
10964 | ||
10965 | /* Remove eq from any list */ | |
10966 | list_del_init(&eq->list); | |
8fa38513 | 10967 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
10968 | return status; |
10969 | } | |
10970 | ||
10971 | /** | |
10972 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
10973 | * @cq: The queue structure associated with the queue to destroy. | |
10974 | * | |
10975 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
10976 | * command, specific to the type of queue, to the HBA. | |
10977 | * | |
10978 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
10979 | * | |
10980 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 10981 | * command fails this function will return -ENXIO. |
4f774513 JS |
10982 | **/ |
10983 | uint32_t | |
10984 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
10985 | { | |
10986 | LPFC_MBOXQ_t *mbox; | |
10987 | int rc, length, status = 0; | |
10988 | uint32_t shdr_status, shdr_add_status; | |
10989 | union lpfc_sli4_cfg_shdr *shdr; | |
10990 | ||
10991 | if (!cq) | |
10992 | return -ENODEV; | |
10993 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
10994 | if (!mbox) | |
10995 | return -ENOMEM; | |
10996 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
10997 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10998 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10999 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
11000 | length, LPFC_SLI4_MBX_EMBED); | |
11001 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
11002 | cq->queue_id); | |
11003 | mbox->vport = cq->phba->pport; | |
11004 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11005 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
11006 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11007 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11008 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
11009 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11010 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11011 | if (shdr_status || shdr_add_status || rc) { | |
11012 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11013 | "2506 CQ_DESTROY mailbox failed with " | |
11014 | "status x%x add_status x%x, mbx status x%x\n", | |
11015 | shdr_status, shdr_add_status, rc); | |
11016 | status = -ENXIO; | |
11017 | } | |
11018 | /* Remove cq from any list */ | |
11019 | list_del_init(&cq->list); | |
8fa38513 | 11020 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
11021 | return status; |
11022 | } | |
11023 | ||
04c68496 JS |
11024 | /** |
11025 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
11026 | * @qm: The queue structure associated with the queue to destroy. | |
11027 | * | |
11028 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
11029 | * command, specific to the type of queue, to the HBA. | |
11030 | * | |
11031 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
11032 | * | |
11033 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11034 | * command fails this function will return -ENXIO. |
04c68496 JS |
11035 | **/ |
11036 | uint32_t | |
11037 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
11038 | { | |
11039 | LPFC_MBOXQ_t *mbox; | |
11040 | int rc, length, status = 0; | |
11041 | uint32_t shdr_status, shdr_add_status; | |
11042 | union lpfc_sli4_cfg_shdr *shdr; | |
11043 | ||
11044 | if (!mq) | |
11045 | return -ENODEV; | |
11046 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
11047 | if (!mbox) | |
11048 | return -ENOMEM; | |
11049 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
11050 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11051 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
11052 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
11053 | length, LPFC_SLI4_MBX_EMBED); | |
11054 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
11055 | mq->queue_id); | |
11056 | mbox->vport = mq->phba->pport; | |
11057 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11058 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
11059 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11060 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11061 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
11062 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11063 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11064 | if (shdr_status || shdr_add_status || rc) { | |
11065 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11066 | "2507 MQ_DESTROY mailbox failed with " | |
11067 | "status x%x add_status x%x, mbx status x%x\n", | |
11068 | shdr_status, shdr_add_status, rc); | |
11069 | status = -ENXIO; | |
11070 | } | |
11071 | /* Remove mq from any list */ | |
11072 | list_del_init(&mq->list); | |
8fa38513 | 11073 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
11074 | return status; |
11075 | } | |
11076 | ||
4f774513 JS |
11077 | /** |
11078 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
11079 | * @wq: The queue structure associated with the queue to destroy. | |
11080 | * | |
11081 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
11082 | * command, specific to the type of queue, to the HBA. | |
11083 | * | |
11084 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
11085 | * | |
11086 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11087 | * command fails this function will return -ENXIO. |
4f774513 JS |
11088 | **/ |
11089 | uint32_t | |
11090 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
11091 | { | |
11092 | LPFC_MBOXQ_t *mbox; | |
11093 | int rc, length, status = 0; | |
11094 | uint32_t shdr_status, shdr_add_status; | |
11095 | union lpfc_sli4_cfg_shdr *shdr; | |
11096 | ||
11097 | if (!wq) | |
11098 | return -ENODEV; | |
11099 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
11100 | if (!mbox) | |
11101 | return -ENOMEM; | |
11102 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
11103 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
11104 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11105 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
11106 | length, LPFC_SLI4_MBX_EMBED); | |
11107 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
11108 | wq->queue_id); | |
11109 | mbox->vport = wq->phba->pport; | |
11110 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11111 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
11112 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11113 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
11114 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11115 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11116 | if (shdr_status || shdr_add_status || rc) { | |
11117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11118 | "2508 WQ_DESTROY mailbox failed with " | |
11119 | "status x%x add_status x%x, mbx status x%x\n", | |
11120 | shdr_status, shdr_add_status, rc); | |
11121 | status = -ENXIO; | |
11122 | } | |
11123 | /* Remove wq from any list */ | |
11124 | list_del_init(&wq->list); | |
8fa38513 | 11125 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
11126 | return status; |
11127 | } | |
11128 | ||
11129 | /** | |
11130 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
11131 | * @rq: The queue structure associated with the queue to destroy. | |
11132 | * | |
11133 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
11134 | * command, specific to the type of queue, to the HBA. | |
11135 | * | |
11136 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
11137 | * | |
11138 | * On success this function will return a zero. If the queue destroy mailbox | |
d439d286 | 11139 | * command fails this function will return -ENXIO. |
4f774513 JS |
11140 | **/ |
11141 | uint32_t | |
11142 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
11143 | struct lpfc_queue *drq) | |
11144 | { | |
11145 | LPFC_MBOXQ_t *mbox; | |
11146 | int rc, length, status = 0; | |
11147 | uint32_t shdr_status, shdr_add_status; | |
11148 | union lpfc_sli4_cfg_shdr *shdr; | |
11149 | ||
11150 | if (!hrq || !drq) | |
11151 | return -ENODEV; | |
11152 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
11153 | if (!mbox) | |
11154 | return -ENOMEM; | |
11155 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
11156 | sizeof(struct mbox_header)); | |
11157 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11158 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
11159 | length, LPFC_SLI4_MBX_EMBED); | |
11160 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
11161 | hrq->queue_id); | |
11162 | mbox->vport = hrq->phba->pport; | |
11163 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
11164 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
11165 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11166 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11167 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
11168 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11169 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11170 | if (shdr_status || shdr_add_status || rc) { | |
11171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11172 | "2509 RQ_DESTROY mailbox failed with " | |
11173 | "status x%x add_status x%x, mbx status x%x\n", | |
11174 | shdr_status, shdr_add_status, rc); | |
11175 | if (rc != MBX_TIMEOUT) | |
11176 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
11177 | return -ENXIO; | |
11178 | } | |
11179 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
11180 | drq->queue_id); | |
11181 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
11182 | shdr = (union lpfc_sli4_cfg_shdr *) | |
11183 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
11184 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11185 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11186 | if (shdr_status || shdr_add_status || rc) { | |
11187 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11188 | "2510 RQ_DESTROY mailbox failed with " | |
11189 | "status x%x add_status x%x, mbx status x%x\n", | |
11190 | shdr_status, shdr_add_status, rc); | |
11191 | status = -ENXIO; | |
11192 | } | |
11193 | list_del_init(&hrq->list); | |
11194 | list_del_init(&drq->list); | |
8fa38513 | 11195 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
11196 | return status; |
11197 | } | |
11198 | ||
11199 | /** | |
11200 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
11201 | * @phba: The virtual port for which this call being executed. | |
11202 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
11203 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
11204 | * @xritag: the xritag that ties this io to the SGL pages. | |
11205 | * | |
11206 | * This routine will post the sgl pages for the IO that has the xritag | |
11207 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
11208 | * creation and persists for as long as the driver is loaded. | |
11209 | * if the caller has fewer than 256 scatter gather segments to map then | |
11210 | * pdma_phys_addr1 should be 0. | |
11211 | * If the caller needs to map more than 256 scatter gather segment then | |
11212 | * pdma_phys_addr1 should be a valid physical address. | |
11213 | * physical address for SGLs must be 64 byte aligned. | |
11214 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
11215 | * the second sgl can have between 1 and 256 entries. | |
11216 | * | |
11217 | * Return codes: | |
11218 | * 0 - Success | |
11219 | * -ENXIO, -ENOMEM - Failure | |
11220 | **/ | |
11221 | int | |
11222 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
11223 | dma_addr_t pdma_phys_addr0, | |
11224 | dma_addr_t pdma_phys_addr1, | |
11225 | uint16_t xritag) | |
11226 | { | |
11227 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
11228 | LPFC_MBOXQ_t *mbox; | |
11229 | int rc; | |
11230 | uint32_t shdr_status, shdr_add_status; | |
11231 | union lpfc_sli4_cfg_shdr *shdr; | |
11232 | ||
11233 | if (xritag == NO_XRI) { | |
11234 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11235 | "0364 Invalid param:\n"); | |
11236 | return -EINVAL; | |
11237 | } | |
11238 | ||
11239 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11240 | if (!mbox) | |
11241 | return -ENOMEM; | |
11242 | ||
11243 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11244 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
11245 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
11246 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | |
11247 | ||
11248 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
11249 | &mbox->u.mqe.un.post_sgl_pages; | |
11250 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
11251 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
11252 | ||
11253 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
11254 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
11255 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
11256 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
11257 | ||
11258 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
11259 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
11260 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
11261 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
11262 | if (!phba->sli4_hba.intr_enable) | |
11263 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11264 | else | |
11265 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
11266 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
11267 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
11268 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11269 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11270 | if (rc != MBX_TIMEOUT) | |
11271 | mempool_free(mbox, phba->mbox_mem_pool); | |
11272 | if (shdr_status || shdr_add_status || rc) { | |
11273 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11274 | "2511 POST_SGL mailbox failed with " | |
11275 | "status x%x add_status x%x, mbx status x%x\n", | |
11276 | shdr_status, shdr_add_status, rc); | |
11277 | rc = -ENXIO; | |
11278 | } | |
11279 | return 0; | |
11280 | } | |
4f774513 JS |
11281 | |
11282 | /** | |
11283 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
11284 | * @phba: Pointer to HBA context object. | |
11285 | * | |
11286 | * This function gets an xritag for the iocb. If there is no unused xritag | |
11287 | * it will return 0xffff. | |
11288 | * The function returns the allocated xritag if successful, else returns zero. | |
11289 | * Zero is not a valid xritag. | |
11290 | * The caller is not required to hold any lock. | |
11291 | **/ | |
11292 | uint16_t | |
11293 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
11294 | { | |
11295 | uint16_t xritag; | |
11296 | ||
11297 | spin_lock_irq(&phba->hbalock); | |
11298 | xritag = phba->sli4_hba.next_xri; | |
11299 | if ((xritag != (uint16_t) -1) && xritag < | |
11300 | (phba->sli4_hba.max_cfg_param.max_xri | |
11301 | + phba->sli4_hba.max_cfg_param.xri_base)) { | |
11302 | phba->sli4_hba.next_xri++; | |
11303 | phba->sli4_hba.max_cfg_param.xri_used++; | |
11304 | spin_unlock_irq(&phba->hbalock); | |
11305 | return xritag; | |
11306 | } | |
11307 | spin_unlock_irq(&phba->hbalock); | |
6a9c52cf | 11308 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
4f774513 JS |
11309 | "2004 Failed to allocate XRI.last XRITAG is %d" |
11310 | " Max XRI is %d, Used XRI is %d\n", | |
11311 | phba->sli4_hba.next_xri, | |
11312 | phba->sli4_hba.max_cfg_param.max_xri, | |
11313 | phba->sli4_hba.max_cfg_param.xri_used); | |
11314 | return -1; | |
11315 | } | |
11316 | ||
11317 | /** | |
11318 | * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware. | |
11319 | * @phba: pointer to lpfc hba data structure. | |
11320 | * | |
11321 | * This routine is invoked to post a block of driver's sgl pages to the | |
11322 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
11323 | * is only called when the driver is loading and after all IO has been | |
11324 | * stopped. | |
11325 | **/ | |
11326 | int | |
11327 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba) | |
11328 | { | |
11329 | struct lpfc_sglq *sglq_entry; | |
11330 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
11331 | struct sgl_page_pairs *sgl_pg_pairs; | |
11332 | void *viraddr; | |
11333 | LPFC_MBOXQ_t *mbox; | |
11334 | uint32_t reqlen, alloclen, pg_pairs; | |
11335 | uint32_t mbox_tmo; | |
11336 | uint16_t xritag_start = 0; | |
11337 | int els_xri_cnt, rc = 0; | |
11338 | uint32_t shdr_status, shdr_add_status; | |
11339 | union lpfc_sli4_cfg_shdr *shdr; | |
11340 | ||
11341 | /* The number of sgls to be posted */ | |
11342 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
11343 | ||
11344 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
11345 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 11346 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
11347 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
11348 | "2559 Block sgl registration required DMA " | |
11349 | "size (%d) great than a page\n", reqlen); | |
11350 | return -ENOMEM; | |
11351 | } | |
11352 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11353 | if (!mbox) { | |
11354 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11355 | "2560 Failed to allocate mbox cmd memory\n"); | |
11356 | return -ENOMEM; | |
11357 | } | |
11358 | ||
11359 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
11360 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11361 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
11362 | LPFC_SLI4_MBX_NEMBED); | |
11363 | ||
11364 | if (alloclen < reqlen) { | |
11365 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11366 | "0285 Allocated DMA memory size (%d) is " | |
11367 | "less than the requested DMA memory " | |
11368 | "size (%d)\n", alloclen, reqlen); | |
11369 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11370 | return -ENOMEM; | |
11371 | } | |
4f774513 | 11372 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
11373 | viraddr = mbox->sge_array->addr[0]; |
11374 | ||
11375 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
11376 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
11377 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
11378 | ||
11379 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | |
11380 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | |
11381 | /* Set up the sge entry */ | |
11382 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
11383 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
11384 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
11385 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
11386 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
11387 | cpu_to_le32(putPaddrLow(0)); | |
11388 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
11389 | cpu_to_le32(putPaddrHigh(0)); | |
11390 | /* Keep the first xritag on the list */ | |
11391 | if (pg_pairs == 0) | |
11392 | xritag_start = sglq_entry->sli4_xritag; | |
11393 | sgl_pg_pairs++; | |
11394 | } | |
11395 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
6a9c52cf | 11396 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
4f774513 JS |
11397 | /* Perform endian conversion if necessary */ |
11398 | sgl->word0 = cpu_to_le32(sgl->word0); | |
11399 | ||
11400 | if (!phba->sli4_hba.intr_enable) | |
11401 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11402 | else { | |
11403 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11404 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11405 | } | |
11406 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11407 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11408 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11409 | if (rc != MBX_TIMEOUT) | |
11410 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11411 | if (shdr_status || shdr_add_status || rc) { | |
11412 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11413 | "2513 POST_SGL_BLOCK mailbox command failed " | |
11414 | "status x%x add_status x%x mbx status x%x\n", | |
11415 | shdr_status, shdr_add_status, rc); | |
11416 | rc = -ENXIO; | |
11417 | } | |
11418 | return rc; | |
11419 | } | |
11420 | ||
11421 | /** | |
11422 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
11423 | * @phba: pointer to lpfc hba data structure. | |
11424 | * @sblist: pointer to scsi buffer list. | |
11425 | * @count: number of scsi buffers on the list. | |
11426 | * | |
11427 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
11428 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
11429 | * No Lock is held. | |
11430 | * | |
11431 | **/ | |
11432 | int | |
11433 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | |
11434 | int cnt) | |
11435 | { | |
11436 | struct lpfc_scsi_buf *psb; | |
11437 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
11438 | struct sgl_page_pairs *sgl_pg_pairs; | |
11439 | void *viraddr; | |
11440 | LPFC_MBOXQ_t *mbox; | |
11441 | uint32_t reqlen, alloclen, pg_pairs; | |
11442 | uint32_t mbox_tmo; | |
11443 | uint16_t xritag_start = 0; | |
11444 | int rc = 0; | |
11445 | uint32_t shdr_status, shdr_add_status; | |
11446 | dma_addr_t pdma_phys_bpl1; | |
11447 | union lpfc_sli4_cfg_shdr *shdr; | |
11448 | ||
11449 | /* Calculate the requested length of the dma memory */ | |
11450 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
11451 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 11452 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
11453 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
11454 | "0217 Block sgl registration required DMA " | |
11455 | "size (%d) great than a page\n", reqlen); | |
11456 | return -ENOMEM; | |
11457 | } | |
11458 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11459 | if (!mbox) { | |
11460 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11461 | "0283 Failed to allocate mbox cmd memory\n"); | |
11462 | return -ENOMEM; | |
11463 | } | |
11464 | ||
11465 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
11466 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11467 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
11468 | LPFC_SLI4_MBX_NEMBED); | |
11469 | ||
11470 | if (alloclen < reqlen) { | |
11471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11472 | "2561 Allocated DMA memory size (%d) is " | |
11473 | "less than the requested DMA memory " | |
11474 | "size (%d)\n", alloclen, reqlen); | |
11475 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11476 | return -ENOMEM; | |
11477 | } | |
4f774513 | 11478 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
11479 | viraddr = mbox->sge_array->addr[0]; |
11480 | ||
11481 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
11482 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
11483 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
11484 | ||
11485 | pg_pairs = 0; | |
11486 | list_for_each_entry(psb, sblist, list) { | |
11487 | /* Set up the sge entry */ | |
11488 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
11489 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
11490 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
11491 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
11492 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
11493 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
11494 | else | |
11495 | pdma_phys_bpl1 = 0; | |
11496 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
11497 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
11498 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
11499 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
11500 | /* Keep the first xritag on the list */ | |
11501 | if (pg_pairs == 0) | |
11502 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
11503 | sgl_pg_pairs++; | |
11504 | pg_pairs++; | |
11505 | } | |
11506 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
11507 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
11508 | /* Perform endian conversion if necessary */ | |
11509 | sgl->word0 = cpu_to_le32(sgl->word0); | |
11510 | ||
11511 | if (!phba->sli4_hba.intr_enable) | |
11512 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
11513 | else { | |
11514 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11515 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11516 | } | |
11517 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11518 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11519 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11520 | if (rc != MBX_TIMEOUT) | |
11521 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11522 | if (shdr_status || shdr_add_status || rc) { | |
11523 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11524 | "2564 POST_SGL_BLOCK mailbox command failed " | |
11525 | "status x%x add_status x%x mbx status x%x\n", | |
11526 | shdr_status, shdr_add_status, rc); | |
11527 | rc = -ENXIO; | |
11528 | } | |
11529 | return rc; | |
11530 | } | |
11531 | ||
11532 | /** | |
11533 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
11534 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
11535 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11536 | * | |
11537 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
11538 | * valid type of frame that the LPFC driver will handle. This function will | |
11539 | * return a zero if the frame is a valid frame or a non zero value when the | |
11540 | * frame does not pass the check. | |
11541 | **/ | |
11542 | static int | |
11543 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
11544 | { | |
11545 | char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
11546 | char *type_names[] = FC_TYPE_NAMES_INIT; | |
11547 | struct fc_vft_header *fc_vft_hdr; | |
11548 | ||
11549 | switch (fc_hdr->fh_r_ctl) { | |
11550 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
11551 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
11552 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
11553 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
11554 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
11555 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
11556 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
11557 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
11558 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
11559 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
11560 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
11561 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
11562 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
11563 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
11564 | case FC_RCTL_BA_RMC: /* remove connection */ | |
11565 | case FC_RCTL_BA_ACC: /* basic accept */ | |
11566 | case FC_RCTL_BA_RJT: /* basic reject */ | |
11567 | case FC_RCTL_BA_PRMT: | |
11568 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
11569 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
11570 | case FC_RCTL_P_RJT: /* port reject */ | |
11571 | case FC_RCTL_F_RJT: /* fabric reject */ | |
11572 | case FC_RCTL_P_BSY: /* port busy */ | |
11573 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
11574 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
11575 | case FC_RCTL_LCR: /* link credit reset */ | |
11576 | case FC_RCTL_END: /* end */ | |
11577 | break; | |
11578 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
11579 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11580 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
11581 | return lpfc_fc_frame_check(phba, fc_hdr); | |
11582 | default: | |
11583 | goto drop; | |
11584 | } | |
11585 | switch (fc_hdr->fh_type) { | |
11586 | case FC_TYPE_BLS: | |
11587 | case FC_TYPE_ELS: | |
11588 | case FC_TYPE_FCP: | |
11589 | case FC_TYPE_CT: | |
11590 | break; | |
11591 | case FC_TYPE_IP: | |
11592 | case FC_TYPE_ILS: | |
11593 | default: | |
11594 | goto drop; | |
11595 | } | |
11596 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
11597 | "2538 Received frame rctl:%s type:%s\n", | |
11598 | rctl_names[fc_hdr->fh_r_ctl], | |
11599 | type_names[fc_hdr->fh_type]); | |
11600 | return 0; | |
11601 | drop: | |
11602 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11603 | "2539 Dropped frame rctl:%s type:%s\n", | |
11604 | rctl_names[fc_hdr->fh_r_ctl], | |
11605 | type_names[fc_hdr->fh_type]); | |
11606 | return 1; | |
11607 | } | |
11608 | ||
11609 | /** | |
11610 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
11611 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11612 | * | |
11613 | * This function processes the FC header to retrieve the VFI from the VF | |
11614 | * header, if one exists. This function will return the VFI if one exists | |
11615 | * or 0 if no VSAN Header exists. | |
11616 | **/ | |
11617 | static uint32_t | |
11618 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
11619 | { | |
11620 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11621 | ||
11622 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
11623 | return 0; | |
11624 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
11625 | } | |
11626 | ||
11627 | /** | |
11628 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
11629 | * @phba: Pointer to the HBA structure to search for the vport on | |
11630 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11631 | * @fcfi: The FC Fabric ID that the frame came from | |
11632 | * | |
11633 | * This function searches the @phba for a vport that matches the content of the | |
11634 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
11635 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
11636 | * returns the matching vport pointer or NULL if unable to match frame to a | |
11637 | * vport. | |
11638 | **/ | |
11639 | static struct lpfc_vport * | |
11640 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
11641 | uint16_t fcfi) | |
11642 | { | |
11643 | struct lpfc_vport **vports; | |
11644 | struct lpfc_vport *vport = NULL; | |
11645 | int i; | |
11646 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
11647 | fc_hdr->fh_d_id[1] << 8 | | |
11648 | fc_hdr->fh_d_id[2]); | |
11649 | ||
11650 | vports = lpfc_create_vport_work_array(phba); | |
11651 | if (vports != NULL) | |
11652 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
11653 | if (phba->fcf.fcfi == fcfi && | |
11654 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
11655 | vports[i]->fc_myDID == did) { | |
11656 | vport = vports[i]; | |
11657 | break; | |
11658 | } | |
11659 | } | |
11660 | lpfc_destroy_vport_work_array(phba, vports); | |
11661 | return vport; | |
11662 | } | |
11663 | ||
45ed1190 JS |
11664 | /** |
11665 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
11666 | * @vport: The vport to work on. | |
11667 | * | |
11668 | * This function updates the receive sequence time stamp for this vport. The | |
11669 | * receive sequence time stamp indicates the time that the last frame of the | |
11670 | * the sequence that has been idle for the longest amount of time was received. | |
11671 | * the driver uses this time stamp to indicate if any received sequences have | |
11672 | * timed out. | |
11673 | **/ | |
11674 | void | |
11675 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
11676 | { | |
11677 | struct lpfc_dmabuf *h_buf; | |
11678 | struct hbq_dmabuf *dmabuf = NULL; | |
11679 | ||
11680 | /* get the oldest sequence on the rcv list */ | |
11681 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
11682 | struct lpfc_dmabuf, list); | |
11683 | if (!h_buf) | |
11684 | return; | |
11685 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11686 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
11687 | } | |
11688 | ||
11689 | /** | |
11690 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
11691 | * @vport: The vport that the received sequences were sent to. | |
11692 | * | |
11693 | * This function cleans up all outstanding received sequences. This is called | |
11694 | * by the driver when a link event or user action invalidates all the received | |
11695 | * sequences. | |
11696 | **/ | |
11697 | void | |
11698 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
11699 | { | |
11700 | struct lpfc_dmabuf *h_buf, *hnext; | |
11701 | struct lpfc_dmabuf *d_buf, *dnext; | |
11702 | struct hbq_dmabuf *dmabuf = NULL; | |
11703 | ||
11704 | /* start with the oldest sequence on the rcv list */ | |
11705 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11706 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11707 | list_del_init(&dmabuf->hbuf.list); | |
11708 | list_for_each_entry_safe(d_buf, dnext, | |
11709 | &dmabuf->dbuf.list, list) { | |
11710 | list_del_init(&d_buf->list); | |
11711 | lpfc_in_buf_free(vport->phba, d_buf); | |
11712 | } | |
11713 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11714 | } | |
11715 | } | |
11716 | ||
11717 | /** | |
11718 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
11719 | * @vport: The vport that the received sequences were sent to. | |
11720 | * | |
11721 | * This function determines whether any received sequences have timed out by | |
11722 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
11723 | * indicates that there is at least one timed out sequence this routine will | |
11724 | * go through the received sequences one at a time from most inactive to most | |
11725 | * active to determine which ones need to be cleaned up. Once it has determined | |
11726 | * that a sequence needs to be cleaned up it will simply free up the resources | |
11727 | * without sending an abort. | |
11728 | **/ | |
11729 | void | |
11730 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
11731 | { | |
11732 | struct lpfc_dmabuf *h_buf, *hnext; | |
11733 | struct lpfc_dmabuf *d_buf, *dnext; | |
11734 | struct hbq_dmabuf *dmabuf = NULL; | |
11735 | unsigned long timeout; | |
11736 | int abort_count = 0; | |
11737 | ||
11738 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11739 | vport->rcv_buffer_time_stamp); | |
11740 | if (list_empty(&vport->rcv_buffer_list) || | |
11741 | time_before(jiffies, timeout)) | |
11742 | return; | |
11743 | /* start with the oldest sequence on the rcv list */ | |
11744 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11745 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11746 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11747 | dmabuf->time_stamp); | |
11748 | if (time_before(jiffies, timeout)) | |
11749 | break; | |
11750 | abort_count++; | |
11751 | list_del_init(&dmabuf->hbuf.list); | |
11752 | list_for_each_entry_safe(d_buf, dnext, | |
11753 | &dmabuf->dbuf.list, list) { | |
11754 | list_del_init(&d_buf->list); | |
11755 | lpfc_in_buf_free(vport->phba, d_buf); | |
11756 | } | |
11757 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11758 | } | |
11759 | if (abort_count) | |
11760 | lpfc_update_rcv_time_stamp(vport); | |
11761 | } | |
11762 | ||
4f774513 JS |
11763 | /** |
11764 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
11765 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
11766 | * | |
11767 | * This function searches through the existing incomplete sequences that have | |
11768 | * been sent to this @vport. If the frame matches one of the incomplete | |
11769 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
11770 | * make up that sequence. If no sequence is found that matches this frame then | |
11771 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
11772 | * This function returns a pointer to the first dmabuf in the sequence list that | |
11773 | * the frame was linked to. | |
11774 | **/ | |
11775 | static struct hbq_dmabuf * | |
11776 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
11777 | { | |
11778 | struct fc_frame_header *new_hdr; | |
11779 | struct fc_frame_header *temp_hdr; | |
11780 | struct lpfc_dmabuf *d_buf; | |
11781 | struct lpfc_dmabuf *h_buf; | |
11782 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
11783 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
11784 | ||
4d9ab994 | 11785 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 11786 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
11787 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
11788 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
11789 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
11790 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
11791 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
11792 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
11793 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
11794 | continue; | |
11795 | /* found a pending sequence that matches this frame */ | |
11796 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11797 | break; | |
11798 | } | |
11799 | if (!seq_dmabuf) { | |
11800 | /* | |
11801 | * This indicates first frame received for this sequence. | |
11802 | * Queue the buffer on the vport's rcv_buffer_list. | |
11803 | */ | |
11804 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 11805 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
11806 | return dmabuf; |
11807 | } | |
11808 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
11809 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
11810 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
11811 | list_del_init(&seq_dmabuf->hbuf.list); |
11812 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
11813 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 11814 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
11815 | return dmabuf; |
11816 | } | |
45ed1190 JS |
11817 | /* move this sequence to the tail to indicate a young sequence */ |
11818 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
11819 | seq_dmabuf->time_stamp = jiffies; | |
11820 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
11821 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
11822 | temp_hdr = dmabuf->hbuf.virt; | |
11823 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
11824 | return seq_dmabuf; | |
11825 | } | |
4f774513 JS |
11826 | /* find the correct place in the sequence to insert this frame */ |
11827 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
11828 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
11829 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
11830 | /* | |
11831 | * If the frame's sequence count is greater than the frame on | |
11832 | * the list then insert the frame right after this frame | |
11833 | */ | |
eeead811 JS |
11834 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
11835 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
11836 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
11837 | return seq_dmabuf; | |
11838 | } | |
11839 | } | |
11840 | return NULL; | |
11841 | } | |
11842 | ||
6669f9bb JS |
11843 | /** |
11844 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
11845 | * @vport: pointer to a vitural port | |
11846 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
11847 | * | |
11848 | * This function tries to abort from the partially assembed sequence, described | |
11849 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
11850 | * partially assembled sequence held by the driver. If so, it shall free up all | |
11851 | * the frames from the partially assembled sequence. | |
11852 | * | |
11853 | * Return | |
11854 | * true -- if there is matching partially assembled sequence present and all | |
11855 | * the frames freed with the sequence; | |
11856 | * false -- if there is no matching partially assembled sequence present so | |
11857 | * nothing got aborted in the lower layer driver | |
11858 | **/ | |
11859 | static bool | |
11860 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
11861 | struct hbq_dmabuf *dmabuf) | |
11862 | { | |
11863 | struct fc_frame_header *new_hdr; | |
11864 | struct fc_frame_header *temp_hdr; | |
11865 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
11866 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
11867 | ||
11868 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
11869 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
11870 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
11871 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
11872 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
11873 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
11874 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
11875 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
11876 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
11877 | continue; | |
11878 | /* found a pending sequence that matches this frame */ | |
11879 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11880 | break; | |
11881 | } | |
11882 | ||
11883 | /* Free up all the frames from the partially assembled sequence */ | |
11884 | if (seq_dmabuf) { | |
11885 | list_for_each_entry_safe(d_buf, n_buf, | |
11886 | &seq_dmabuf->dbuf.list, list) { | |
11887 | list_del_init(&d_buf->list); | |
11888 | lpfc_in_buf_free(vport->phba, d_buf); | |
11889 | } | |
11890 | return true; | |
11891 | } | |
11892 | return false; | |
11893 | } | |
11894 | ||
11895 | /** | |
11896 | * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler | |
11897 | * @phba: Pointer to HBA context object. | |
11898 | * @cmd_iocbq: pointer to the command iocbq structure. | |
11899 | * @rsp_iocbq: pointer to the response iocbq structure. | |
11900 | * | |
11901 | * This function handles the sequence abort accept iocb command complete | |
11902 | * event. It properly releases the memory allocated to the sequence abort | |
11903 | * accept iocb. | |
11904 | **/ | |
11905 | static void | |
11906 | lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba, | |
11907 | struct lpfc_iocbq *cmd_iocbq, | |
11908 | struct lpfc_iocbq *rsp_iocbq) | |
11909 | { | |
11910 | if (cmd_iocbq) | |
11911 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
11912 | } | |
11913 | ||
11914 | /** | |
11915 | * lpfc_sli4_seq_abort_acc - Accept sequence abort | |
11916 | * @phba: Pointer to HBA context object. | |
11917 | * @fc_hdr: pointer to a FC frame header. | |
11918 | * | |
11919 | * This function sends a basic accept to a previous unsol sequence abort | |
11920 | * event after aborting the sequence handling. | |
11921 | **/ | |
11922 | static void | |
11923 | lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba, | |
11924 | struct fc_frame_header *fc_hdr) | |
11925 | { | |
11926 | struct lpfc_iocbq *ctiocb = NULL; | |
11927 | struct lpfc_nodelist *ndlp; | |
5ffc266e JS |
11928 | uint16_t oxid, rxid; |
11929 | uint32_t sid, fctl; | |
6669f9bb JS |
11930 | IOCB_t *icmd; |
11931 | ||
11932 | if (!lpfc_is_link_up(phba)) | |
11933 | return; | |
11934 | ||
11935 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
11936 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 11937 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
11938 | |
11939 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
11940 | if (!ndlp) { | |
11941 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11942 | "1268 Find ndlp returned NULL for oxid:x%x " | |
11943 | "SID:x%x\n", oxid, sid); | |
11944 | return; | |
11945 | } | |
19ca7609 JS |
11946 | if (rxid >= phba->sli4_hba.max_cfg_param.xri_base |
11947 | && rxid <= (phba->sli4_hba.max_cfg_param.max_xri | |
11948 | + phba->sli4_hba.max_cfg_param.xri_base)) | |
11949 | lpfc_set_rrq_active(phba, ndlp, rxid, oxid, 0); | |
6669f9bb JS |
11950 | |
11951 | /* Allocate buffer for acc iocb */ | |
11952 | ctiocb = lpfc_sli_get_iocbq(phba); | |
11953 | if (!ctiocb) | |
11954 | return; | |
11955 | ||
5ffc266e JS |
11956 | /* Extract the F_CTL field from FC_HDR */ |
11957 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
11958 | ||
6669f9bb | 11959 | icmd = &ctiocb->iocb; |
6669f9bb | 11960 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 11961 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
11962 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
11963 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
11964 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
11965 | ||
11966 | /* Fill in the rest of iocb fields */ | |
11967 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
11968 | icmd->ulpBdeCount = 0; | |
11969 | icmd->ulpLe = 1; | |
11970 | icmd->ulpClass = CLASS3; | |
11971 | icmd->ulpContext = ndlp->nlp_rpi; | |
6669f9bb | 11972 | |
6669f9bb JS |
11973 | ctiocb->iocb_cmpl = NULL; |
11974 | ctiocb->vport = phba->pport; | |
11975 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl; | |
11976 | ||
5ffc266e JS |
11977 | if (fctl & FC_FC_EX_CTX) { |
11978 | /* ABTS sent by responder to CT exchange, construction | |
11979 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
11980 | * field and RX_ID from ABTS for RX_ID field. | |
11981 | */ | |
11982 | bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP); | |
11983 | bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid); | |
11984 | ctiocb->sli4_xritag = oxid; | |
11985 | } else { | |
11986 | /* ABTS sent by initiator to CT exchange, construction | |
11987 | * of BA_ACC will need to allocate a new XRI as for the | |
11988 | * XRI_TAG and RX_ID fields. | |
11989 | */ | |
11990 | bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT); | |
11991 | bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI); | |
11992 | ctiocb->sli4_xritag = NO_XRI; | |
11993 | } | |
11994 | bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid); | |
11995 | ||
6669f9bb JS |
11996 | /* Xmit CT abts accept on exchange <xid> */ |
11997 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
11998 | "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n", | |
11999 | CMD_XMIT_BLS_RSP64_CX, phba->link_state); | |
12000 | lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
12001 | } | |
12002 | ||
12003 | /** | |
12004 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
12005 | * @vport: Pointer to the vport on which this sequence was received | |
12006 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12007 | * | |
12008 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
12009 | * receive sequence is only partially assembed by the driver, it shall abort | |
12010 | * the partially assembled frames for the sequence. Otherwise, if the | |
12011 | * unsolicited receive sequence has been completely assembled and passed to | |
12012 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
12013 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
12014 | * accept to accept the abort. | |
12015 | **/ | |
12016 | void | |
12017 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
12018 | struct hbq_dmabuf *dmabuf) | |
12019 | { | |
12020 | struct lpfc_hba *phba = vport->phba; | |
12021 | struct fc_frame_header fc_hdr; | |
5ffc266e | 12022 | uint32_t fctl; |
6669f9bb JS |
12023 | bool abts_par; |
12024 | ||
6669f9bb JS |
12025 | /* Make a copy of fc_hdr before the dmabuf being released */ |
12026 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 12027 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 12028 | |
5ffc266e JS |
12029 | if (fctl & FC_FC_EX_CTX) { |
12030 | /* | |
12031 | * ABTS sent by responder to exchange, just free the buffer | |
12032 | */ | |
6669f9bb | 12033 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
12034 | } else { |
12035 | /* | |
12036 | * ABTS sent by initiator to exchange, need to do cleanup | |
12037 | */ | |
12038 | /* Try to abort partially assembled seq */ | |
12039 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
12040 | ||
12041 | /* Send abort to ULP if partially seq abort failed */ | |
12042 | if (abts_par == false) | |
12043 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
12044 | else | |
12045 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12046 | } | |
6669f9bb JS |
12047 | /* Send basic accept (BA_ACC) to the abort requester */ |
12048 | lpfc_sli4_seq_abort_acc(phba, &fc_hdr); | |
12049 | } | |
12050 | ||
4f774513 JS |
12051 | /** |
12052 | * lpfc_seq_complete - Indicates if a sequence is complete | |
12053 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12054 | * | |
12055 | * This function checks the sequence, starting with the frame described by | |
12056 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
12057 | * the frames associated with this sequence are linked to the @dmabuf using the | |
12058 | * dbuf list. This function looks for two major things. 1) That the first frame | |
12059 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
12060 | * set. 3) That there are no holes in the sequence count. The function will | |
12061 | * return 1 when the sequence is complete, otherwise it will return 0. | |
12062 | **/ | |
12063 | static int | |
12064 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
12065 | { | |
12066 | struct fc_frame_header *hdr; | |
12067 | struct lpfc_dmabuf *d_buf; | |
12068 | struct hbq_dmabuf *seq_dmabuf; | |
12069 | uint32_t fctl; | |
12070 | int seq_count = 0; | |
12071 | ||
12072 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
12073 | /* make sure first fame of sequence has a sequence count of zero */ | |
12074 | if (hdr->fh_seq_cnt != seq_count) | |
12075 | return 0; | |
12076 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
12077 | hdr->fh_f_ctl[1] << 8 | | |
12078 | hdr->fh_f_ctl[2]); | |
12079 | /* If last frame of sequence we can return success. */ | |
12080 | if (fctl & FC_FC_END_SEQ) | |
12081 | return 1; | |
12082 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
12083 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
12084 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12085 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 12086 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
12087 | return 0; |
12088 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
12089 | hdr->fh_f_ctl[1] << 8 | | |
12090 | hdr->fh_f_ctl[2]); | |
12091 | /* If last frame of sequence we can return success. */ | |
12092 | if (fctl & FC_FC_END_SEQ) | |
12093 | return 1; | |
12094 | } | |
12095 | return 0; | |
12096 | } | |
12097 | ||
12098 | /** | |
12099 | * lpfc_prep_seq - Prep sequence for ULP processing | |
12100 | * @vport: Pointer to the vport on which this sequence was received | |
12101 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
12102 | * | |
12103 | * This function takes a sequence, described by a list of frames, and creates | |
12104 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
12105 | * used to issue to the generic unsolicited sequence handler. This routine | |
12106 | * returns a pointer to the first iocbq in the list. If the function is unable | |
12107 | * to allocate an iocbq then it throw out the received frames that were not | |
12108 | * able to be described and return a pointer to the first iocbq. If unable to | |
12109 | * allocate any iocbqs (including the first) this function will return NULL. | |
12110 | **/ | |
12111 | static struct lpfc_iocbq * | |
12112 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
12113 | { | |
12114 | struct lpfc_dmabuf *d_buf, *n_buf; | |
12115 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
12116 | struct fc_frame_header *fc_hdr; | |
12117 | uint32_t sid; | |
eeead811 | 12118 | struct ulp_bde64 *pbde; |
4f774513 JS |
12119 | |
12120 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12121 | /* remove from receive buffer list */ | |
12122 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 12123 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 12124 | /* get the Remote Port's SID */ |
6669f9bb | 12125 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
4f774513 JS |
12126 | /* Get an iocbq struct to fill in. */ |
12127 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
12128 | if (first_iocbq) { | |
12129 | /* Initialize the first IOCB. */ | |
8fa38513 | 12130 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 JS |
12131 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
12132 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
12133 | first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id); | |
12134 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
12135 | vport->vpi + vport->phba->vpi_base; | |
12136 | /* put the first buffer into the first IOCBq */ | |
12137 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
12138 | first_iocbq->context3 = NULL; | |
12139 | first_iocbq->iocb.ulpBdeCount = 1; | |
12140 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
12141 | LPFC_DATA_BUF_SIZE; | |
12142 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
8fa38513 | 12143 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12144 | bf_get(lpfc_rcqe_length, |
12145 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12146 | } |
12147 | iocbq = first_iocbq; | |
12148 | /* | |
12149 | * Each IOCBq can have two Buffers assigned, so go through the list | |
12150 | * of buffers for this sequence and save two buffers in each IOCBq | |
12151 | */ | |
12152 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
12153 | if (!iocbq) { | |
12154 | lpfc_in_buf_free(vport->phba, d_buf); | |
12155 | continue; | |
12156 | } | |
12157 | if (!iocbq->context3) { | |
12158 | iocbq->context3 = d_buf; | |
12159 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
12160 | pbde = (struct ulp_bde64 *) |
12161 | &iocbq->iocb.unsli3.sli3Words[4]; | |
12162 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
8fa38513 | 12163 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12164 | bf_get(lpfc_rcqe_length, |
12165 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12166 | } else { |
12167 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
12168 | if (!iocbq) { | |
12169 | if (first_iocbq) { | |
12170 | first_iocbq->iocb.ulpStatus = | |
12171 | IOSTAT_FCP_RSP_ERROR; | |
12172 | first_iocbq->iocb.un.ulpWord[4] = | |
12173 | IOERR_NO_RESOURCES; | |
12174 | } | |
12175 | lpfc_in_buf_free(vport->phba, d_buf); | |
12176 | continue; | |
12177 | } | |
12178 | iocbq->context2 = d_buf; | |
12179 | iocbq->context3 = NULL; | |
12180 | iocbq->iocb.ulpBdeCount = 1; | |
12181 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
12182 | LPFC_DATA_BUF_SIZE; | |
8fa38513 | 12183 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
12184 | bf_get(lpfc_rcqe_length, |
12185 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
12186 | iocbq->iocb.un.rcvels.remoteID = sid; |
12187 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
12188 | } | |
12189 | } | |
12190 | return first_iocbq; | |
12191 | } | |
12192 | ||
6669f9bb JS |
12193 | static void |
12194 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
12195 | struct hbq_dmabuf *seq_dmabuf) | |
12196 | { | |
12197 | struct fc_frame_header *fc_hdr; | |
12198 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
12199 | struct lpfc_hba *phba = vport->phba; | |
12200 | ||
12201 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
12202 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
12203 | if (!iocbq) { | |
12204 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12205 | "2707 Ring %d handler: Failed to allocate " | |
12206 | "iocb Rctl x%x Type x%x received\n", | |
12207 | LPFC_ELS_RING, | |
12208 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
12209 | return; | |
12210 | } | |
12211 | if (!lpfc_complete_unsol_iocb(phba, | |
12212 | &phba->sli.ring[LPFC_ELS_RING], | |
12213 | iocbq, fc_hdr->fh_r_ctl, | |
12214 | fc_hdr->fh_type)) | |
12215 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
12216 | "2540 Ring %d handler: unexpected Rctl " | |
12217 | "x%x Type x%x received\n", | |
12218 | LPFC_ELS_RING, | |
12219 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
12220 | ||
12221 | /* Free iocb created in lpfc_prep_seq */ | |
12222 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
12223 | &iocbq->list, list) { | |
12224 | list_del_init(&curr_iocb->list); | |
12225 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
12226 | } | |
12227 | lpfc_sli_release_iocbq(phba, iocbq); | |
12228 | } | |
12229 | ||
4f774513 JS |
12230 | /** |
12231 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
12232 | * @phba: Pointer to HBA context object. | |
12233 | * | |
12234 | * This function is called with no lock held. This function processes all | |
12235 | * the received buffers and gives it to upper layers when a received buffer | |
12236 | * indicates that it is the final frame in the sequence. The interrupt | |
12237 | * service routine processes received buffers at interrupt contexts and adds | |
12238 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
12239 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
12240 | * appropriate receive function when the final frame in a sequence is received. | |
12241 | **/ | |
4d9ab994 JS |
12242 | void |
12243 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
12244 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 12245 | { |
4d9ab994 | 12246 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
12247 | struct fc_frame_header *fc_hdr; |
12248 | struct lpfc_vport *vport; | |
12249 | uint32_t fcfi; | |
4f774513 | 12250 | |
4f774513 | 12251 | /* Process each received buffer */ |
4d9ab994 JS |
12252 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
12253 | /* check to see if this a valid type of frame */ | |
12254 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
12255 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12256 | return; | |
12257 | } | |
12258 | fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl); | |
12259 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); | |
c868595d | 12260 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
4d9ab994 JS |
12261 | /* throw out the frame */ |
12262 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12263 | return; | |
12264 | } | |
6669f9bb JS |
12265 | /* Handle the basic abort sequence (BA_ABTS) event */ |
12266 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
12267 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
12268 | return; | |
12269 | } | |
12270 | ||
4d9ab994 JS |
12271 | /* Link this frame */ |
12272 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
12273 | if (!seq_dmabuf) { | |
12274 | /* unable to add frame to vport - throw it out */ | |
12275 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
12276 | return; | |
12277 | } | |
12278 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 12279 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 12280 | return; |
def9c7a9 | 12281 | |
6669f9bb JS |
12282 | /* Send the complete sequence to the upper layer protocol */ |
12283 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 12284 | } |
6fb120a7 JS |
12285 | |
12286 | /** | |
12287 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
12288 | * @phba: pointer to lpfc hba data structure. | |
12289 | * | |
12290 | * This routine is invoked to post rpi header templates to the | |
12291 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
12292 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
12293 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
12294 | * |
12295 | * This routine does not require any locks. It's usage is expected | |
12296 | * to be driver load or reset recovery when the driver is | |
12297 | * sequential. | |
12298 | * | |
12299 | * Return codes | |
af901ca1 | 12300 | * 0 - successful |
d439d286 | 12301 | * -EIO - The mailbox failed to complete successfully. |
6fb120a7 JS |
12302 | * When this error occurs, the driver is not guaranteed |
12303 | * to have any rpi regions posted to the device and | |
12304 | * must either attempt to repost the regions or take a | |
12305 | * fatal error. | |
12306 | **/ | |
12307 | int | |
12308 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
12309 | { | |
12310 | struct lpfc_rpi_hdr *rpi_page; | |
12311 | uint32_t rc = 0; | |
12312 | ||
12313 | /* Post all rpi memory regions to the port. */ | |
12314 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
12315 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); | |
12316 | if (rc != MBX_SUCCESS) { | |
12317 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12318 | "2008 Error %d posting all rpi " | |
12319 | "headers\n", rc); | |
12320 | rc = -EIO; | |
12321 | break; | |
12322 | } | |
12323 | } | |
12324 | ||
12325 | return rc; | |
12326 | } | |
12327 | ||
12328 | /** | |
12329 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
12330 | * @phba: pointer to lpfc hba data structure. | |
12331 | * @rpi_page: pointer to the rpi memory region. | |
12332 | * | |
12333 | * This routine is invoked to post a single rpi header to the | |
12334 | * HBA consistent with the SLI-4 interface spec. This memory region | |
12335 | * maps up to 64 rpi context regions. | |
12336 | * | |
12337 | * Return codes | |
af901ca1 | 12338 | * 0 - successful |
d439d286 JS |
12339 | * -ENOMEM - No available memory |
12340 | * -EIO - The mailbox failed to complete successfully. | |
6fb120a7 JS |
12341 | **/ |
12342 | int | |
12343 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
12344 | { | |
12345 | LPFC_MBOXQ_t *mboxq; | |
12346 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
12347 | uint32_t rc = 0; | |
12348 | uint32_t mbox_tmo; | |
12349 | uint32_t shdr_status, shdr_add_status; | |
12350 | union lpfc_sli4_cfg_shdr *shdr; | |
12351 | ||
12352 | /* The port is notified of the header region via a mailbox command. */ | |
12353 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12354 | if (!mboxq) { | |
12355 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12356 | "2001 Unable to allocate memory for issuing " | |
12357 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
12358 | return -ENOMEM; | |
12359 | } | |
12360 | ||
12361 | /* Post all rpi memory regions to the port. */ | |
12362 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
12363 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
12364 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12365 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
12366 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
12367 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | |
12368 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, | |
12369 | hdr_tmpl, rpi_page->page_count); | |
12370 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, | |
12371 | rpi_page->start_rpi); | |
12372 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); | |
12373 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 12374 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
12375 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
12376 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12377 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12378 | if (rc != MBX_TIMEOUT) | |
12379 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12380 | if (shdr_status || shdr_add_status || rc) { | |
12381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12382 | "2514 POST_RPI_HDR mailbox failed with " | |
12383 | "status x%x add_status x%x, mbx status x%x\n", | |
12384 | shdr_status, shdr_add_status, rc); | |
12385 | rc = -ENXIO; | |
12386 | } | |
12387 | return rc; | |
12388 | } | |
12389 | ||
12390 | /** | |
12391 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
12392 | * @phba: pointer to lpfc hba data structure. | |
12393 | * | |
12394 | * This routine is invoked to post rpi header templates to the | |
12395 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
12396 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
12397 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
12398 | * |
12399 | * Returns | |
af901ca1 | 12400 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
12401 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
12402 | **/ | |
12403 | int | |
12404 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
12405 | { | |
12406 | int rpi; | |
12407 | uint16_t max_rpi, rpi_base, rpi_limit; | |
12408 | uint16_t rpi_remaining; | |
12409 | struct lpfc_rpi_hdr *rpi_hdr; | |
12410 | ||
12411 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
12412 | rpi_base = phba->sli4_hba.max_cfg_param.rpi_base; | |
12413 | rpi_limit = phba->sli4_hba.next_rpi; | |
12414 | ||
12415 | /* | |
12416 | * The valid rpi range is not guaranteed to be zero-based. Start | |
12417 | * the search at the rpi_base as reported by the port. | |
12418 | */ | |
12419 | spin_lock_irq(&phba->hbalock); | |
12420 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base); | |
12421 | if (rpi >= rpi_limit || rpi < rpi_base) | |
12422 | rpi = LPFC_RPI_ALLOC_ERROR; | |
12423 | else { | |
12424 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
12425 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
12426 | phba->sli4_hba.rpi_count++; | |
12427 | } | |
12428 | ||
12429 | /* | |
12430 | * Don't try to allocate more rpi header regions if the device limit | |
12431 | * on available rpis max has been exhausted. | |
12432 | */ | |
12433 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
12434 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
12435 | spin_unlock_irq(&phba->hbalock); | |
12436 | return rpi; | |
12437 | } | |
12438 | ||
12439 | /* | |
12440 | * If the driver is running low on rpi resources, allocate another | |
12441 | * page now. Note that the next_rpi value is used because | |
12442 | * it represents how many are actually in use whereas max_rpi notes | |
12443 | * how many are supported max by the device. | |
12444 | */ | |
12445 | rpi_remaining = phba->sli4_hba.next_rpi - rpi_base - | |
12446 | phba->sli4_hba.rpi_count; | |
12447 | spin_unlock_irq(&phba->hbalock); | |
12448 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
12449 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
12450 | if (!rpi_hdr) { | |
12451 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12452 | "2002 Error Could not grow rpi " | |
12453 | "count\n"); | |
12454 | } else { | |
12455 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); | |
12456 | } | |
12457 | } | |
12458 | ||
12459 | return rpi; | |
12460 | } | |
12461 | ||
d7c47992 JS |
12462 | /** |
12463 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
12464 | * @phba: pointer to lpfc hba data structure. | |
12465 | * | |
12466 | * This routine is invoked to release an rpi to the pool of | |
12467 | * available rpis maintained by the driver. | |
12468 | **/ | |
12469 | void | |
12470 | __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
12471 | { | |
12472 | if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) { | |
12473 | phba->sli4_hba.rpi_count--; | |
12474 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
12475 | } | |
12476 | } | |
12477 | ||
6fb120a7 JS |
12478 | /** |
12479 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
12480 | * @phba: pointer to lpfc hba data structure. | |
12481 | * | |
12482 | * This routine is invoked to release an rpi to the pool of | |
12483 | * available rpis maintained by the driver. | |
12484 | **/ | |
12485 | void | |
12486 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
12487 | { | |
12488 | spin_lock_irq(&phba->hbalock); | |
d7c47992 | 12489 | __lpfc_sli4_free_rpi(phba, rpi); |
6fb120a7 JS |
12490 | spin_unlock_irq(&phba->hbalock); |
12491 | } | |
12492 | ||
12493 | /** | |
12494 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
12495 | * @phba: pointer to lpfc hba data structure. | |
12496 | * | |
12497 | * This routine is invoked to remove the memory region that | |
12498 | * provided rpi via a bitmask. | |
12499 | **/ | |
12500 | void | |
12501 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
12502 | { | |
12503 | kfree(phba->sli4_hba.rpi_bmask); | |
12504 | } | |
12505 | ||
12506 | /** | |
12507 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
12508 | * @phba: pointer to lpfc hba data structure. | |
12509 | * | |
12510 | * This routine is invoked to remove the memory region that | |
12511 | * provided rpi via a bitmask. | |
12512 | **/ | |
12513 | int | |
12514 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | |
12515 | { | |
12516 | LPFC_MBOXQ_t *mboxq; | |
12517 | struct lpfc_hba *phba = ndlp->phba; | |
12518 | int rc; | |
12519 | ||
12520 | /* The port is notified of the header region via a mailbox command. */ | |
12521 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12522 | if (!mboxq) | |
12523 | return -ENOMEM; | |
12524 | ||
12525 | /* Post all rpi memory regions to the port. */ | |
12526 | lpfc_resume_rpi(mboxq, ndlp); | |
12527 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12528 | if (rc == MBX_NOT_FINISHED) { | |
12529 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12530 | "2010 Resume RPI Mailbox failed " | |
12531 | "status %d, mbxStatus x%x\n", rc, | |
12532 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
12533 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12534 | return -EIO; | |
12535 | } | |
12536 | return 0; | |
12537 | } | |
12538 | ||
12539 | /** | |
12540 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
76a95d75 | 12541 | * @vport: Pointer to the vport for which the vpi is being initialized |
6fb120a7 | 12542 | * |
76a95d75 | 12543 | * This routine is invoked to activate a vpi with the port. |
6fb120a7 JS |
12544 | * |
12545 | * Returns: | |
12546 | * 0 success | |
12547 | * -Evalue otherwise | |
12548 | **/ | |
12549 | int | |
76a95d75 | 12550 | lpfc_sli4_init_vpi(struct lpfc_vport *vport) |
6fb120a7 JS |
12551 | { |
12552 | LPFC_MBOXQ_t *mboxq; | |
12553 | int rc = 0; | |
6a9c52cf | 12554 | int retval = MBX_SUCCESS; |
6fb120a7 | 12555 | uint32_t mbox_tmo; |
76a95d75 | 12556 | struct lpfc_hba *phba = vport->phba; |
6fb120a7 JS |
12557 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12558 | if (!mboxq) | |
12559 | return -ENOMEM; | |
76a95d75 | 12560 | lpfc_init_vpi(phba, mboxq, vport->vpi); |
6fb120a7 JS |
12561 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI); |
12562 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6fb120a7 | 12563 | if (rc != MBX_SUCCESS) { |
76a95d75 | 12564 | lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI, |
6fb120a7 JS |
12565 | "2022 INIT VPI Mailbox failed " |
12566 | "status %d, mbxStatus x%x\n", rc, | |
12567 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 12568 | retval = -EIO; |
6fb120a7 | 12569 | } |
6a9c52cf | 12570 | if (rc != MBX_TIMEOUT) |
76a95d75 | 12571 | mempool_free(mboxq, vport->phba->mbox_mem_pool); |
6a9c52cf JS |
12572 | |
12573 | return retval; | |
6fb120a7 JS |
12574 | } |
12575 | ||
12576 | /** | |
12577 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
12578 | * @phba: pointer to lpfc hba data structure. | |
12579 | * @mboxq: Pointer to mailbox object. | |
12580 | * | |
12581 | * This routine is invoked to manually add a single FCF record. The caller | |
12582 | * must pass a completely initialized FCF_Record. This routine takes | |
12583 | * care of the nonembedded mailbox operations. | |
12584 | **/ | |
12585 | static void | |
12586 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
12587 | { | |
12588 | void *virt_addr; | |
12589 | union lpfc_sli4_cfg_shdr *shdr; | |
12590 | uint32_t shdr_status, shdr_add_status; | |
12591 | ||
12592 | virt_addr = mboxq->sge_array->addr[0]; | |
12593 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12594 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
12595 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12596 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12597 | ||
12598 | if ((shdr_status || shdr_add_status) && | |
12599 | (shdr_status != STATUS_FCF_IN_USE)) | |
12600 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12601 | "2558 ADD_FCF_RECORD mailbox failed with " | |
12602 | "status x%x add_status x%x\n", | |
12603 | shdr_status, shdr_add_status); | |
12604 | ||
12605 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12606 | } | |
12607 | ||
12608 | /** | |
12609 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
12610 | * @phba: pointer to lpfc hba data structure. | |
12611 | * @fcf_record: pointer to the initialized fcf record to add. | |
12612 | * | |
12613 | * This routine is invoked to manually add a single FCF record. The caller | |
12614 | * must pass a completely initialized FCF_Record. This routine takes | |
12615 | * care of the nonembedded mailbox operations. | |
12616 | **/ | |
12617 | int | |
12618 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
12619 | { | |
12620 | int rc = 0; | |
12621 | LPFC_MBOXQ_t *mboxq; | |
12622 | uint8_t *bytep; | |
12623 | void *virt_addr; | |
12624 | dma_addr_t phys_addr; | |
12625 | struct lpfc_mbx_sge sge; | |
12626 | uint32_t alloc_len, req_len; | |
12627 | uint32_t fcfindex; | |
12628 | ||
12629 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12630 | if (!mboxq) { | |
12631 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12632 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
12633 | return -ENOMEM; | |
12634 | } | |
12635 | ||
12636 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
12637 | sizeof(uint32_t); | |
12638 | ||
12639 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
12640 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12641 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
12642 | req_len, LPFC_SLI4_MBX_NEMBED); | |
12643 | if (alloc_len < req_len) { | |
12644 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12645 | "2523 Allocated DMA memory size (x%x) is " | |
12646 | "less than the requested DMA memory " | |
12647 | "size (x%x)\n", alloc_len, req_len); | |
12648 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12649 | return -ENOMEM; | |
12650 | } | |
12651 | ||
12652 | /* | |
12653 | * Get the first SGE entry from the non-embedded DMA memory. This | |
12654 | * routine only uses a single SGE. | |
12655 | */ | |
12656 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
12657 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
12658 | virt_addr = mboxq->sge_array->addr[0]; |
12659 | /* | |
12660 | * Configure the FCF record for FCFI 0. This is the driver's | |
12661 | * hardcoded default and gets used in nonFIP mode. | |
12662 | */ | |
12663 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
12664 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
12665 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
12666 | ||
12667 | /* | |
12668 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
12669 | * the FCoE header plus word10. The data copy needs to be endian | |
12670 | * correct. | |
12671 | */ | |
12672 | bytep += sizeof(uint32_t); | |
12673 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
12674 | mboxq->vport = phba->pport; | |
12675 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
12676 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12677 | if (rc == MBX_NOT_FINISHED) { | |
12678 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12679 | "2515 ADD_FCF_RECORD mailbox failed with " | |
12680 | "status 0x%x\n", rc); | |
12681 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12682 | rc = -EIO; | |
12683 | } else | |
12684 | rc = 0; | |
12685 | ||
12686 | return rc; | |
12687 | } | |
12688 | ||
12689 | /** | |
12690 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
12691 | * @phba: pointer to lpfc hba data structure. | |
12692 | * @fcf_record: pointer to the fcf record to write the default data. | |
12693 | * @fcf_index: FCF table entry index. | |
12694 | * | |
12695 | * This routine is invoked to build the driver's default FCF record. The | |
12696 | * values used are hardcoded. This routine handles memory initialization. | |
12697 | * | |
12698 | **/ | |
12699 | void | |
12700 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
12701 | struct fcf_record *fcf_record, | |
12702 | uint16_t fcf_index) | |
12703 | { | |
12704 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
12705 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
12706 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
12707 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
12708 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
12709 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
12710 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
12711 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
12712 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
12713 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
12714 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
12715 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
12716 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
12717 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 12718 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
12719 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
12720 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
12721 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
12722 | /* Set the VLAN bit map */ | |
12723 | if (phba->valid_vlan) { | |
12724 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
12725 | = 1 << (phba->vlan_id % 8); | |
12726 | } | |
12727 | } | |
12728 | ||
12729 | /** | |
0c9ab6f5 | 12730 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
12731 | * @phba: pointer to lpfc hba data structure. |
12732 | * @fcf_index: FCF table entry offset. | |
12733 | * | |
0c9ab6f5 JS |
12734 | * This routine is invoked to scan the entire FCF table by reading FCF |
12735 | * record and processing it one at a time starting from the @fcf_index | |
12736 | * for initial FCF discovery or fast FCF failover rediscovery. | |
12737 | * | |
12738 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12739 | * otherwise. | |
6fb120a7 JS |
12740 | **/ |
12741 | int | |
0c9ab6f5 | 12742 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
12743 | { |
12744 | int rc = 0, error; | |
12745 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 12746 | |
32b9793f | 12747 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
6fb120a7 JS |
12748 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12749 | if (!mboxq) { | |
12750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12751 | "2000 Failed to allocate mbox for " | |
12752 | "READ_FCF cmd\n"); | |
4d9ab994 | 12753 | error = -ENOMEM; |
0c9ab6f5 | 12754 | goto fail_fcf_scan; |
6fb120a7 | 12755 | } |
ecfd03c6 | 12756 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 12757 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
12758 | if (rc) { |
12759 | error = -EINVAL; | |
0c9ab6f5 | 12760 | goto fail_fcf_scan; |
6fb120a7 | 12761 | } |
ecfd03c6 | 12762 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 12763 | mboxq->vport = phba->pport; |
0c9ab6f5 | 12764 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
a93ff37a JS |
12765 | |
12766 | spin_lock_irq(&phba->hbalock); | |
12767 | phba->hba_flag |= FCF_TS_INPROG; | |
12768 | spin_unlock_irq(&phba->hbalock); | |
12769 | ||
6fb120a7 | 12770 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 12771 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 12772 | error = -EIO; |
ecfd03c6 | 12773 | else { |
38b92ef8 JS |
12774 | /* Reset eligible FCF count for new scan */ |
12775 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) | |
999d813f | 12776 | phba->fcf.eligible_fcf_cnt = 0; |
6fb120a7 | 12777 | error = 0; |
32b9793f | 12778 | } |
0c9ab6f5 | 12779 | fail_fcf_scan: |
4d9ab994 JS |
12780 | if (error) { |
12781 | if (mboxq) | |
12782 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
a93ff37a | 12783 | /* FCF scan failed, clear FCF_TS_INPROG flag */ |
4d9ab994 | 12784 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 12785 | phba->hba_flag &= ~FCF_TS_INPROG; |
4d9ab994 JS |
12786 | spin_unlock_irq(&phba->hbalock); |
12787 | } | |
6fb120a7 JS |
12788 | return error; |
12789 | } | |
a0c87cbd | 12790 | |
0c9ab6f5 | 12791 | /** |
a93ff37a | 12792 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf. |
0c9ab6f5 JS |
12793 | * @phba: pointer to lpfc hba data structure. |
12794 | * @fcf_index: FCF table entry offset. | |
12795 | * | |
12796 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
a93ff37a | 12797 | * and to use it for FLOGI roundrobin FCF failover. |
0c9ab6f5 JS |
12798 | * |
12799 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12800 | * otherwise. | |
12801 | **/ | |
12802 | int | |
12803 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
12804 | { | |
12805 | int rc = 0, error; | |
12806 | LPFC_MBOXQ_t *mboxq; | |
12807 | ||
12808 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12809 | if (!mboxq) { | |
12810 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
12811 | "2763 Failed to allocate mbox for " | |
12812 | "READ_FCF cmd\n"); | |
12813 | error = -ENOMEM; | |
12814 | goto fail_fcf_read; | |
12815 | } | |
12816 | /* Construct the read FCF record mailbox command */ | |
12817 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
12818 | if (rc) { | |
12819 | error = -EINVAL; | |
12820 | goto fail_fcf_read; | |
12821 | } | |
12822 | /* Issue the mailbox command asynchronously */ | |
12823 | mboxq->vport = phba->pport; | |
12824 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
12825 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12826 | if (rc == MBX_NOT_FINISHED) | |
12827 | error = -EIO; | |
12828 | else | |
12829 | error = 0; | |
12830 | ||
12831 | fail_fcf_read: | |
12832 | if (error && mboxq) | |
12833 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12834 | return error; | |
12835 | } | |
12836 | ||
12837 | /** | |
12838 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
12839 | * @phba: pointer to lpfc hba data structure. | |
12840 | * @fcf_index: FCF table entry offset. | |
12841 | * | |
12842 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
a93ff37a | 12843 | * determine whether it's eligible for FLOGI roundrobin failover list. |
0c9ab6f5 JS |
12844 | * |
12845 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12846 | * otherwise. | |
12847 | **/ | |
12848 | int | |
12849 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
12850 | { | |
12851 | int rc = 0, error; | |
12852 | LPFC_MBOXQ_t *mboxq; | |
12853 | ||
12854 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12855 | if (!mboxq) { | |
12856 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
12857 | "2758 Failed to allocate mbox for " | |
12858 | "READ_FCF cmd\n"); | |
12859 | error = -ENOMEM; | |
12860 | goto fail_fcf_read; | |
12861 | } | |
12862 | /* Construct the read FCF record mailbox command */ | |
12863 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
12864 | if (rc) { | |
12865 | error = -EINVAL; | |
12866 | goto fail_fcf_read; | |
12867 | } | |
12868 | /* Issue the mailbox command asynchronously */ | |
12869 | mboxq->vport = phba->pport; | |
12870 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
12871 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12872 | if (rc == MBX_NOT_FINISHED) | |
12873 | error = -EIO; | |
12874 | else | |
12875 | error = 0; | |
12876 | ||
12877 | fail_fcf_read: | |
12878 | if (error && mboxq) | |
12879 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12880 | return error; | |
12881 | } | |
12882 | ||
12883 | /** | |
12884 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
12885 | * @phba: pointer to lpfc hba data structure. | |
12886 | * | |
12887 | * This routine is to get the next eligible FCF record index in a round | |
12888 | * robin fashion. If the next eligible FCF record index equals to the | |
a93ff37a | 12889 | * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) |
0c9ab6f5 JS |
12890 | * shall be returned, otherwise, the next eligible FCF record's index |
12891 | * shall be returned. | |
12892 | **/ | |
12893 | uint16_t | |
12894 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
12895 | { | |
12896 | uint16_t next_fcf_index; | |
12897 | ||
3804dc84 JS |
12898 | /* Search start from next bit of currently registered FCF index */ |
12899 | next_fcf_index = (phba->fcf.current_rec.fcf_indx + 1) % | |
12900 | LPFC_SLI4_FCF_TBL_INDX_MAX; | |
0c9ab6f5 JS |
12901 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, |
12902 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
3804dc84 JS |
12903 | next_fcf_index); |
12904 | ||
0c9ab6f5 JS |
12905 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ |
12906 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) | |
12907 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, | |
12908 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
3804dc84 JS |
12909 | |
12910 | /* Check roundrobin failover list empty condition */ | |
12911 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12912 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP, | |
12913 | "2844 No roundrobin failover FCF available\n"); | |
0c9ab6f5 | 12914 | return LPFC_FCOE_FCF_NEXT_NONE; |
3804dc84 JS |
12915 | } |
12916 | ||
3804dc84 | 12917 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a JS |
12918 | "2845 Get next roundrobin failover FCF (x%x)\n", |
12919 | next_fcf_index); | |
12920 | ||
0c9ab6f5 JS |
12921 | return next_fcf_index; |
12922 | } | |
12923 | ||
12924 | /** | |
12925 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
12926 | * @phba: pointer to lpfc hba data structure. | |
12927 | * | |
12928 | * This routine sets the FCF record index in to the eligible bmask for | |
a93ff37a | 12929 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
12930 | * does not go beyond the range of the driver allocated bmask dimension |
12931 | * before setting the bit. | |
12932 | * | |
12933 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
12934 | * -EINVAL. | |
12935 | **/ | |
12936 | int | |
12937 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
12938 | { | |
12939 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12940 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
12941 | "2610 FCF (x%x) reached driver's book " |
12942 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
12943 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
12944 | return -EINVAL; | |
12945 | } | |
12946 | /* Set the eligible FCF record index bmask */ | |
12947 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
12948 | ||
3804dc84 | 12949 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 12950 | "2790 Set FCF (x%x) to roundrobin FCF failover " |
3804dc84 JS |
12951 | "bmask\n", fcf_index); |
12952 | ||
0c9ab6f5 JS |
12953 | return 0; |
12954 | } | |
12955 | ||
12956 | /** | |
3804dc84 | 12957 | * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index |
0c9ab6f5 JS |
12958 | * @phba: pointer to lpfc hba data structure. |
12959 | * | |
12960 | * This routine clears the FCF record index from the eligible bmask for | |
a93ff37a | 12961 | * roundrobin failover search. It checks to make sure that the index |
0c9ab6f5 JS |
12962 | * does not go beyond the range of the driver allocated bmask dimension |
12963 | * before clearing the bit. | |
12964 | **/ | |
12965 | void | |
12966 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
12967 | { | |
12968 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12969 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
a93ff37a JS |
12970 | "2762 FCF (x%x) reached driver's book " |
12971 | "keeping dimension:x%x\n", | |
0c9ab6f5 JS |
12972 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); |
12973 | return; | |
12974 | } | |
12975 | /* Clear the eligible FCF record index bmask */ | |
12976 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
3804dc84 JS |
12977 | |
12978 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 12979 | "2791 Clear FCF (x%x) from roundrobin failover " |
3804dc84 | 12980 | "bmask\n", fcf_index); |
0c9ab6f5 JS |
12981 | } |
12982 | ||
ecfd03c6 JS |
12983 | /** |
12984 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
12985 | * @phba: pointer to lpfc hba data structure. | |
12986 | * | |
12987 | * This routine is the completion routine for the rediscover FCF table mailbox | |
12988 | * command. If the mailbox command returned failure, it will try to stop the | |
12989 | * FCF rediscover wait timer. | |
12990 | **/ | |
12991 | void | |
12992 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
12993 | { | |
12994 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
12995 | uint32_t shdr_status, shdr_add_status; | |
12996 | ||
12997 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
12998 | ||
12999 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
13000 | &redisc_fcf->header.cfg_shdr.response); | |
13001 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
13002 | &redisc_fcf->header.cfg_shdr.response); | |
13003 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 13004 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
13005 | "2746 Requesting for FCF rediscovery failed " |
13006 | "status x%x add_status x%x\n", | |
13007 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 13008 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 13009 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 13010 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
13011 | spin_unlock_irq(&phba->hbalock); |
13012 | /* | |
13013 | * CVL event triggered FCF rediscover request failed, | |
13014 | * last resort to re-try current registered FCF entry. | |
13015 | */ | |
13016 | lpfc_retry_pport_discovery(phba); | |
13017 | } else { | |
13018 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 13019 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
13020 | spin_unlock_irq(&phba->hbalock); |
13021 | /* | |
13022 | * DEAD FCF event triggered FCF rediscover request | |
13023 | * failed, last resort to fail over as a link down | |
13024 | * to FCF registration. | |
13025 | */ | |
13026 | lpfc_sli4_fcf_dead_failthrough(phba); | |
13027 | } | |
0c9ab6f5 JS |
13028 | } else { |
13029 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
a93ff37a | 13030 | "2775 Start FCF rediscover quiescent timer\n"); |
ecfd03c6 JS |
13031 | /* |
13032 | * Start FCF rediscovery wait timer for pending FCF | |
13033 | * before rescan FCF record table. | |
13034 | */ | |
13035 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 13036 | } |
ecfd03c6 JS |
13037 | |
13038 | mempool_free(mbox, phba->mbox_mem_pool); | |
13039 | } | |
13040 | ||
13041 | /** | |
3804dc84 | 13042 | * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port. |
ecfd03c6 JS |
13043 | * @phba: pointer to lpfc hba data structure. |
13044 | * | |
13045 | * This routine is invoked to request for rediscovery of the entire FCF table | |
13046 | * by the port. | |
13047 | **/ | |
13048 | int | |
13049 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
13050 | { | |
13051 | LPFC_MBOXQ_t *mbox; | |
13052 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
13053 | int rc, length; | |
13054 | ||
0c9ab6f5 JS |
13055 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
13056 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
13057 | ||
ecfd03c6 JS |
13058 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
13059 | if (!mbox) { | |
13060 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13061 | "2745 Failed to allocate mbox for " | |
13062 | "requesting FCF rediscover.\n"); | |
13063 | return -ENOMEM; | |
13064 | } | |
13065 | ||
13066 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
13067 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
13068 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
13069 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
13070 | length, LPFC_SLI4_MBX_EMBED); | |
13071 | ||
13072 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
13073 | /* Set count to 0 for invalidating the entire FCF database */ | |
13074 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
13075 | ||
13076 | /* Issue the mailbox command asynchronously */ | |
13077 | mbox->vport = phba->pport; | |
13078 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
13079 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
13080 | ||
13081 | if (rc == MBX_NOT_FINISHED) { | |
13082 | mempool_free(mbox, phba->mbox_mem_pool); | |
13083 | return -EIO; | |
13084 | } | |
13085 | return 0; | |
13086 | } | |
13087 | ||
fc2b989b JS |
13088 | /** |
13089 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
13090 | * @phba: pointer to lpfc hba data structure. | |
13091 | * | |
13092 | * This function is the failover routine as a last resort to the FCF DEAD | |
13093 | * event when driver failed to perform fast FCF failover. | |
13094 | **/ | |
13095 | void | |
13096 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
13097 | { | |
13098 | uint32_t link_state; | |
13099 | ||
13100 | /* | |
13101 | * Last resort as FCF DEAD event failover will treat this as | |
13102 | * a link down, but save the link state because we don't want | |
13103 | * it to be changed to Link Down unless it is already down. | |
13104 | */ | |
13105 | link_state = phba->link_state; | |
13106 | lpfc_linkdown(phba); | |
13107 | phba->link_state = link_state; | |
13108 | ||
13109 | /* Unregister FCF if no devices connected to it */ | |
13110 | lpfc_unregister_unused_fcf(phba); | |
13111 | } | |
13112 | ||
a0c87cbd JS |
13113 | /** |
13114 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
13115 | * @phba: pointer to lpfc hba data structure. | |
13116 | * | |
13117 | * This function read region 23 and parse TLV for port status to | |
13118 | * decide if the user disaled the port. If the TLV indicates the | |
13119 | * port is disabled, the hba_flag is set accordingly. | |
13120 | **/ | |
13121 | void | |
13122 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
13123 | { | |
13124 | LPFC_MBOXQ_t *pmb = NULL; | |
13125 | MAILBOX_t *mb; | |
13126 | uint8_t *rgn23_data = NULL; | |
13127 | uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset; | |
13128 | int rc; | |
13129 | ||
13130 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
13131 | if (!pmb) { | |
13132 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13133 | "2600 lpfc_sli_read_serdes_param failed to" | |
13134 | " allocate mailbox memory\n"); | |
13135 | goto out; | |
13136 | } | |
13137 | mb = &pmb->u.mb; | |
13138 | ||
13139 | /* Get adapter Region 23 data */ | |
13140 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
13141 | if (!rgn23_data) | |
13142 | goto out; | |
13143 | ||
13144 | do { | |
13145 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
13146 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
13147 | ||
13148 | if (rc != MBX_SUCCESS) { | |
13149 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
13150 | "2601 lpfc_sli_read_link_ste failed to" | |
13151 | " read config region 23 rc 0x%x Status 0x%x\n", | |
13152 | rc, mb->mbxStatus); | |
13153 | mb->un.varDmp.word_cnt = 0; | |
13154 | } | |
13155 | /* | |
13156 | * dump mem may return a zero when finished or we got a | |
13157 | * mailbox error, either way we are done. | |
13158 | */ | |
13159 | if (mb->un.varDmp.word_cnt == 0) | |
13160 | break; | |
13161 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
13162 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
13163 | ||
13164 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
13165 | rgn23_data + offset, | |
13166 | mb->un.varDmp.word_cnt); | |
13167 | offset += mb->un.varDmp.word_cnt; | |
13168 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
13169 | ||
13170 | data_size = offset; | |
13171 | offset = 0; | |
13172 | ||
13173 | if (!data_size) | |
13174 | goto out; | |
13175 | ||
13176 | /* Check the region signature first */ | |
13177 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
13178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13179 | "2619 Config region 23 has bad signature\n"); | |
13180 | goto out; | |
13181 | } | |
13182 | offset += 4; | |
13183 | ||
13184 | /* Check the data structure version */ | |
13185 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
13186 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
13187 | "2620 Config region 23 has bad version\n"); | |
13188 | goto out; | |
13189 | } | |
13190 | offset += 4; | |
13191 | ||
13192 | /* Parse TLV entries in the region */ | |
13193 | while (offset < data_size) { | |
13194 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
13195 | break; | |
13196 | /* | |
13197 | * If the TLV is not driver specific TLV or driver id is | |
13198 | * not linux driver id, skip the record. | |
13199 | */ | |
13200 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
13201 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
13202 | (rgn23_data[offset + 3] != 0)) { | |
13203 | offset += rgn23_data[offset + 1] * 4 + 4; | |
13204 | continue; | |
13205 | } | |
13206 | ||
13207 | /* Driver found a driver specific TLV in the config region */ | |
13208 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
13209 | offset += 4; | |
13210 | tlv_offset = 0; | |
13211 | ||
13212 | /* | |
13213 | * Search for configured port state sub-TLV. | |
13214 | */ | |
13215 | while ((offset < data_size) && | |
13216 | (tlv_offset < sub_tlv_len)) { | |
13217 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
13218 | offset += 4; | |
13219 | tlv_offset += 4; | |
13220 | break; | |
13221 | } | |
13222 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
13223 | offset += rgn23_data[offset + 1] * 4 + 4; | |
13224 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
13225 | continue; | |
13226 | } | |
13227 | ||
13228 | /* This HBA contains PORT_STE configured */ | |
13229 | if (!rgn23_data[offset + 2]) | |
13230 | phba->hba_flag |= LINK_DISABLED; | |
13231 | ||
13232 | goto out; | |
13233 | } | |
13234 | } | |
13235 | out: | |
13236 | if (pmb) | |
13237 | mempool_free(pmb, phba->mbox_mem_pool); | |
13238 | kfree(rgn23_data); | |
13239 | return; | |
13240 | } | |
695a814e JS |
13241 | |
13242 | /** | |
13243 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
13244 | * @vport: pointer to vport data structure. | |
13245 | * | |
13246 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
13247 | * and REG_VPI mailbox commands associated with the vport. This function | |
13248 | * is called when driver want to restart discovery of the vport due to | |
13249 | * a Clear Virtual Link event. | |
13250 | **/ | |
13251 | void | |
13252 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
13253 | { | |
13254 | struct lpfc_hba *phba = vport->phba; | |
13255 | LPFC_MBOXQ_t *mb, *nextmb; | |
13256 | struct lpfc_dmabuf *mp; | |
78730cfe | 13257 | struct lpfc_nodelist *ndlp; |
d439d286 | 13258 | struct lpfc_nodelist *act_mbx_ndlp = NULL; |
589a52d6 | 13259 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
d439d286 | 13260 | LIST_HEAD(mbox_cmd_list); |
63e801ce | 13261 | uint8_t restart_loop; |
695a814e | 13262 | |
d439d286 | 13263 | /* Clean up internally queued mailbox commands with the vport */ |
695a814e JS |
13264 | spin_lock_irq(&phba->hbalock); |
13265 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
13266 | if (mb->vport != vport) | |
13267 | continue; | |
13268 | ||
13269 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
13270 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
13271 | continue; | |
13272 | ||
d439d286 JS |
13273 | list_del(&mb->list); |
13274 | list_add_tail(&mb->list, &mbox_cmd_list); | |
13275 | } | |
13276 | /* Clean up active mailbox command with the vport */ | |
13277 | mb = phba->sli.mbox_active; | |
13278 | if (mb && (mb->vport == vport)) { | |
13279 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
13280 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
13281 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13282 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
13283 | act_mbx_ndlp = (struct lpfc_nodelist *)mb->context2; | |
13284 | /* Put reference count for delayed processing */ | |
13285 | act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp); | |
13286 | /* Unregister the RPI when mailbox complete */ | |
13287 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
13288 | } | |
13289 | } | |
63e801ce JS |
13290 | /* Cleanup any mailbox completions which are not yet processed */ |
13291 | do { | |
13292 | restart_loop = 0; | |
13293 | list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) { | |
13294 | /* | |
13295 | * If this mailox is already processed or it is | |
13296 | * for another vport ignore it. | |
13297 | */ | |
13298 | if ((mb->vport != vport) || | |
13299 | (mb->mbox_flag & LPFC_MBX_IMED_UNREG)) | |
13300 | continue; | |
13301 | ||
13302 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
13303 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
13304 | continue; | |
13305 | ||
13306 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
13307 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
13308 | ndlp = (struct lpfc_nodelist *)mb->context2; | |
13309 | /* Unregister the RPI when mailbox complete */ | |
13310 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
13311 | restart_loop = 1; | |
13312 | spin_unlock_irq(&phba->hbalock); | |
13313 | spin_lock(shost->host_lock); | |
13314 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
13315 | spin_unlock(shost->host_lock); | |
13316 | spin_lock_irq(&phba->hbalock); | |
13317 | break; | |
13318 | } | |
13319 | } | |
13320 | } while (restart_loop); | |
13321 | ||
d439d286 JS |
13322 | spin_unlock_irq(&phba->hbalock); |
13323 | ||
13324 | /* Release the cleaned-up mailbox commands */ | |
13325 | while (!list_empty(&mbox_cmd_list)) { | |
13326 | list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list); | |
695a814e | 13327 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
d7c47992 JS |
13328 | if (phba->sli_rev == LPFC_SLI_REV4) |
13329 | __lpfc_sli4_free_rpi(phba, | |
13330 | mb->u.mb.un.varRegLogin.rpi); | |
695a814e JS |
13331 | mp = (struct lpfc_dmabuf *) (mb->context1); |
13332 | if (mp) { | |
13333 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
13334 | kfree(mp); | |
13335 | } | |
78730cfe | 13336 | ndlp = (struct lpfc_nodelist *) mb->context2; |
d439d286 | 13337 | mb->context2 = NULL; |
78730cfe | 13338 | if (ndlp) { |
ec21b3b0 | 13339 | spin_lock(shost->host_lock); |
589a52d6 | 13340 | ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; |
ec21b3b0 | 13341 | spin_unlock(shost->host_lock); |
78730cfe | 13342 | lpfc_nlp_put(ndlp); |
78730cfe | 13343 | } |
695a814e | 13344 | } |
695a814e JS |
13345 | mempool_free(mb, phba->mbox_mem_pool); |
13346 | } | |
d439d286 JS |
13347 | |
13348 | /* Release the ndlp with the cleaned-up active mailbox command */ | |
13349 | if (act_mbx_ndlp) { | |
13350 | spin_lock(shost->host_lock); | |
13351 | act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL; | |
13352 | spin_unlock(shost->host_lock); | |
13353 | lpfc_nlp_put(act_mbx_ndlp); | |
695a814e | 13354 | } |
695a814e JS |
13355 | } |
13356 | ||
2a9bf3d0 JS |
13357 | /** |
13358 | * lpfc_drain_txq - Drain the txq | |
13359 | * @phba: Pointer to HBA context object. | |
13360 | * | |
13361 | * This function attempt to submit IOCBs on the txq | |
13362 | * to the adapter. For SLI4 adapters, the txq contains | |
13363 | * ELS IOCBs that have been deferred because the there | |
13364 | * are no SGLs. This congestion can occur with large | |
13365 | * vport counts during node discovery. | |
13366 | **/ | |
13367 | ||
13368 | uint32_t | |
13369 | lpfc_drain_txq(struct lpfc_hba *phba) | |
13370 | { | |
13371 | LIST_HEAD(completions); | |
13372 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
13373 | struct lpfc_iocbq *piocbq = 0; | |
13374 | unsigned long iflags = 0; | |
13375 | char *fail_msg = NULL; | |
13376 | struct lpfc_sglq *sglq; | |
13377 | union lpfc_wqe wqe; | |
13378 | ||
13379 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13380 | if (pring->txq_cnt > pring->txq_max) | |
13381 | pring->txq_max = pring->txq_cnt; | |
13382 | ||
13383 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13384 | ||
13385 | while (pring->txq_cnt) { | |
13386 | spin_lock_irqsave(&phba->hbalock, iflags); | |
13387 | ||
19ca7609 JS |
13388 | piocbq = lpfc_sli_ringtx_get(phba, pring); |
13389 | sglq = __lpfc_sli_get_sglq(phba, piocbq); | |
2a9bf3d0 | 13390 | if (!sglq) { |
19ca7609 | 13391 | __lpfc_sli_ringtx_put(phba, pring, piocbq); |
2a9bf3d0 JS |
13392 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
13393 | break; | |
13394 | } else { | |
2a9bf3d0 JS |
13395 | if (!piocbq) { |
13396 | /* The txq_cnt out of sync. This should | |
13397 | * never happen | |
13398 | */ | |
13399 | sglq = __lpfc_clear_active_sglq(phba, | |
13400 | sglq->sli4_xritag); | |
13401 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13402 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13403 | "2823 txq empty and txq_cnt is %d\n ", | |
13404 | pring->txq_cnt); | |
13405 | break; | |
13406 | } | |
13407 | } | |
13408 | ||
13409 | /* The xri and iocb resources secured, | |
13410 | * attempt to issue request | |
13411 | */ | |
13412 | piocbq->sli4_xritag = sglq->sli4_xritag; | |
13413 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
13414 | fail_msg = "to convert bpl to sgl"; | |
13415 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
13416 | fail_msg = "to convert iocb to wqe"; | |
13417 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
13418 | fail_msg = " - Wq is full"; | |
13419 | else | |
13420 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
13421 | ||
13422 | if (fail_msg) { | |
13423 | /* Failed means we can't issue and need to cancel */ | |
13424 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
13425 | "2822 IOCB failed %s iotag 0x%x " | |
13426 | "xri 0x%x\n", | |
13427 | fail_msg, | |
13428 | piocbq->iotag, piocbq->sli4_xritag); | |
13429 | list_add_tail(&piocbq->list, &completions); | |
13430 | } | |
13431 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
13432 | } | |
13433 | ||
2a9bf3d0 JS |
13434 | /* Cancel all the IOCBs that cannot be issued */ |
13435 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
13436 | IOERR_SLI_ABORTED); | |
13437 | ||
13438 | return pring->txq_cnt; | |
13439 | } |