]>
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)) | |
98 | bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1); | |
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 | ||
515 | /** | |
516 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | |
517 | * @phba: Pointer to HBA context object. | |
518 | * | |
519 | * This function is called with hbalock held. This function | |
520 | * Gets a new driver sglq object from the sglq list. If the | |
521 | * list is not empty then it is successful, it returns pointer to the newly | |
522 | * allocated sglq object else it returns NULL. | |
523 | **/ | |
524 | static struct lpfc_sglq * | |
525 | __lpfc_sli_get_sglq(struct lpfc_hba *phba) | |
526 | { | |
527 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | |
528 | struct lpfc_sglq *sglq = NULL; | |
529 | uint16_t adj_xri; | |
530 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); | |
6a9c52cf JS |
531 | if (!sglq) |
532 | return NULL; | |
da0436e9 JS |
533 | adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base; |
534 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq; | |
0f65ff68 | 535 | sglq->state = SGL_ALLOCATED; |
da0436e9 JS |
536 | return sglq; |
537 | } | |
538 | ||
e59058c4 | 539 | /** |
3621a710 | 540 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
e59058c4 JS |
541 | * @phba: Pointer to HBA context object. |
542 | * | |
543 | * This function is called with no lock held. This function | |
544 | * allocates a new driver iocb object from the iocb pool. If the | |
545 | * allocation is successful, it returns pointer to the newly | |
546 | * allocated iocb object else it returns NULL. | |
547 | **/ | |
2e0fef85 JS |
548 | struct lpfc_iocbq * |
549 | lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |
550 | { | |
551 | struct lpfc_iocbq * iocbq = NULL; | |
552 | unsigned long iflags; | |
553 | ||
554 | spin_lock_irqsave(&phba->hbalock, iflags); | |
555 | iocbq = __lpfc_sli_get_iocbq(phba); | |
556 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
557 | return iocbq; | |
558 | } | |
559 | ||
4f774513 JS |
560 | /** |
561 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool | |
562 | * @phba: Pointer to HBA context object. | |
563 | * @iocbq: Pointer to driver iocb object. | |
564 | * | |
565 | * This function is called with hbalock held to release driver | |
566 | * iocb object to the iocb pool. The iotag in the iocb object | |
567 | * does not change for each use of the iocb object. This function | |
568 | * clears all other fields of the iocb object when it is freed. | |
569 | * The sqlq structure that holds the xritag and phys and virtual | |
570 | * mappings for the scatter gather list is retrieved from the | |
571 | * active array of sglq. The get of the sglq pointer also clears | |
572 | * the entry in the array. If the status of the IO indiactes that | |
573 | * this IO was aborted then the sglq entry it put on the | |
574 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | |
575 | * IO has good status or fails for any other reason then the sglq | |
576 | * entry is added to the free list (lpfc_sgl_list). | |
577 | **/ | |
578 | static void | |
579 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
580 | { | |
581 | struct lpfc_sglq *sglq; | |
582 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | |
2a9bf3d0 JS |
583 | unsigned long iflag = 0; |
584 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
4f774513 JS |
585 | |
586 | if (iocbq->sli4_xritag == NO_XRI) | |
587 | sglq = NULL; | |
588 | else | |
589 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag); | |
590 | if (sglq) { | |
0f65ff68 JS |
591 | if ((iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) && |
592 | (sglq->state != SGL_XRI_ABORTED)) { | |
4f774513 JS |
593 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, |
594 | iflag); | |
595 | list_add(&sglq->list, | |
596 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | |
597 | spin_unlock_irqrestore( | |
598 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | |
0f65ff68 JS |
599 | } else { |
600 | sglq->state = SGL_FREED; | |
4f774513 | 601 | list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list); |
2a9bf3d0 JS |
602 | |
603 | /* Check if TXQ queue needs to be serviced */ | |
604 | if (pring->txq_cnt) { | |
605 | spin_lock_irqsave( | |
606 | &phba->pport->work_port_lock, iflag); | |
607 | phba->pport->work_port_events |= | |
608 | WORKER_SERVICE_TXQ; | |
609 | lpfc_worker_wake_up(phba); | |
610 | spin_unlock_irqrestore( | |
611 | &phba->pport->work_port_lock, iflag); | |
612 | } | |
0f65ff68 | 613 | } |
4f774513 JS |
614 | } |
615 | ||
616 | ||
617 | /* | |
618 | * Clean all volatile data fields, preserve iotag and node struct. | |
619 | */ | |
620 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
621 | iocbq->sli4_xritag = NO_XRI; | |
622 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | |
623 | } | |
624 | ||
2a9bf3d0 | 625 | |
e59058c4 | 626 | /** |
3772a991 | 627 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool |
e59058c4 JS |
628 | * @phba: Pointer to HBA context object. |
629 | * @iocbq: Pointer to driver iocb object. | |
630 | * | |
631 | * This function is called with hbalock held to release driver | |
632 | * iocb object to the iocb pool. The iotag in the iocb object | |
633 | * does not change for each use of the iocb object. This function | |
634 | * clears all other fields of the iocb object when it is freed. | |
635 | **/ | |
a6ababd2 | 636 | static void |
3772a991 | 637 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
604a3e30 | 638 | { |
2e0fef85 | 639 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
604a3e30 JB |
640 | |
641 | /* | |
642 | * Clean all volatile data fields, preserve iotag and node struct. | |
643 | */ | |
644 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | |
3772a991 | 645 | iocbq->sli4_xritag = NO_XRI; |
604a3e30 JB |
646 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
647 | } | |
648 | ||
3772a991 JS |
649 | /** |
650 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | |
651 | * @phba: Pointer to HBA context object. | |
652 | * @iocbq: Pointer to driver iocb object. | |
653 | * | |
654 | * This function is called with hbalock held to release driver | |
655 | * iocb object to the iocb pool. The iotag in the iocb object | |
656 | * does not change for each use of the iocb object. This function | |
657 | * clears all other fields of the iocb object when it is freed. | |
658 | **/ | |
659 | static void | |
660 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
661 | { | |
662 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | |
2a9bf3d0 | 663 | phba->iocb_cnt--; |
3772a991 JS |
664 | } |
665 | ||
e59058c4 | 666 | /** |
3621a710 | 667 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
e59058c4 JS |
668 | * @phba: Pointer to HBA context object. |
669 | * @iocbq: Pointer to driver iocb object. | |
670 | * | |
671 | * This function is called with no lock held to release the iocb to | |
672 | * iocb pool. | |
673 | **/ | |
2e0fef85 JS |
674 | void |
675 | lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |
676 | { | |
677 | unsigned long iflags; | |
678 | ||
679 | /* | |
680 | * Clean all volatile data fields, preserve iotag and node struct. | |
681 | */ | |
682 | spin_lock_irqsave(&phba->hbalock, iflags); | |
683 | __lpfc_sli_release_iocbq(phba, iocbq); | |
684 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
685 | } | |
686 | ||
a257bf90 JS |
687 | /** |
688 | * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list. | |
689 | * @phba: Pointer to HBA context object. | |
690 | * @iocblist: List of IOCBs. | |
691 | * @ulpstatus: ULP status in IOCB command field. | |
692 | * @ulpWord4: ULP word-4 in IOCB command field. | |
693 | * | |
694 | * This function is called with a list of IOCBs to cancel. It cancels the IOCB | |
695 | * on the list by invoking the complete callback function associated with the | |
696 | * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond | |
697 | * fields. | |
698 | **/ | |
699 | void | |
700 | lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist, | |
701 | uint32_t ulpstatus, uint32_t ulpWord4) | |
702 | { | |
703 | struct lpfc_iocbq *piocb; | |
704 | ||
705 | while (!list_empty(iocblist)) { | |
706 | list_remove_head(iocblist, piocb, struct lpfc_iocbq, list); | |
707 | ||
708 | if (!piocb->iocb_cmpl) | |
709 | lpfc_sli_release_iocbq(phba, piocb); | |
710 | else { | |
711 | piocb->iocb.ulpStatus = ulpstatus; | |
712 | piocb->iocb.un.ulpWord[4] = ulpWord4; | |
713 | (piocb->iocb_cmpl) (phba, piocb, piocb); | |
714 | } | |
715 | } | |
716 | return; | |
717 | } | |
718 | ||
e59058c4 | 719 | /** |
3621a710 JS |
720 | * lpfc_sli_iocb_cmd_type - Get the iocb type |
721 | * @iocb_cmnd: iocb command code. | |
e59058c4 JS |
722 | * |
723 | * This function is called by ring event handler function to get the iocb type. | |
724 | * This function translates the iocb command to an iocb command type used to | |
725 | * decide the final disposition of each completed IOCB. | |
726 | * The function returns | |
727 | * LPFC_UNKNOWN_IOCB if it is an unsupported iocb | |
728 | * LPFC_SOL_IOCB if it is a solicited iocb completion | |
729 | * LPFC_ABORT_IOCB if it is an abort iocb | |
730 | * LPFC_UNSOL_IOCB if it is an unsolicited iocb | |
731 | * | |
732 | * The caller is not required to hold any lock. | |
733 | **/ | |
dea3101e JB |
734 | static lpfc_iocb_type |
735 | lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |
736 | { | |
737 | lpfc_iocb_type type = LPFC_UNKNOWN_IOCB; | |
738 | ||
739 | if (iocb_cmnd > CMD_MAX_IOCB_CMD) | |
740 | return 0; | |
741 | ||
742 | switch (iocb_cmnd) { | |
743 | case CMD_XMIT_SEQUENCE_CR: | |
744 | case CMD_XMIT_SEQUENCE_CX: | |
745 | case CMD_XMIT_BCAST_CN: | |
746 | case CMD_XMIT_BCAST_CX: | |
747 | case CMD_ELS_REQUEST_CR: | |
748 | case CMD_ELS_REQUEST_CX: | |
749 | case CMD_CREATE_XRI_CR: | |
750 | case CMD_CREATE_XRI_CX: | |
751 | case CMD_GET_RPI_CN: | |
752 | case CMD_XMIT_ELS_RSP_CX: | |
753 | case CMD_GET_RPI_CR: | |
754 | case CMD_FCP_IWRITE_CR: | |
755 | case CMD_FCP_IWRITE_CX: | |
756 | case CMD_FCP_IREAD_CR: | |
757 | case CMD_FCP_IREAD_CX: | |
758 | case CMD_FCP_ICMND_CR: | |
759 | case CMD_FCP_ICMND_CX: | |
f5603511 JS |
760 | case CMD_FCP_TSEND_CX: |
761 | case CMD_FCP_TRSP_CX: | |
762 | case CMD_FCP_TRECEIVE_CX: | |
763 | case CMD_FCP_AUTO_TRSP_CX: | |
dea3101e JB |
764 | case CMD_ADAPTER_MSG: |
765 | case CMD_ADAPTER_DUMP: | |
766 | case CMD_XMIT_SEQUENCE64_CR: | |
767 | case CMD_XMIT_SEQUENCE64_CX: | |
768 | case CMD_XMIT_BCAST64_CN: | |
769 | case CMD_XMIT_BCAST64_CX: | |
770 | case CMD_ELS_REQUEST64_CR: | |
771 | case CMD_ELS_REQUEST64_CX: | |
772 | case CMD_FCP_IWRITE64_CR: | |
773 | case CMD_FCP_IWRITE64_CX: | |
774 | case CMD_FCP_IREAD64_CR: | |
775 | case CMD_FCP_IREAD64_CX: | |
776 | case CMD_FCP_ICMND64_CR: | |
777 | case CMD_FCP_ICMND64_CX: | |
f5603511 JS |
778 | case CMD_FCP_TSEND64_CX: |
779 | case CMD_FCP_TRSP64_CX: | |
780 | case CMD_FCP_TRECEIVE64_CX: | |
dea3101e JB |
781 | case CMD_GEN_REQUEST64_CR: |
782 | case CMD_GEN_REQUEST64_CX: | |
783 | case CMD_XMIT_ELS_RSP64_CX: | |
da0436e9 JS |
784 | case DSSCMD_IWRITE64_CR: |
785 | case DSSCMD_IWRITE64_CX: | |
786 | case DSSCMD_IREAD64_CR: | |
787 | case DSSCMD_IREAD64_CX: | |
dea3101e JB |
788 | type = LPFC_SOL_IOCB; |
789 | break; | |
790 | case CMD_ABORT_XRI_CN: | |
791 | case CMD_ABORT_XRI_CX: | |
792 | case CMD_CLOSE_XRI_CN: | |
793 | case CMD_CLOSE_XRI_CX: | |
794 | case CMD_XRI_ABORTED_CX: | |
795 | case CMD_ABORT_MXRI64_CN: | |
6669f9bb | 796 | case CMD_XMIT_BLS_RSP64_CX: |
dea3101e JB |
797 | type = LPFC_ABORT_IOCB; |
798 | break; | |
799 | case CMD_RCV_SEQUENCE_CX: | |
800 | case CMD_RCV_ELS_REQ_CX: | |
801 | case CMD_RCV_SEQUENCE64_CX: | |
802 | case CMD_RCV_ELS_REQ64_CX: | |
57127f15 | 803 | case CMD_ASYNC_STATUS: |
ed957684 JS |
804 | case CMD_IOCB_RCV_SEQ64_CX: |
805 | case CMD_IOCB_RCV_ELS64_CX: | |
806 | case CMD_IOCB_RCV_CONT64_CX: | |
3163f725 | 807 | case CMD_IOCB_RET_XRI64_CX: |
dea3101e JB |
808 | type = LPFC_UNSOL_IOCB; |
809 | break; | |
3163f725 JS |
810 | case CMD_IOCB_XMIT_MSEQ64_CR: |
811 | case CMD_IOCB_XMIT_MSEQ64_CX: | |
812 | case CMD_IOCB_RCV_SEQ_LIST64_CX: | |
813 | case CMD_IOCB_RCV_ELS_LIST64_CX: | |
814 | case CMD_IOCB_CLOSE_EXTENDED_CN: | |
815 | case CMD_IOCB_ABORT_EXTENDED_CN: | |
816 | case CMD_IOCB_RET_HBQE64_CN: | |
817 | case CMD_IOCB_FCP_IBIDIR64_CR: | |
818 | case CMD_IOCB_FCP_IBIDIR64_CX: | |
819 | case CMD_IOCB_FCP_ITASKMGT64_CX: | |
820 | case CMD_IOCB_LOGENTRY_CN: | |
821 | case CMD_IOCB_LOGENTRY_ASYNC_CN: | |
822 | printk("%s - Unhandled SLI-3 Command x%x\n", | |
cadbd4a5 | 823 | __func__, iocb_cmnd); |
3163f725 JS |
824 | type = LPFC_UNKNOWN_IOCB; |
825 | break; | |
dea3101e JB |
826 | default: |
827 | type = LPFC_UNKNOWN_IOCB; | |
828 | break; | |
829 | } | |
830 | ||
831 | return type; | |
832 | } | |
833 | ||
e59058c4 | 834 | /** |
3621a710 | 835 | * lpfc_sli_ring_map - Issue config_ring mbox for all rings |
e59058c4 JS |
836 | * @phba: Pointer to HBA context object. |
837 | * | |
838 | * This function is called from SLI initialization code | |
839 | * to configure every ring of the HBA's SLI interface. The | |
840 | * caller is not required to hold any lock. This function issues | |
841 | * a config_ring mailbox command for each ring. | |
842 | * This function returns zero if successful else returns a negative | |
843 | * error code. | |
844 | **/ | |
dea3101e | 845 | static int |
ed957684 | 846 | lpfc_sli_ring_map(struct lpfc_hba *phba) |
dea3101e JB |
847 | { |
848 | struct lpfc_sli *psli = &phba->sli; | |
ed957684 JS |
849 | LPFC_MBOXQ_t *pmb; |
850 | MAILBOX_t *pmbox; | |
851 | int i, rc, ret = 0; | |
dea3101e | 852 | |
ed957684 JS |
853 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
854 | if (!pmb) | |
855 | return -ENOMEM; | |
04c68496 | 856 | pmbox = &pmb->u.mb; |
ed957684 | 857 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 858 | for (i = 0; i < psli->num_rings; i++) { |
dea3101e JB |
859 | lpfc_config_ring(phba, i, pmb); |
860 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
861 | if (rc != MBX_SUCCESS) { | |
92d7f7b0 | 862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 863 | "0446 Adapter failed to init (%d), " |
dea3101e JB |
864 | "mbxCmd x%x CFG_RING, mbxStatus x%x, " |
865 | "ring %d\n", | |
e8b62011 JS |
866 | rc, pmbox->mbxCommand, |
867 | pmbox->mbxStatus, i); | |
2e0fef85 | 868 | phba->link_state = LPFC_HBA_ERROR; |
ed957684 JS |
869 | ret = -ENXIO; |
870 | break; | |
dea3101e JB |
871 | } |
872 | } | |
ed957684 JS |
873 | mempool_free(pmb, phba->mbox_mem_pool); |
874 | return ret; | |
dea3101e JB |
875 | } |
876 | ||
e59058c4 | 877 | /** |
3621a710 | 878 | * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq |
e59058c4 JS |
879 | * @phba: Pointer to HBA context object. |
880 | * @pring: Pointer to driver SLI ring object. | |
881 | * @piocb: Pointer to the driver iocb object. | |
882 | * | |
883 | * This function is called with hbalock held. The function adds the | |
884 | * new iocb to txcmplq of the given ring. This function always returns | |
885 | * 0. If this function is called for ELS ring, this function checks if | |
886 | * there is a vport associated with the ELS command. This function also | |
887 | * starts els_tmofunc timer if this is an ELS command. | |
888 | **/ | |
dea3101e | 889 | static int |
2e0fef85 JS |
890 | lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
891 | struct lpfc_iocbq *piocb) | |
dea3101e | 892 | { |
dea3101e | 893 | list_add_tail(&piocb->list, &pring->txcmplq); |
2a9bf3d0 | 894 | piocb->iocb_flag |= LPFC_IO_ON_Q; |
dea3101e | 895 | pring->txcmplq_cnt++; |
2a9bf3d0 JS |
896 | if (pring->txcmplq_cnt > pring->txcmplq_max) |
897 | pring->txcmplq_max = pring->txcmplq_cnt; | |
898 | ||
92d7f7b0 JS |
899 | if ((unlikely(pring->ringno == LPFC_ELS_RING)) && |
900 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
901 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
902 | if (!piocb->vport) | |
903 | BUG(); | |
904 | else | |
905 | mod_timer(&piocb->vport->els_tmofunc, | |
906 | jiffies + HZ * (phba->fc_ratov << 1)); | |
907 | } | |
908 | ||
dea3101e | 909 | |
2e0fef85 | 910 | return 0; |
dea3101e JB |
911 | } |
912 | ||
e59058c4 | 913 | /** |
3621a710 | 914 | * lpfc_sli_ringtx_get - Get first element of the txq |
e59058c4 JS |
915 | * @phba: Pointer to HBA context object. |
916 | * @pring: Pointer to driver SLI ring object. | |
917 | * | |
918 | * This function is called with hbalock held to get next | |
919 | * iocb in txq of the given ring. If there is any iocb in | |
920 | * the txq, the function returns first iocb in the list after | |
921 | * removing the iocb from the list, else it returns NULL. | |
922 | **/ | |
2a9bf3d0 | 923 | struct lpfc_iocbq * |
2e0fef85 | 924 | lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e | 925 | { |
dea3101e JB |
926 | struct lpfc_iocbq *cmd_iocb; |
927 | ||
858c9f6c JS |
928 | list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list); |
929 | if (cmd_iocb != NULL) | |
dea3101e | 930 | pring->txq_cnt--; |
2e0fef85 | 931 | return cmd_iocb; |
dea3101e JB |
932 | } |
933 | ||
e59058c4 | 934 | /** |
3621a710 | 935 | * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring |
e59058c4 JS |
936 | * @phba: Pointer to HBA context object. |
937 | * @pring: Pointer to driver SLI ring object. | |
938 | * | |
939 | * This function is called with hbalock held and the caller must post the | |
940 | * iocb without releasing the lock. If the caller releases the lock, | |
941 | * iocb slot returned by the function is not guaranteed to be available. | |
942 | * The function returns pointer to the next available iocb slot if there | |
943 | * is available slot in the ring, else it returns NULL. | |
944 | * If the get index of the ring is ahead of the put index, the function | |
945 | * will post an error attention event to the worker thread to take the | |
946 | * HBA to offline state. | |
947 | **/ | |
dea3101e JB |
948 | static IOCB_t * |
949 | lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
950 | { | |
34b02dcd | 951 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 952 | uint32_t max_cmd_idx = pring->numCiocb; |
dea3101e JB |
953 | if ((pring->next_cmdidx == pring->cmdidx) && |
954 | (++pring->next_cmdidx >= max_cmd_idx)) | |
955 | pring->next_cmdidx = 0; | |
956 | ||
957 | if (unlikely(pring->local_getidx == pring->next_cmdidx)) { | |
958 | ||
959 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
960 | ||
961 | if (unlikely(pring->local_getidx >= max_cmd_idx)) { | |
962 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 963 | "0315 Ring %d issue: portCmdGet %d " |
025dfdaf | 964 | "is bigger than cmd ring %d\n", |
e8b62011 | 965 | pring->ringno, |
dea3101e JB |
966 | pring->local_getidx, max_cmd_idx); |
967 | ||
2e0fef85 | 968 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
969 | /* |
970 | * All error attention handlers are posted to | |
971 | * worker thread | |
972 | */ | |
973 | phba->work_ha |= HA_ERATT; | |
974 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 975 | |
5e9d9b82 | 976 | lpfc_worker_wake_up(phba); |
dea3101e JB |
977 | |
978 | return NULL; | |
979 | } | |
980 | ||
981 | if (pring->local_getidx == pring->next_cmdidx) | |
982 | return NULL; | |
983 | } | |
984 | ||
ed957684 | 985 | return lpfc_cmd_iocb(phba, pring); |
dea3101e JB |
986 | } |
987 | ||
e59058c4 | 988 | /** |
3621a710 | 989 | * lpfc_sli_next_iotag - Get an iotag for the iocb |
e59058c4 JS |
990 | * @phba: Pointer to HBA context object. |
991 | * @iocbq: Pointer to driver iocb object. | |
992 | * | |
993 | * This function gets an iotag for the iocb. If there is no unused iotag and | |
994 | * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup | |
995 | * array and assigns a new iotag. | |
996 | * The function returns the allocated iotag if successful, else returns zero. | |
997 | * Zero is not a valid iotag. | |
998 | * The caller is not required to hold any lock. | |
999 | **/ | |
604a3e30 | 1000 | uint16_t |
2e0fef85 | 1001 | lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
dea3101e | 1002 | { |
2e0fef85 JS |
1003 | struct lpfc_iocbq **new_arr; |
1004 | struct lpfc_iocbq **old_arr; | |
604a3e30 JB |
1005 | size_t new_len; |
1006 | struct lpfc_sli *psli = &phba->sli; | |
1007 | uint16_t iotag; | |
dea3101e | 1008 | |
2e0fef85 | 1009 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1010 | iotag = psli->last_iotag; |
1011 | if(++iotag < psli->iocbq_lookup_len) { | |
1012 | psli->last_iotag = iotag; | |
1013 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1014 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1015 | iocbq->iotag = iotag; |
1016 | return iotag; | |
2e0fef85 | 1017 | } else if (psli->iocbq_lookup_len < (0xffff |
604a3e30 JB |
1018 | - LPFC_IOCBQ_LOOKUP_INCREMENT)) { |
1019 | new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; | |
2e0fef85 JS |
1020 | spin_unlock_irq(&phba->hbalock); |
1021 | new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *), | |
604a3e30 JB |
1022 | GFP_KERNEL); |
1023 | if (new_arr) { | |
2e0fef85 | 1024 | spin_lock_irq(&phba->hbalock); |
604a3e30 JB |
1025 | old_arr = psli->iocbq_lookup; |
1026 | if (new_len <= psli->iocbq_lookup_len) { | |
1027 | /* highly unprobable case */ | |
1028 | kfree(new_arr); | |
1029 | iotag = psli->last_iotag; | |
1030 | if(++iotag < psli->iocbq_lookup_len) { | |
1031 | psli->last_iotag = iotag; | |
1032 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1033 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1034 | iocbq->iotag = iotag; |
1035 | return iotag; | |
1036 | } | |
2e0fef85 | 1037 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1038 | return 0; |
1039 | } | |
1040 | if (psli->iocbq_lookup) | |
1041 | memcpy(new_arr, old_arr, | |
1042 | ((psli->last_iotag + 1) * | |
311464ec | 1043 | sizeof (struct lpfc_iocbq *))); |
604a3e30 JB |
1044 | psli->iocbq_lookup = new_arr; |
1045 | psli->iocbq_lookup_len = new_len; | |
1046 | psli->last_iotag = iotag; | |
1047 | psli->iocbq_lookup[iotag] = iocbq; | |
2e0fef85 | 1048 | spin_unlock_irq(&phba->hbalock); |
604a3e30 JB |
1049 | iocbq->iotag = iotag; |
1050 | kfree(old_arr); | |
1051 | return iotag; | |
1052 | } | |
8f6d98d2 | 1053 | } else |
2e0fef85 | 1054 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1055 | |
604a3e30 | 1056 | lpfc_printf_log(phba, KERN_ERR,LOG_SLI, |
e8b62011 JS |
1057 | "0318 Failed to allocate IOTAG.last IOTAG is %d\n", |
1058 | psli->last_iotag); | |
dea3101e | 1059 | |
604a3e30 | 1060 | return 0; |
dea3101e JB |
1061 | } |
1062 | ||
e59058c4 | 1063 | /** |
3621a710 | 1064 | * lpfc_sli_submit_iocb - Submit an iocb to the firmware |
e59058c4 JS |
1065 | * @phba: Pointer to HBA context object. |
1066 | * @pring: Pointer to driver SLI ring object. | |
1067 | * @iocb: Pointer to iocb slot in the ring. | |
1068 | * @nextiocb: Pointer to driver iocb object which need to be | |
1069 | * posted to firmware. | |
1070 | * | |
1071 | * This function is called with hbalock held to post a new iocb to | |
1072 | * the firmware. This function copies the new iocb to ring iocb slot and | |
1073 | * updates the ring pointers. It adds the new iocb to txcmplq if there is | |
1074 | * a completion call back for this iocb else the function will free the | |
1075 | * iocb object. | |
1076 | **/ | |
dea3101e JB |
1077 | static void |
1078 | lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1079 | IOCB_t *iocb, struct lpfc_iocbq *nextiocb) | |
1080 | { | |
1081 | /* | |
604a3e30 | 1082 | * Set up an iotag |
dea3101e | 1083 | */ |
604a3e30 | 1084 | nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0; |
dea3101e | 1085 | |
e2a0a9d6 | 1086 | |
a58cbd52 JS |
1087 | if (pring->ringno == LPFC_ELS_RING) { |
1088 | lpfc_debugfs_slow_ring_trc(phba, | |
1089 | "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
1090 | *(((uint32_t *) &nextiocb->iocb) + 4), | |
1091 | *(((uint32_t *) &nextiocb->iocb) + 6), | |
1092 | *(((uint32_t *) &nextiocb->iocb) + 7)); | |
1093 | } | |
1094 | ||
dea3101e JB |
1095 | /* |
1096 | * Issue iocb command to adapter | |
1097 | */ | |
92d7f7b0 | 1098 | lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size); |
dea3101e JB |
1099 | wmb(); |
1100 | pring->stats.iocb_cmd++; | |
1101 | ||
1102 | /* | |
1103 | * If there is no completion routine to call, we can release the | |
1104 | * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF, | |
1105 | * that have no rsp ring completion, iocb_cmpl MUST be NULL. | |
1106 | */ | |
1107 | if (nextiocb->iocb_cmpl) | |
1108 | lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); | |
604a3e30 | 1109 | else |
2e0fef85 | 1110 | __lpfc_sli_release_iocbq(phba, nextiocb); |
dea3101e JB |
1111 | |
1112 | /* | |
1113 | * Let the HBA know what IOCB slot will be the next one the | |
1114 | * driver will put a command into. | |
1115 | */ | |
1116 | pring->cmdidx = pring->next_cmdidx; | |
ed957684 | 1117 | writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); |
dea3101e JB |
1118 | } |
1119 | ||
e59058c4 | 1120 | /** |
3621a710 | 1121 | * lpfc_sli_update_full_ring - Update the chip attention register |
e59058c4 JS |
1122 | * @phba: Pointer to HBA context object. |
1123 | * @pring: Pointer to driver SLI ring object. | |
1124 | * | |
1125 | * The caller is not required to hold any lock for calling this function. | |
1126 | * This function updates the chip attention bits for the ring to inform firmware | |
1127 | * that there are pending work to be done for this ring and requests an | |
1128 | * interrupt when there is space available in the ring. This function is | |
1129 | * called when the driver is unable to post more iocbs to the ring due | |
1130 | * to unavailability of space in the ring. | |
1131 | **/ | |
dea3101e | 1132 | static void |
2e0fef85 | 1133 | lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1134 | { |
1135 | int ringno = pring->ringno; | |
1136 | ||
1137 | pring->flag |= LPFC_CALL_RING_AVAILABLE; | |
1138 | ||
1139 | wmb(); | |
1140 | ||
1141 | /* | |
1142 | * Set ring 'ringno' to SET R0CE_REQ in Chip Att register. | |
1143 | * The HBA will tell us when an IOCB entry is available. | |
1144 | */ | |
1145 | writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr); | |
1146 | readl(phba->CAregaddr); /* flush */ | |
1147 | ||
1148 | pring->stats.iocb_cmd_full++; | |
1149 | } | |
1150 | ||
e59058c4 | 1151 | /** |
3621a710 | 1152 | * lpfc_sli_update_ring - Update chip attention register |
e59058c4 JS |
1153 | * @phba: Pointer to HBA context object. |
1154 | * @pring: Pointer to driver SLI ring object. | |
1155 | * | |
1156 | * This function updates the chip attention register bit for the | |
1157 | * given ring to inform HBA that there is more work to be done | |
1158 | * in this ring. The caller is not required to hold any lock. | |
1159 | **/ | |
dea3101e | 1160 | static void |
2e0fef85 | 1161 | lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1162 | { |
1163 | int ringno = pring->ringno; | |
1164 | ||
1165 | /* | |
1166 | * Tell the HBA that there is work to do in this ring. | |
1167 | */ | |
34b02dcd JS |
1168 | if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) { |
1169 | wmb(); | |
1170 | writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); | |
1171 | readl(phba->CAregaddr); /* flush */ | |
1172 | } | |
dea3101e JB |
1173 | } |
1174 | ||
e59058c4 | 1175 | /** |
3621a710 | 1176 | * lpfc_sli_resume_iocb - Process iocbs in the txq |
e59058c4 JS |
1177 | * @phba: Pointer to HBA context object. |
1178 | * @pring: Pointer to driver SLI ring object. | |
1179 | * | |
1180 | * This function is called with hbalock held to post pending iocbs | |
1181 | * in the txq to the firmware. This function is called when driver | |
1182 | * detects space available in the ring. | |
1183 | **/ | |
dea3101e | 1184 | static void |
2e0fef85 | 1185 | lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
dea3101e JB |
1186 | { |
1187 | IOCB_t *iocb; | |
1188 | struct lpfc_iocbq *nextiocb; | |
1189 | ||
1190 | /* | |
1191 | * Check to see if: | |
1192 | * (a) there is anything on the txq to send | |
1193 | * (b) link is up | |
1194 | * (c) link attention events can be processed (fcp ring only) | |
1195 | * (d) IOCB processing is not blocked by the outstanding mbox command. | |
1196 | */ | |
1197 | if (pring->txq_cnt && | |
2e0fef85 | 1198 | lpfc_is_link_up(phba) && |
dea3101e | 1199 | (pring->ringno != phba->sli.fcp_ring || |
0b727fea | 1200 | phba->sli.sli_flag & LPFC_PROCESS_LA)) { |
dea3101e JB |
1201 | |
1202 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && | |
1203 | (nextiocb = lpfc_sli_ringtx_get(phba, pring))) | |
1204 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
1205 | ||
1206 | if (iocb) | |
1207 | lpfc_sli_update_ring(phba, pring); | |
1208 | else | |
1209 | lpfc_sli_update_full_ring(phba, pring); | |
1210 | } | |
1211 | ||
1212 | return; | |
1213 | } | |
1214 | ||
e59058c4 | 1215 | /** |
3621a710 | 1216 | * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ |
e59058c4 JS |
1217 | * @phba: Pointer to HBA context object. |
1218 | * @hbqno: HBQ number. | |
1219 | * | |
1220 | * This function is called with hbalock held to get the next | |
1221 | * available slot for the given HBQ. If there is free slot | |
1222 | * available for the HBQ it will return pointer to the next available | |
1223 | * HBQ entry else it will return NULL. | |
1224 | **/ | |
a6ababd2 | 1225 | static struct lpfc_hbq_entry * |
ed957684 JS |
1226 | lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) |
1227 | { | |
1228 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1229 | ||
1230 | if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx && | |
1231 | ++hbqp->next_hbqPutIdx >= hbqp->entry_count) | |
1232 | hbqp->next_hbqPutIdx = 0; | |
1233 | ||
1234 | if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) { | |
92d7f7b0 | 1235 | uint32_t raw_index = phba->hbq_get[hbqno]; |
ed957684 JS |
1236 | uint32_t getidx = le32_to_cpu(raw_index); |
1237 | ||
1238 | hbqp->local_hbqGetIdx = getidx; | |
1239 | ||
1240 | if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) { | |
1241 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 1242 | LOG_SLI | LOG_VPORT, |
e8b62011 | 1243 | "1802 HBQ %d: local_hbqGetIdx " |
ed957684 | 1244 | "%u is > than hbqp->entry_count %u\n", |
e8b62011 | 1245 | hbqno, hbqp->local_hbqGetIdx, |
ed957684 JS |
1246 | hbqp->entry_count); |
1247 | ||
1248 | phba->link_state = LPFC_HBA_ERROR; | |
1249 | return NULL; | |
1250 | } | |
1251 | ||
1252 | if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx) | |
1253 | return NULL; | |
1254 | } | |
1255 | ||
51ef4c26 JS |
1256 | return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt + |
1257 | hbqp->hbqPutIdx; | |
ed957684 JS |
1258 | } |
1259 | ||
e59058c4 | 1260 | /** |
3621a710 | 1261 | * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers |
e59058c4 JS |
1262 | * @phba: Pointer to HBA context object. |
1263 | * | |
1264 | * This function is called with no lock held to free all the | |
1265 | * hbq buffers while uninitializing the SLI interface. It also | |
1266 | * frees the HBQ buffers returned by the firmware but not yet | |
1267 | * processed by the upper layers. | |
1268 | **/ | |
ed957684 JS |
1269 | void |
1270 | lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |
1271 | { | |
92d7f7b0 JS |
1272 | struct lpfc_dmabuf *dmabuf, *next_dmabuf; |
1273 | struct hbq_dmabuf *hbq_buf; | |
3163f725 | 1274 | unsigned long flags; |
51ef4c26 | 1275 | int i, hbq_count; |
3163f725 | 1276 | uint32_t hbqno; |
ed957684 | 1277 | |
51ef4c26 | 1278 | hbq_count = lpfc_sli_hbq_count(); |
ed957684 | 1279 | /* Return all memory used by all HBQs */ |
3163f725 | 1280 | spin_lock_irqsave(&phba->hbalock, flags); |
51ef4c26 JS |
1281 | for (i = 0; i < hbq_count; ++i) { |
1282 | list_for_each_entry_safe(dmabuf, next_dmabuf, | |
1283 | &phba->hbqs[i].hbq_buffer_list, list) { | |
1284 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | |
1285 | list_del(&hbq_buf->dbuf.list); | |
1286 | (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf); | |
1287 | } | |
a8adb832 | 1288 | phba->hbqs[i].buffer_count = 0; |
ed957684 | 1289 | } |
3163f725 | 1290 | /* Return all HBQ buffer that are in-fly */ |
3772a991 JS |
1291 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
1292 | list) { | |
3163f725 JS |
1293 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
1294 | list_del(&hbq_buf->dbuf.list); | |
1295 | if (hbq_buf->tag == -1) { | |
1296 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1297 | (phba, hbq_buf); | |
1298 | } else { | |
1299 | hbqno = hbq_buf->tag >> 16; | |
1300 | if (hbqno >= LPFC_MAX_HBQS) | |
1301 | (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) | |
1302 | (phba, hbq_buf); | |
1303 | else | |
1304 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, | |
1305 | hbq_buf); | |
1306 | } | |
1307 | } | |
1308 | ||
1309 | /* Mark the HBQs not in use */ | |
1310 | phba->hbq_in_use = 0; | |
1311 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
ed957684 JS |
1312 | } |
1313 | ||
e59058c4 | 1314 | /** |
3621a710 | 1315 | * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware |
e59058c4 JS |
1316 | * @phba: Pointer to HBA context object. |
1317 | * @hbqno: HBQ number. | |
1318 | * @hbq_buf: Pointer to HBQ buffer. | |
1319 | * | |
1320 | * This function is called with the hbalock held to post a | |
1321 | * hbq buffer to the firmware. If the function finds an empty | |
1322 | * slot in the HBQ, it will post the buffer. The function will return | |
1323 | * pointer to the hbq entry if it successfully post the buffer | |
1324 | * else it will return NULL. | |
1325 | **/ | |
3772a991 | 1326 | static int |
ed957684 | 1327 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
92d7f7b0 | 1328 | struct hbq_dmabuf *hbq_buf) |
3772a991 JS |
1329 | { |
1330 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | |
1331 | } | |
1332 | ||
1333 | /** | |
1334 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | |
1335 | * @phba: Pointer to HBA context object. | |
1336 | * @hbqno: HBQ number. | |
1337 | * @hbq_buf: Pointer to HBQ buffer. | |
1338 | * | |
1339 | * This function is called with the hbalock held to post a hbq buffer to the | |
1340 | * firmware. If the function finds an empty slot in the HBQ, it will post the | |
1341 | * buffer and place it on the hbq_buffer_list. The function will return zero if | |
1342 | * it successfully post the buffer else it will return an error. | |
1343 | **/ | |
1344 | static int | |
1345 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | |
1346 | struct hbq_dmabuf *hbq_buf) | |
ed957684 JS |
1347 | { |
1348 | struct lpfc_hbq_entry *hbqe; | |
92d7f7b0 | 1349 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
ed957684 JS |
1350 | |
1351 | /* Get next HBQ entry slot to use */ | |
1352 | hbqe = lpfc_sli_next_hbq_slot(phba, hbqno); | |
1353 | if (hbqe) { | |
1354 | struct hbq_s *hbqp = &phba->hbqs[hbqno]; | |
1355 | ||
92d7f7b0 JS |
1356 | hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr)); |
1357 | hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr)); | |
51ef4c26 | 1358 | hbqe->bde.tus.f.bdeSize = hbq_buf->size; |
ed957684 | 1359 | hbqe->bde.tus.f.bdeFlags = 0; |
92d7f7b0 JS |
1360 | hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w); |
1361 | hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag); | |
1362 | /* Sync SLIM */ | |
ed957684 JS |
1363 | hbqp->hbqPutIdx = hbqp->next_hbqPutIdx; |
1364 | writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno); | |
92d7f7b0 | 1365 | /* flush */ |
ed957684 | 1366 | readl(phba->hbq_put + hbqno); |
51ef4c26 | 1367 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
3772a991 JS |
1368 | return 0; |
1369 | } else | |
1370 | return -ENOMEM; | |
ed957684 JS |
1371 | } |
1372 | ||
4f774513 JS |
1373 | /** |
1374 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | |
1375 | * @phba: Pointer to HBA context object. | |
1376 | * @hbqno: HBQ number. | |
1377 | * @hbq_buf: Pointer to HBQ buffer. | |
1378 | * | |
1379 | * This function is called with the hbalock held to post an RQE to the SLI4 | |
1380 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | |
1381 | * the hbq_buffer_list and return zero, otherwise it will return an error. | |
1382 | **/ | |
1383 | static int | |
1384 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | |
1385 | struct hbq_dmabuf *hbq_buf) | |
1386 | { | |
1387 | int rc; | |
1388 | struct lpfc_rqe hrqe; | |
1389 | struct lpfc_rqe drqe; | |
1390 | ||
1391 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | |
1392 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | |
1393 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | |
1394 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | |
1395 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
1396 | &hrqe, &drqe); | |
1397 | if (rc < 0) | |
1398 | return rc; | |
1399 | hbq_buf->tag = rc; | |
1400 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | |
1401 | return 0; | |
1402 | } | |
1403 | ||
e59058c4 | 1404 | /* HBQ for ELS and CT traffic. */ |
92d7f7b0 JS |
1405 | static struct lpfc_hbq_init lpfc_els_hbq = { |
1406 | .rn = 1, | |
def9c7a9 | 1407 | .entry_count = 256, |
92d7f7b0 JS |
1408 | .mask_count = 0, |
1409 | .profile = 0, | |
51ef4c26 | 1410 | .ring_mask = (1 << LPFC_ELS_RING), |
92d7f7b0 | 1411 | .buffer_count = 0, |
a257bf90 JS |
1412 | .init_count = 40, |
1413 | .add_count = 40, | |
92d7f7b0 | 1414 | }; |
ed957684 | 1415 | |
e59058c4 | 1416 | /* HBQ for the extra ring if needed */ |
51ef4c26 JS |
1417 | static struct lpfc_hbq_init lpfc_extra_hbq = { |
1418 | .rn = 1, | |
1419 | .entry_count = 200, | |
1420 | .mask_count = 0, | |
1421 | .profile = 0, | |
1422 | .ring_mask = (1 << LPFC_EXTRA_RING), | |
1423 | .buffer_count = 0, | |
1424 | .init_count = 0, | |
1425 | .add_count = 5, | |
1426 | }; | |
1427 | ||
e59058c4 | 1428 | /* Array of HBQs */ |
78b2d852 | 1429 | struct lpfc_hbq_init *lpfc_hbq_defs[] = { |
92d7f7b0 | 1430 | &lpfc_els_hbq, |
51ef4c26 | 1431 | &lpfc_extra_hbq, |
92d7f7b0 | 1432 | }; |
ed957684 | 1433 | |
e59058c4 | 1434 | /** |
3621a710 | 1435 | * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ |
e59058c4 JS |
1436 | * @phba: Pointer to HBA context object. |
1437 | * @hbqno: HBQ number. | |
1438 | * @count: Number of HBQ buffers to be posted. | |
1439 | * | |
d7c255b2 JS |
1440 | * This function is called with no lock held to post more hbq buffers to the |
1441 | * given HBQ. The function returns the number of HBQ buffers successfully | |
1442 | * posted. | |
e59058c4 | 1443 | **/ |
311464ec | 1444 | static int |
92d7f7b0 | 1445 | lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) |
ed957684 | 1446 | { |
d7c255b2 | 1447 | uint32_t i, posted = 0; |
3163f725 | 1448 | unsigned long flags; |
92d7f7b0 | 1449 | struct hbq_dmabuf *hbq_buffer; |
d7c255b2 | 1450 | LIST_HEAD(hbq_buf_list); |
eafe1df9 | 1451 | if (!phba->hbqs[hbqno].hbq_alloc_buffer) |
51ef4c26 | 1452 | return 0; |
51ef4c26 | 1453 | |
d7c255b2 JS |
1454 | if ((phba->hbqs[hbqno].buffer_count + count) > |
1455 | lpfc_hbq_defs[hbqno]->entry_count) | |
1456 | count = lpfc_hbq_defs[hbqno]->entry_count - | |
1457 | phba->hbqs[hbqno].buffer_count; | |
1458 | if (!count) | |
1459 | return 0; | |
1460 | /* Allocate HBQ entries */ | |
1461 | for (i = 0; i < count; i++) { | |
1462 | hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); | |
1463 | if (!hbq_buffer) | |
1464 | break; | |
1465 | list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list); | |
1466 | } | |
3163f725 JS |
1467 | /* Check whether HBQ is still in use */ |
1468 | spin_lock_irqsave(&phba->hbalock, flags); | |
eafe1df9 | 1469 | if (!phba->hbq_in_use) |
d7c255b2 JS |
1470 | goto err; |
1471 | while (!list_empty(&hbq_buf_list)) { | |
1472 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1473 | dbuf.list); | |
1474 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | |
1475 | (hbqno << 16)); | |
3772a991 | 1476 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
a8adb832 | 1477 | phba->hbqs[hbqno].buffer_count++; |
d7c255b2 JS |
1478 | posted++; |
1479 | } else | |
51ef4c26 | 1480 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 | 1481 | } |
3163f725 | 1482 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1483 | return posted; |
1484 | err: | |
eafe1df9 | 1485 | spin_unlock_irqrestore(&phba->hbalock, flags); |
d7c255b2 JS |
1486 | while (!list_empty(&hbq_buf_list)) { |
1487 | list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf, | |
1488 | dbuf.list); | |
1489 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | |
1490 | } | |
1491 | return 0; | |
ed957684 JS |
1492 | } |
1493 | ||
e59058c4 | 1494 | /** |
3621a710 | 1495 | * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware |
e59058c4 JS |
1496 | * @phba: Pointer to HBA context object. |
1497 | * @qno: HBQ number. | |
1498 | * | |
1499 | * This function posts more buffers to the HBQ. This function | |
d7c255b2 JS |
1500 | * is called with no lock held. The function returns the number of HBQ entries |
1501 | * successfully allocated. | |
e59058c4 | 1502 | **/ |
92d7f7b0 JS |
1503 | int |
1504 | lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) | |
ed957684 | 1505 | { |
def9c7a9 JS |
1506 | if (phba->sli_rev == LPFC_SLI_REV4) |
1507 | return 0; | |
1508 | else | |
1509 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1510 | lpfc_hbq_defs[qno]->add_count); | |
92d7f7b0 | 1511 | } |
ed957684 | 1512 | |
e59058c4 | 1513 | /** |
3621a710 | 1514 | * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ |
e59058c4 JS |
1515 | * @phba: Pointer to HBA context object. |
1516 | * @qno: HBQ queue number. | |
1517 | * | |
1518 | * This function is called from SLI initialization code path with | |
1519 | * no lock held to post initial HBQ buffers to firmware. The | |
d7c255b2 | 1520 | * function returns the number of HBQ entries successfully allocated. |
e59058c4 | 1521 | **/ |
a6ababd2 | 1522 | static int |
92d7f7b0 JS |
1523 | lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) |
1524 | { | |
def9c7a9 JS |
1525 | if (phba->sli_rev == LPFC_SLI_REV4) |
1526 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1527 | lpfc_hbq_defs[qno]->entry_count); | |
1528 | else | |
1529 | return lpfc_sli_hbqbuf_fill_hbqs(phba, qno, | |
1530 | lpfc_hbq_defs[qno]->init_count); | |
ed957684 JS |
1531 | } |
1532 | ||
3772a991 JS |
1533 | /** |
1534 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | |
1535 | * @phba: Pointer to HBA context object. | |
1536 | * @hbqno: HBQ number. | |
1537 | * | |
1538 | * This function removes the first hbq buffer on an hbq list and returns a | |
1539 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | |
1540 | **/ | |
1541 | static struct hbq_dmabuf * | |
1542 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | |
1543 | { | |
1544 | struct lpfc_dmabuf *d_buf; | |
1545 | ||
1546 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | |
1547 | if (!d_buf) | |
1548 | return NULL; | |
1549 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | |
1550 | } | |
1551 | ||
e59058c4 | 1552 | /** |
3621a710 | 1553 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
e59058c4 JS |
1554 | * @phba: Pointer to HBA context object. |
1555 | * @tag: Tag of the hbq buffer. | |
1556 | * | |
1557 | * This function is called with hbalock held. This function searches | |
1558 | * for the hbq buffer associated with the given tag in the hbq buffer | |
1559 | * list. If it finds the hbq buffer, it returns the hbq_buffer other wise | |
1560 | * it returns NULL. | |
1561 | **/ | |
a6ababd2 | 1562 | static struct hbq_dmabuf * |
92d7f7b0 | 1563 | lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) |
ed957684 | 1564 | { |
92d7f7b0 JS |
1565 | struct lpfc_dmabuf *d_buf; |
1566 | struct hbq_dmabuf *hbq_buf; | |
51ef4c26 JS |
1567 | uint32_t hbqno; |
1568 | ||
1569 | hbqno = tag >> 16; | |
a0a74e45 | 1570 | if (hbqno >= LPFC_MAX_HBQS) |
51ef4c26 | 1571 | return NULL; |
ed957684 | 1572 | |
3772a991 | 1573 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 1574 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
92d7f7b0 | 1575 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
51ef4c26 | 1576 | if (hbq_buf->tag == tag) { |
3772a991 | 1577 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1578 | return hbq_buf; |
ed957684 JS |
1579 | } |
1580 | } | |
3772a991 | 1581 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 1582 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
e8b62011 | 1583 | "1803 Bad hbq tag. Data: x%x x%x\n", |
a8adb832 | 1584 | tag, phba->hbqs[tag >> 16].buffer_count); |
92d7f7b0 | 1585 | return NULL; |
ed957684 JS |
1586 | } |
1587 | ||
e59058c4 | 1588 | /** |
3621a710 | 1589 | * lpfc_sli_free_hbq - Give back the hbq buffer to firmware |
e59058c4 JS |
1590 | * @phba: Pointer to HBA context object. |
1591 | * @hbq_buffer: Pointer to HBQ buffer. | |
1592 | * | |
1593 | * This function is called with hbalock. This function gives back | |
1594 | * the hbq buffer to firmware. If the HBQ does not have space to | |
1595 | * post the buffer, it will free the buffer. | |
1596 | **/ | |
ed957684 | 1597 | void |
51ef4c26 | 1598 | lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) |
ed957684 JS |
1599 | { |
1600 | uint32_t hbqno; | |
1601 | ||
51ef4c26 JS |
1602 | if (hbq_buffer) { |
1603 | hbqno = hbq_buffer->tag >> 16; | |
3772a991 | 1604 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
51ef4c26 | 1605 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
ed957684 JS |
1606 | } |
1607 | } | |
1608 | ||
e59058c4 | 1609 | /** |
3621a710 | 1610 | * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox |
e59058c4 JS |
1611 | * @mbxCommand: mailbox command code. |
1612 | * | |
1613 | * This function is called by the mailbox event handler function to verify | |
1614 | * that the completed mailbox command is a legitimate mailbox command. If the | |
1615 | * completed mailbox is not known to the function, it will return MBX_SHUTDOWN | |
1616 | * and the mailbox event handler will take the HBA offline. | |
1617 | **/ | |
dea3101e JB |
1618 | static int |
1619 | lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |
1620 | { | |
1621 | uint8_t ret; | |
1622 | ||
1623 | switch (mbxCommand) { | |
1624 | case MBX_LOAD_SM: | |
1625 | case MBX_READ_NV: | |
1626 | case MBX_WRITE_NV: | |
a8adb832 | 1627 | case MBX_WRITE_VPARMS: |
dea3101e JB |
1628 | case MBX_RUN_BIU_DIAG: |
1629 | case MBX_INIT_LINK: | |
1630 | case MBX_DOWN_LINK: | |
1631 | case MBX_CONFIG_LINK: | |
1632 | case MBX_CONFIG_RING: | |
1633 | case MBX_RESET_RING: | |
1634 | case MBX_READ_CONFIG: | |
1635 | case MBX_READ_RCONFIG: | |
1636 | case MBX_READ_SPARM: | |
1637 | case MBX_READ_STATUS: | |
1638 | case MBX_READ_RPI: | |
1639 | case MBX_READ_XRI: | |
1640 | case MBX_READ_REV: | |
1641 | case MBX_READ_LNK_STAT: | |
1642 | case MBX_REG_LOGIN: | |
1643 | case MBX_UNREG_LOGIN: | |
1644 | case MBX_READ_LA: | |
1645 | case MBX_CLEAR_LA: | |
1646 | case MBX_DUMP_MEMORY: | |
1647 | case MBX_DUMP_CONTEXT: | |
1648 | case MBX_RUN_DIAGS: | |
1649 | case MBX_RESTART: | |
1650 | case MBX_UPDATE_CFG: | |
1651 | case MBX_DOWN_LOAD: | |
1652 | case MBX_DEL_LD_ENTRY: | |
1653 | case MBX_RUN_PROGRAM: | |
1654 | case MBX_SET_MASK: | |
09372820 | 1655 | case MBX_SET_VARIABLE: |
dea3101e | 1656 | case MBX_UNREG_D_ID: |
41415862 | 1657 | case MBX_KILL_BOARD: |
dea3101e | 1658 | case MBX_CONFIG_FARP: |
41415862 | 1659 | case MBX_BEACON: |
dea3101e JB |
1660 | case MBX_LOAD_AREA: |
1661 | case MBX_RUN_BIU_DIAG64: | |
1662 | case MBX_CONFIG_PORT: | |
1663 | case MBX_READ_SPARM64: | |
1664 | case MBX_READ_RPI64: | |
1665 | case MBX_REG_LOGIN64: | |
1666 | case MBX_READ_LA64: | |
09372820 | 1667 | case MBX_WRITE_WWN: |
dea3101e JB |
1668 | case MBX_SET_DEBUG: |
1669 | case MBX_LOAD_EXP_ROM: | |
57127f15 | 1670 | case MBX_ASYNCEVT_ENABLE: |
92d7f7b0 JS |
1671 | case MBX_REG_VPI: |
1672 | case MBX_UNREG_VPI: | |
858c9f6c | 1673 | case MBX_HEARTBEAT: |
84774a4d JS |
1674 | case MBX_PORT_CAPABILITIES: |
1675 | case MBX_PORT_IOV_CONTROL: | |
04c68496 JS |
1676 | case MBX_SLI4_CONFIG: |
1677 | case MBX_SLI4_REQ_FTRS: | |
1678 | case MBX_REG_FCFI: | |
1679 | case MBX_UNREG_FCFI: | |
1680 | case MBX_REG_VFI: | |
1681 | case MBX_UNREG_VFI: | |
1682 | case MBX_INIT_VPI: | |
1683 | case MBX_INIT_VFI: | |
1684 | case MBX_RESUME_RPI: | |
c7495937 JS |
1685 | case MBX_READ_EVENT_LOG_STATUS: |
1686 | case MBX_READ_EVENT_LOG: | |
dea3101e JB |
1687 | ret = mbxCommand; |
1688 | break; | |
1689 | default: | |
1690 | ret = MBX_SHUTDOWN; | |
1691 | break; | |
1692 | } | |
2e0fef85 | 1693 | return ret; |
dea3101e | 1694 | } |
e59058c4 JS |
1695 | |
1696 | /** | |
3621a710 | 1697 | * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler |
e59058c4 JS |
1698 | * @phba: Pointer to HBA context object. |
1699 | * @pmboxq: Pointer to mailbox command. | |
1700 | * | |
1701 | * This is completion handler function for mailbox commands issued from | |
1702 | * lpfc_sli_issue_mbox_wait function. This function is called by the | |
1703 | * mailbox event handler function with no lock held. This function | |
1704 | * will wake up thread waiting on the wait queue pointed by context1 | |
1705 | * of the mailbox. | |
1706 | **/ | |
04c68496 | 1707 | void |
2e0fef85 | 1708 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
dea3101e JB |
1709 | { |
1710 | wait_queue_head_t *pdone_q; | |
858c9f6c | 1711 | unsigned long drvr_flag; |
dea3101e JB |
1712 | |
1713 | /* | |
1714 | * If pdone_q is empty, the driver thread gave up waiting and | |
1715 | * continued running. | |
1716 | */ | |
7054a606 | 1717 | pmboxq->mbox_flag |= LPFC_MBX_WAKE; |
858c9f6c | 1718 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
dea3101e JB |
1719 | pdone_q = (wait_queue_head_t *) pmboxq->context1; |
1720 | if (pdone_q) | |
1721 | wake_up_interruptible(pdone_q); | |
858c9f6c | 1722 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
1723 | return; |
1724 | } | |
1725 | ||
e59058c4 JS |
1726 | |
1727 | /** | |
3621a710 | 1728 | * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler |
e59058c4 JS |
1729 | * @phba: Pointer to HBA context object. |
1730 | * @pmb: Pointer to mailbox object. | |
1731 | * | |
1732 | * This function is the default mailbox completion handler. It | |
1733 | * frees the memory resources associated with the completed mailbox | |
1734 | * command. If the completed command is a REG_LOGIN mailbox command, | |
1735 | * this function will issue a UREG_LOGIN to re-claim the RPI. | |
1736 | **/ | |
dea3101e | 1737 | void |
2e0fef85 | 1738 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
dea3101e JB |
1739 | { |
1740 | struct lpfc_dmabuf *mp; | |
04c68496 | 1741 | uint16_t rpi, vpi; |
7054a606 | 1742 | int rc; |
695a814e | 1743 | struct lpfc_vport *vport = pmb->vport; |
7054a606 | 1744 | |
dea3101e | 1745 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
7054a606 | 1746 | |
dea3101e JB |
1747 | if (mp) { |
1748 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
1749 | kfree(mp); | |
1750 | } | |
7054a606 | 1751 | |
04c68496 JS |
1752 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && |
1753 | (phba->sli_rev == LPFC_SLI_REV4)) | |
1754 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); | |
1755 | ||
7054a606 JS |
1756 | /* |
1757 | * If a REG_LOGIN succeeded after node is destroyed or node | |
1758 | * is in re-discovery driver need to cleanup the RPI. | |
1759 | */ | |
2e0fef85 | 1760 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
04c68496 JS |
1761 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
1762 | !pmb->u.mb.mbxStatus) { | |
1763 | rpi = pmb->u.mb.un.varWords[0]; | |
1764 | vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base; | |
1765 | lpfc_unreg_login(phba, vpi, rpi, pmb); | |
92d7f7b0 | 1766 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7054a606 JS |
1767 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
1768 | if (rc != MBX_NOT_FINISHED) | |
1769 | return; | |
1770 | } | |
1771 | ||
695a814e JS |
1772 | /* Unreg VPI, if the REG_VPI succeed after VLink failure */ |
1773 | if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) && | |
1774 | !(phba->pport->load_flag & FC_UNLOADING) && | |
1775 | !pmb->u.mb.mbxStatus) { | |
1776 | lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb); | |
1777 | pmb->vport = vport; | |
1778 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
1779 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
1780 | if (rc != MBX_NOT_FINISHED) | |
1781 | return; | |
1782 | } | |
1783 | ||
04c68496 JS |
1784 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
1785 | lpfc_sli4_mbox_cmd_free(phba, pmb); | |
1786 | else | |
1787 | mempool_free(pmb, phba->mbox_mem_pool); | |
dea3101e JB |
1788 | } |
1789 | ||
e59058c4 | 1790 | /** |
3621a710 | 1791 | * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware |
e59058c4 JS |
1792 | * @phba: Pointer to HBA context object. |
1793 | * | |
1794 | * This function is called with no lock held. This function processes all | |
1795 | * the completed mailbox commands and gives it to upper layers. The interrupt | |
1796 | * service routine processes mailbox completion interrupt and adds completed | |
1797 | * mailbox commands to the mboxq_cmpl queue and signals the worker thread. | |
1798 | * Worker thread call lpfc_sli_handle_mb_event, which will return the | |
1799 | * completed mailbox commands in mboxq_cmpl queue to the upper layers. This | |
1800 | * function returns the mailbox commands to the upper layer by calling the | |
1801 | * completion handler function of each mailbox. | |
1802 | **/ | |
dea3101e | 1803 | int |
2e0fef85 | 1804 | lpfc_sli_handle_mb_event(struct lpfc_hba *phba) |
dea3101e | 1805 | { |
92d7f7b0 | 1806 | MAILBOX_t *pmbox; |
dea3101e | 1807 | LPFC_MBOXQ_t *pmb; |
92d7f7b0 JS |
1808 | int rc; |
1809 | LIST_HEAD(cmplq); | |
dea3101e JB |
1810 | |
1811 | phba->sli.slistat.mbox_event++; | |
1812 | ||
92d7f7b0 JS |
1813 | /* Get all completed mailboxe buffers into the cmplq */ |
1814 | spin_lock_irq(&phba->hbalock); | |
1815 | list_splice_init(&phba->sli.mboxq_cmpl, &cmplq); | |
1816 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 1817 | |
92d7f7b0 JS |
1818 | /* Get a Mailbox buffer to setup mailbox commands for callback */ |
1819 | do { | |
1820 | list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list); | |
1821 | if (pmb == NULL) | |
1822 | break; | |
2e0fef85 | 1823 | |
04c68496 | 1824 | pmbox = &pmb->u.mb; |
dea3101e | 1825 | |
858c9f6c JS |
1826 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
1827 | if (pmb->vport) { | |
1828 | lpfc_debugfs_disc_trc(pmb->vport, | |
1829 | LPFC_DISC_TRC_MBOX_VPORT, | |
1830 | "MBOX cmpl vport: cmd:x%x mb:x%x x%x", | |
1831 | (uint32_t)pmbox->mbxCommand, | |
1832 | pmbox->un.varWords[0], | |
1833 | pmbox->un.varWords[1]); | |
1834 | } | |
1835 | else { | |
1836 | lpfc_debugfs_disc_trc(phba->pport, | |
1837 | LPFC_DISC_TRC_MBOX, | |
1838 | "MBOX cmpl: cmd:x%x mb:x%x x%x", | |
1839 | (uint32_t)pmbox->mbxCommand, | |
1840 | pmbox->un.varWords[0], | |
1841 | pmbox->un.varWords[1]); | |
1842 | } | |
1843 | } | |
1844 | ||
dea3101e JB |
1845 | /* |
1846 | * It is a fatal error if unknown mbox command completion. | |
1847 | */ | |
1848 | if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) == | |
1849 | MBX_SHUTDOWN) { | |
af901ca1 | 1850 | /* Unknown mailbox command compl */ |
92d7f7b0 | 1851 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
e8b62011 | 1852 | "(%d):0323 Unknown Mailbox command " |
04c68496 | 1853 | "x%x (x%x) Cmpl\n", |
92d7f7b0 | 1854 | pmb->vport ? pmb->vport->vpi : 0, |
04c68496 JS |
1855 | pmbox->mbxCommand, |
1856 | lpfc_sli4_mbox_opcode_get(phba, pmb)); | |
2e0fef85 | 1857 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
1858 | phba->work_hs = HS_FFER3; |
1859 | lpfc_handle_eratt(phba); | |
92d7f7b0 | 1860 | continue; |
dea3101e JB |
1861 | } |
1862 | ||
dea3101e JB |
1863 | if (pmbox->mbxStatus) { |
1864 | phba->sli.slistat.mbox_stat_err++; | |
1865 | if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) { | |
1866 | /* Mbox cmd cmpl error - RETRYing */ | |
92d7f7b0 JS |
1867 | lpfc_printf_log(phba, KERN_INFO, |
1868 | LOG_MBOX | LOG_SLI, | |
e8b62011 | 1869 | "(%d):0305 Mbox cmd cmpl " |
92d7f7b0 | 1870 | "error - RETRYing Data: x%x " |
04c68496 | 1871 | "(x%x) x%x x%x x%x\n", |
92d7f7b0 JS |
1872 | pmb->vport ? pmb->vport->vpi :0, |
1873 | pmbox->mbxCommand, | |
04c68496 JS |
1874 | lpfc_sli4_mbox_opcode_get(phba, |
1875 | pmb), | |
92d7f7b0 JS |
1876 | pmbox->mbxStatus, |
1877 | pmbox->un.varWords[0], | |
1878 | pmb->vport->port_state); | |
dea3101e JB |
1879 | pmbox->mbxStatus = 0; |
1880 | pmbox->mbxOwner = OWN_HOST; | |
dea3101e | 1881 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
04c68496 | 1882 | if (rc != MBX_NOT_FINISHED) |
92d7f7b0 | 1883 | continue; |
dea3101e JB |
1884 | } |
1885 | } | |
1886 | ||
1887 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | |
92d7f7b0 | 1888 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
04c68496 | 1889 | "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p " |
dea3101e | 1890 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
92d7f7b0 | 1891 | pmb->vport ? pmb->vport->vpi : 0, |
dea3101e | 1892 | pmbox->mbxCommand, |
04c68496 | 1893 | lpfc_sli4_mbox_opcode_get(phba, pmb), |
dea3101e JB |
1894 | pmb->mbox_cmpl, |
1895 | *((uint32_t *) pmbox), | |
1896 | pmbox->un.varWords[0], | |
1897 | pmbox->un.varWords[1], | |
1898 | pmbox->un.varWords[2], | |
1899 | pmbox->un.varWords[3], | |
1900 | pmbox->un.varWords[4], | |
1901 | pmbox->un.varWords[5], | |
1902 | pmbox->un.varWords[6], | |
1903 | pmbox->un.varWords[7]); | |
1904 | ||
92d7f7b0 | 1905 | if (pmb->mbox_cmpl) |
dea3101e | 1906 | pmb->mbox_cmpl(phba,pmb); |
92d7f7b0 JS |
1907 | } while (1); |
1908 | return 0; | |
1909 | } | |
dea3101e | 1910 | |
e59058c4 | 1911 | /** |
3621a710 | 1912 | * lpfc_sli_get_buff - Get the buffer associated with the buffer tag |
e59058c4 JS |
1913 | * @phba: Pointer to HBA context object. |
1914 | * @pring: Pointer to driver SLI ring object. | |
1915 | * @tag: buffer tag. | |
1916 | * | |
1917 | * This function is called with no lock held. When QUE_BUFTAG_BIT bit | |
1918 | * is set in the tag the buffer is posted for a particular exchange, | |
1919 | * the function will return the buffer without replacing the buffer. | |
1920 | * If the buffer is for unsolicited ELS or CT traffic, this function | |
1921 | * returns the buffer and also posts another buffer to the firmware. | |
1922 | **/ | |
76bb24ef JS |
1923 | static struct lpfc_dmabuf * |
1924 | lpfc_sli_get_buff(struct lpfc_hba *phba, | |
9f1e1b50 JS |
1925 | struct lpfc_sli_ring *pring, |
1926 | uint32_t tag) | |
76bb24ef | 1927 | { |
9f1e1b50 JS |
1928 | struct hbq_dmabuf *hbq_entry; |
1929 | ||
76bb24ef JS |
1930 | if (tag & QUE_BUFTAG_BIT) |
1931 | return lpfc_sli_ring_taggedbuf_get(phba, pring, tag); | |
9f1e1b50 JS |
1932 | hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); |
1933 | if (!hbq_entry) | |
1934 | return NULL; | |
1935 | return &hbq_entry->dbuf; | |
76bb24ef | 1936 | } |
57127f15 | 1937 | |
3772a991 JS |
1938 | /** |
1939 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | |
1940 | * @phba: Pointer to HBA context object. | |
1941 | * @pring: Pointer to driver SLI ring object. | |
1942 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | |
1943 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | |
1944 | * @fch_type: the type for the first frame of the sequence. | |
1945 | * | |
1946 | * This function is called with no lock held. This function uses the r_ctl and | |
1947 | * type of the received sequence to find the correct callback function to call | |
1948 | * to process the sequence. | |
1949 | **/ | |
1950 | static int | |
1951 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1952 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | |
1953 | uint32_t fch_type) | |
1954 | { | |
1955 | int i; | |
1956 | ||
1957 | /* unSolicited Responses */ | |
1958 | if (pring->prt[0].profile) { | |
1959 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | |
1960 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | |
1961 | saveq); | |
1962 | return 1; | |
1963 | } | |
1964 | /* We must search, based on rctl / type | |
1965 | for the right routine */ | |
1966 | for (i = 0; i < pring->num_mask; i++) { | |
1967 | if ((pring->prt[i].rctl == fch_r_ctl) && | |
1968 | (pring->prt[i].type == fch_type)) { | |
1969 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
1970 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | |
1971 | (phba, pring, saveq); | |
1972 | return 1; | |
1973 | } | |
1974 | } | |
1975 | return 0; | |
1976 | } | |
e59058c4 JS |
1977 | |
1978 | /** | |
3621a710 | 1979 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
e59058c4 JS |
1980 | * @phba: Pointer to HBA context object. |
1981 | * @pring: Pointer to driver SLI ring object. | |
1982 | * @saveq: Pointer to the unsolicited iocb. | |
1983 | * | |
1984 | * This function is called with no lock held by the ring event handler | |
1985 | * when there is an unsolicited iocb posted to the response ring by the | |
1986 | * firmware. This function gets the buffer associated with the iocbs | |
1987 | * and calls the event handler for the ring. This function handles both | |
1988 | * qring buffers and hbq buffers. | |
1989 | * When the function returns 1 the caller can free the iocb object otherwise | |
1990 | * upper layer functions will free the iocb objects. | |
1991 | **/ | |
dea3101e JB |
1992 | static int |
1993 | lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
1994 | struct lpfc_iocbq *saveq) | |
1995 | { | |
1996 | IOCB_t * irsp; | |
1997 | WORD5 * w5p; | |
1998 | uint32_t Rctl, Type; | |
3772a991 | 1999 | uint32_t match; |
76bb24ef | 2000 | struct lpfc_iocbq *iocbq; |
3163f725 | 2001 | struct lpfc_dmabuf *dmzbuf; |
dea3101e JB |
2002 | |
2003 | match = 0; | |
2004 | irsp = &(saveq->iocb); | |
57127f15 JS |
2005 | |
2006 | if (irsp->ulpCommand == CMD_ASYNC_STATUS) { | |
2007 | if (pring->lpfc_sli_rcv_async_status) | |
2008 | pring->lpfc_sli_rcv_async_status(phba, pring, saveq); | |
2009 | else | |
2010 | lpfc_printf_log(phba, | |
2011 | KERN_WARNING, | |
2012 | LOG_SLI, | |
2013 | "0316 Ring %d handler: unexpected " | |
2014 | "ASYNC_STATUS iocb received evt_code " | |
2015 | "0x%x\n", | |
2016 | pring->ringno, | |
2017 | irsp->un.asyncstat.evt_code); | |
2018 | return 1; | |
2019 | } | |
2020 | ||
3163f725 JS |
2021 | if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) && |
2022 | (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) { | |
2023 | if (irsp->ulpBdeCount > 0) { | |
2024 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2025 | irsp->un.ulpWord[3]); | |
2026 | lpfc_in_buf_free(phba, dmzbuf); | |
2027 | } | |
2028 | ||
2029 | if (irsp->ulpBdeCount > 1) { | |
2030 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2031 | irsp->unsli3.sli3Words[3]); | |
2032 | lpfc_in_buf_free(phba, dmzbuf); | |
2033 | } | |
2034 | ||
2035 | if (irsp->ulpBdeCount > 2) { | |
2036 | dmzbuf = lpfc_sli_get_buff(phba, pring, | |
2037 | irsp->unsli3.sli3Words[7]); | |
2038 | lpfc_in_buf_free(phba, dmzbuf); | |
2039 | } | |
2040 | ||
2041 | return 1; | |
2042 | } | |
2043 | ||
92d7f7b0 | 2044 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
76bb24ef JS |
2045 | if (irsp->ulpBdeCount != 0) { |
2046 | saveq->context2 = lpfc_sli_get_buff(phba, pring, | |
2047 | irsp->un.ulpWord[3]); | |
2048 | if (!saveq->context2) | |
2049 | lpfc_printf_log(phba, | |
2050 | KERN_ERR, | |
2051 | LOG_SLI, | |
2052 | "0341 Ring %d Cannot find buffer for " | |
2053 | "an unsolicited iocb. tag 0x%x\n", | |
2054 | pring->ringno, | |
2055 | irsp->un.ulpWord[3]); | |
76bb24ef JS |
2056 | } |
2057 | if (irsp->ulpBdeCount == 2) { | |
2058 | saveq->context3 = lpfc_sli_get_buff(phba, pring, | |
2059 | irsp->unsli3.sli3Words[7]); | |
2060 | if (!saveq->context3) | |
2061 | lpfc_printf_log(phba, | |
2062 | KERN_ERR, | |
2063 | LOG_SLI, | |
2064 | "0342 Ring %d Cannot find buffer for an" | |
2065 | " unsolicited iocb. tag 0x%x\n", | |
2066 | pring->ringno, | |
2067 | irsp->unsli3.sli3Words[7]); | |
2068 | } | |
2069 | list_for_each_entry(iocbq, &saveq->list, list) { | |
76bb24ef | 2070 | irsp = &(iocbq->iocb); |
76bb24ef JS |
2071 | if (irsp->ulpBdeCount != 0) { |
2072 | iocbq->context2 = lpfc_sli_get_buff(phba, pring, | |
2073 | irsp->un.ulpWord[3]); | |
9c2face6 | 2074 | if (!iocbq->context2) |
76bb24ef JS |
2075 | lpfc_printf_log(phba, |
2076 | KERN_ERR, | |
2077 | LOG_SLI, | |
2078 | "0343 Ring %d Cannot find " | |
2079 | "buffer for an unsolicited iocb" | |
2080 | ". tag 0x%x\n", pring->ringno, | |
92d7f7b0 | 2081 | irsp->un.ulpWord[3]); |
76bb24ef JS |
2082 | } |
2083 | if (irsp->ulpBdeCount == 2) { | |
2084 | iocbq->context3 = lpfc_sli_get_buff(phba, pring, | |
51ef4c26 | 2085 | irsp->unsli3.sli3Words[7]); |
9c2face6 | 2086 | if (!iocbq->context3) |
76bb24ef JS |
2087 | lpfc_printf_log(phba, |
2088 | KERN_ERR, | |
2089 | LOG_SLI, | |
2090 | "0344 Ring %d Cannot find " | |
2091 | "buffer for an unsolicited " | |
2092 | "iocb. tag 0x%x\n", | |
2093 | pring->ringno, | |
2094 | irsp->unsli3.sli3Words[7]); | |
2095 | } | |
2096 | } | |
92d7f7b0 | 2097 | } |
9c2face6 JS |
2098 | if (irsp->ulpBdeCount != 0 && |
2099 | (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX || | |
2100 | irsp->ulpStatus == IOSTAT_INTERMED_RSP)) { | |
2101 | int found = 0; | |
2102 | ||
2103 | /* search continue save q for same XRI */ | |
2104 | list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) { | |
2105 | if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) { | |
2106 | list_add_tail(&saveq->list, &iocbq->list); | |
2107 | found = 1; | |
2108 | break; | |
2109 | } | |
2110 | } | |
2111 | if (!found) | |
2112 | list_add_tail(&saveq->clist, | |
2113 | &pring->iocb_continue_saveq); | |
2114 | if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) { | |
2115 | list_del_init(&iocbq->clist); | |
2116 | saveq = iocbq; | |
2117 | irsp = &(saveq->iocb); | |
2118 | } else | |
2119 | return 0; | |
2120 | } | |
2121 | if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) || | |
2122 | (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) || | |
2123 | (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) { | |
6a9c52cf JS |
2124 | Rctl = FC_RCTL_ELS_REQ; |
2125 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2126 | } else { |
2127 | w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]); | |
2128 | Rctl = w5p->hcsw.Rctl; | |
2129 | Type = w5p->hcsw.Type; | |
2130 | ||
2131 | /* Firmware Workaround */ | |
2132 | if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && | |
2133 | (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX || | |
2134 | irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) { | |
6a9c52cf JS |
2135 | Rctl = FC_RCTL_ELS_REQ; |
2136 | Type = FC_TYPE_ELS; | |
9c2face6 JS |
2137 | w5p->hcsw.Rctl = Rctl; |
2138 | w5p->hcsw.Type = Type; | |
2139 | } | |
2140 | } | |
92d7f7b0 | 2141 | |
3772a991 | 2142 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
92d7f7b0 | 2143 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 | 2144 | "0313 Ring %d handler: unexpected Rctl x%x " |
92d7f7b0 | 2145 | "Type x%x received\n", |
e8b62011 | 2146 | pring->ringno, Rctl, Type); |
3772a991 | 2147 | |
92d7f7b0 | 2148 | return 1; |
dea3101e JB |
2149 | } |
2150 | ||
e59058c4 | 2151 | /** |
3621a710 | 2152 | * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb |
e59058c4 JS |
2153 | * @phba: Pointer to HBA context object. |
2154 | * @pring: Pointer to driver SLI ring object. | |
2155 | * @prspiocb: Pointer to response iocb object. | |
2156 | * | |
2157 | * This function looks up the iocb_lookup table to get the command iocb | |
2158 | * corresponding to the given response iocb using the iotag of the | |
2159 | * response iocb. This function is called with the hbalock held. | |
2160 | * This function returns the command iocb object if it finds the command | |
2161 | * iocb else returns NULL. | |
2162 | **/ | |
dea3101e | 2163 | static struct lpfc_iocbq * |
2e0fef85 JS |
2164 | lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, |
2165 | struct lpfc_sli_ring *pring, | |
2166 | struct lpfc_iocbq *prspiocb) | |
dea3101e | 2167 | { |
dea3101e JB |
2168 | struct lpfc_iocbq *cmd_iocb = NULL; |
2169 | uint16_t iotag; | |
2170 | ||
604a3e30 JB |
2171 | iotag = prspiocb->iocb.ulpIoTag; |
2172 | ||
2173 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2174 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
92d7f7b0 | 2175 | list_del_init(&cmd_iocb->list); |
2a9bf3d0 JS |
2176 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2177 | pring->txcmplq_cnt--; | |
2178 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2179 | } | |
604a3e30 | 2180 | return cmd_iocb; |
dea3101e JB |
2181 | } |
2182 | ||
dea3101e | 2183 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2184 | "0317 iotag x%x is out off " |
604a3e30 | 2185 | "range: max iotag x%x wd0 x%x\n", |
e8b62011 | 2186 | iotag, phba->sli.last_iotag, |
604a3e30 | 2187 | *(((uint32_t *) &prspiocb->iocb) + 7)); |
dea3101e JB |
2188 | return NULL; |
2189 | } | |
2190 | ||
3772a991 JS |
2191 | /** |
2192 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | |
2193 | * @phba: Pointer to HBA context object. | |
2194 | * @pring: Pointer to driver SLI ring object. | |
2195 | * @iotag: IOCB tag. | |
2196 | * | |
2197 | * This function looks up the iocb_lookup table to get the command iocb | |
2198 | * corresponding to the given iotag. This function is called with the | |
2199 | * hbalock held. | |
2200 | * This function returns the command iocb object if it finds the command | |
2201 | * iocb else returns NULL. | |
2202 | **/ | |
2203 | static struct lpfc_iocbq * | |
2204 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | |
2205 | struct lpfc_sli_ring *pring, uint16_t iotag) | |
2206 | { | |
2207 | struct lpfc_iocbq *cmd_iocb; | |
2208 | ||
2209 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | |
2210 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | |
2211 | list_del_init(&cmd_iocb->list); | |
2a9bf3d0 JS |
2212 | if (cmd_iocb->iocb_flag & LPFC_IO_ON_Q) { |
2213 | cmd_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
2214 | pring->txcmplq_cnt--; | |
2215 | } | |
3772a991 JS |
2216 | return cmd_iocb; |
2217 | } | |
2218 | ||
2219 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2220 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | |
2221 | iotag, phba->sli.last_iotag); | |
2222 | return NULL; | |
2223 | } | |
2224 | ||
e59058c4 | 2225 | /** |
3621a710 | 2226 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
e59058c4 JS |
2227 | * @phba: Pointer to HBA context object. |
2228 | * @pring: Pointer to driver SLI ring object. | |
2229 | * @saveq: Pointer to the response iocb to be processed. | |
2230 | * | |
2231 | * This function is called by the ring event handler for non-fcp | |
2232 | * rings when there is a new response iocb in the response ring. | |
2233 | * The caller is not required to hold any locks. This function | |
2234 | * gets the command iocb associated with the response iocb and | |
2235 | * calls the completion handler for the command iocb. If there | |
2236 | * is no completion handler, the function will free the resources | |
2237 | * associated with command iocb. If the response iocb is for | |
2238 | * an already aborted command iocb, the status of the completion | |
2239 | * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED. | |
2240 | * This function always returns 1. | |
2241 | **/ | |
dea3101e | 2242 | static int |
2e0fef85 | 2243 | lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
dea3101e JB |
2244 | struct lpfc_iocbq *saveq) |
2245 | { | |
2e0fef85 | 2246 | struct lpfc_iocbq *cmdiocbp; |
dea3101e JB |
2247 | int rc = 1; |
2248 | unsigned long iflag; | |
2249 | ||
2250 | /* Based on the iotag field, get the cmd IOCB from the txcmplq */ | |
2e0fef85 | 2251 | spin_lock_irqsave(&phba->hbalock, iflag); |
604a3e30 | 2252 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); |
2e0fef85 JS |
2253 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2254 | ||
dea3101e JB |
2255 | if (cmdiocbp) { |
2256 | if (cmdiocbp->iocb_cmpl) { | |
ea2151b4 JS |
2257 | /* |
2258 | * If an ELS command failed send an event to mgmt | |
2259 | * application. | |
2260 | */ | |
2261 | if (saveq->iocb.ulpStatus && | |
2262 | (pring->ringno == LPFC_ELS_RING) && | |
2263 | (cmdiocbp->iocb.ulpCommand == | |
2264 | CMD_ELS_REQUEST64_CR)) | |
2265 | lpfc_send_els_failure_event(phba, | |
2266 | cmdiocbp, saveq); | |
2267 | ||
dea3101e JB |
2268 | /* |
2269 | * Post all ELS completions to the worker thread. | |
2270 | * All other are passed to the completion callback. | |
2271 | */ | |
2272 | if (pring->ringno == LPFC_ELS_RING) { | |
341af102 JS |
2273 | if ((phba->sli_rev < LPFC_SLI_REV4) && |
2274 | (cmdiocbp->iocb_flag & | |
2275 | LPFC_DRIVER_ABORTED)) { | |
2276 | spin_lock_irqsave(&phba->hbalock, | |
2277 | iflag); | |
07951076 JS |
2278 | cmdiocbp->iocb_flag &= |
2279 | ~LPFC_DRIVER_ABORTED; | |
341af102 JS |
2280 | spin_unlock_irqrestore(&phba->hbalock, |
2281 | iflag); | |
07951076 JS |
2282 | saveq->iocb.ulpStatus = |
2283 | IOSTAT_LOCAL_REJECT; | |
2284 | saveq->iocb.un.ulpWord[4] = | |
2285 | IOERR_SLI_ABORTED; | |
0ff10d46 JS |
2286 | |
2287 | /* Firmware could still be in progress | |
2288 | * of DMAing payload, so don't free data | |
2289 | * buffer till after a hbeat. | |
2290 | */ | |
341af102 JS |
2291 | spin_lock_irqsave(&phba->hbalock, |
2292 | iflag); | |
0ff10d46 | 2293 | saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; |
341af102 JS |
2294 | spin_unlock_irqrestore(&phba->hbalock, |
2295 | iflag); | |
2296 | } | |
0f65ff68 JS |
2297 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2298 | if (saveq->iocb_flag & | |
2299 | LPFC_EXCHANGE_BUSY) { | |
2300 | /* Set cmdiocb flag for the | |
2301 | * exchange busy so sgl (xri) | |
2302 | * will not be released until | |
2303 | * the abort xri is received | |
2304 | * from hba. | |
2305 | */ | |
2306 | spin_lock_irqsave( | |
2307 | &phba->hbalock, iflag); | |
2308 | cmdiocbp->iocb_flag |= | |
2309 | LPFC_EXCHANGE_BUSY; | |
2310 | spin_unlock_irqrestore( | |
2311 | &phba->hbalock, iflag); | |
2312 | } | |
2313 | if (cmdiocbp->iocb_flag & | |
2314 | LPFC_DRIVER_ABORTED) { | |
2315 | /* | |
2316 | * Clear LPFC_DRIVER_ABORTED | |
2317 | * bit in case it was driver | |
2318 | * initiated abort. | |
2319 | */ | |
2320 | spin_lock_irqsave( | |
2321 | &phba->hbalock, iflag); | |
2322 | cmdiocbp->iocb_flag &= | |
2323 | ~LPFC_DRIVER_ABORTED; | |
2324 | spin_unlock_irqrestore( | |
2325 | &phba->hbalock, iflag); | |
2326 | cmdiocbp->iocb.ulpStatus = | |
2327 | IOSTAT_LOCAL_REJECT; | |
2328 | cmdiocbp->iocb.un.ulpWord[4] = | |
2329 | IOERR_ABORT_REQUESTED; | |
2330 | /* | |
2331 | * For SLI4, irsiocb contains | |
2332 | * NO_XRI in sli_xritag, it | |
2333 | * shall not affect releasing | |
2334 | * sgl (xri) process. | |
2335 | */ | |
2336 | saveq->iocb.ulpStatus = | |
2337 | IOSTAT_LOCAL_REJECT; | |
2338 | saveq->iocb.un.ulpWord[4] = | |
2339 | IOERR_SLI_ABORTED; | |
2340 | spin_lock_irqsave( | |
2341 | &phba->hbalock, iflag); | |
2342 | saveq->iocb_flag |= | |
2343 | LPFC_DELAY_MEM_FREE; | |
2344 | spin_unlock_irqrestore( | |
2345 | &phba->hbalock, iflag); | |
2346 | } | |
07951076 | 2347 | } |
dea3101e | 2348 | } |
2e0fef85 | 2349 | (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); |
604a3e30 JB |
2350 | } else |
2351 | lpfc_sli_release_iocbq(phba, cmdiocbp); | |
dea3101e JB |
2352 | } else { |
2353 | /* | |
2354 | * Unknown initiating command based on the response iotag. | |
2355 | * This could be the case on the ELS ring because of | |
2356 | * lpfc_els_abort(). | |
2357 | */ | |
2358 | if (pring->ringno != LPFC_ELS_RING) { | |
2359 | /* | |
2360 | * Ring <ringno> handler: unexpected completion IoTag | |
2361 | * <IoTag> | |
2362 | */ | |
a257bf90 | 2363 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
e8b62011 JS |
2364 | "0322 Ring %d handler: " |
2365 | "unexpected completion IoTag x%x " | |
2366 | "Data: x%x x%x x%x x%x\n", | |
2367 | pring->ringno, | |
2368 | saveq->iocb.ulpIoTag, | |
2369 | saveq->iocb.ulpStatus, | |
2370 | saveq->iocb.un.ulpWord[4], | |
2371 | saveq->iocb.ulpCommand, | |
2372 | saveq->iocb.ulpContext); | |
dea3101e JB |
2373 | } |
2374 | } | |
68876920 | 2375 | |
dea3101e JB |
2376 | return rc; |
2377 | } | |
2378 | ||
e59058c4 | 2379 | /** |
3621a710 | 2380 | * lpfc_sli_rsp_pointers_error - Response ring pointer error handler |
e59058c4 JS |
2381 | * @phba: Pointer to HBA context object. |
2382 | * @pring: Pointer to driver SLI ring object. | |
2383 | * | |
2384 | * This function is called from the iocb ring event handlers when | |
2385 | * put pointer is ahead of the get pointer for a ring. This function signal | |
2386 | * an error attention condition to the worker thread and the worker | |
2387 | * thread will transition the HBA to offline state. | |
2388 | **/ | |
2e0fef85 JS |
2389 | static void |
2390 | lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) | |
875fbdfe | 2391 | { |
34b02dcd | 2392 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
875fbdfe | 2393 | /* |
025dfdaf | 2394 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
875fbdfe JSEC |
2395 | * rsp ring <portRspMax> |
2396 | */ | |
2397 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2398 | "0312 Ring %d handler: portRspPut %d " |
025dfdaf | 2399 | "is bigger than rsp ring %d\n", |
e8b62011 | 2400 | pring->ringno, le32_to_cpu(pgp->rspPutInx), |
875fbdfe JSEC |
2401 | pring->numRiocb); |
2402 | ||
2e0fef85 | 2403 | phba->link_state = LPFC_HBA_ERROR; |
875fbdfe JSEC |
2404 | |
2405 | /* | |
2406 | * All error attention handlers are posted to | |
2407 | * worker thread | |
2408 | */ | |
2409 | phba->work_ha |= HA_ERATT; | |
2410 | phba->work_hs = HS_FFER3; | |
92d7f7b0 | 2411 | |
5e9d9b82 | 2412 | lpfc_worker_wake_up(phba); |
875fbdfe JSEC |
2413 | |
2414 | return; | |
2415 | } | |
2416 | ||
9399627f | 2417 | /** |
3621a710 | 2418 | * lpfc_poll_eratt - Error attention polling timer timeout handler |
9399627f JS |
2419 | * @ptr: Pointer to address of HBA context object. |
2420 | * | |
2421 | * This function is invoked by the Error Attention polling timer when the | |
2422 | * timer times out. It will check the SLI Error Attention register for | |
2423 | * possible attention events. If so, it will post an Error Attention event | |
2424 | * and wake up worker thread to process it. Otherwise, it will set up the | |
2425 | * Error Attention polling timer for the next poll. | |
2426 | **/ | |
2427 | void lpfc_poll_eratt(unsigned long ptr) | |
2428 | { | |
2429 | struct lpfc_hba *phba; | |
2430 | uint32_t eratt = 0; | |
2431 | ||
2432 | phba = (struct lpfc_hba *)ptr; | |
2433 | ||
2434 | /* Check chip HA register for error event */ | |
2435 | eratt = lpfc_sli_check_eratt(phba); | |
2436 | ||
2437 | if (eratt) | |
2438 | /* Tell the worker thread there is work to do */ | |
2439 | lpfc_worker_wake_up(phba); | |
2440 | else | |
2441 | /* Restart the timer for next eratt poll */ | |
2442 | mod_timer(&phba->eratt_poll, jiffies + | |
2443 | HZ * LPFC_ERATT_POLL_INTERVAL); | |
2444 | return; | |
2445 | } | |
2446 | ||
875fbdfe | 2447 | |
e59058c4 | 2448 | /** |
3621a710 | 2449 | * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring |
e59058c4 JS |
2450 | * @phba: Pointer to HBA context object. |
2451 | * @pring: Pointer to driver SLI ring object. | |
2452 | * @mask: Host attention register mask for this ring. | |
2453 | * | |
2454 | * This function is called from the interrupt context when there is a ring | |
2455 | * event for the fcp ring. The caller does not hold any lock. | |
2456 | * The function processes each response iocb in the response ring until it | |
2457 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | |
2458 | * LE bit set. The function will call the completion handler of the command iocb | |
2459 | * if the response iocb indicates a completion for a command iocb or it is | |
2460 | * an abort completion. The function will call lpfc_sli_process_unsol_iocb | |
2461 | * function if this is an unsolicited iocb. | |
dea3101e | 2462 | * This routine presumes LPFC_FCP_RING handling and doesn't bother |
45ed1190 JS |
2463 | * to check it explicitly. |
2464 | */ | |
2465 | int | |
2e0fef85 JS |
2466 | lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, |
2467 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2468 | { |
34b02dcd | 2469 | struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno]; |
dea3101e | 2470 | IOCB_t *irsp = NULL; |
87f6eaff | 2471 | IOCB_t *entry = NULL; |
dea3101e JB |
2472 | struct lpfc_iocbq *cmdiocbq = NULL; |
2473 | struct lpfc_iocbq rspiocbq; | |
dea3101e JB |
2474 | uint32_t status; |
2475 | uint32_t portRspPut, portRspMax; | |
2476 | int rc = 1; | |
2477 | lpfc_iocb_type type; | |
2478 | unsigned long iflag; | |
2479 | uint32_t rsp_cmpl = 0; | |
dea3101e | 2480 | |
2e0fef85 | 2481 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2482 | pring->stats.iocb_event++; |
2483 | ||
dea3101e JB |
2484 | /* |
2485 | * The next available response entry should never exceed the maximum | |
2486 | * entries. If it does, treat it as an adapter hardware error. | |
2487 | */ | |
2488 | portRspMax = pring->numRiocb; | |
2489 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2490 | if (unlikely(portRspPut >= portRspMax)) { | |
875fbdfe | 2491 | lpfc_sli_rsp_pointers_error(phba, pring); |
2e0fef85 | 2492 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2493 | return 1; |
2494 | } | |
45ed1190 JS |
2495 | if (phba->fcp_ring_in_use) { |
2496 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2497 | return 1; | |
2498 | } else | |
2499 | phba->fcp_ring_in_use = 1; | |
dea3101e JB |
2500 | |
2501 | rmb(); | |
2502 | while (pring->rspidx != portRspPut) { | |
87f6eaff JSEC |
2503 | /* |
2504 | * Fetch an entry off the ring and copy it into a local data | |
2505 | * structure. The copy involves a byte-swap since the | |
2506 | * network byte order and pci byte orders are different. | |
2507 | */ | |
ed957684 | 2508 | entry = lpfc_resp_iocb(phba, pring); |
858c9f6c | 2509 | phba->last_completion_time = jiffies; |
875fbdfe JSEC |
2510 | |
2511 | if (++pring->rspidx >= portRspMax) | |
2512 | pring->rspidx = 0; | |
2513 | ||
87f6eaff JSEC |
2514 | lpfc_sli_pcimem_bcopy((uint32_t *) entry, |
2515 | (uint32_t *) &rspiocbq.iocb, | |
ed957684 | 2516 | phba->iocb_rsp_size); |
a4bc3379 | 2517 | INIT_LIST_HEAD(&(rspiocbq.list)); |
87f6eaff JSEC |
2518 | irsp = &rspiocbq.iocb; |
2519 | ||
dea3101e JB |
2520 | type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); |
2521 | pring->stats.iocb_rsp++; | |
2522 | rsp_cmpl++; | |
2523 | ||
2524 | if (unlikely(irsp->ulpStatus)) { | |
92d7f7b0 JS |
2525 | /* |
2526 | * If resource errors reported from HBA, reduce | |
2527 | * queuedepths of the SCSI device. | |
2528 | */ | |
2529 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2530 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2531 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
3772a991 | 2532 | phba->lpfc_rampdown_queue_depth(phba); |
92d7f7b0 JS |
2533 | spin_lock_irqsave(&phba->hbalock, iflag); |
2534 | } | |
2535 | ||
dea3101e JB |
2536 | /* Rsp ring <ringno> error: IOCB */ |
2537 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
e8b62011 | 2538 | "0336 Rsp Ring %d error: IOCB Data: " |
92d7f7b0 | 2539 | "x%x x%x x%x x%x x%x x%x x%x x%x\n", |
e8b62011 | 2540 | pring->ringno, |
92d7f7b0 JS |
2541 | irsp->un.ulpWord[0], |
2542 | irsp->un.ulpWord[1], | |
2543 | irsp->un.ulpWord[2], | |
2544 | irsp->un.ulpWord[3], | |
2545 | irsp->un.ulpWord[4], | |
2546 | irsp->un.ulpWord[5], | |
d7c255b2 JS |
2547 | *(uint32_t *)&irsp->un1, |
2548 | *((uint32_t *)&irsp->un1 + 1)); | |
dea3101e JB |
2549 | } |
2550 | ||
2551 | switch (type) { | |
2552 | case LPFC_ABORT_IOCB: | |
2553 | case LPFC_SOL_IOCB: | |
2554 | /* | |
2555 | * Idle exchange closed via ABTS from port. No iocb | |
2556 | * resources need to be recovered. | |
2557 | */ | |
2558 | if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) { | |
dca9479b | 2559 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 | 2560 | "0333 IOCB cmd 0x%x" |
dca9479b | 2561 | " processed. Skipping" |
92d7f7b0 | 2562 | " completion\n", |
dca9479b | 2563 | irsp->ulpCommand); |
dea3101e JB |
2564 | break; |
2565 | } | |
2566 | ||
604a3e30 JB |
2567 | cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, |
2568 | &rspiocbq); | |
0f65ff68 JS |
2569 | if (unlikely(!cmdiocbq)) |
2570 | break; | |
2571 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) | |
2572 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
2573 | if (cmdiocbq->iocb_cmpl) { | |
2574 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2575 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, | |
2576 | &rspiocbq); | |
2577 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2578 | } | |
dea3101e | 2579 | break; |
a4bc3379 | 2580 | case LPFC_UNSOL_IOCB: |
2e0fef85 | 2581 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a4bc3379 | 2582 | lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); |
2e0fef85 | 2583 | spin_lock_irqsave(&phba->hbalock, iflag); |
a4bc3379 | 2584 | break; |
dea3101e JB |
2585 | default: |
2586 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2587 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2588 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2589 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | |
2590 | MAX_MSG_DATA); | |
898eb71c JP |
2591 | dev_warn(&((phba->pcidev)->dev), |
2592 | "lpfc%d: %s\n", | |
dea3101e JB |
2593 | phba->brd_no, adaptermsg); |
2594 | } else { | |
2595 | /* Unknown IOCB command */ | |
2596 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e8b62011 | 2597 | "0334 Unknown IOCB command " |
92d7f7b0 | 2598 | "Data: x%x, x%x x%x x%x x%x\n", |
e8b62011 | 2599 | type, irsp->ulpCommand, |
92d7f7b0 JS |
2600 | irsp->ulpStatus, |
2601 | irsp->ulpIoTag, | |
2602 | irsp->ulpContext); | |
dea3101e JB |
2603 | } |
2604 | break; | |
2605 | } | |
2606 | ||
2607 | /* | |
2608 | * The response IOCB has been processed. Update the ring | |
2609 | * pointer in SLIM. If the port response put pointer has not | |
2610 | * been updated, sync the pgp->rspPutInx and fetch the new port | |
2611 | * response put pointer. | |
2612 | */ | |
ed957684 | 2613 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e JB |
2614 | |
2615 | if (pring->rspidx == portRspPut) | |
2616 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2617 | } | |
2618 | ||
2619 | if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) { | |
2620 | pring->stats.iocb_rsp_full++; | |
2621 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2622 | writel(status, phba->CAregaddr); | |
2623 | readl(phba->CAregaddr); | |
2624 | } | |
2625 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2626 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2627 | pring->stats.iocb_cmd_empty++; | |
2628 | ||
2629 | /* Force update of the local copy of cmdGetInx */ | |
2630 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2631 | lpfc_sli_resume_iocb(phba, pring); | |
2632 | ||
2633 | if ((pring->lpfc_sli_cmd_available)) | |
2634 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2635 | ||
2636 | } | |
2637 | ||
45ed1190 | 2638 | phba->fcp_ring_in_use = 0; |
2e0fef85 | 2639 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
2640 | return rc; |
2641 | } | |
2642 | ||
e59058c4 | 2643 | /** |
3772a991 JS |
2644 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
2645 | * @phba: Pointer to HBA context object. | |
2646 | * @pring: Pointer to driver SLI ring object. | |
2647 | * @rspiocbp: Pointer to driver response IOCB object. | |
2648 | * | |
2649 | * This function is called from the worker thread when there is a slow-path | |
2650 | * response IOCB to process. This function chains all the response iocbs until | |
2651 | * seeing the iocb with the LE bit set. The function will call | |
2652 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | |
2653 | * completion of a command iocb. The function will call the | |
2654 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | |
2655 | * The function frees the resources or calls the completion handler if this | |
2656 | * iocb is an abort completion. The function returns NULL when the response | |
2657 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | |
2658 | * this function shall chain the iocb on to the iocb_continueq and return the | |
2659 | * response iocb passed in. | |
2660 | **/ | |
2661 | static struct lpfc_iocbq * | |
2662 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2663 | struct lpfc_iocbq *rspiocbp) | |
2664 | { | |
2665 | struct lpfc_iocbq *saveq; | |
2666 | struct lpfc_iocbq *cmdiocbp; | |
2667 | struct lpfc_iocbq *next_iocb; | |
2668 | IOCB_t *irsp = NULL; | |
2669 | uint32_t free_saveq; | |
2670 | uint8_t iocb_cmd_type; | |
2671 | lpfc_iocb_type type; | |
2672 | unsigned long iflag; | |
2673 | int rc; | |
2674 | ||
2675 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2676 | /* First add the response iocb to the countinueq list */ | |
2677 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | |
2678 | pring->iocb_continueq_cnt++; | |
2679 | ||
2680 | /* Now, determine whetehr the list is completed for processing */ | |
2681 | irsp = &rspiocbp->iocb; | |
2682 | if (irsp->ulpLe) { | |
2683 | /* | |
2684 | * By default, the driver expects to free all resources | |
2685 | * associated with this iocb completion. | |
2686 | */ | |
2687 | free_saveq = 1; | |
2688 | saveq = list_get_first(&pring->iocb_continueq, | |
2689 | struct lpfc_iocbq, list); | |
2690 | irsp = &(saveq->iocb); | |
2691 | list_del_init(&pring->iocb_continueq); | |
2692 | pring->iocb_continueq_cnt = 0; | |
2693 | ||
2694 | pring->stats.iocb_rsp++; | |
2695 | ||
2696 | /* | |
2697 | * If resource errors reported from HBA, reduce | |
2698 | * queuedepths of the SCSI device. | |
2699 | */ | |
2700 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | |
2701 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | |
2702 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2703 | phba->lpfc_rampdown_queue_depth(phba); | |
2704 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2705 | } | |
2706 | ||
2707 | if (irsp->ulpStatus) { | |
2708 | /* Rsp ring <ringno> error: IOCB */ | |
2709 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
2710 | "0328 Rsp Ring %d error: " | |
2711 | "IOCB Data: " | |
2712 | "x%x x%x x%x x%x " | |
2713 | "x%x x%x x%x x%x " | |
2714 | "x%x x%x x%x x%x " | |
2715 | "x%x x%x x%x x%x\n", | |
2716 | pring->ringno, | |
2717 | irsp->un.ulpWord[0], | |
2718 | irsp->un.ulpWord[1], | |
2719 | irsp->un.ulpWord[2], | |
2720 | irsp->un.ulpWord[3], | |
2721 | irsp->un.ulpWord[4], | |
2722 | irsp->un.ulpWord[5], | |
2723 | *(((uint32_t *) irsp) + 6), | |
2724 | *(((uint32_t *) irsp) + 7), | |
2725 | *(((uint32_t *) irsp) + 8), | |
2726 | *(((uint32_t *) irsp) + 9), | |
2727 | *(((uint32_t *) irsp) + 10), | |
2728 | *(((uint32_t *) irsp) + 11), | |
2729 | *(((uint32_t *) irsp) + 12), | |
2730 | *(((uint32_t *) irsp) + 13), | |
2731 | *(((uint32_t *) irsp) + 14), | |
2732 | *(((uint32_t *) irsp) + 15)); | |
2733 | } | |
2734 | ||
2735 | /* | |
2736 | * Fetch the IOCB command type and call the correct completion | |
2737 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | |
2738 | * get freed back to the lpfc_iocb_list by the discovery | |
2739 | * kernel thread. | |
2740 | */ | |
2741 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | |
2742 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | |
2743 | switch (type) { | |
2744 | case LPFC_SOL_IOCB: | |
2745 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2746 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | |
2747 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2748 | break; | |
2749 | ||
2750 | case LPFC_UNSOL_IOCB: | |
2751 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2752 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | |
2753 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2754 | if (!rc) | |
2755 | free_saveq = 0; | |
2756 | break; | |
2757 | ||
2758 | case LPFC_ABORT_IOCB: | |
2759 | cmdiocbp = NULL; | |
2760 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | |
2761 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | |
2762 | saveq); | |
2763 | if (cmdiocbp) { | |
2764 | /* Call the specified completion routine */ | |
2765 | if (cmdiocbp->iocb_cmpl) { | |
2766 | spin_unlock_irqrestore(&phba->hbalock, | |
2767 | iflag); | |
2768 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | |
2769 | saveq); | |
2770 | spin_lock_irqsave(&phba->hbalock, | |
2771 | iflag); | |
2772 | } else | |
2773 | __lpfc_sli_release_iocbq(phba, | |
2774 | cmdiocbp); | |
2775 | } | |
2776 | break; | |
2777 | ||
2778 | case LPFC_UNKNOWN_IOCB: | |
2779 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | |
2780 | char adaptermsg[LPFC_MAX_ADPTMSG]; | |
2781 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | |
2782 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | |
2783 | MAX_MSG_DATA); | |
2784 | dev_warn(&((phba->pcidev)->dev), | |
2785 | "lpfc%d: %s\n", | |
2786 | phba->brd_no, adaptermsg); | |
2787 | } else { | |
2788 | /* Unknown IOCB command */ | |
2789 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2790 | "0335 Unknown IOCB " | |
2791 | "command Data: x%x " | |
2792 | "x%x x%x x%x\n", | |
2793 | irsp->ulpCommand, | |
2794 | irsp->ulpStatus, | |
2795 | irsp->ulpIoTag, | |
2796 | irsp->ulpContext); | |
2797 | } | |
2798 | break; | |
2799 | } | |
2800 | ||
2801 | if (free_saveq) { | |
2802 | list_for_each_entry_safe(rspiocbp, next_iocb, | |
2803 | &saveq->list, list) { | |
2804 | list_del(&rspiocbp->list); | |
2805 | __lpfc_sli_release_iocbq(phba, rspiocbp); | |
2806 | } | |
2807 | __lpfc_sli_release_iocbq(phba, saveq); | |
2808 | } | |
2809 | rspiocbp = NULL; | |
2810 | } | |
2811 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2812 | return rspiocbp; | |
2813 | } | |
2814 | ||
2815 | /** | |
2816 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | |
e59058c4 JS |
2817 | * @phba: Pointer to HBA context object. |
2818 | * @pring: Pointer to driver SLI ring object. | |
2819 | * @mask: Host attention register mask for this ring. | |
2820 | * | |
3772a991 JS |
2821 | * This routine wraps the actual slow_ring event process routine from the |
2822 | * API jump table function pointer from the lpfc_hba struct. | |
e59058c4 | 2823 | **/ |
3772a991 | 2824 | void |
2e0fef85 JS |
2825 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
2826 | struct lpfc_sli_ring *pring, uint32_t mask) | |
3772a991 JS |
2827 | { |
2828 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | |
2829 | } | |
2830 | ||
2831 | /** | |
2832 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | |
2833 | * @phba: Pointer to HBA context object. | |
2834 | * @pring: Pointer to driver SLI ring object. | |
2835 | * @mask: Host attention register mask for this ring. | |
2836 | * | |
2837 | * This function is called from the worker thread when there is a ring event | |
2838 | * for non-fcp rings. The caller does not hold any lock. The function will | |
2839 | * remove each response iocb in the response ring and calls the handle | |
2840 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
2841 | **/ | |
2842 | static void | |
2843 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | |
2844 | struct lpfc_sli_ring *pring, uint32_t mask) | |
dea3101e | 2845 | { |
34b02dcd | 2846 | struct lpfc_pgp *pgp; |
dea3101e JB |
2847 | IOCB_t *entry; |
2848 | IOCB_t *irsp = NULL; | |
2849 | struct lpfc_iocbq *rspiocbp = NULL; | |
dea3101e | 2850 | uint32_t portRspPut, portRspMax; |
dea3101e | 2851 | unsigned long iflag; |
3772a991 | 2852 | uint32_t status; |
dea3101e | 2853 | |
34b02dcd | 2854 | pgp = &phba->port_gp[pring->ringno]; |
2e0fef85 | 2855 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
2856 | pring->stats.iocb_event++; |
2857 | ||
dea3101e JB |
2858 | /* |
2859 | * The next available response entry should never exceed the maximum | |
2860 | * entries. If it does, treat it as an adapter hardware error. | |
2861 | */ | |
2862 | portRspMax = pring->numRiocb; | |
2863 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2864 | if (portRspPut >= portRspMax) { | |
2865 | /* | |
025dfdaf | 2866 | * Ring <ringno> handler: portRspPut <portRspPut> is bigger than |
dea3101e JB |
2867 | * rsp ring <portRspMax> |
2868 | */ | |
ed957684 | 2869 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 | 2870 | "0303 Ring %d handler: portRspPut %d " |
025dfdaf | 2871 | "is bigger than rsp ring %d\n", |
e8b62011 | 2872 | pring->ringno, portRspPut, portRspMax); |
dea3101e | 2873 | |
2e0fef85 JS |
2874 | phba->link_state = LPFC_HBA_ERROR; |
2875 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
dea3101e JB |
2876 | |
2877 | phba->work_hs = HS_FFER3; | |
2878 | lpfc_handle_eratt(phba); | |
2879 | ||
3772a991 | 2880 | return; |
dea3101e JB |
2881 | } |
2882 | ||
2883 | rmb(); | |
dea3101e JB |
2884 | while (pring->rspidx != portRspPut) { |
2885 | /* | |
2886 | * Build a completion list and call the appropriate handler. | |
2887 | * The process is to get the next available response iocb, get | |
2888 | * a free iocb from the list, copy the response data into the | |
2889 | * free iocb, insert to the continuation list, and update the | |
2890 | * next response index to slim. This process makes response | |
2891 | * iocb's in the ring available to DMA as fast as possible but | |
2892 | * pays a penalty for a copy operation. Since the iocb is | |
2893 | * only 32 bytes, this penalty is considered small relative to | |
2894 | * the PCI reads for register values and a slim write. When | |
2895 | * the ulpLe field is set, the entire Command has been | |
2896 | * received. | |
2897 | */ | |
ed957684 JS |
2898 | entry = lpfc_resp_iocb(phba, pring); |
2899 | ||
858c9f6c | 2900 | phba->last_completion_time = jiffies; |
2e0fef85 | 2901 | rspiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2902 | if (rspiocbp == NULL) { |
2903 | printk(KERN_ERR "%s: out of buffers! Failing " | |
cadbd4a5 | 2904 | "completion.\n", __func__); |
dea3101e JB |
2905 | break; |
2906 | } | |
2907 | ||
ed957684 JS |
2908 | lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, |
2909 | phba->iocb_rsp_size); | |
dea3101e JB |
2910 | irsp = &rspiocbp->iocb; |
2911 | ||
2912 | if (++pring->rspidx >= portRspMax) | |
2913 | pring->rspidx = 0; | |
2914 | ||
a58cbd52 JS |
2915 | if (pring->ringno == LPFC_ELS_RING) { |
2916 | lpfc_debugfs_slow_ring_trc(phba, | |
2917 | "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x", | |
2918 | *(((uint32_t *) irsp) + 4), | |
2919 | *(((uint32_t *) irsp) + 6), | |
2920 | *(((uint32_t *) irsp) + 7)); | |
2921 | } | |
2922 | ||
ed957684 | 2923 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
dea3101e | 2924 | |
3772a991 JS |
2925 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2926 | /* Handle the response IOCB */ | |
2927 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); | |
2928 | spin_lock_irqsave(&phba->hbalock, iflag); | |
dea3101e JB |
2929 | |
2930 | /* | |
2931 | * If the port response put pointer has not been updated, sync | |
2932 | * the pgp->rspPutInx in the MAILBOX_tand fetch the new port | |
2933 | * response put pointer. | |
2934 | */ | |
2935 | if (pring->rspidx == portRspPut) { | |
2936 | portRspPut = le32_to_cpu(pgp->rspPutInx); | |
2937 | } | |
2938 | } /* while (pring->rspidx != portRspPut) */ | |
2939 | ||
92d7f7b0 | 2940 | if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) { |
dea3101e JB |
2941 | /* At least one response entry has been freed */ |
2942 | pring->stats.iocb_rsp_full++; | |
2943 | /* SET RxRE_RSP in Chip Att register */ | |
2944 | status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4)); | |
2945 | writel(status, phba->CAregaddr); | |
2946 | readl(phba->CAregaddr); /* flush */ | |
2947 | } | |
2948 | if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) { | |
2949 | pring->flag &= ~LPFC_CALL_RING_AVAILABLE; | |
2950 | pring->stats.iocb_cmd_empty++; | |
2951 | ||
2952 | /* Force update of the local copy of cmdGetInx */ | |
2953 | pring->local_getidx = le32_to_cpu(pgp->cmdGetInx); | |
2954 | lpfc_sli_resume_iocb(phba, pring); | |
2955 | ||
2956 | if ((pring->lpfc_sli_cmd_available)) | |
2957 | (pring->lpfc_sli_cmd_available) (phba, pring); | |
2958 | ||
2959 | } | |
2960 | ||
2e0fef85 | 2961 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
3772a991 | 2962 | return; |
dea3101e JB |
2963 | } |
2964 | ||
4f774513 JS |
2965 | /** |
2966 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | |
2967 | * @phba: Pointer to HBA context object. | |
2968 | * @pring: Pointer to driver SLI ring object. | |
2969 | * @mask: Host attention register mask for this ring. | |
2970 | * | |
2971 | * This function is called from the worker thread when there is a pending | |
2972 | * ELS response iocb on the driver internal slow-path response iocb worker | |
2973 | * queue. The caller does not hold any lock. The function will remove each | |
2974 | * response iocb from the response worker queue and calls the handle | |
2975 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | |
2976 | **/ | |
2977 | static void | |
2978 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | |
2979 | struct lpfc_sli_ring *pring, uint32_t mask) | |
2980 | { | |
2981 | struct lpfc_iocbq *irspiocbq; | |
4d9ab994 JS |
2982 | struct hbq_dmabuf *dmabuf; |
2983 | struct lpfc_cq_event *cq_event; | |
4f774513 JS |
2984 | unsigned long iflag; |
2985 | ||
45ed1190 JS |
2986 | spin_lock_irqsave(&phba->hbalock, iflag); |
2987 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
2988 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
2989 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
4f774513 JS |
2990 | /* Get the response iocb from the head of work queue */ |
2991 | spin_lock_irqsave(&phba->hbalock, iflag); | |
45ed1190 | 2992 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
4d9ab994 | 2993 | cq_event, struct lpfc_cq_event, list); |
4f774513 | 2994 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
4d9ab994 JS |
2995 | |
2996 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
2997 | case CQE_CODE_COMPL_WQE: | |
2998 | irspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
2999 | cq_event); | |
45ed1190 JS |
3000 | /* Translate ELS WCQE to response IOCBQ */ |
3001 | irspiocbq = lpfc_sli4_els_wcqe_to_rspiocbq(phba, | |
3002 | irspiocbq); | |
3003 | if (irspiocbq) | |
3004 | lpfc_sli_sp_handle_rspiocb(phba, pring, | |
3005 | irspiocbq); | |
4d9ab994 JS |
3006 | break; |
3007 | case CQE_CODE_RECEIVE: | |
3008 | dmabuf = container_of(cq_event, struct hbq_dmabuf, | |
3009 | cq_event); | |
3010 | lpfc_sli4_handle_received_buffer(phba, dmabuf); | |
3011 | break; | |
3012 | default: | |
3013 | break; | |
3014 | } | |
4f774513 JS |
3015 | } |
3016 | } | |
3017 | ||
e59058c4 | 3018 | /** |
3621a710 | 3019 | * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring |
e59058c4 JS |
3020 | * @phba: Pointer to HBA context object. |
3021 | * @pring: Pointer to driver SLI ring object. | |
3022 | * | |
3023 | * This function aborts all iocbs in the given ring and frees all the iocb | |
3024 | * objects in txq. This function issues an abort iocb for all the iocb commands | |
3025 | * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before | |
3026 | * the return of this function. The caller is not required to hold any locks. | |
3027 | **/ | |
2e0fef85 | 3028 | void |
dea3101e JB |
3029 | lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) |
3030 | { | |
2534ba75 | 3031 | LIST_HEAD(completions); |
dea3101e | 3032 | struct lpfc_iocbq *iocb, *next_iocb; |
dea3101e | 3033 | |
92d7f7b0 JS |
3034 | if (pring->ringno == LPFC_ELS_RING) { |
3035 | lpfc_fabric_abort_hba(phba); | |
3036 | } | |
3037 | ||
dea3101e JB |
3038 | /* Error everything on txq and txcmplq |
3039 | * First do the txq. | |
3040 | */ | |
2e0fef85 | 3041 | spin_lock_irq(&phba->hbalock); |
2534ba75 | 3042 | list_splice_init(&pring->txq, &completions); |
dea3101e | 3043 | pring->txq_cnt = 0; |
dea3101e JB |
3044 | |
3045 | /* Next issue ABTS for everything on the txcmplq */ | |
2534ba75 JS |
3046 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) |
3047 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
dea3101e | 3048 | |
2e0fef85 | 3049 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 3050 | |
a257bf90 JS |
3051 | /* Cancel all the IOCBs from the completions list */ |
3052 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
3053 | IOERR_SLI_ABORTED); | |
dea3101e JB |
3054 | } |
3055 | ||
a8e497d5 | 3056 | /** |
3621a710 | 3057 | * lpfc_sli_flush_fcp_rings - flush all iocbs in the fcp ring |
a8e497d5 JS |
3058 | * @phba: Pointer to HBA context object. |
3059 | * | |
3060 | * This function flushes all iocbs in the fcp ring and frees all the iocb | |
3061 | * objects in txq and txcmplq. This function will not issue abort iocbs | |
3062 | * for all the iocb commands in txcmplq, they will just be returned with | |
3063 | * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI | |
3064 | * slot has been permanently disabled. | |
3065 | **/ | |
3066 | void | |
3067 | lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |
3068 | { | |
3069 | LIST_HEAD(txq); | |
3070 | LIST_HEAD(txcmplq); | |
a8e497d5 JS |
3071 | struct lpfc_sli *psli = &phba->sli; |
3072 | struct lpfc_sli_ring *pring; | |
3073 | ||
3074 | /* Currently, only one fcp ring */ | |
3075 | pring = &psli->ring[psli->fcp_ring]; | |
3076 | ||
3077 | spin_lock_irq(&phba->hbalock); | |
3078 | /* Retrieve everything on txq */ | |
3079 | list_splice_init(&pring->txq, &txq); | |
3080 | pring->txq_cnt = 0; | |
3081 | ||
3082 | /* Retrieve everything on the txcmplq */ | |
3083 | list_splice_init(&pring->txcmplq, &txcmplq); | |
3084 | pring->txcmplq_cnt = 0; | |
3085 | spin_unlock_irq(&phba->hbalock); | |
3086 | ||
3087 | /* Flush the txq */ | |
a257bf90 JS |
3088 | lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT, |
3089 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3090 | |
3091 | /* Flush the txcmpq */ | |
a257bf90 JS |
3092 | lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT, |
3093 | IOERR_SLI_DOWN); | |
a8e497d5 JS |
3094 | } |
3095 | ||
e59058c4 | 3096 | /** |
3772a991 | 3097 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
e59058c4 JS |
3098 | * @phba: Pointer to HBA context object. |
3099 | * @mask: Bit mask to be checked. | |
3100 | * | |
3101 | * This function reads the host status register and compares | |
3102 | * with the provided bit mask to check if HBA completed | |
3103 | * the restart. This function will wait in a loop for the | |
3104 | * HBA to complete restart. If the HBA does not restart within | |
3105 | * 15 iterations, the function will reset the HBA again. The | |
3106 | * function returns 1 when HBA fail to restart otherwise returns | |
3107 | * zero. | |
3108 | **/ | |
3772a991 JS |
3109 | static int |
3110 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) | |
dea3101e | 3111 | { |
41415862 JW |
3112 | uint32_t status; |
3113 | int i = 0; | |
3114 | int retval = 0; | |
dea3101e | 3115 | |
41415862 JW |
3116 | /* Read the HBA Host Status Register */ |
3117 | status = readl(phba->HSregaddr); | |
dea3101e | 3118 | |
41415862 JW |
3119 | /* |
3120 | * Check status register every 100ms for 5 retries, then every | |
3121 | * 500ms for 5, then every 2.5 sec for 5, then reset board and | |
3122 | * every 2.5 sec for 4. | |
3123 | * Break our of the loop if errors occurred during init. | |
3124 | */ | |
3125 | while (((status & mask) != mask) && | |
3126 | !(status & HS_FFERM) && | |
3127 | i++ < 20) { | |
dea3101e | 3128 | |
41415862 JW |
3129 | if (i <= 5) |
3130 | msleep(10); | |
3131 | else if (i <= 10) | |
3132 | msleep(500); | |
3133 | else | |
3134 | msleep(2500); | |
dea3101e | 3135 | |
41415862 | 3136 | if (i == 15) { |
2e0fef85 | 3137 | /* Do post */ |
92d7f7b0 | 3138 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 JW |
3139 | lpfc_sli_brdrestart(phba); |
3140 | } | |
3141 | /* Read the HBA Host Status Register */ | |
3142 | status = readl(phba->HSregaddr); | |
3143 | } | |
dea3101e | 3144 | |
41415862 JW |
3145 | /* Check to see if any errors occurred during init */ |
3146 | if ((status & HS_FFERM) || (i >= 20)) { | |
e40a02c1 JS |
3147 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3148 | "2751 Adapter failed to restart, " | |
3149 | "status reg x%x, FW Data: A8 x%x AC x%x\n", | |
3150 | status, | |
3151 | readl(phba->MBslimaddr + 0xa8), | |
3152 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3153 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3154 | retval = 1; |
dea3101e | 3155 | } |
dea3101e | 3156 | |
41415862 JW |
3157 | return retval; |
3158 | } | |
dea3101e | 3159 | |
da0436e9 JS |
3160 | /** |
3161 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | |
3162 | * @phba: Pointer to HBA context object. | |
3163 | * @mask: Bit mask to be checked. | |
3164 | * | |
3165 | * This function checks the host status register to check if HBA is | |
3166 | * ready. This function will wait in a loop for the HBA to be ready | |
3167 | * If the HBA is not ready , the function will will reset the HBA PCI | |
3168 | * function again. The function returns 1 when HBA fail to be ready | |
3169 | * otherwise returns zero. | |
3170 | **/ | |
3171 | static int | |
3172 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | |
3173 | { | |
3174 | uint32_t status; | |
3175 | int retval = 0; | |
3176 | ||
3177 | /* Read the HBA Host Status Register */ | |
3178 | status = lpfc_sli4_post_status_check(phba); | |
3179 | ||
3180 | if (status) { | |
3181 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | |
3182 | lpfc_sli_brdrestart(phba); | |
3183 | status = lpfc_sli4_post_status_check(phba); | |
3184 | } | |
3185 | ||
3186 | /* Check to see if any errors occurred during init */ | |
3187 | if (status) { | |
3188 | phba->link_state = LPFC_HBA_ERROR; | |
3189 | retval = 1; | |
3190 | } else | |
3191 | phba->sli4_hba.intr_enable = 0; | |
3192 | ||
3193 | return retval; | |
3194 | } | |
3195 | ||
3196 | /** | |
3197 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | |
3198 | * @phba: Pointer to HBA context object. | |
3199 | * @mask: Bit mask to be checked. | |
3200 | * | |
3201 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | |
3202 | * from the API jump table function pointer from the lpfc_hba struct. | |
3203 | **/ | |
3204 | int | |
3205 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |
3206 | { | |
3207 | return phba->lpfc_sli_brdready(phba, mask); | |
3208 | } | |
3209 | ||
9290831f JS |
3210 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
3211 | ||
e59058c4 | 3212 | /** |
3621a710 | 3213 | * lpfc_reset_barrier - Make HBA ready for HBA reset |
e59058c4 JS |
3214 | * @phba: Pointer to HBA context object. |
3215 | * | |
3216 | * This function is called before resetting an HBA. This | |
3217 | * function requests HBA to quiesce DMAs before a reset. | |
3218 | **/ | |
2e0fef85 | 3219 | void lpfc_reset_barrier(struct lpfc_hba *phba) |
9290831f | 3220 | { |
65a29c16 JS |
3221 | uint32_t __iomem *resp_buf; |
3222 | uint32_t __iomem *mbox_buf; | |
9290831f JS |
3223 | volatile uint32_t mbox; |
3224 | uint32_t hc_copy; | |
3225 | int i; | |
3226 | uint8_t hdrtype; | |
3227 | ||
3228 | pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype); | |
3229 | if (hdrtype != 0x80 || | |
3230 | (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID && | |
3231 | FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID)) | |
3232 | return; | |
3233 | ||
3234 | /* | |
3235 | * Tell the other part of the chip to suspend temporarily all | |
3236 | * its DMA activity. | |
3237 | */ | |
65a29c16 | 3238 | resp_buf = phba->MBslimaddr; |
9290831f JS |
3239 | |
3240 | /* Disable the error attention */ | |
3241 | hc_copy = readl(phba->HCregaddr); | |
3242 | writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); | |
3243 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 3244 | phba->link_flag |= LS_IGNORE_ERATT; |
9290831f JS |
3245 | |
3246 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3247 | /* Clear Chip error bit */ | |
3248 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3249 | phba->pport->stopped = 1; |
9290831f JS |
3250 | } |
3251 | ||
3252 | mbox = 0; | |
3253 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; | |
3254 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; | |
3255 | ||
3256 | writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); | |
65a29c16 | 3257 | mbox_buf = phba->MBslimaddr; |
9290831f JS |
3258 | writel(mbox, mbox_buf); |
3259 | ||
3260 | for (i = 0; | |
3261 | readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++) | |
3262 | mdelay(1); | |
3263 | ||
3264 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { | |
f4b4c68f | 3265 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2e0fef85 | 3266 | phba->pport->stopped) |
9290831f JS |
3267 | goto restore_hc; |
3268 | else | |
3269 | goto clear_errat; | |
3270 | } | |
3271 | ||
3272 | ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; | |
3273 | for (i = 0; readl(resp_buf) != mbox && i < 500; i++) | |
3274 | mdelay(1); | |
3275 | ||
3276 | clear_errat: | |
3277 | ||
3278 | while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500) | |
3279 | mdelay(1); | |
3280 | ||
3281 | if (readl(phba->HAregaddr) & HA_ERATT) { | |
3282 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3283 | phba->pport->stopped = 1; |
9290831f JS |
3284 | } |
3285 | ||
3286 | restore_hc: | |
2e0fef85 | 3287 | phba->link_flag &= ~LS_IGNORE_ERATT; |
9290831f JS |
3288 | writel(hc_copy, phba->HCregaddr); |
3289 | readl(phba->HCregaddr); /* flush */ | |
3290 | } | |
3291 | ||
e59058c4 | 3292 | /** |
3621a710 | 3293 | * lpfc_sli_brdkill - Issue a kill_board mailbox command |
e59058c4 JS |
3294 | * @phba: Pointer to HBA context object. |
3295 | * | |
3296 | * This function issues a kill_board mailbox command and waits for | |
3297 | * the error attention interrupt. This function is called for stopping | |
3298 | * the firmware processing. The caller is not required to hold any | |
3299 | * locks. This function calls lpfc_hba_down_post function to free | |
3300 | * any pending commands after the kill. The function will return 1 when it | |
3301 | * fails to kill the board else will return 0. | |
3302 | **/ | |
41415862 | 3303 | int |
2e0fef85 | 3304 | lpfc_sli_brdkill(struct lpfc_hba *phba) |
41415862 JW |
3305 | { |
3306 | struct lpfc_sli *psli; | |
3307 | LPFC_MBOXQ_t *pmb; | |
3308 | uint32_t status; | |
3309 | uint32_t ha_copy; | |
3310 | int retval; | |
3311 | int i = 0; | |
dea3101e | 3312 | |
41415862 | 3313 | psli = &phba->sli; |
dea3101e | 3314 | |
41415862 | 3315 | /* Kill HBA */ |
ed957684 | 3316 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
e8b62011 JS |
3317 | "0329 Kill HBA Data: x%x x%x\n", |
3318 | phba->pport->port_state, psli->sli_flag); | |
41415862 | 3319 | |
98c9ea5c JS |
3320 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3321 | if (!pmb) | |
41415862 | 3322 | return 1; |
41415862 JW |
3323 | |
3324 | /* Disable the error attention */ | |
2e0fef85 | 3325 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
3326 | status = readl(phba->HCregaddr); |
3327 | status &= ~HC_ERINT_ENA; | |
3328 | writel(status, phba->HCregaddr); | |
3329 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 JS |
3330 | phba->link_flag |= LS_IGNORE_ERATT; |
3331 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3332 | |
3333 | lpfc_kill_board(phba, pmb); | |
3334 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
3335 | retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3336 | ||
3337 | if (retval != MBX_SUCCESS) { | |
3338 | if (retval != MBX_BUSY) | |
3339 | mempool_free(pmb, phba->mbox_mem_pool); | |
e40a02c1 JS |
3340 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3341 | "2752 KILL_BOARD command failed retval %d\n", | |
3342 | retval); | |
2e0fef85 JS |
3343 | spin_lock_irq(&phba->hbalock); |
3344 | phba->link_flag &= ~LS_IGNORE_ERATT; | |
3345 | spin_unlock_irq(&phba->hbalock); | |
41415862 JW |
3346 | return 1; |
3347 | } | |
3348 | ||
f4b4c68f JS |
3349 | spin_lock_irq(&phba->hbalock); |
3350 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
3351 | spin_unlock_irq(&phba->hbalock); | |
9290831f | 3352 | |
41415862 JW |
3353 | mempool_free(pmb, phba->mbox_mem_pool); |
3354 | ||
3355 | /* There is no completion for a KILL_BOARD mbox cmd. Check for an error | |
3356 | * attention every 100ms for 3 seconds. If we don't get ERATT after | |
3357 | * 3 seconds we still set HBA_ERROR state because the status of the | |
3358 | * board is now undefined. | |
3359 | */ | |
3360 | ha_copy = readl(phba->HAregaddr); | |
3361 | ||
3362 | while ((i++ < 30) && !(ha_copy & HA_ERATT)) { | |
3363 | mdelay(100); | |
3364 | ha_copy = readl(phba->HAregaddr); | |
3365 | } | |
3366 | ||
3367 | del_timer_sync(&psli->mbox_tmo); | |
9290831f JS |
3368 | if (ha_copy & HA_ERATT) { |
3369 | writel(HA_ERATT, phba->HAregaddr); | |
2e0fef85 | 3370 | phba->pport->stopped = 1; |
9290831f | 3371 | } |
2e0fef85 | 3372 | spin_lock_irq(&phba->hbalock); |
41415862 | 3373 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
04c68496 | 3374 | psli->mbox_active = NULL; |
2e0fef85 JS |
3375 | phba->link_flag &= ~LS_IGNORE_ERATT; |
3376 | spin_unlock_irq(&phba->hbalock); | |
41415862 | 3377 | |
41415862 | 3378 | lpfc_hba_down_post(phba); |
2e0fef85 | 3379 | phba->link_state = LPFC_HBA_ERROR; |
41415862 | 3380 | |
2e0fef85 | 3381 | return ha_copy & HA_ERATT ? 0 : 1; |
dea3101e JB |
3382 | } |
3383 | ||
e59058c4 | 3384 | /** |
3772a991 | 3385 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
e59058c4 JS |
3386 | * @phba: Pointer to HBA context object. |
3387 | * | |
3388 | * This function resets the HBA by writing HC_INITFF to the control | |
3389 | * register. After the HBA resets, this function resets all the iocb ring | |
3390 | * indices. This function disables PCI layer parity checking during | |
3391 | * the reset. | |
3392 | * This function returns 0 always. | |
3393 | * The caller is not required to hold any locks. | |
3394 | **/ | |
41415862 | 3395 | int |
2e0fef85 | 3396 | lpfc_sli_brdreset(struct lpfc_hba *phba) |
dea3101e | 3397 | { |
41415862 | 3398 | struct lpfc_sli *psli; |
dea3101e | 3399 | struct lpfc_sli_ring *pring; |
41415862 | 3400 | uint16_t cfg_value; |
dea3101e | 3401 | int i; |
dea3101e | 3402 | |
41415862 | 3403 | psli = &phba->sli; |
dea3101e | 3404 | |
41415862 JW |
3405 | /* Reset HBA */ |
3406 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3407 | "0325 Reset HBA Data: x%x x%x\n", |
2e0fef85 | 3408 | phba->pport->port_state, psli->sli_flag); |
dea3101e JB |
3409 | |
3410 | /* perform board reset */ | |
3411 | phba->fc_eventTag = 0; | |
4d9ab994 | 3412 | phba->link_events = 0; |
2e0fef85 JS |
3413 | phba->pport->fc_myDID = 0; |
3414 | phba->pport->fc_prevDID = 0; | |
dea3101e | 3415 | |
41415862 JW |
3416 | /* Turn off parity checking and serr during the physical reset */ |
3417 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3418 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3419 | (cfg_value & | |
3420 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3421 | ||
3772a991 JS |
3422 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3423 | ||
41415862 JW |
3424 | /* Now toggle INITFF bit in the Host Control Register */ |
3425 | writel(HC_INITFF, phba->HCregaddr); | |
3426 | mdelay(1); | |
3427 | readl(phba->HCregaddr); /* flush */ | |
3428 | writel(0, phba->HCregaddr); | |
3429 | readl(phba->HCregaddr); /* flush */ | |
3430 | ||
3431 | /* Restore PCI cmd register */ | |
3432 | pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value); | |
dea3101e JB |
3433 | |
3434 | /* Initialize relevant SLI info */ | |
41415862 JW |
3435 | for (i = 0; i < psli->num_rings; i++) { |
3436 | pring = &psli->ring[i]; | |
dea3101e JB |
3437 | pring->flag = 0; |
3438 | pring->rspidx = 0; | |
3439 | pring->next_cmdidx = 0; | |
3440 | pring->local_getidx = 0; | |
3441 | pring->cmdidx = 0; | |
3442 | pring->missbufcnt = 0; | |
3443 | } | |
dea3101e | 3444 | |
2e0fef85 | 3445 | phba->link_state = LPFC_WARM_START; |
41415862 JW |
3446 | return 0; |
3447 | } | |
3448 | ||
e59058c4 | 3449 | /** |
da0436e9 JS |
3450 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3451 | * @phba: Pointer to HBA context object. | |
3452 | * | |
3453 | * This function resets a SLI4 HBA. This function disables PCI layer parity | |
3454 | * checking during resets the device. The caller is not required to hold | |
3455 | * any locks. | |
3456 | * | |
3457 | * This function returns 0 always. | |
3458 | **/ | |
3459 | int | |
3460 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | |
3461 | { | |
3462 | struct lpfc_sli *psli = &phba->sli; | |
3463 | uint16_t cfg_value; | |
3464 | uint8_t qindx; | |
3465 | ||
3466 | /* Reset HBA */ | |
3467 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3468 | "0295 Reset HBA Data: x%x x%x\n", | |
3469 | phba->pport->port_state, psli->sli_flag); | |
3470 | ||
3471 | /* perform board reset */ | |
3472 | phba->fc_eventTag = 0; | |
4d9ab994 | 3473 | phba->link_events = 0; |
da0436e9 JS |
3474 | phba->pport->fc_myDID = 0; |
3475 | phba->pport->fc_prevDID = 0; | |
3476 | ||
3477 | /* Turn off parity checking and serr during the physical reset */ | |
3478 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | |
3479 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | |
3480 | (cfg_value & | |
3481 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | |
3482 | ||
3483 | spin_lock_irq(&phba->hbalock); | |
3484 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | |
3485 | phba->fcf.fcf_flag = 0; | |
3486 | /* Clean up the child queue list for the CQs */ | |
3487 | list_del_init(&phba->sli4_hba.mbx_wq->list); | |
3488 | list_del_init(&phba->sli4_hba.els_wq->list); | |
3489 | list_del_init(&phba->sli4_hba.hdr_rq->list); | |
3490 | list_del_init(&phba->sli4_hba.dat_rq->list); | |
3491 | list_del_init(&phba->sli4_hba.mbx_cq->list); | |
3492 | list_del_init(&phba->sli4_hba.els_cq->list); | |
da0436e9 JS |
3493 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) |
3494 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | |
3495 | for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++) | |
3496 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); | |
3497 | spin_unlock_irq(&phba->hbalock); | |
3498 | ||
3499 | /* Now physically reset the device */ | |
3500 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3501 | "0389 Performing PCI function reset!\n"); | |
3502 | /* Perform FCoE PCI function reset */ | |
3503 | lpfc_pci_function_reset(phba); | |
3504 | ||
3505 | return 0; | |
3506 | } | |
3507 | ||
3508 | /** | |
3509 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | |
e59058c4 JS |
3510 | * @phba: Pointer to HBA context object. |
3511 | * | |
3512 | * This function is called in the SLI initialization code path to | |
3513 | * restart the HBA. The caller is not required to hold any lock. | |
3514 | * This function writes MBX_RESTART mailbox command to the SLIM and | |
3515 | * resets the HBA. At the end of the function, it calls lpfc_hba_down_post | |
3516 | * function to free any pending commands. The function enables | |
3517 | * POST only during the first initialization. The function returns zero. | |
3518 | * The function does not guarantee completion of MBX_RESTART mailbox | |
3519 | * command before the return of this function. | |
3520 | **/ | |
da0436e9 JS |
3521 | static int |
3522 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) | |
41415862 JW |
3523 | { |
3524 | MAILBOX_t *mb; | |
3525 | struct lpfc_sli *psli; | |
41415862 JW |
3526 | volatile uint32_t word0; |
3527 | void __iomem *to_slim; | |
0d878419 | 3528 | uint32_t hba_aer_enabled; |
41415862 | 3529 | |
2e0fef85 | 3530 | spin_lock_irq(&phba->hbalock); |
41415862 | 3531 | |
0d878419 JS |
3532 | /* Take PCIe device Advanced Error Reporting (AER) state */ |
3533 | hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED; | |
3534 | ||
41415862 JW |
3535 | psli = &phba->sli; |
3536 | ||
3537 | /* Restart HBA */ | |
3538 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 3539 | "0337 Restart HBA Data: x%x x%x\n", |
2e0fef85 | 3540 | phba->pport->port_state, psli->sli_flag); |
41415862 JW |
3541 | |
3542 | word0 = 0; | |
3543 | mb = (MAILBOX_t *) &word0; | |
3544 | mb->mbxCommand = MBX_RESTART; | |
3545 | mb->mbxHc = 1; | |
3546 | ||
9290831f JS |
3547 | lpfc_reset_barrier(phba); |
3548 | ||
41415862 JW |
3549 | to_slim = phba->MBslimaddr; |
3550 | writel(*(uint32_t *) mb, to_slim); | |
3551 | readl(to_slim); /* flush */ | |
3552 | ||
3553 | /* Only skip post after fc_ffinit is completed */ | |
eaf15d5b | 3554 | if (phba->pport->port_state) |
41415862 | 3555 | word0 = 1; /* This is really setting up word1 */ |
eaf15d5b | 3556 | else |
41415862 | 3557 | word0 = 0; /* This is really setting up word1 */ |
65a29c16 | 3558 | to_slim = phba->MBslimaddr + sizeof (uint32_t); |
41415862 JW |
3559 | writel(*(uint32_t *) mb, to_slim); |
3560 | readl(to_slim); /* flush */ | |
dea3101e | 3561 | |
41415862 | 3562 | lpfc_sli_brdreset(phba); |
2e0fef85 JS |
3563 | phba->pport->stopped = 0; |
3564 | phba->link_state = LPFC_INIT_START; | |
da0436e9 | 3565 | phba->hba_flag = 0; |
2e0fef85 | 3566 | spin_unlock_irq(&phba->hbalock); |
41415862 | 3567 | |
64ba8818 JS |
3568 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
3569 | psli->stats_start = get_seconds(); | |
3570 | ||
eaf15d5b JS |
3571 | /* Give the INITFF and Post time to settle. */ |
3572 | mdelay(100); | |
41415862 | 3573 | |
0d878419 JS |
3574 | /* Reset HBA AER if it was enabled, note hba_flag was reset above */ |
3575 | if (hba_aer_enabled) | |
3576 | pci_disable_pcie_error_reporting(phba->pcidev); | |
3577 | ||
41415862 | 3578 | lpfc_hba_down_post(phba); |
dea3101e JB |
3579 | |
3580 | return 0; | |
3581 | } | |
3582 | ||
da0436e9 JS |
3583 | /** |
3584 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | |
3585 | * @phba: Pointer to HBA context object. | |
3586 | * | |
3587 | * This function is called in the SLI initialization code path to restart | |
3588 | * a SLI4 HBA. The caller is not required to hold any lock. | |
3589 | * At the end of the function, it calls lpfc_hba_down_post function to | |
3590 | * free any pending commands. | |
3591 | **/ | |
3592 | static int | |
3593 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | |
3594 | { | |
3595 | struct lpfc_sli *psli = &phba->sli; | |
3596 | ||
3597 | ||
3598 | /* Restart HBA */ | |
3599 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3600 | "0296 Restart HBA Data: x%x x%x\n", | |
3601 | phba->pport->port_state, psli->sli_flag); | |
3602 | ||
3603 | lpfc_sli4_brdreset(phba); | |
3604 | ||
3605 | spin_lock_irq(&phba->hbalock); | |
3606 | phba->pport->stopped = 0; | |
3607 | phba->link_state = LPFC_INIT_START; | |
3608 | phba->hba_flag = 0; | |
3609 | spin_unlock_irq(&phba->hbalock); | |
3610 | ||
3611 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | |
3612 | psli->stats_start = get_seconds(); | |
3613 | ||
3614 | lpfc_hba_down_post(phba); | |
3615 | ||
3616 | return 0; | |
3617 | } | |
3618 | ||
3619 | /** | |
3620 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | |
3621 | * @phba: Pointer to HBA context object. | |
3622 | * | |
3623 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | |
3624 | * API jump table function pointer from the lpfc_hba struct. | |
3625 | **/ | |
3626 | int | |
3627 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | |
3628 | { | |
3629 | return phba->lpfc_sli_brdrestart(phba); | |
3630 | } | |
3631 | ||
e59058c4 | 3632 | /** |
3621a710 | 3633 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
e59058c4 JS |
3634 | * @phba: Pointer to HBA context object. |
3635 | * | |
3636 | * This function is called after a HBA restart to wait for successful | |
3637 | * restart of the HBA. Successful restart of the HBA is indicated by | |
3638 | * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15 | |
3639 | * iteration, the function will restart the HBA again. The function returns | |
3640 | * zero if HBA successfully restarted else returns negative error code. | |
3641 | **/ | |
dea3101e JB |
3642 | static int |
3643 | lpfc_sli_chipset_init(struct lpfc_hba *phba) | |
3644 | { | |
3645 | uint32_t status, i = 0; | |
3646 | ||
3647 | /* Read the HBA Host Status Register */ | |
3648 | status = readl(phba->HSregaddr); | |
3649 | ||
3650 | /* Check status register to see what current state is */ | |
3651 | i = 0; | |
3652 | while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) { | |
3653 | ||
3654 | /* Check every 100ms for 5 retries, then every 500ms for 5, then | |
3655 | * every 2.5 sec for 5, then reset board and every 2.5 sec for | |
3656 | * 4. | |
3657 | */ | |
3658 | if (i++ >= 20) { | |
3659 | /* Adapter failed to init, timeout, status reg | |
3660 | <status> */ | |
ed957684 | 3661 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 3662 | "0436 Adapter failed to init, " |
09372820 JS |
3663 | "timeout, status reg x%x, " |
3664 | "FW Data: A8 x%x AC x%x\n", status, | |
3665 | readl(phba->MBslimaddr + 0xa8), | |
3666 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3667 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
3668 | return -ETIMEDOUT; |
3669 | } | |
3670 | ||
3671 | /* Check to see if any errors occurred during init */ | |
3672 | if (status & HS_FFERM) { | |
3673 | /* ERROR: During chipset initialization */ | |
3674 | /* Adapter failed to init, chipset, status reg | |
3675 | <status> */ | |
ed957684 | 3676 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 3677 | "0437 Adapter failed to init, " |
09372820 JS |
3678 | "chipset, status reg x%x, " |
3679 | "FW Data: A8 x%x AC x%x\n", status, | |
3680 | readl(phba->MBslimaddr + 0xa8), | |
3681 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3682 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
3683 | return -EIO; |
3684 | } | |
3685 | ||
3686 | if (i <= 5) { | |
3687 | msleep(10); | |
3688 | } else if (i <= 10) { | |
3689 | msleep(500); | |
3690 | } else { | |
3691 | msleep(2500); | |
3692 | } | |
3693 | ||
3694 | if (i == 15) { | |
2e0fef85 | 3695 | /* Do post */ |
92d7f7b0 | 3696 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 3697 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
3698 | } |
3699 | /* Read the HBA Host Status Register */ | |
3700 | status = readl(phba->HSregaddr); | |
3701 | } | |
3702 | ||
3703 | /* Check to see if any errors occurred during init */ | |
3704 | if (status & HS_FFERM) { | |
3705 | /* ERROR: During chipset initialization */ | |
3706 | /* Adapter failed to init, chipset, status reg <status> */ | |
ed957684 | 3707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 3708 | "0438 Adapter failed to init, chipset, " |
09372820 JS |
3709 | "status reg x%x, " |
3710 | "FW Data: A8 x%x AC x%x\n", status, | |
3711 | readl(phba->MBslimaddr + 0xa8), | |
3712 | readl(phba->MBslimaddr + 0xac)); | |
2e0fef85 | 3713 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
3714 | return -EIO; |
3715 | } | |
3716 | ||
3717 | /* Clear all interrupt enable conditions */ | |
3718 | writel(0, phba->HCregaddr); | |
3719 | readl(phba->HCregaddr); /* flush */ | |
3720 | ||
3721 | /* setup host attn register */ | |
3722 | writel(0xffffffff, phba->HAregaddr); | |
3723 | readl(phba->HAregaddr); /* flush */ | |
3724 | return 0; | |
3725 | } | |
3726 | ||
e59058c4 | 3727 | /** |
3621a710 | 3728 | * lpfc_sli_hbq_count - Get the number of HBQs to be configured |
e59058c4 JS |
3729 | * |
3730 | * This function calculates and returns the number of HBQs required to be | |
3731 | * configured. | |
3732 | **/ | |
78b2d852 | 3733 | int |
ed957684 JS |
3734 | lpfc_sli_hbq_count(void) |
3735 | { | |
92d7f7b0 | 3736 | return ARRAY_SIZE(lpfc_hbq_defs); |
ed957684 JS |
3737 | } |
3738 | ||
e59058c4 | 3739 | /** |
3621a710 | 3740 | * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries |
e59058c4 JS |
3741 | * |
3742 | * This function adds the number of hbq entries in every HBQ to get | |
3743 | * the total number of hbq entries required for the HBA and returns | |
3744 | * the total count. | |
3745 | **/ | |
ed957684 JS |
3746 | static int |
3747 | lpfc_sli_hbq_entry_count(void) | |
3748 | { | |
3749 | int hbq_count = lpfc_sli_hbq_count(); | |
3750 | int count = 0; | |
3751 | int i; | |
3752 | ||
3753 | for (i = 0; i < hbq_count; ++i) | |
92d7f7b0 | 3754 | count += lpfc_hbq_defs[i]->entry_count; |
ed957684 JS |
3755 | return count; |
3756 | } | |
3757 | ||
e59058c4 | 3758 | /** |
3621a710 | 3759 | * lpfc_sli_hbq_size - Calculate memory required for all hbq entries |
e59058c4 JS |
3760 | * |
3761 | * This function calculates amount of memory required for all hbq entries | |
3762 | * to be configured and returns the total memory required. | |
3763 | **/ | |
dea3101e | 3764 | int |
ed957684 JS |
3765 | lpfc_sli_hbq_size(void) |
3766 | { | |
3767 | return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); | |
3768 | } | |
3769 | ||
e59058c4 | 3770 | /** |
3621a710 | 3771 | * lpfc_sli_hbq_setup - configure and initialize HBQs |
e59058c4 JS |
3772 | * @phba: Pointer to HBA context object. |
3773 | * | |
3774 | * This function is called during the SLI initialization to configure | |
3775 | * all the HBQs and post buffers to the HBQ. The caller is not | |
3776 | * required to hold any locks. This function will return zero if successful | |
3777 | * else it will return negative error code. | |
3778 | **/ | |
ed957684 JS |
3779 | static int |
3780 | lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |
3781 | { | |
3782 | int hbq_count = lpfc_sli_hbq_count(); | |
3783 | LPFC_MBOXQ_t *pmb; | |
3784 | MAILBOX_t *pmbox; | |
3785 | uint32_t hbqno; | |
3786 | uint32_t hbq_entry_index; | |
ed957684 | 3787 | |
92d7f7b0 JS |
3788 | /* Get a Mailbox buffer to setup mailbox |
3789 | * commands for HBA initialization | |
3790 | */ | |
ed957684 JS |
3791 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3792 | ||
3793 | if (!pmb) | |
3794 | return -ENOMEM; | |
3795 | ||
04c68496 | 3796 | pmbox = &pmb->u.mb; |
ed957684 JS |
3797 | |
3798 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | |
3799 | phba->link_state = LPFC_INIT_MBX_CMDS; | |
3163f725 | 3800 | phba->hbq_in_use = 1; |
ed957684 JS |
3801 | |
3802 | hbq_entry_index = 0; | |
3803 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) { | |
3804 | phba->hbqs[hbqno].next_hbqPutIdx = 0; | |
3805 | phba->hbqs[hbqno].hbqPutIdx = 0; | |
3806 | phba->hbqs[hbqno].local_hbqGetIdx = 0; | |
3807 | phba->hbqs[hbqno].entry_count = | |
92d7f7b0 | 3808 | lpfc_hbq_defs[hbqno]->entry_count; |
51ef4c26 JS |
3809 | lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno], |
3810 | hbq_entry_index, pmb); | |
ed957684 JS |
3811 | hbq_entry_index += phba->hbqs[hbqno].entry_count; |
3812 | ||
3813 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { | |
3814 | /* Adapter failed to init, mbxCmd <cmd> CFG_RING, | |
3815 | mbxStatus <status>, ring <num> */ | |
3816 | ||
3817 | lpfc_printf_log(phba, KERN_ERR, | |
92d7f7b0 | 3818 | LOG_SLI | LOG_VPORT, |
e8b62011 | 3819 | "1805 Adapter failed to init. " |
ed957684 | 3820 | "Data: x%x x%x x%x\n", |
e8b62011 | 3821 | pmbox->mbxCommand, |
ed957684 JS |
3822 | pmbox->mbxStatus, hbqno); |
3823 | ||
3824 | phba->link_state = LPFC_HBA_ERROR; | |
3825 | mempool_free(pmb, phba->mbox_mem_pool); | |
6e7288d9 | 3826 | return -ENXIO; |
ed957684 JS |
3827 | } |
3828 | } | |
3829 | phba->hbq_count = hbq_count; | |
3830 | ||
ed957684 JS |
3831 | mempool_free(pmb, phba->mbox_mem_pool); |
3832 | ||
92d7f7b0 | 3833 | /* Initially populate or replenish the HBQs */ |
d7c255b2 JS |
3834 | for (hbqno = 0; hbqno < hbq_count; ++hbqno) |
3835 | lpfc_sli_hbqbuf_init_hbqs(phba, hbqno); | |
ed957684 JS |
3836 | return 0; |
3837 | } | |
3838 | ||
4f774513 JS |
3839 | /** |
3840 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | |
3841 | * @phba: Pointer to HBA context object. | |
3842 | * | |
3843 | * This function is called during the SLI initialization to configure | |
3844 | * all the HBQs and post buffers to the HBQ. The caller is not | |
3845 | * required to hold any locks. This function will return zero if successful | |
3846 | * else it will return negative error code. | |
3847 | **/ | |
3848 | static int | |
3849 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | |
3850 | { | |
3851 | phba->hbq_in_use = 1; | |
3852 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | |
3853 | phba->hbq_count = 1; | |
3854 | /* Initially populate or replenish the HBQs */ | |
3855 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | |
3856 | return 0; | |
3857 | } | |
3858 | ||
e59058c4 | 3859 | /** |
3621a710 | 3860 | * lpfc_sli_config_port - Issue config port mailbox command |
e59058c4 JS |
3861 | * @phba: Pointer to HBA context object. |
3862 | * @sli_mode: sli mode - 2/3 | |
3863 | * | |
3864 | * This function is called by the sli intialization code path | |
3865 | * to issue config_port mailbox command. This function restarts the | |
3866 | * HBA firmware and issues a config_port mailbox command to configure | |
3867 | * the SLI interface in the sli mode specified by sli_mode | |
3868 | * variable. The caller is not required to hold any locks. | |
3869 | * The function returns 0 if successful, else returns negative error | |
3870 | * code. | |
3871 | **/ | |
9399627f JS |
3872 | int |
3873 | lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |
dea3101e JB |
3874 | { |
3875 | LPFC_MBOXQ_t *pmb; | |
3876 | uint32_t resetcount = 0, rc = 0, done = 0; | |
3877 | ||
3878 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3879 | if (!pmb) { | |
2e0fef85 | 3880 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
3881 | return -ENOMEM; |
3882 | } | |
3883 | ||
ed957684 | 3884 | phba->sli_rev = sli_mode; |
dea3101e | 3885 | while (resetcount < 2 && !done) { |
2e0fef85 | 3886 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 3887 | phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 3888 | spin_unlock_irq(&phba->hbalock); |
92d7f7b0 | 3889 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; |
41415862 | 3890 | lpfc_sli_brdrestart(phba); |
dea3101e JB |
3891 | rc = lpfc_sli_chipset_init(phba); |
3892 | if (rc) | |
3893 | break; | |
3894 | ||
2e0fef85 | 3895 | spin_lock_irq(&phba->hbalock); |
1c067a42 | 3896 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 3897 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
3898 | resetcount++; |
3899 | ||
ed957684 JS |
3900 | /* Call pre CONFIG_PORT mailbox command initialization. A |
3901 | * value of 0 means the call was successful. Any other | |
3902 | * nonzero value is a failure, but if ERESTART is returned, | |
3903 | * the driver may reset the HBA and try again. | |
3904 | */ | |
dea3101e JB |
3905 | rc = lpfc_config_port_prep(phba); |
3906 | if (rc == -ERESTART) { | |
ed957684 | 3907 | phba->link_state = LPFC_LINK_UNKNOWN; |
dea3101e | 3908 | continue; |
34b02dcd | 3909 | } else if (rc) |
dea3101e | 3910 | break; |
2e0fef85 | 3911 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
3912 | lpfc_config_port(phba, pmb); |
3913 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
34b02dcd JS |
3914 | phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | |
3915 | LPFC_SLI3_HBQ_ENABLED | | |
3916 | LPFC_SLI3_CRP_ENABLED | | |
e2a0a9d6 | 3917 | LPFC_SLI3_BG_ENABLED); |
ed957684 | 3918 | if (rc != MBX_SUCCESS) { |
dea3101e | 3919 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 3920 | "0442 Adapter failed to init, mbxCmd x%x " |
92d7f7b0 | 3921 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
04c68496 | 3922 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
2e0fef85 | 3923 | spin_lock_irq(&phba->hbalock); |
04c68496 | 3924 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
2e0fef85 JS |
3925 | spin_unlock_irq(&phba->hbalock); |
3926 | rc = -ENXIO; | |
04c68496 JS |
3927 | } else { |
3928 | /* Allow asynchronous mailbox command to go through */ | |
3929 | spin_lock_irq(&phba->hbalock); | |
3930 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
3931 | spin_unlock_irq(&phba->hbalock); | |
ed957684 | 3932 | done = 1; |
04c68496 | 3933 | } |
dea3101e | 3934 | } |
ed957684 JS |
3935 | if (!done) { |
3936 | rc = -EINVAL; | |
3937 | goto do_prep_failed; | |
3938 | } | |
04c68496 JS |
3939 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
3940 | if (!pmb->u.mb.un.varCfgPort.cMA) { | |
34b02dcd JS |
3941 | rc = -ENXIO; |
3942 | goto do_prep_failed; | |
3943 | } | |
04c68496 | 3944 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
34b02dcd | 3945 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
04c68496 JS |
3946 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
3947 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | |
3948 | phba->max_vpi : phba->max_vports; | |
3949 | ||
34b02dcd JS |
3950 | } else |
3951 | phba->max_vpi = 0; | |
04c68496 JS |
3952 | if (pmb->u.mb.un.varCfgPort.gdss) |
3953 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; | |
3954 | if (pmb->u.mb.un.varCfgPort.gerbm) | |
34b02dcd | 3955 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
04c68496 | 3956 | if (pmb->u.mb.un.varCfgPort.gcrp) |
34b02dcd | 3957 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
6e7288d9 JS |
3958 | |
3959 | phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get; | |
3960 | phba->port_gp = phba->mbox->us.s3_pgp.port; | |
e2a0a9d6 JS |
3961 | |
3962 | if (phba->cfg_enable_bg) { | |
04c68496 | 3963 | if (pmb->u.mb.un.varCfgPort.gbg) |
e2a0a9d6 JS |
3964 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
3965 | else | |
3966 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3967 | "0443 Adapter did not grant " | |
3968 | "BlockGuard\n"); | |
3969 | } | |
34b02dcd | 3970 | } else { |
8f34f4ce | 3971 | phba->hbq_get = NULL; |
34b02dcd | 3972 | phba->port_gp = phba->mbox->us.s2.port; |
d7c255b2 | 3973 | phba->max_vpi = 0; |
ed957684 | 3974 | } |
92d7f7b0 | 3975 | do_prep_failed: |
ed957684 JS |
3976 | mempool_free(pmb, phba->mbox_mem_pool); |
3977 | return rc; | |
3978 | } | |
3979 | ||
e59058c4 JS |
3980 | |
3981 | /** | |
3621a710 | 3982 | * lpfc_sli_hba_setup - SLI intialization function |
e59058c4 JS |
3983 | * @phba: Pointer to HBA context object. |
3984 | * | |
3985 | * This function is the main SLI intialization function. This function | |
3986 | * is called by the HBA intialization code, HBA reset code and HBA | |
3987 | * error attention handler code. Caller is not required to hold any | |
3988 | * locks. This function issues config_port mailbox command to configure | |
3989 | * the SLI, setup iocb rings and HBQ rings. In the end the function | |
3990 | * calls the config_port_post function to issue init_link mailbox | |
3991 | * command and to start the discovery. The function will return zero | |
3992 | * if successful, else it will return negative error code. | |
3993 | **/ | |
ed957684 JS |
3994 | int |
3995 | lpfc_sli_hba_setup(struct lpfc_hba *phba) | |
3996 | { | |
3997 | uint32_t rc; | |
92d7f7b0 | 3998 | int mode = 3; |
ed957684 JS |
3999 | |
4000 | switch (lpfc_sli_mode) { | |
4001 | case 2: | |
78b2d852 | 4002 | if (phba->cfg_enable_npiv) { |
92d7f7b0 | 4003 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 | 4004 | "1824 NPIV enabled: Override lpfc_sli_mode " |
92d7f7b0 | 4005 | "parameter (%d) to auto (0).\n", |
e8b62011 | 4006 | lpfc_sli_mode); |
92d7f7b0 JS |
4007 | break; |
4008 | } | |
ed957684 JS |
4009 | mode = 2; |
4010 | break; | |
4011 | case 0: | |
4012 | case 3: | |
4013 | break; | |
4014 | default: | |
92d7f7b0 | 4015 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4016 | "1819 Unrecognized lpfc_sli_mode " |
4017 | "parameter: %d.\n", lpfc_sli_mode); | |
ed957684 JS |
4018 | |
4019 | break; | |
4020 | } | |
4021 | ||
9399627f JS |
4022 | rc = lpfc_sli_config_port(phba, mode); |
4023 | ||
ed957684 | 4024 | if (rc && lpfc_sli_mode == 3) |
92d7f7b0 | 4025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, |
e8b62011 JS |
4026 | "1820 Unable to select SLI-3. " |
4027 | "Not supported by adapter.\n"); | |
ed957684 | 4028 | if (rc && mode != 2) |
9399627f | 4029 | rc = lpfc_sli_config_port(phba, 2); |
ed957684 | 4030 | if (rc) |
dea3101e JB |
4031 | goto lpfc_sli_hba_setup_error; |
4032 | ||
0d878419 JS |
4033 | /* Enable PCIe device Advanced Error Reporting (AER) if configured */ |
4034 | if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) { | |
4035 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4036 | if (!rc) { | |
4037 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4038 | "2709 This device supports " | |
4039 | "Advanced Error Reporting (AER)\n"); | |
4040 | spin_lock_irq(&phba->hbalock); | |
4041 | phba->hba_flag |= HBA_AER_ENABLED; | |
4042 | spin_unlock_irq(&phba->hbalock); | |
4043 | } else { | |
4044 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4045 | "2708 This device does not support " | |
4046 | "Advanced Error Reporting (AER)\n"); | |
4047 | phba->cfg_aer_support = 0; | |
4048 | } | |
4049 | } | |
4050 | ||
ed957684 JS |
4051 | if (phba->sli_rev == 3) { |
4052 | phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; | |
4053 | phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; | |
ed957684 JS |
4054 | } else { |
4055 | phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; | |
4056 | phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; | |
92d7f7b0 | 4057 | phba->sli3_options = 0; |
ed957684 JS |
4058 | } |
4059 | ||
4060 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
4061 | "0444 Firmware in SLI %x mode. Max_vpi %d\n", |
4062 | phba->sli_rev, phba->max_vpi); | |
ed957684 | 4063 | rc = lpfc_sli_ring_map(phba); |
dea3101e JB |
4064 | |
4065 | if (rc) | |
4066 | goto lpfc_sli_hba_setup_error; | |
4067 | ||
9399627f | 4068 | /* Init HBQs */ |
ed957684 JS |
4069 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { |
4070 | rc = lpfc_sli_hbq_setup(phba); | |
4071 | if (rc) | |
4072 | goto lpfc_sli_hba_setup_error; | |
4073 | } | |
04c68496 | 4074 | spin_lock_irq(&phba->hbalock); |
dea3101e | 4075 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
04c68496 | 4076 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4077 | |
4078 | rc = lpfc_config_port_post(phba); | |
4079 | if (rc) | |
4080 | goto lpfc_sli_hba_setup_error; | |
4081 | ||
ed957684 JS |
4082 | return rc; |
4083 | ||
92d7f7b0 | 4084 | lpfc_sli_hba_setup_error: |
2e0fef85 | 4085 | phba->link_state = LPFC_HBA_ERROR; |
e40a02c1 | 4086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 4087 | "0445 Firmware initialization failed\n"); |
dea3101e JB |
4088 | return rc; |
4089 | } | |
4090 | ||
e59058c4 | 4091 | /** |
da0436e9 JS |
4092 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region |
4093 | * @phba: Pointer to HBA context object. | |
4094 | * @mboxq: mailbox pointer. | |
4095 | * This function issue a dump mailbox command to read config region | |
4096 | * 23 and parse the records in the region and populate driver | |
4097 | * data structure. | |
e59058c4 | 4098 | **/ |
da0436e9 JS |
4099 | static int |
4100 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, | |
4101 | LPFC_MBOXQ_t *mboxq) | |
dea3101e | 4102 | { |
da0436e9 JS |
4103 | struct lpfc_dmabuf *mp; |
4104 | struct lpfc_mqe *mqe; | |
4105 | uint32_t data_length; | |
4106 | int rc; | |
dea3101e | 4107 | |
da0436e9 JS |
4108 | /* Program the default value of vlan_id and fc_map */ |
4109 | phba->valid_vlan = 0; | |
4110 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4111 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4112 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
2e0fef85 | 4113 | |
da0436e9 JS |
4114 | mqe = &mboxq->u.mqe; |
4115 | if (lpfc_dump_fcoe_param(phba, mboxq)) | |
4116 | return -ENOMEM; | |
4117 | ||
4118 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4119 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4120 | ||
4121 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4122 | "(%d):2571 Mailbox cmd x%x Status x%x " | |
4123 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4124 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | |
4125 | "CQ: x%x x%x x%x x%x\n", | |
4126 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4127 | bf_get(lpfc_mqe_command, mqe), | |
4128 | bf_get(lpfc_mqe_status, mqe), | |
4129 | mqe->un.mb_words[0], mqe->un.mb_words[1], | |
4130 | mqe->un.mb_words[2], mqe->un.mb_words[3], | |
4131 | mqe->un.mb_words[4], mqe->un.mb_words[5], | |
4132 | mqe->un.mb_words[6], mqe->un.mb_words[7], | |
4133 | mqe->un.mb_words[8], mqe->un.mb_words[9], | |
4134 | mqe->un.mb_words[10], mqe->un.mb_words[11], | |
4135 | mqe->un.mb_words[12], mqe->un.mb_words[13], | |
4136 | mqe->un.mb_words[14], mqe->un.mb_words[15], | |
4137 | mqe->un.mb_words[16], mqe->un.mb_words[50], | |
4138 | mboxq->mcqe.word0, | |
4139 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
4140 | mboxq->mcqe.trailer); | |
4141 | ||
4142 | if (rc) { | |
4143 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4144 | kfree(mp); | |
4145 | return -EIO; | |
4146 | } | |
4147 | data_length = mqe->un.mb_words[5]; | |
a0c87cbd | 4148 | if (data_length > DMP_RGN23_SIZE) { |
d11e31dd JS |
4149 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
4150 | kfree(mp); | |
da0436e9 | 4151 | return -EIO; |
d11e31dd | 4152 | } |
dea3101e | 4153 | |
da0436e9 JS |
4154 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); |
4155 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4156 | kfree(mp); | |
4157 | return 0; | |
4158 | } | |
e59058c4 JS |
4159 | |
4160 | /** | |
da0436e9 JS |
4161 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data |
4162 | * @phba: pointer to lpfc hba data structure. | |
4163 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | |
4164 | * @vpd: pointer to the memory to hold resulting port vpd data. | |
4165 | * @vpd_size: On input, the number of bytes allocated to @vpd. | |
4166 | * On output, the number of data bytes in @vpd. | |
e59058c4 | 4167 | * |
da0436e9 JS |
4168 | * This routine executes a READ_REV SLI4 mailbox command. In |
4169 | * addition, this routine gets the port vpd data. | |
4170 | * | |
4171 | * Return codes | |
af901ca1 | 4172 | * 0 - successful |
da0436e9 | 4173 | * ENOMEM - could not allocated memory. |
e59058c4 | 4174 | **/ |
da0436e9 JS |
4175 | static int |
4176 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
4177 | uint8_t *vpd, uint32_t *vpd_size) | |
dea3101e | 4178 | { |
da0436e9 JS |
4179 | int rc = 0; |
4180 | uint32_t dma_size; | |
4181 | struct lpfc_dmabuf *dmabuf; | |
4182 | struct lpfc_mqe *mqe; | |
dea3101e | 4183 | |
da0436e9 JS |
4184 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
4185 | if (!dmabuf) | |
4186 | return -ENOMEM; | |
4187 | ||
4188 | /* | |
4189 | * Get a DMA buffer for the vpd data resulting from the READ_REV | |
4190 | * mailbox command. | |
a257bf90 | 4191 | */ |
da0436e9 JS |
4192 | dma_size = *vpd_size; |
4193 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4194 | dma_size, | |
4195 | &dmabuf->phys, | |
4196 | GFP_KERNEL); | |
4197 | if (!dmabuf->virt) { | |
4198 | kfree(dmabuf); | |
4199 | return -ENOMEM; | |
a257bf90 | 4200 | } |
da0436e9 | 4201 | memset(dmabuf->virt, 0, dma_size); |
a257bf90 | 4202 | |
da0436e9 JS |
4203 | /* |
4204 | * The SLI4 implementation of READ_REV conflicts at word1, | |
4205 | * bits 31:16 and SLI4 adds vpd functionality not present | |
4206 | * in SLI3. This code corrects the conflicts. | |
1dcb58e5 | 4207 | */ |
da0436e9 JS |
4208 | lpfc_read_rev(phba, mboxq); |
4209 | mqe = &mboxq->u.mqe; | |
4210 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | |
4211 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | |
4212 | mqe->un.read_rev.word1 &= 0x0000FFFF; | |
4213 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | |
4214 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | |
4215 | ||
4216 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4217 | if (rc) { | |
4218 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4219 | dmabuf->virt, dmabuf->phys); | |
def9c7a9 | 4220 | kfree(dmabuf); |
da0436e9 JS |
4221 | return -EIO; |
4222 | } | |
1dcb58e5 | 4223 | |
da0436e9 JS |
4224 | /* |
4225 | * The available vpd length cannot be bigger than the | |
4226 | * DMA buffer passed to the port. Catch the less than | |
4227 | * case and update the caller's size. | |
4228 | */ | |
4229 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | |
4230 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | |
3772a991 | 4231 | |
da0436e9 JS |
4232 | lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size); |
4233 | dma_free_coherent(&phba->pcidev->dev, dma_size, | |
4234 | dmabuf->virt, dmabuf->phys); | |
4235 | kfree(dmabuf); | |
4236 | return 0; | |
dea3101e JB |
4237 | } |
4238 | ||
e59058c4 | 4239 | /** |
da0436e9 JS |
4240 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues |
4241 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4242 | * |
da0436e9 JS |
4243 | * This routine is called to explicitly arm the SLI4 device's completion and |
4244 | * event queues | |
4245 | **/ | |
4246 | static void | |
4247 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | |
4248 | { | |
4249 | uint8_t fcp_eqidx; | |
4250 | ||
4251 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | |
4252 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | |
da0436e9 JS |
4253 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) |
4254 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], | |
4255 | LPFC_QUEUE_REARM); | |
4256 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); | |
4257 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | |
4258 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | |
4259 | LPFC_QUEUE_REARM); | |
4260 | } | |
4261 | ||
4262 | /** | |
4263 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | |
4264 | * @phba: Pointer to HBA context object. | |
4265 | * | |
4266 | * This function is the main SLI4 device intialization PCI function. This | |
4267 | * function is called by the HBA intialization code, HBA reset code and | |
4268 | * HBA error attention handler code. Caller is not required to hold any | |
4269 | * locks. | |
4270 | **/ | |
4271 | int | |
4272 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | |
4273 | { | |
4274 | int rc; | |
4275 | LPFC_MBOXQ_t *mboxq; | |
4276 | struct lpfc_mqe *mqe; | |
4277 | uint8_t *vpd; | |
4278 | uint32_t vpd_size; | |
4279 | uint32_t ftr_rsp = 0; | |
4280 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | |
4281 | struct lpfc_vport *vport = phba->pport; | |
4282 | struct lpfc_dmabuf *mp; | |
4283 | ||
4284 | /* Perform a PCI function reset to start from clean */ | |
4285 | rc = lpfc_pci_function_reset(phba); | |
4286 | if (unlikely(rc)) | |
4287 | return -ENODEV; | |
4288 | ||
4289 | /* Check the HBA Host Status Register for readyness */ | |
4290 | rc = lpfc_sli4_post_status_check(phba); | |
4291 | if (unlikely(rc)) | |
4292 | return -ENODEV; | |
4293 | else { | |
4294 | spin_lock_irq(&phba->hbalock); | |
4295 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | |
4296 | spin_unlock_irq(&phba->hbalock); | |
4297 | } | |
4298 | ||
4299 | /* | |
4300 | * Allocate a single mailbox container for initializing the | |
4301 | * port. | |
4302 | */ | |
4303 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4304 | if (!mboxq) | |
4305 | return -ENOMEM; | |
4306 | ||
4307 | /* | |
4308 | * Continue initialization with default values even if driver failed | |
4309 | * to read FCoE param config regions | |
4310 | */ | |
4311 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) | |
4312 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | |
e4e74273 | 4313 | "2570 Failed to read FCoE parameters\n"); |
da0436e9 JS |
4314 | |
4315 | /* Issue READ_REV to collect vpd and FW information. */ | |
49198b37 | 4316 | vpd_size = SLI4_PAGE_SIZE; |
da0436e9 JS |
4317 | vpd = kzalloc(vpd_size, GFP_KERNEL); |
4318 | if (!vpd) { | |
4319 | rc = -ENOMEM; | |
4320 | goto out_free_mbox; | |
4321 | } | |
4322 | ||
4323 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | |
4324 | if (unlikely(rc)) | |
4325 | goto out_free_vpd; | |
4326 | ||
4327 | mqe = &mboxq->u.mqe; | |
f1126688 JS |
4328 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); |
4329 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | |
4330 | phba->hba_flag |= HBA_FCOE_SUPPORT; | |
45ed1190 JS |
4331 | |
4332 | if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) == | |
4333 | LPFC_DCBX_CEE_MODE) | |
4334 | phba->hba_flag |= HBA_FIP_SUPPORT; | |
4335 | else | |
4336 | phba->hba_flag &= ~HBA_FIP_SUPPORT; | |
4337 | ||
f1126688 JS |
4338 | if (phba->sli_rev != LPFC_SLI_REV4 || |
4339 | !(phba->hba_flag & HBA_FCOE_SUPPORT)) { | |
da0436e9 JS |
4340 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4341 | "0376 READ_REV Error. SLI Level %d " | |
4342 | "FCoE enabled %d\n", | |
f1126688 | 4343 | phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT); |
da0436e9 JS |
4344 | rc = -EIO; |
4345 | goto out_free_vpd; | |
4346 | } | |
da0436e9 JS |
4347 | /* |
4348 | * Evaluate the read rev and vpd data. Populate the driver | |
4349 | * state with the results. If this routine fails, the failure | |
4350 | * is not fatal as the driver will use generic values. | |
4351 | */ | |
4352 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | |
4353 | if (unlikely(!rc)) { | |
4354 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4355 | "0377 Error %d parsing vpd. " | |
4356 | "Using defaults.\n", rc); | |
4357 | rc = 0; | |
4358 | } | |
4359 | ||
f1126688 JS |
4360 | /* Save information as VPD data */ |
4361 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | |
4362 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | |
4363 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | |
4364 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | |
4365 | &mqe->un.read_rev); | |
4366 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | |
4367 | &mqe->un.read_rev); | |
4368 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | |
4369 | &mqe->un.read_rev); | |
4370 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | |
4371 | &mqe->un.read_rev); | |
4372 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | |
4373 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | |
4374 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | |
4375 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | |
4376 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | |
4377 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | |
4378 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
4379 | "(%d):0380 READ_REV Status x%x " | |
4380 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | |
4381 | mboxq->vport ? mboxq->vport->vpi : 0, | |
4382 | bf_get(lpfc_mqe_status, mqe), | |
4383 | phba->vpd.rev.opFwName, | |
4384 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | |
4385 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | |
da0436e9 JS |
4386 | |
4387 | /* | |
4388 | * Discover the port's supported feature set and match it against the | |
4389 | * hosts requests. | |
4390 | */ | |
4391 | lpfc_request_features(phba, mboxq); | |
4392 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4393 | if (unlikely(rc)) { | |
4394 | rc = -EIO; | |
4395 | goto out_free_vpd; | |
4396 | } | |
4397 | ||
4398 | /* | |
4399 | * The port must support FCP initiator mode as this is the | |
4400 | * only mode running in the host. | |
4401 | */ | |
4402 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | |
4403 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4404 | "0378 No support for fcpi mode.\n"); | |
4405 | ftr_rsp++; | |
4406 | } | |
4407 | ||
4408 | /* | |
4409 | * If the port cannot support the host's requested features | |
4410 | * then turn off the global config parameters to disable the | |
4411 | * feature in the driver. This is not a fatal error. | |
4412 | */ | |
4413 | if ((phba->cfg_enable_bg) && | |
4414 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4415 | ftr_rsp++; | |
4416 | ||
4417 | if (phba->max_vpi && phba->cfg_enable_npiv && | |
4418 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4419 | ftr_rsp++; | |
4420 | ||
4421 | if (ftr_rsp) { | |
4422 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
4423 | "0379 Feature Mismatch Data: x%08x %08x " | |
4424 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | |
4425 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | |
4426 | phba->cfg_enable_npiv, phba->max_vpi); | |
4427 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | |
4428 | phba->cfg_enable_bg = 0; | |
4429 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | |
4430 | phba->cfg_enable_npiv = 0; | |
4431 | } | |
4432 | ||
4433 | /* These SLI3 features are assumed in SLI4 */ | |
4434 | spin_lock_irq(&phba->hbalock); | |
4435 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | |
4436 | spin_unlock_irq(&phba->hbalock); | |
4437 | ||
4438 | /* Read the port's service parameters. */ | |
9f1177a3 JS |
4439 | rc = lpfc_read_sparam(phba, mboxq, vport->vpi); |
4440 | if (rc) { | |
4441 | phba->link_state = LPFC_HBA_ERROR; | |
4442 | rc = -ENOMEM; | |
4443 | goto out_free_vpd; | |
4444 | } | |
4445 | ||
da0436e9 JS |
4446 | mboxq->vport = vport; |
4447 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4448 | mp = (struct lpfc_dmabuf *) mboxq->context1; | |
4449 | if (rc == MBX_SUCCESS) { | |
4450 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | |
4451 | rc = 0; | |
4452 | } | |
4453 | ||
4454 | /* | |
4455 | * This memory was allocated by the lpfc_read_sparam routine. Release | |
4456 | * it to the mbuf pool. | |
4457 | */ | |
4458 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
4459 | kfree(mp); | |
4460 | mboxq->context1 = NULL; | |
4461 | if (unlikely(rc)) { | |
4462 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4463 | "0382 READ_SPARAM command failed " | |
4464 | "status %d, mbxStatus x%x\n", | |
4465 | rc, bf_get(lpfc_mqe_status, mqe)); | |
4466 | phba->link_state = LPFC_HBA_ERROR; | |
4467 | rc = -EIO; | |
4468 | goto out_free_vpd; | |
4469 | } | |
4470 | ||
4471 | if (phba->cfg_soft_wwnn) | |
4472 | u64_to_wwn(phba->cfg_soft_wwnn, | |
4473 | vport->fc_sparam.nodeName.u.wwn); | |
4474 | if (phba->cfg_soft_wwpn) | |
4475 | u64_to_wwn(phba->cfg_soft_wwpn, | |
4476 | vport->fc_sparam.portName.u.wwn); | |
4477 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
4478 | sizeof(struct lpfc_name)); | |
4479 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
4480 | sizeof(struct lpfc_name)); | |
4481 | ||
4482 | /* Update the fc_host data structures with new wwn. */ | |
4483 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
4484 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
4485 | ||
4486 | /* Register SGL pool to the device using non-embedded mailbox command */ | |
4487 | rc = lpfc_sli4_post_sgl_list(phba); | |
4488 | if (unlikely(rc)) { | |
4489 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4490 | "0582 Error %d during sgl post operation\n", |
4491 | rc); | |
da0436e9 JS |
4492 | rc = -ENODEV; |
4493 | goto out_free_vpd; | |
4494 | } | |
4495 | ||
4496 | /* Register SCSI SGL pool to the device */ | |
4497 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | |
4498 | if (unlikely(rc)) { | |
4499 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | |
6a9c52cf JS |
4500 | "0383 Error %d during scsi sgl post " |
4501 | "operation\n", rc); | |
da0436e9 JS |
4502 | /* Some Scsi buffers were moved to the abort scsi list */ |
4503 | /* A pci function reset will repost them */ | |
4504 | rc = -ENODEV; | |
4505 | goto out_free_vpd; | |
4506 | } | |
4507 | ||
4508 | /* Post the rpi header region to the device. */ | |
4509 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | |
4510 | if (unlikely(rc)) { | |
4511 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4512 | "0393 Error %d during rpi post operation\n", | |
4513 | rc); | |
4514 | rc = -ENODEV; | |
4515 | goto out_free_vpd; | |
4516 | } | |
da0436e9 JS |
4517 | |
4518 | /* Set up all the queues to the device */ | |
4519 | rc = lpfc_sli4_queue_setup(phba); | |
4520 | if (unlikely(rc)) { | |
4521 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4522 | "0381 Error %d during queue setup.\n ", rc); | |
4523 | goto out_stop_timers; | |
4524 | } | |
4525 | ||
4526 | /* Arm the CQs and then EQs on device */ | |
4527 | lpfc_sli4_arm_cqeq_intr(phba); | |
4528 | ||
4529 | /* Indicate device interrupt mode */ | |
4530 | phba->sli4_hba.intr_enable = 1; | |
4531 | ||
4532 | /* Allow asynchronous mailbox command to go through */ | |
4533 | spin_lock_irq(&phba->hbalock); | |
4534 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
4535 | spin_unlock_irq(&phba->hbalock); | |
4536 | ||
4537 | /* Post receive buffers to the device */ | |
4538 | lpfc_sli4_rb_setup(phba); | |
4539 | ||
fc2b989b JS |
4540 | /* Reset HBA FCF states after HBA reset */ |
4541 | phba->fcf.fcf_flag = 0; | |
4542 | phba->fcf.current_rec.flag = 0; | |
4543 | ||
da0436e9 | 4544 | /* Start the ELS watchdog timer */ |
8fa38513 JS |
4545 | mod_timer(&vport->els_tmofunc, |
4546 | jiffies + HZ * (phba->fc_ratov * 2)); | |
da0436e9 JS |
4547 | |
4548 | /* Start heart beat timer */ | |
4549 | mod_timer(&phba->hb_tmofunc, | |
4550 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
4551 | phba->hb_outstanding = 0; | |
4552 | phba->last_completion_time = jiffies; | |
4553 | ||
4554 | /* Start error attention (ERATT) polling timer */ | |
4555 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
4556 | ||
4557 | /* | |
4558 | * The port is ready, set the host's link state to LINK_DOWN | |
4559 | * in preparation for link interrupts. | |
4560 | */ | |
4561 | lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed); | |
4562 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
4563 | lpfc_set_loopback_flag(phba); | |
4564 | /* Change driver state to LPFC_LINK_DOWN right before init link */ | |
4565 | spin_lock_irq(&phba->hbalock); | |
4566 | phba->link_state = LPFC_LINK_DOWN; | |
4567 | spin_unlock_irq(&phba->hbalock); | |
4568 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
4569 | if (unlikely(rc != MBX_NOT_FINISHED)) { | |
4570 | kfree(vpd); | |
4571 | return 0; | |
4572 | } else | |
4573 | rc = -EIO; | |
4574 | ||
4575 | /* Unset all the queues set up in this routine when error out */ | |
4576 | if (rc) | |
4577 | lpfc_sli4_queue_unset(phba); | |
4578 | ||
4579 | out_stop_timers: | |
4580 | if (rc) | |
4581 | lpfc_stop_hba_timers(phba); | |
4582 | out_free_vpd: | |
4583 | kfree(vpd); | |
4584 | out_free_mbox: | |
4585 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4586 | return rc; | |
4587 | } | |
4588 | ||
4589 | /** | |
4590 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | |
4591 | * @ptr: context object - pointer to hba structure. | |
4592 | * | |
4593 | * This is the callback function for mailbox timer. The mailbox | |
4594 | * timer is armed when a new mailbox command is issued and the timer | |
4595 | * is deleted when the mailbox complete. The function is called by | |
4596 | * the kernel timer code when a mailbox does not complete within | |
4597 | * expected time. This function wakes up the worker thread to | |
4598 | * process the mailbox timeout and returns. All the processing is | |
4599 | * done by the worker thread function lpfc_mbox_timeout_handler. | |
4600 | **/ | |
4601 | void | |
4602 | lpfc_mbox_timeout(unsigned long ptr) | |
4603 | { | |
4604 | struct lpfc_hba *phba = (struct lpfc_hba *) ptr; | |
4605 | unsigned long iflag; | |
4606 | uint32_t tmo_posted; | |
4607 | ||
4608 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
4609 | tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO; | |
4610 | if (!tmo_posted) | |
4611 | phba->pport->work_port_events |= WORKER_MBOX_TMO; | |
4612 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
4613 | ||
4614 | if (!tmo_posted) | |
4615 | lpfc_worker_wake_up(phba); | |
4616 | return; | |
4617 | } | |
4618 | ||
4619 | ||
4620 | /** | |
4621 | * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout | |
4622 | * @phba: Pointer to HBA context object. | |
4623 | * | |
4624 | * This function is called from worker thread when a mailbox command times out. | |
4625 | * The caller is not required to hold any locks. This function will reset the | |
4626 | * HBA and recover all the pending commands. | |
4627 | **/ | |
4628 | void | |
4629 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |
4630 | { | |
4631 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | |
04c68496 | 4632 | MAILBOX_t *mb = &pmbox->u.mb; |
da0436e9 JS |
4633 | struct lpfc_sli *psli = &phba->sli; |
4634 | struct lpfc_sli_ring *pring; | |
4635 | ||
4636 | /* Check the pmbox pointer first. There is a race condition | |
4637 | * between the mbox timeout handler getting executed in the | |
4638 | * worklist and the mailbox actually completing. When this | |
4639 | * race condition occurs, the mbox_active will be NULL. | |
4640 | */ | |
4641 | spin_lock_irq(&phba->hbalock); | |
4642 | if (pmbox == NULL) { | |
4643 | lpfc_printf_log(phba, KERN_WARNING, | |
4644 | LOG_MBOX | LOG_SLI, | |
4645 | "0353 Active Mailbox cleared - mailbox timeout " | |
4646 | "exiting\n"); | |
4647 | spin_unlock_irq(&phba->hbalock); | |
4648 | return; | |
4649 | } | |
4650 | ||
4651 | /* Mbox cmd <mbxCommand> timeout */ | |
4652 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4653 | "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", | |
4654 | mb->mbxCommand, | |
4655 | phba->pport->port_state, | |
4656 | phba->sli.sli_flag, | |
4657 | phba->sli.mbox_active); | |
4658 | spin_unlock_irq(&phba->hbalock); | |
4659 | ||
4660 | /* Setting state unknown so lpfc_sli_abort_iocb_ring | |
4661 | * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing | |
4662 | * it to fail all oustanding SCSI IO. | |
4663 | */ | |
4664 | spin_lock_irq(&phba->pport->work_port_lock); | |
4665 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
4666 | spin_unlock_irq(&phba->pport->work_port_lock); | |
4667 | spin_lock_irq(&phba->hbalock); | |
4668 | phba->link_state = LPFC_LINK_UNKNOWN; | |
f4b4c68f | 4669 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
da0436e9 JS |
4670 | spin_unlock_irq(&phba->hbalock); |
4671 | ||
4672 | pring = &psli->ring[psli->fcp_ring]; | |
4673 | lpfc_sli_abort_iocb_ring(phba, pring); | |
4674 | ||
4675 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4676 | "0345 Resetting board due to mailbox timeout\n"); | |
4677 | ||
4678 | /* Reset the HBA device */ | |
4679 | lpfc_reset_hba(phba); | |
4680 | } | |
4681 | ||
4682 | /** | |
4683 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware | |
4684 | * @phba: Pointer to HBA context object. | |
4685 | * @pmbox: Pointer to mailbox object. | |
4686 | * @flag: Flag indicating how the mailbox need to be processed. | |
4687 | * | |
4688 | * This function is called by discovery code and HBA management code | |
4689 | * to submit a mailbox command to firmware with SLI-3 interface spec. This | |
4690 | * function gets the hbalock to protect the data structures. | |
4691 | * The mailbox command can be submitted in polling mode, in which case | |
4692 | * this function will wait in a polling loop for the completion of the | |
4693 | * mailbox. | |
4694 | * If the mailbox is submitted in no_wait mode (not polling) the | |
4695 | * function will submit the command and returns immediately without waiting | |
4696 | * for the mailbox completion. The no_wait is supported only when HBA | |
4697 | * is in SLI2/SLI3 mode - interrupts are enabled. | |
4698 | * The SLI interface allows only one mailbox pending at a time. If the | |
4699 | * mailbox is issued in polling mode and there is already a mailbox | |
4700 | * pending, then the function will return an error. If the mailbox is issued | |
4701 | * in NO_WAIT mode and there is a mailbox pending already, the function | |
4702 | * will return MBX_BUSY after queuing the mailbox into mailbox queue. | |
4703 | * The sli layer owns the mailbox object until the completion of mailbox | |
4704 | * command if this function return MBX_BUSY or MBX_SUCCESS. For all other | |
4705 | * return codes the caller owns the mailbox command after the return of | |
4706 | * the function. | |
e59058c4 | 4707 | **/ |
3772a991 JS |
4708 | static int |
4709 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, | |
4710 | uint32_t flag) | |
dea3101e | 4711 | { |
dea3101e | 4712 | MAILBOX_t *mb; |
2e0fef85 | 4713 | struct lpfc_sli *psli = &phba->sli; |
dea3101e JB |
4714 | uint32_t status, evtctr; |
4715 | uint32_t ha_copy; | |
4716 | int i; | |
09372820 | 4717 | unsigned long timeout; |
dea3101e | 4718 | unsigned long drvr_flag = 0; |
34b02dcd | 4719 | uint32_t word0, ldata; |
dea3101e | 4720 | void __iomem *to_slim; |
58da1ffb JS |
4721 | int processing_queue = 0; |
4722 | ||
4723 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
4724 | if (!pmbox) { | |
8568a4d2 | 4725 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
58da1ffb | 4726 | /* processing mbox queue from intr_handler */ |
3772a991 JS |
4727 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { |
4728 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
4729 | return MBX_SUCCESS; | |
4730 | } | |
58da1ffb | 4731 | processing_queue = 1; |
58da1ffb JS |
4732 | pmbox = lpfc_mbox_get(phba); |
4733 | if (!pmbox) { | |
4734 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
4735 | return MBX_SUCCESS; | |
4736 | } | |
4737 | } | |
dea3101e | 4738 | |
ed957684 | 4739 | if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
92d7f7b0 | 4740 | pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
ed957684 | 4741 | if(!pmbox->vport) { |
58da1ffb | 4742 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
ed957684 | 4743 | lpfc_printf_log(phba, KERN_ERR, |
92d7f7b0 | 4744 | LOG_MBOX | LOG_VPORT, |
e8b62011 | 4745 | "1806 Mbox x%x failed. No vport\n", |
3772a991 | 4746 | pmbox->u.mb.mbxCommand); |
ed957684 | 4747 | dump_stack(); |
58da1ffb | 4748 | goto out_not_finished; |
ed957684 JS |
4749 | } |
4750 | } | |
4751 | ||
8d63f375 | 4752 | /* If the PCI channel is in offline state, do not post mbox. */ |
58da1ffb JS |
4753 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
4754 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
4755 | goto out_not_finished; | |
4756 | } | |
8d63f375 | 4757 | |
a257bf90 JS |
4758 | /* If HBA has a deferred error attention, fail the iocb. */ |
4759 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
4760 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
4761 | goto out_not_finished; | |
4762 | } | |
4763 | ||
dea3101e | 4764 | psli = &phba->sli; |
92d7f7b0 | 4765 | |
3772a991 | 4766 | mb = &pmbox->u.mb; |
dea3101e JB |
4767 | status = MBX_SUCCESS; |
4768 | ||
2e0fef85 JS |
4769 | if (phba->link_state == LPFC_HBA_ERROR) { |
4770 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
41415862 JW |
4771 | |
4772 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
4773 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4774 | "(%d):0311 Mailbox command x%x cannot " | |
4775 | "issue Data: x%x x%x\n", | |
4776 | pmbox->vport ? pmbox->vport->vpi : 0, | |
4777 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 4778 | goto out_not_finished; |
41415862 JW |
4779 | } |
4780 | ||
9290831f JS |
4781 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
4782 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { | |
2e0fef85 | 4783 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3772a991 JS |
4784 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4785 | "(%d):2528 Mailbox command x%x cannot " | |
4786 | "issue Data: x%x x%x\n", | |
4787 | pmbox->vport ? pmbox->vport->vpi : 0, | |
4788 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | |
58da1ffb | 4789 | goto out_not_finished; |
9290831f JS |
4790 | } |
4791 | ||
dea3101e JB |
4792 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
4793 | /* Polling for a mbox command when another one is already active | |
4794 | * is not allowed in SLI. Also, the driver must have established | |
4795 | * SLI2 mode to queue and process multiple mbox commands. | |
4796 | */ | |
4797 | ||
4798 | if (flag & MBX_POLL) { | |
2e0fef85 | 4799 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e JB |
4800 | |
4801 | /* Mbox command <mbxCommand> cannot issue */ | |
3772a991 JS |
4802 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4803 | "(%d):2529 Mailbox command x%x " | |
4804 | "cannot issue Data: x%x x%x\n", | |
4805 | pmbox->vport ? pmbox->vport->vpi : 0, | |
4806 | pmbox->u.mb.mbxCommand, | |
4807 | psli->sli_flag, flag); | |
58da1ffb | 4808 | goto out_not_finished; |
dea3101e JB |
4809 | } |
4810 | ||
3772a991 | 4811 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
2e0fef85 | 4812 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 4813 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
4814 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4815 | "(%d):2530 Mailbox command x%x " | |
4816 | "cannot issue Data: x%x x%x\n", | |
4817 | pmbox->vport ? pmbox->vport->vpi : 0, | |
4818 | pmbox->u.mb.mbxCommand, | |
4819 | psli->sli_flag, flag); | |
58da1ffb | 4820 | goto out_not_finished; |
dea3101e JB |
4821 | } |
4822 | ||
dea3101e JB |
4823 | /* Another mailbox command is still being processed, queue this |
4824 | * command to be processed later. | |
4825 | */ | |
4826 | lpfc_mbox_put(phba, pmbox); | |
4827 | ||
4828 | /* Mbox cmd issue - BUSY */ | |
ed957684 | 4829 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 4830 | "(%d):0308 Mbox cmd issue - BUSY Data: " |
92d7f7b0 | 4831 | "x%x x%x x%x x%x\n", |
92d7f7b0 JS |
4832 | pmbox->vport ? pmbox->vport->vpi : 0xffffff, |
4833 | mb->mbxCommand, phba->pport->port_state, | |
4834 | psli->sli_flag, flag); | |
dea3101e JB |
4835 | |
4836 | psli->slistat.mbox_busy++; | |
2e0fef85 | 4837 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 4838 | |
858c9f6c JS |
4839 | if (pmbox->vport) { |
4840 | lpfc_debugfs_disc_trc(pmbox->vport, | |
4841 | LPFC_DISC_TRC_MBOX_VPORT, | |
4842 | "MBOX Bsy vport: cmd:x%x mb:x%x x%x", | |
4843 | (uint32_t)mb->mbxCommand, | |
4844 | mb->un.varWords[0], mb->un.varWords[1]); | |
4845 | } | |
4846 | else { | |
4847 | lpfc_debugfs_disc_trc(phba->pport, | |
4848 | LPFC_DISC_TRC_MBOX, | |
4849 | "MBOX Bsy: cmd:x%x mb:x%x x%x", | |
4850 | (uint32_t)mb->mbxCommand, | |
4851 | mb->un.varWords[0], mb->un.varWords[1]); | |
4852 | } | |
4853 | ||
2e0fef85 | 4854 | return MBX_BUSY; |
dea3101e JB |
4855 | } |
4856 | ||
dea3101e JB |
4857 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; |
4858 | ||
4859 | /* If we are not polling, we MUST be in SLI2 mode */ | |
4860 | if (flag != MBX_POLL) { | |
3772a991 | 4861 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
41415862 | 4862 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
dea3101e | 4863 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 4864 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
dea3101e | 4865 | /* Mbox command <mbxCommand> cannot issue */ |
3772a991 JS |
4866 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4867 | "(%d):2531 Mailbox command x%x " | |
4868 | "cannot issue Data: x%x x%x\n", | |
4869 | pmbox->vport ? pmbox->vport->vpi : 0, | |
4870 | pmbox->u.mb.mbxCommand, | |
4871 | psli->sli_flag, flag); | |
58da1ffb | 4872 | goto out_not_finished; |
dea3101e JB |
4873 | } |
4874 | /* timeout active mbox command */ | |
a309a6b6 JS |
4875 | mod_timer(&psli->mbox_tmo, (jiffies + |
4876 | (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand)))); | |
dea3101e JB |
4877 | } |
4878 | ||
4879 | /* Mailbox cmd <cmd> issue */ | |
ed957684 | 4880 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
e8b62011 | 4881 | "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x " |
92d7f7b0 | 4882 | "x%x\n", |
e8b62011 | 4883 | pmbox->vport ? pmbox->vport->vpi : 0, |
92d7f7b0 JS |
4884 | mb->mbxCommand, phba->pport->port_state, |
4885 | psli->sli_flag, flag); | |
dea3101e | 4886 | |
858c9f6c JS |
4887 | if (mb->mbxCommand != MBX_HEARTBEAT) { |
4888 | if (pmbox->vport) { | |
4889 | lpfc_debugfs_disc_trc(pmbox->vport, | |
4890 | LPFC_DISC_TRC_MBOX_VPORT, | |
4891 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
4892 | (uint32_t)mb->mbxCommand, | |
4893 | mb->un.varWords[0], mb->un.varWords[1]); | |
4894 | } | |
4895 | else { | |
4896 | lpfc_debugfs_disc_trc(phba->pport, | |
4897 | LPFC_DISC_TRC_MBOX, | |
4898 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
4899 | (uint32_t)mb->mbxCommand, | |
4900 | mb->un.varWords[0], mb->un.varWords[1]); | |
4901 | } | |
4902 | } | |
4903 | ||
dea3101e JB |
4904 | psli->slistat.mbox_cmd++; |
4905 | evtctr = psli->slistat.mbox_event; | |
4906 | ||
4907 | /* next set own bit for the adapter and copy over command word */ | |
4908 | mb->mbxOwner = OWN_CHIP; | |
4909 | ||
3772a991 | 4910 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
7a470277 JS |
4911 | /* Populate mbox extension offset word. */ |
4912 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) { | |
4913 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
4914 | = (uint8_t *)phba->mbox_ext | |
4915 | - (uint8_t *)phba->mbox; | |
4916 | } | |
4917 | ||
4918 | /* Copy the mailbox extension data */ | |
4919 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
4920 | lpfc_sli_pcimem_bcopy(pmbox->context2, | |
4921 | (uint8_t *)phba->mbox_ext, | |
4922 | pmbox->in_ext_byte_len); | |
4923 | } | |
4924 | /* Copy command data to host SLIM area */ | |
34b02dcd | 4925 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e | 4926 | } else { |
7a470277 JS |
4927 | /* Populate mbox extension offset word. */ |
4928 | if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) | |
4929 | *(((uint32_t *)mb) + pmbox->mbox_offset_word) | |
4930 | = MAILBOX_HBA_EXT_OFFSET; | |
4931 | ||
4932 | /* Copy the mailbox extension data */ | |
4933 | if (pmbox->in_ext_byte_len && pmbox->context2) { | |
4934 | lpfc_memcpy_to_slim(phba->MBslimaddr + | |
4935 | MAILBOX_HBA_EXT_OFFSET, | |
4936 | pmbox->context2, pmbox->in_ext_byte_len); | |
4937 | ||
4938 | } | |
9290831f | 4939 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
dea3101e | 4940 | /* copy command data into host mbox for cmpl */ |
34b02dcd | 4941 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
dea3101e JB |
4942 | } |
4943 | ||
4944 | /* First copy mbox command data to HBA SLIM, skip past first | |
4945 | word */ | |
4946 | to_slim = phba->MBslimaddr + sizeof (uint32_t); | |
4947 | lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0], | |
4948 | MAILBOX_CMD_SIZE - sizeof (uint32_t)); | |
4949 | ||
4950 | /* Next copy over first word, with mbxOwner set */ | |
34b02dcd | 4951 | ldata = *((uint32_t *)mb); |
dea3101e JB |
4952 | to_slim = phba->MBslimaddr; |
4953 | writel(ldata, to_slim); | |
4954 | readl(to_slim); /* flush */ | |
4955 | ||
4956 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
4957 | /* switch over to host mailbox */ | |
3772a991 | 4958 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
dea3101e JB |
4959 | } |
4960 | } | |
4961 | ||
4962 | wmb(); | |
dea3101e JB |
4963 | |
4964 | switch (flag) { | |
4965 | case MBX_NOWAIT: | |
09372820 | 4966 | /* Set up reference to mailbox command */ |
dea3101e | 4967 | psli->mbox_active = pmbox; |
09372820 JS |
4968 | /* Interrupt board to do it */ |
4969 | writel(CA_MBATT, phba->CAregaddr); | |
4970 | readl(phba->CAregaddr); /* flush */ | |
4971 | /* Don't wait for it to finish, just return */ | |
dea3101e JB |
4972 | break; |
4973 | ||
4974 | case MBX_POLL: | |
09372820 | 4975 | /* Set up null reference to mailbox command */ |
dea3101e | 4976 | psli->mbox_active = NULL; |
09372820 JS |
4977 | /* Interrupt board to do it */ |
4978 | writel(CA_MBATT, phba->CAregaddr); | |
4979 | readl(phba->CAregaddr); /* flush */ | |
4980 | ||
3772a991 | 4981 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 4982 | /* First read mbox status word */ |
34b02dcd | 4983 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
4984 | word0 = le32_to_cpu(word0); |
4985 | } else { | |
4986 | /* First read mbox status word */ | |
4987 | word0 = readl(phba->MBslimaddr); | |
4988 | } | |
4989 | ||
4990 | /* Read the HBA Host Attention Register */ | |
4991 | ha_copy = readl(phba->HAregaddr); | |
09372820 JS |
4992 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
4993 | mb->mbxCommand) * | |
4994 | 1000) + jiffies; | |
4995 | i = 0; | |
dea3101e | 4996 | /* Wait for command to complete */ |
41415862 JW |
4997 | while (((word0 & OWN_CHIP) == OWN_CHIP) || |
4998 | (!(ha_copy & HA_MBATT) && | |
2e0fef85 | 4999 | (phba->link_state > LPFC_WARM_START))) { |
09372820 | 5000 | if (time_after(jiffies, timeout)) { |
dea3101e | 5001 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
2e0fef85 | 5002 | spin_unlock_irqrestore(&phba->hbalock, |
dea3101e | 5003 | drvr_flag); |
58da1ffb | 5004 | goto out_not_finished; |
dea3101e JB |
5005 | } |
5006 | ||
5007 | /* Check if we took a mbox interrupt while we were | |
5008 | polling */ | |
5009 | if (((word0 & OWN_CHIP) != OWN_CHIP) | |
5010 | && (evtctr != psli->slistat.mbox_event)) | |
5011 | break; | |
5012 | ||
09372820 JS |
5013 | if (i++ > 10) { |
5014 | spin_unlock_irqrestore(&phba->hbalock, | |
5015 | drvr_flag); | |
5016 | msleep(1); | |
5017 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
5018 | } | |
dea3101e | 5019 | |
3772a991 | 5020 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5021 | /* First copy command data */ |
34b02dcd | 5022 | word0 = *((uint32_t *)phba->mbox); |
dea3101e JB |
5023 | word0 = le32_to_cpu(word0); |
5024 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | |
5025 | MAILBOX_t *slimmb; | |
34b02dcd | 5026 | uint32_t slimword0; |
dea3101e JB |
5027 | /* Check real SLIM for any errors */ |
5028 | slimword0 = readl(phba->MBslimaddr); | |
5029 | slimmb = (MAILBOX_t *) & slimword0; | |
5030 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | |
5031 | && slimmb->mbxStatus) { | |
5032 | psli->sli_flag &= | |
3772a991 | 5033 | ~LPFC_SLI_ACTIVE; |
dea3101e JB |
5034 | word0 = slimword0; |
5035 | } | |
5036 | } | |
5037 | } else { | |
5038 | /* First copy command data */ | |
5039 | word0 = readl(phba->MBslimaddr); | |
5040 | } | |
5041 | /* Read the HBA Host Attention Register */ | |
5042 | ha_copy = readl(phba->HAregaddr); | |
5043 | } | |
5044 | ||
3772a991 | 5045 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
dea3101e | 5046 | /* copy results back to user */ |
34b02dcd | 5047 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
7a470277 JS |
5048 | /* Copy the mailbox extension data */ |
5049 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5050 | lpfc_sli_pcimem_bcopy(phba->mbox_ext, | |
5051 | pmbox->context2, | |
5052 | pmbox->out_ext_byte_len); | |
5053 | } | |
dea3101e JB |
5054 | } else { |
5055 | /* First copy command data */ | |
5056 | lpfc_memcpy_from_slim(mb, phba->MBslimaddr, | |
5057 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
5058 | /* Copy the mailbox extension data */ |
5059 | if (pmbox->out_ext_byte_len && pmbox->context2) { | |
5060 | lpfc_memcpy_from_slim(pmbox->context2, | |
5061 | phba->MBslimaddr + | |
5062 | MAILBOX_HBA_EXT_OFFSET, | |
5063 | pmbox->out_ext_byte_len); | |
dea3101e JB |
5064 | } |
5065 | } | |
5066 | ||
5067 | writel(HA_MBATT, phba->HAregaddr); | |
5068 | readl(phba->HAregaddr); /* flush */ | |
5069 | ||
5070 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5071 | status = mb->mbxStatus; | |
5072 | } | |
5073 | ||
2e0fef85 JS |
5074 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
5075 | return status; | |
58da1ffb JS |
5076 | |
5077 | out_not_finished: | |
5078 | if (processing_queue) { | |
da0436e9 | 5079 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
58da1ffb JS |
5080 | lpfc_mbox_cmpl_put(phba, pmbox); |
5081 | } | |
5082 | return MBX_NOT_FINISHED; | |
dea3101e JB |
5083 | } |
5084 | ||
f1126688 JS |
5085 | /** |
5086 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | |
5087 | * @phba: Pointer to HBA context object. | |
5088 | * | |
5089 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | |
5090 | * the driver internal pending mailbox queue. It will then try to wait out the | |
5091 | * possible outstanding mailbox command before return. | |
5092 | * | |
5093 | * Returns: | |
5094 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | |
5095 | * the outstanding mailbox command timed out. | |
5096 | **/ | |
5097 | static int | |
5098 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | |
5099 | { | |
5100 | struct lpfc_sli *psli = &phba->sli; | |
5101 | uint8_t actcmd = MBX_HEARTBEAT; | |
5102 | int rc = 0; | |
5103 | unsigned long timeout; | |
5104 | ||
5105 | /* Mark the asynchronous mailbox command posting as blocked */ | |
5106 | spin_lock_irq(&phba->hbalock); | |
5107 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
5108 | if (phba->sli.mbox_active) | |
5109 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
5110 | spin_unlock_irq(&phba->hbalock); | |
5111 | /* Determine how long we might wait for the active mailbox | |
5112 | * command to be gracefully completed by firmware. | |
5113 | */ | |
5114 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
5115 | jiffies; | |
5116 | /* Wait for the outstnading mailbox command to complete */ | |
5117 | while (phba->sli.mbox_active) { | |
5118 | /* Check active mailbox complete status every 2ms */ | |
5119 | msleep(2); | |
5120 | if (time_after(jiffies, timeout)) { | |
5121 | /* Timeout, marked the outstanding cmd not complete */ | |
5122 | rc = 1; | |
5123 | break; | |
5124 | } | |
5125 | } | |
5126 | ||
5127 | /* Can not cleanly block async mailbox command, fails it */ | |
5128 | if (rc) { | |
5129 | spin_lock_irq(&phba->hbalock); | |
5130 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5131 | spin_unlock_irq(&phba->hbalock); | |
5132 | } | |
5133 | return rc; | |
5134 | } | |
5135 | ||
5136 | /** | |
5137 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | |
5138 | * @phba: Pointer to HBA context object. | |
5139 | * | |
5140 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | |
5141 | * commands from the driver internal pending mailbox queue. It makes sure | |
5142 | * that there is no outstanding mailbox command before resuming posting | |
5143 | * asynchronous mailbox commands. If, for any reason, there is outstanding | |
5144 | * mailbox command, it will try to wait it out before resuming asynchronous | |
5145 | * mailbox command posting. | |
5146 | **/ | |
5147 | static void | |
5148 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | |
5149 | { | |
5150 | struct lpfc_sli *psli = &phba->sli; | |
5151 | ||
5152 | spin_lock_irq(&phba->hbalock); | |
5153 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5154 | /* Asynchronous mailbox posting is not blocked, do nothing */ | |
5155 | spin_unlock_irq(&phba->hbalock); | |
5156 | return; | |
5157 | } | |
5158 | ||
5159 | /* Outstanding synchronous mailbox command is guaranteed to be done, | |
5160 | * successful or timeout, after timing-out the outstanding mailbox | |
5161 | * command shall always be removed, so just unblock posting async | |
5162 | * mailbox command and resume | |
5163 | */ | |
5164 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | |
5165 | spin_unlock_irq(&phba->hbalock); | |
5166 | ||
5167 | /* wake up worker thread to post asynchronlous mailbox command */ | |
5168 | lpfc_worker_wake_up(phba); | |
5169 | } | |
5170 | ||
da0436e9 JS |
5171 | /** |
5172 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | |
5173 | * @phba: Pointer to HBA context object. | |
5174 | * @mboxq: Pointer to mailbox object. | |
5175 | * | |
5176 | * The function posts a mailbox to the port. The mailbox is expected | |
5177 | * to be comletely filled in and ready for the port to operate on it. | |
5178 | * This routine executes a synchronous completion operation on the | |
5179 | * mailbox by polling for its completion. | |
5180 | * | |
5181 | * The caller must not be holding any locks when calling this routine. | |
5182 | * | |
5183 | * Returns: | |
5184 | * MBX_SUCCESS - mailbox posted successfully | |
5185 | * Any of the MBX error values. | |
5186 | **/ | |
5187 | static int | |
5188 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
5189 | { | |
5190 | int rc = MBX_SUCCESS; | |
5191 | unsigned long iflag; | |
5192 | uint32_t db_ready; | |
5193 | uint32_t mcqe_status; | |
5194 | uint32_t mbx_cmnd; | |
5195 | unsigned long timeout; | |
5196 | struct lpfc_sli *psli = &phba->sli; | |
5197 | struct lpfc_mqe *mb = &mboxq->u.mqe; | |
5198 | struct lpfc_bmbx_create *mbox_rgn; | |
5199 | struct dma_address *dma_address; | |
5200 | struct lpfc_register bmbx_reg; | |
5201 | ||
5202 | /* | |
5203 | * Only one mailbox can be active to the bootstrap mailbox region | |
5204 | * at a time and there is no queueing provided. | |
5205 | */ | |
5206 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5207 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5208 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5209 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5210 | "(%d):2532 Mailbox command x%x (x%x) " | |
5211 | "cannot issue Data: x%x x%x\n", | |
5212 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5213 | mboxq->u.mb.mbxCommand, | |
5214 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5215 | psli->sli_flag, MBX_POLL); | |
5216 | return MBXERR_ERROR; | |
5217 | } | |
5218 | /* The server grabs the token and owns it until release */ | |
5219 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5220 | phba->sli.mbox_active = mboxq; | |
5221 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5222 | ||
5223 | /* | |
5224 | * Initialize the bootstrap memory region to avoid stale data areas | |
5225 | * in the mailbox post. Then copy the caller's mailbox contents to | |
5226 | * the bmbx mailbox region. | |
5227 | */ | |
5228 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | |
5229 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | |
5230 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | |
5231 | sizeof(struct lpfc_mqe)); | |
5232 | ||
5233 | /* Post the high mailbox dma address to the port and wait for ready. */ | |
5234 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5235 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | |
5236 | ||
5237 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5238 | * 1000) + jiffies; | |
5239 | do { | |
5240 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5241 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5242 | if (!db_ready) | |
5243 | msleep(2); | |
5244 | ||
5245 | if (time_after(jiffies, timeout)) { | |
5246 | rc = MBXERR_ERROR; | |
5247 | goto exit; | |
5248 | } | |
5249 | } while (!db_ready); | |
5250 | ||
5251 | /* Post the low mailbox dma address to the port. */ | |
5252 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | |
5253 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | |
5254 | * 1000) + jiffies; | |
5255 | do { | |
5256 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | |
5257 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | |
5258 | if (!db_ready) | |
5259 | msleep(2); | |
5260 | ||
5261 | if (time_after(jiffies, timeout)) { | |
5262 | rc = MBXERR_ERROR; | |
5263 | goto exit; | |
5264 | } | |
5265 | } while (!db_ready); | |
5266 | ||
5267 | /* | |
5268 | * Read the CQ to ensure the mailbox has completed. | |
5269 | * If so, update the mailbox status so that the upper layers | |
5270 | * can complete the request normally. | |
5271 | */ | |
5272 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | |
5273 | sizeof(struct lpfc_mqe)); | |
5274 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | |
5275 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | |
5276 | sizeof(struct lpfc_mcqe)); | |
5277 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | |
5278 | ||
5279 | /* Prefix the mailbox status with range x4000 to note SLI4 status. */ | |
5280 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | |
5281 | bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status); | |
5282 | rc = MBXERR_ERROR; | |
5283 | } | |
5284 | ||
5285 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5286 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " | |
5287 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" | |
5288 | " x%x x%x CQ: x%x x%x x%x x%x\n", | |
5289 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5290 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5291 | bf_get(lpfc_mqe_status, mb), | |
5292 | mb->un.mb_words[0], mb->un.mb_words[1], | |
5293 | mb->un.mb_words[2], mb->un.mb_words[3], | |
5294 | mb->un.mb_words[4], mb->un.mb_words[5], | |
5295 | mb->un.mb_words[6], mb->un.mb_words[7], | |
5296 | mb->un.mb_words[8], mb->un.mb_words[9], | |
5297 | mb->un.mb_words[10], mb->un.mb_words[11], | |
5298 | mb->un.mb_words[12], mboxq->mcqe.word0, | |
5299 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | |
5300 | mboxq->mcqe.trailer); | |
5301 | exit: | |
5302 | /* We are holding the token, no needed for lock when release */ | |
5303 | spin_lock_irqsave(&phba->hbalock, iflag); | |
5304 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5305 | phba->sli.mbox_active = NULL; | |
5306 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
5307 | return rc; | |
5308 | } | |
5309 | ||
5310 | /** | |
5311 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | |
5312 | * @phba: Pointer to HBA context object. | |
5313 | * @pmbox: Pointer to mailbox object. | |
5314 | * @flag: Flag indicating how the mailbox need to be processed. | |
5315 | * | |
5316 | * This function is called by discovery code and HBA management code to submit | |
5317 | * a mailbox command to firmware with SLI-4 interface spec. | |
5318 | * | |
5319 | * Return codes the caller owns the mailbox command after the return of the | |
5320 | * function. | |
5321 | **/ | |
5322 | static int | |
5323 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | |
5324 | uint32_t flag) | |
5325 | { | |
5326 | struct lpfc_sli *psli = &phba->sli; | |
5327 | unsigned long iflags; | |
5328 | int rc; | |
5329 | ||
8fa38513 JS |
5330 | rc = lpfc_mbox_dev_check(phba); |
5331 | if (unlikely(rc)) { | |
5332 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5333 | "(%d):2544 Mailbox command x%x (x%x) " | |
5334 | "cannot issue Data: x%x x%x\n", | |
5335 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5336 | mboxq->u.mb.mbxCommand, | |
5337 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5338 | psli->sli_flag, flag); | |
5339 | goto out_not_finished; | |
5340 | } | |
5341 | ||
da0436e9 JS |
5342 | /* Detect polling mode and jump to a handler */ |
5343 | if (!phba->sli4_hba.intr_enable) { | |
5344 | if (flag == MBX_POLL) | |
5345 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5346 | else | |
5347 | rc = -EIO; | |
5348 | if (rc != MBX_SUCCESS) | |
5349 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5350 | "(%d):2541 Mailbox command x%x " | |
5351 | "(x%x) cannot issue Data: x%x x%x\n", | |
5352 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5353 | mboxq->u.mb.mbxCommand, | |
5354 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5355 | psli->sli_flag, flag); | |
5356 | return rc; | |
5357 | } else if (flag == MBX_POLL) { | |
f1126688 JS |
5358 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, |
5359 | "(%d):2542 Try to issue mailbox command " | |
5360 | "x%x (x%x) synchronously ahead of async" | |
5361 | "mailbox command queue: x%x x%x\n", | |
da0436e9 JS |
5362 | mboxq->vport ? mboxq->vport->vpi : 0, |
5363 | mboxq->u.mb.mbxCommand, | |
5364 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5365 | psli->sli_flag, flag); | |
f1126688 JS |
5366 | /* Try to block the asynchronous mailbox posting */ |
5367 | rc = lpfc_sli4_async_mbox_block(phba); | |
5368 | if (!rc) { | |
5369 | /* Successfully blocked, now issue sync mbox cmd */ | |
5370 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | |
5371 | if (rc != MBX_SUCCESS) | |
5372 | lpfc_printf_log(phba, KERN_ERR, | |
5373 | LOG_MBOX | LOG_SLI, | |
5374 | "(%d):2597 Mailbox command " | |
5375 | "x%x (x%x) cannot issue " | |
5376 | "Data: x%x x%x\n", | |
5377 | mboxq->vport ? | |
5378 | mboxq->vport->vpi : 0, | |
5379 | mboxq->u.mb.mbxCommand, | |
5380 | lpfc_sli4_mbox_opcode_get(phba, | |
5381 | mboxq), | |
5382 | psli->sli_flag, flag); | |
5383 | /* Unblock the async mailbox posting afterward */ | |
5384 | lpfc_sli4_async_mbox_unblock(phba); | |
5385 | } | |
5386 | return rc; | |
da0436e9 JS |
5387 | } |
5388 | ||
5389 | /* Now, interrupt mode asynchrous mailbox command */ | |
5390 | rc = lpfc_mbox_cmd_check(phba, mboxq); | |
5391 | if (rc) { | |
5392 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5393 | "(%d):2543 Mailbox command x%x (x%x) " | |
5394 | "cannot issue Data: x%x x%x\n", | |
5395 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5396 | mboxq->u.mb.mbxCommand, | |
5397 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5398 | psli->sli_flag, flag); | |
5399 | goto out_not_finished; | |
5400 | } | |
da0436e9 JS |
5401 | |
5402 | /* Put the mailbox command to the driver internal FIFO */ | |
5403 | psli->slistat.mbox_busy++; | |
5404 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5405 | lpfc_mbox_put(phba, mboxq); | |
5406 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5407 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5408 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | |
5409 | "x%x (x%x) x%x x%x x%x\n", | |
5410 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, | |
5411 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5412 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5413 | phba->pport->port_state, | |
5414 | psli->sli_flag, MBX_NOWAIT); | |
5415 | /* Wake up worker thread to transport mailbox command from head */ | |
5416 | lpfc_worker_wake_up(phba); | |
5417 | ||
5418 | return MBX_BUSY; | |
5419 | ||
5420 | out_not_finished: | |
5421 | return MBX_NOT_FINISHED; | |
5422 | } | |
5423 | ||
5424 | /** | |
5425 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | |
5426 | * @phba: Pointer to HBA context object. | |
5427 | * | |
5428 | * This function is called by worker thread to send a mailbox command to | |
5429 | * SLI4 HBA firmware. | |
5430 | * | |
5431 | **/ | |
5432 | int | |
5433 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | |
5434 | { | |
5435 | struct lpfc_sli *psli = &phba->sli; | |
5436 | LPFC_MBOXQ_t *mboxq; | |
5437 | int rc = MBX_SUCCESS; | |
5438 | unsigned long iflags; | |
5439 | struct lpfc_mqe *mqe; | |
5440 | uint32_t mbx_cmnd; | |
5441 | ||
5442 | /* Check interrupt mode before post async mailbox command */ | |
5443 | if (unlikely(!phba->sli4_hba.intr_enable)) | |
5444 | return MBX_NOT_FINISHED; | |
5445 | ||
5446 | /* Check for mailbox command service token */ | |
5447 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5448 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | |
5449 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5450 | return MBX_NOT_FINISHED; | |
5451 | } | |
5452 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
5453 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5454 | return MBX_NOT_FINISHED; | |
5455 | } | |
5456 | if (unlikely(phba->sli.mbox_active)) { | |
5457 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5458 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5459 | "0384 There is pending active mailbox cmd\n"); | |
5460 | return MBX_NOT_FINISHED; | |
5461 | } | |
5462 | /* Take the mailbox command service token */ | |
5463 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | |
5464 | ||
5465 | /* Get the next mailbox command from head of queue */ | |
5466 | mboxq = lpfc_mbox_get(phba); | |
5467 | ||
5468 | /* If no more mailbox command waiting for post, we're done */ | |
5469 | if (!mboxq) { | |
5470 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5471 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5472 | return MBX_SUCCESS; | |
5473 | } | |
5474 | phba->sli.mbox_active = mboxq; | |
5475 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5476 | ||
5477 | /* Check device readiness for posting mailbox command */ | |
5478 | rc = lpfc_mbox_dev_check(phba); | |
5479 | if (unlikely(rc)) | |
5480 | /* Driver clean routine will clean up pending mailbox */ | |
5481 | goto out_not_finished; | |
5482 | ||
5483 | /* Prepare the mbox command to be posted */ | |
5484 | mqe = &mboxq->u.mqe; | |
5485 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | |
5486 | ||
5487 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | |
5488 | mod_timer(&psli->mbox_tmo, (jiffies + | |
5489 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); | |
5490 | ||
5491 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | |
5492 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " | |
5493 | "x%x x%x\n", | |
5494 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | |
5495 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5496 | phba->pport->port_state, psli->sli_flag); | |
5497 | ||
5498 | if (mbx_cmnd != MBX_HEARTBEAT) { | |
5499 | if (mboxq->vport) { | |
5500 | lpfc_debugfs_disc_trc(mboxq->vport, | |
5501 | LPFC_DISC_TRC_MBOX_VPORT, | |
5502 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | |
5503 | mbx_cmnd, mqe->un.mb_words[0], | |
5504 | mqe->un.mb_words[1]); | |
5505 | } else { | |
5506 | lpfc_debugfs_disc_trc(phba->pport, | |
5507 | LPFC_DISC_TRC_MBOX, | |
5508 | "MBOX Send: cmd:x%x mb:x%x x%x", | |
5509 | mbx_cmnd, mqe->un.mb_words[0], | |
5510 | mqe->un.mb_words[1]); | |
5511 | } | |
5512 | } | |
5513 | psli->slistat.mbox_cmd++; | |
5514 | ||
5515 | /* Post the mailbox command to the port */ | |
5516 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | |
5517 | if (rc != MBX_SUCCESS) { | |
5518 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5519 | "(%d):2533 Mailbox command x%x (x%x) " | |
5520 | "cannot issue Data: x%x x%x\n", | |
5521 | mboxq->vport ? mboxq->vport->vpi : 0, | |
5522 | mboxq->u.mb.mbxCommand, | |
5523 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | |
5524 | psli->sli_flag, MBX_NOWAIT); | |
5525 | goto out_not_finished; | |
5526 | } | |
5527 | ||
5528 | return rc; | |
5529 | ||
5530 | out_not_finished: | |
5531 | spin_lock_irqsave(&phba->hbalock, iflags); | |
5532 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
5533 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
5534 | /* Release the token */ | |
5535 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
5536 | phba->sli.mbox_active = NULL; | |
5537 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
5538 | ||
5539 | return MBX_NOT_FINISHED; | |
5540 | } | |
5541 | ||
5542 | /** | |
5543 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | |
5544 | * @phba: Pointer to HBA context object. | |
5545 | * @pmbox: Pointer to mailbox object. | |
5546 | * @flag: Flag indicating how the mailbox need to be processed. | |
5547 | * | |
5548 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | |
5549 | * the API jump table function pointer from the lpfc_hba struct. | |
5550 | * | |
5551 | * Return codes the caller owns the mailbox command after the return of the | |
5552 | * function. | |
5553 | **/ | |
5554 | int | |
5555 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |
5556 | { | |
5557 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | |
5558 | } | |
5559 | ||
5560 | /** | |
5561 | * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table | |
5562 | * @phba: The hba struct for which this call is being executed. | |
5563 | * @dev_grp: The HBA PCI-Device group number. | |
5564 | * | |
5565 | * This routine sets up the mbox interface API function jump table in @phba | |
5566 | * struct. | |
5567 | * Returns: 0 - success, -ENODEV - failure. | |
5568 | **/ | |
5569 | int | |
5570 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
5571 | { | |
5572 | ||
5573 | switch (dev_grp) { | |
5574 | case LPFC_PCI_DEV_LP: | |
5575 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | |
5576 | phba->lpfc_sli_handle_slow_ring_event = | |
5577 | lpfc_sli_handle_slow_ring_event_s3; | |
5578 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | |
5579 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | |
5580 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | |
5581 | break; | |
5582 | case LPFC_PCI_DEV_OC: | |
5583 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | |
5584 | phba->lpfc_sli_handle_slow_ring_event = | |
5585 | lpfc_sli_handle_slow_ring_event_s4; | |
5586 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | |
5587 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | |
5588 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | |
5589 | break; | |
5590 | default: | |
5591 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5592 | "1420 Invalid HBA PCI-device group: 0x%x\n", | |
5593 | dev_grp); | |
5594 | return -ENODEV; | |
5595 | break; | |
5596 | } | |
5597 | return 0; | |
5598 | } | |
5599 | ||
e59058c4 | 5600 | /** |
3621a710 | 5601 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
e59058c4 JS |
5602 | * @phba: Pointer to HBA context object. |
5603 | * @pring: Pointer to driver SLI ring object. | |
5604 | * @piocb: Pointer to address of newly added command iocb. | |
5605 | * | |
5606 | * This function is called with hbalock held to add a command | |
5607 | * iocb to the txq when SLI layer cannot submit the command iocb | |
5608 | * to the ring. | |
5609 | **/ | |
2a9bf3d0 | 5610 | void |
92d7f7b0 | 5611 | __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
2e0fef85 | 5612 | struct lpfc_iocbq *piocb) |
dea3101e JB |
5613 | { |
5614 | /* Insert the caller's iocb in the txq tail for later processing. */ | |
5615 | list_add_tail(&piocb->list, &pring->txq); | |
5616 | pring->txq_cnt++; | |
dea3101e JB |
5617 | } |
5618 | ||
e59058c4 | 5619 | /** |
3621a710 | 5620 | * lpfc_sli_next_iocb - Get the next iocb in the txq |
e59058c4 JS |
5621 | * @phba: Pointer to HBA context object. |
5622 | * @pring: Pointer to driver SLI ring object. | |
5623 | * @piocb: Pointer to address of newly added command iocb. | |
5624 | * | |
5625 | * This function is called with hbalock held before a new | |
5626 | * iocb is submitted to the firmware. This function checks | |
5627 | * txq to flush the iocbs in txq to Firmware before | |
5628 | * submitting new iocbs to the Firmware. | |
5629 | * If there are iocbs in the txq which need to be submitted | |
5630 | * to firmware, lpfc_sli_next_iocb returns the first element | |
5631 | * of the txq after dequeuing it from txq. | |
5632 | * If there is no iocb in the txq then the function will return | |
5633 | * *piocb and *piocb is set to NULL. Caller needs to check | |
5634 | * *piocb to find if there are more commands in the txq. | |
5635 | **/ | |
dea3101e JB |
5636 | static struct lpfc_iocbq * |
5637 | lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
2e0fef85 | 5638 | struct lpfc_iocbq **piocb) |
dea3101e JB |
5639 | { |
5640 | struct lpfc_iocbq * nextiocb; | |
5641 | ||
5642 | nextiocb = lpfc_sli_ringtx_get(phba, pring); | |
5643 | if (!nextiocb) { | |
5644 | nextiocb = *piocb; | |
5645 | *piocb = NULL; | |
5646 | } | |
5647 | ||
5648 | return nextiocb; | |
5649 | } | |
5650 | ||
e59058c4 | 5651 | /** |
3772a991 | 5652 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
e59058c4 | 5653 | * @phba: Pointer to HBA context object. |
3772a991 | 5654 | * @ring_number: SLI ring number to issue iocb on. |
e59058c4 JS |
5655 | * @piocb: Pointer to command iocb. |
5656 | * @flag: Flag indicating if this command can be put into txq. | |
5657 | * | |
3772a991 JS |
5658 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
5659 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is | |
5660 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT | |
5661 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, | |
5662 | * this function allows only iocbs for posting buffers. This function finds | |
5663 | * next available slot in the command ring and posts the command to the | |
5664 | * available slot and writes the port attention register to request HBA start | |
5665 | * processing new iocb. If there is no slot available in the ring and | |
5666 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise | |
5667 | * the function returns IOCB_BUSY. | |
e59058c4 | 5668 | * |
3772a991 JS |
5669 | * This function is called with hbalock held. The function will return success |
5670 | * after it successfully submit the iocb to firmware or after adding to the | |
5671 | * txq. | |
e59058c4 | 5672 | **/ |
98c9ea5c | 5673 | static int |
3772a991 | 5674 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
dea3101e JB |
5675 | struct lpfc_iocbq *piocb, uint32_t flag) |
5676 | { | |
5677 | struct lpfc_iocbq *nextiocb; | |
5678 | IOCB_t *iocb; | |
3772a991 | 5679 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; |
dea3101e | 5680 | |
92d7f7b0 JS |
5681 | if (piocb->iocb_cmpl && (!piocb->vport) && |
5682 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | |
5683 | (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) { | |
5684 | lpfc_printf_log(phba, KERN_ERR, | |
5685 | LOG_SLI | LOG_VPORT, | |
e8b62011 | 5686 | "1807 IOCB x%x failed. No vport\n", |
92d7f7b0 JS |
5687 | piocb->iocb.ulpCommand); |
5688 | dump_stack(); | |
5689 | return IOCB_ERROR; | |
5690 | } | |
5691 | ||
5692 | ||
8d63f375 LV |
5693 | /* If the PCI channel is in offline state, do not post iocbs. */ |
5694 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
5695 | return IOCB_ERROR; | |
5696 | ||
a257bf90 JS |
5697 | /* If HBA has a deferred error attention, fail the iocb. */ |
5698 | if (unlikely(phba->hba_flag & DEFER_ERATT)) | |
5699 | return IOCB_ERROR; | |
5700 | ||
dea3101e JB |
5701 | /* |
5702 | * We should never get an IOCB if we are in a < LINK_DOWN state | |
5703 | */ | |
2e0fef85 | 5704 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) |
dea3101e JB |
5705 | return IOCB_ERROR; |
5706 | ||
5707 | /* | |
5708 | * Check to see if we are blocking IOCB processing because of a | |
0b727fea | 5709 | * outstanding event. |
dea3101e | 5710 | */ |
0b727fea | 5711 | if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT)) |
dea3101e JB |
5712 | goto iocb_busy; |
5713 | ||
2e0fef85 | 5714 | if (unlikely(phba->link_state == LPFC_LINK_DOWN)) { |
dea3101e | 5715 | /* |
2680eeaa | 5716 | * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF |
dea3101e JB |
5717 | * can be issued if the link is not up. |
5718 | */ | |
5719 | switch (piocb->iocb.ulpCommand) { | |
84774a4d JS |
5720 | case CMD_GEN_REQUEST64_CR: |
5721 | case CMD_GEN_REQUEST64_CX: | |
5722 | if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) || | |
5723 | (piocb->iocb.un.genreq64.w5.hcsw.Rctl != | |
6a9c52cf | 5724 | FC_RCTL_DD_UNSOL_CMD) || |
84774a4d JS |
5725 | (piocb->iocb.un.genreq64.w5.hcsw.Type != |
5726 | MENLO_TRANSPORT_TYPE)) | |
5727 | ||
5728 | goto iocb_busy; | |
5729 | break; | |
dea3101e JB |
5730 | case CMD_QUE_RING_BUF_CN: |
5731 | case CMD_QUE_RING_BUF64_CN: | |
dea3101e JB |
5732 | /* |
5733 | * For IOCBs, like QUE_RING_BUF, that have no rsp ring | |
5734 | * completion, iocb_cmpl MUST be 0. | |
5735 | */ | |
5736 | if (piocb->iocb_cmpl) | |
5737 | piocb->iocb_cmpl = NULL; | |
5738 | /*FALLTHROUGH*/ | |
5739 | case CMD_CREATE_XRI_CR: | |
2680eeaa JS |
5740 | case CMD_CLOSE_XRI_CN: |
5741 | case CMD_CLOSE_XRI_CX: | |
dea3101e JB |
5742 | break; |
5743 | default: | |
5744 | goto iocb_busy; | |
5745 | } | |
5746 | ||
5747 | /* | |
5748 | * For FCP commands, we must be in a state where we can process link | |
5749 | * attention events. | |
5750 | */ | |
5751 | } else if (unlikely(pring->ringno == phba->sli.fcp_ring && | |
92d7f7b0 | 5752 | !(phba->sli.sli_flag & LPFC_PROCESS_LA))) { |
dea3101e | 5753 | goto iocb_busy; |
92d7f7b0 | 5754 | } |
dea3101e | 5755 | |
dea3101e JB |
5756 | while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && |
5757 | (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) | |
5758 | lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); | |
5759 | ||
5760 | if (iocb) | |
5761 | lpfc_sli_update_ring(phba, pring); | |
5762 | else | |
5763 | lpfc_sli_update_full_ring(phba, pring); | |
5764 | ||
5765 | if (!piocb) | |
5766 | return IOCB_SUCCESS; | |
5767 | ||
5768 | goto out_busy; | |
5769 | ||
5770 | iocb_busy: | |
5771 | pring->stats.iocb_cmd_delay++; | |
5772 | ||
5773 | out_busy: | |
5774 | ||
5775 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
92d7f7b0 | 5776 | __lpfc_sli_ringtx_put(phba, pring, piocb); |
dea3101e JB |
5777 | return IOCB_SUCCESS; |
5778 | } | |
5779 | ||
5780 | return IOCB_BUSY; | |
5781 | } | |
5782 | ||
3772a991 | 5783 | /** |
4f774513 JS |
5784 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. |
5785 | * @phba: Pointer to HBA context object. | |
5786 | * @piocb: Pointer to command iocb. | |
5787 | * @sglq: Pointer to the scatter gather queue object. | |
5788 | * | |
5789 | * This routine converts the bpl or bde that is in the IOCB | |
5790 | * to a sgl list for the sli4 hardware. The physical address | |
5791 | * of the bpl/bde is converted back to a virtual address. | |
5792 | * If the IOCB contains a BPL then the list of BDE's is | |
5793 | * converted to sli4_sge's. If the IOCB contains a single | |
5794 | * BDE then it is converted to a single sli_sge. | |
5795 | * The IOCB is still in cpu endianess so the contents of | |
5796 | * the bpl can be used without byte swapping. | |
5797 | * | |
5798 | * Returns valid XRI = Success, NO_XRI = Failure. | |
5799 | **/ | |
5800 | static uint16_t | |
5801 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | |
5802 | struct lpfc_sglq *sglq) | |
3772a991 | 5803 | { |
4f774513 JS |
5804 | uint16_t xritag = NO_XRI; |
5805 | struct ulp_bde64 *bpl = NULL; | |
5806 | struct ulp_bde64 bde; | |
5807 | struct sli4_sge *sgl = NULL; | |
5808 | IOCB_t *icmd; | |
5809 | int numBdes = 0; | |
5810 | int i = 0; | |
3772a991 | 5811 | |
4f774513 JS |
5812 | if (!piocbq || !sglq) |
5813 | return xritag; | |
5814 | ||
5815 | sgl = (struct sli4_sge *)sglq->sgl; | |
5816 | icmd = &piocbq->iocb; | |
5817 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5818 | numBdes = icmd->un.genreq64.bdl.bdeSize / | |
5819 | sizeof(struct ulp_bde64); | |
5820 | /* The addrHigh and addrLow fields within the IOCB | |
5821 | * have not been byteswapped yet so there is no | |
5822 | * need to swap them back. | |
5823 | */ | |
5824 | bpl = (struct ulp_bde64 *) | |
5825 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | |
5826 | ||
5827 | if (!bpl) | |
5828 | return xritag; | |
5829 | ||
5830 | for (i = 0; i < numBdes; i++) { | |
5831 | /* Should already be byte swapped. */ | |
28baac74 JS |
5832 | sgl->addr_hi = bpl->addrHigh; |
5833 | sgl->addr_lo = bpl->addrLow; | |
5834 | ||
4f774513 JS |
5835 | if ((i+1) == numBdes) |
5836 | bf_set(lpfc_sli4_sge_last, sgl, 1); | |
5837 | else | |
5838 | bf_set(lpfc_sli4_sge_last, sgl, 0); | |
5839 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
5840 | /* swap the size field back to the cpu so we |
5841 | * can assign it to the sgl. | |
5842 | */ | |
5843 | bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5844 | sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize); | |
4f774513 JS |
5845 | bpl++; |
5846 | sgl++; | |
5847 | } | |
5848 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | |
5849 | /* The addrHigh and addrLow fields of the BDE have not | |
5850 | * been byteswapped yet so they need to be swapped | |
5851 | * before putting them in the sgl. | |
5852 | */ | |
5853 | sgl->addr_hi = | |
5854 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | |
5855 | sgl->addr_lo = | |
5856 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | |
4f774513 JS |
5857 | bf_set(lpfc_sli4_sge_last, sgl, 1); |
5858 | sgl->word2 = cpu_to_le32(sgl->word2); | |
28baac74 JS |
5859 | sgl->sge_len = |
5860 | cpu_to_le32(icmd->un.genreq64.bdl.bdeSize); | |
4f774513 JS |
5861 | } |
5862 | return sglq->sli4_xritag; | |
3772a991 | 5863 | } |
92d7f7b0 | 5864 | |
e59058c4 | 5865 | /** |
4f774513 | 5866 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution |
e59058c4 | 5867 | * @phba: Pointer to HBA context object. |
e59058c4 | 5868 | * |
4f774513 | 5869 | * This routine performs a round robin SCSI command to SLI4 FCP WQ index |
8fa38513 JS |
5870 | * distribution. This is called by __lpfc_sli_issue_iocb_s4() with the hbalock |
5871 | * held. | |
4f774513 JS |
5872 | * |
5873 | * Return: index into SLI4 fast-path FCP queue index. | |
e59058c4 | 5874 | **/ |
4f774513 | 5875 | static uint32_t |
8fa38513 | 5876 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba) |
92d7f7b0 | 5877 | { |
8fa38513 JS |
5878 | ++phba->fcp_qidx; |
5879 | if (phba->fcp_qidx >= phba->cfg_fcp_wq_count) | |
5880 | phba->fcp_qidx = 0; | |
92d7f7b0 | 5881 | |
8fa38513 | 5882 | return phba->fcp_qidx; |
92d7f7b0 JS |
5883 | } |
5884 | ||
e59058c4 | 5885 | /** |
4f774513 | 5886 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. |
e59058c4 | 5887 | * @phba: Pointer to HBA context object. |
4f774513 JS |
5888 | * @piocb: Pointer to command iocb. |
5889 | * @wqe: Pointer to the work queue entry. | |
e59058c4 | 5890 | * |
4f774513 JS |
5891 | * This routine converts the iocb command to its Work Queue Entry |
5892 | * equivalent. The wqe pointer should not have any fields set when | |
5893 | * this routine is called because it will memcpy over them. | |
5894 | * This routine does not set the CQ_ID or the WQEC bits in the | |
5895 | * wqe. | |
e59058c4 | 5896 | * |
4f774513 | 5897 | * Returns: 0 = Success, IOCB_ERROR = Failure. |
e59058c4 | 5898 | **/ |
cf5bf97e | 5899 | static int |
4f774513 JS |
5900 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, |
5901 | union lpfc_wqe *wqe) | |
cf5bf97e | 5902 | { |
5ffc266e | 5903 | uint32_t xmit_len = 0, total_len = 0; |
4f774513 JS |
5904 | uint8_t ct = 0; |
5905 | uint32_t fip; | |
5906 | uint32_t abort_tag; | |
5907 | uint8_t command_type = ELS_COMMAND_NON_FIP; | |
5908 | uint8_t cmnd; | |
5909 | uint16_t xritag; | |
5910 | struct ulp_bde64 *bpl = NULL; | |
c868595d | 5911 | uint32_t els_id = ELS_ID_DEFAULT; |
5ffc266e JS |
5912 | int numBdes, i; |
5913 | struct ulp_bde64 bde; | |
4f774513 | 5914 | |
45ed1190 | 5915 | fip = phba->hba_flag & HBA_FIP_SUPPORT; |
4f774513 | 5916 | /* The fcp commands will set command type */ |
0c287589 | 5917 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
4f774513 | 5918 | command_type = FCP_COMMAND; |
c868595d | 5919 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK)) |
0c287589 JS |
5920 | command_type = ELS_COMMAND_FIP; |
5921 | else | |
5922 | command_type = ELS_COMMAND_NON_FIP; | |
5923 | ||
4f774513 JS |
5924 | /* Some of the fields are in the right position already */ |
5925 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | |
5926 | abort_tag = (uint32_t) iocbq->iotag; | |
5927 | xritag = iocbq->sli4_xritag; | |
5928 | wqe->words[7] = 0; /* The ct field has moved so reset */ | |
5929 | /* words0-2 bpl convert bde */ | |
5930 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | |
5ffc266e JS |
5931 | numBdes = iocbq->iocb.un.genreq64.bdl.bdeSize / |
5932 | sizeof(struct ulp_bde64); | |
4f774513 JS |
5933 | bpl = (struct ulp_bde64 *) |
5934 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | |
5935 | if (!bpl) | |
5936 | return IOCB_ERROR; | |
cf5bf97e | 5937 | |
4f774513 JS |
5938 | /* Should already be byte swapped. */ |
5939 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | |
5940 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | |
5941 | /* swap the size field back to the cpu so we | |
5942 | * can assign it to the sgl. | |
5943 | */ | |
5944 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | |
5ffc266e JS |
5945 | xmit_len = wqe->generic.bde.tus.f.bdeSize; |
5946 | total_len = 0; | |
5947 | for (i = 0; i < numBdes; i++) { | |
5948 | bde.tus.w = le32_to_cpu(bpl[i].tus.w); | |
5949 | total_len += bde.tus.f.bdeSize; | |
5950 | } | |
4f774513 | 5951 | } else |
5ffc266e | 5952 | xmit_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; |
cf5bf97e | 5953 | |
4f774513 JS |
5954 | iocbq->iocb.ulpIoTag = iocbq->iotag; |
5955 | cmnd = iocbq->iocb.ulpCommand; | |
a4bc3379 | 5956 | |
4f774513 JS |
5957 | switch (iocbq->iocb.ulpCommand) { |
5958 | case CMD_ELS_REQUEST64_CR: | |
5959 | if (!iocbq->iocb.ulpLe) { | |
5960 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5961 | "2007 Only Limited Edition cmd Format" | |
5962 | " supported 0x%x\n", | |
5963 | iocbq->iocb.ulpCommand); | |
5964 | return IOCB_ERROR; | |
5965 | } | |
5ffc266e | 5966 | wqe->els_req.payload_len = xmit_len; |
4f774513 JS |
5967 | /* Els_reguest64 has a TMO */ |
5968 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | |
5969 | iocbq->iocb.ulpTimeout); | |
5970 | /* Need a VF for word 4 set the vf bit*/ | |
5971 | bf_set(els_req64_vf, &wqe->els_req, 0); | |
5972 | /* And a VFID for word 12 */ | |
5973 | bf_set(els_req64_vfid, &wqe->els_req, 0); | |
5974 | /* | |
5975 | * Set ct field to 3, indicates that the context_tag field | |
5976 | * contains the FCFI and remote N_Port_ID is | |
5977 | * in word 5. | |
5978 | */ | |
5979 | ||
5980 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
5981 | bf_set(lpfc_wqe_gen_context, &wqe->generic, | |
5982 | iocbq->iocb.ulpContext); | |
5983 | ||
4f774513 JS |
5984 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct); |
5985 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); | |
5986 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ | |
c868595d JS |
5987 | |
5988 | if (command_type == ELS_COMMAND_FIP) { | |
5989 | els_id = ((iocbq->iocb_flag & LPFC_FIP_ELS_ID_MASK) | |
5990 | >> LPFC_FIP_ELS_ID_SHIFT); | |
5991 | } | |
5992 | bf_set(lpfc_wqe_gen_els_id, &wqe->generic, els_id); | |
5993 | ||
4f774513 | 5994 | break; |
5ffc266e JS |
5995 | case CMD_XMIT_SEQUENCE64_CX: |
5996 | bf_set(lpfc_wqe_gen_context, &wqe->generic, | |
5997 | iocbq->iocb.un.ulpWord[3]); | |
5998 | wqe->generic.word3 = 0; | |
5999 | bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext); | |
5ffc266e JS |
6000 | /* The entire sequence is transmitted for this IOCB */ |
6001 | xmit_len = total_len; | |
6002 | cmnd = CMD_XMIT_SEQUENCE64_CR; | |
4f774513 JS |
6003 | case CMD_XMIT_SEQUENCE64_CR: |
6004 | /* word3 iocb=io_tag32 wqe=payload_offset */ | |
6005 | /* payload offset used for multilpe outstanding | |
6006 | * sequences on the same exchange | |
6007 | */ | |
6008 | wqe->words[3] = 0; | |
6009 | /* word4 relative_offset memcpy */ | |
6010 | /* word5 r_ctl/df_ctl memcpy */ | |
6011 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); | |
5ffc266e JS |
6012 | wqe->xmit_sequence.xmit_len = xmit_len; |
6013 | command_type = OTHER_COMMAND; | |
4f774513 JS |
6014 | break; |
6015 | case CMD_XMIT_BCAST64_CN: | |
6016 | /* word3 iocb=iotag32 wqe=payload_len */ | |
6017 | wqe->words[3] = 0; /* no definition for this in wqe */ | |
6018 | /* word4 iocb=rsvd wqe=rsvd */ | |
6019 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | |
6020 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | |
6021 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, | |
6022 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
6023 | break; | |
6024 | case CMD_FCP_IWRITE64_CR: | |
6025 | command_type = FCP_COMMAND_DATA_OUT; | |
6026 | /* The struct for wqe fcp_iwrite has 3 fields that are somewhat | |
6027 | * confusing. | |
6028 | * word3 is payload_len: byte offset to the sgl entry for the | |
6029 | * fcp_command. | |
6030 | * word4 is total xfer len, same as the IOCB->ulpParameter. | |
6031 | * word5 is initial xfer len 0 = wait for xfer-ready | |
6032 | */ | |
6033 | ||
6034 | /* Always wait for xfer-ready before sending data */ | |
6035 | wqe->fcp_iwrite.initial_xfer_len = 0; | |
6036 | /* word 4 (xfer length) should have been set on the memcpy */ | |
6037 | ||
6038 | /* allow write to fall through to read */ | |
6039 | case CMD_FCP_IREAD64_CR: | |
6040 | /* FCP_CMD is always the 1st sgl entry */ | |
6041 | wqe->fcp_iread.payload_len = | |
5ffc266e | 6042 | xmit_len + sizeof(struct fcp_rsp); |
4f774513 JS |
6043 | |
6044 | /* word 4 (xfer length) should have been set on the memcpy */ | |
6045 | ||
6046 | bf_set(lpfc_wqe_gen_erp, &wqe->generic, | |
6047 | iocbq->iocb.ulpFCP2Rcvy); | |
6048 | bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS); | |
6049 | /* The XC bit and the XS bit are similar. The driver never | |
6050 | * tracked whether or not the exchange was previouslly open. | |
6051 | * XC = Exchange create, 0 is create. 1 is already open. | |
6052 | * XS = link cmd: 1 do not close the exchange after command. | |
6053 | * XS = 0 close exchange when command completes. | |
6054 | * The only time we would not set the XC bit is when the XS bit | |
6055 | * is set and we are sending our 2nd or greater command on | |
6056 | * this exchange. | |
6057 | */ | |
f1126688 JS |
6058 | /* Always open the exchange */ |
6059 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
4f774513 | 6060 | |
f1126688 JS |
6061 | wqe->words[10] &= 0xffff0000; /* zero out ebde count */ |
6062 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); | |
6063 | break; | |
4f774513 JS |
6064 | case CMD_FCP_ICMND64_CR: |
6065 | /* Always open the exchange */ | |
6066 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | |
6067 | ||
f1126688 | 6068 | wqe->words[4] = 0; |
4f774513 | 6069 | wqe->words[10] &= 0xffff0000; /* zero out ebde count */ |
f1126688 | 6070 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); |
4f774513 JS |
6071 | break; |
6072 | case CMD_GEN_REQUEST64_CR: | |
6073 | /* word3 command length is described as byte offset to the | |
6074 | * rsp_data. Would always be 16, sizeof(struct sli4_sge) | |
6075 | * sgl[0] = cmnd | |
6076 | * sgl[1] = rsp. | |
6077 | * | |
6078 | */ | |
5ffc266e | 6079 | wqe->gen_req.command_len = xmit_len; |
4f774513 JS |
6080 | /* Word4 parameter copied in the memcpy */ |
6081 | /* Word5 [rctl, type, df_ctl, la] copied in memcpy */ | |
6082 | /* word6 context tag copied in memcpy */ | |
6083 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | |
6084 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | |
6085 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6086 | "2015 Invalid CT %x command 0x%x\n", | |
6087 | ct, iocbq->iocb.ulpCommand); | |
6088 | return IOCB_ERROR; | |
6089 | } | |
6090 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0); | |
6091 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, | |
6092 | iocbq->iocb.ulpTimeout); | |
6093 | ||
6094 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); | |
6095 | command_type = OTHER_COMMAND; | |
6096 | break; | |
6097 | case CMD_XMIT_ELS_RSP64_CX: | |
6098 | /* words0-2 BDE memcpy */ | |
6099 | /* word3 iocb=iotag32 wqe=rsvd */ | |
6100 | wqe->words[3] = 0; | |
6101 | /* word4 iocb=did wge=rsvd. */ | |
6102 | wqe->words[4] = 0; | |
6103 | /* word5 iocb=rsvd wge=did */ | |
6104 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | |
6105 | iocbq->iocb.un.elsreq64.remoteID); | |
6106 | ||
6107 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, | |
6108 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
6109 | ||
6110 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); | |
6111 | bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext); | |
6112 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) | |
6113 | bf_set(lpfc_wqe_gen_context, &wqe->generic, | |
6114 | iocbq->vport->vpi + phba->vpi_base); | |
6115 | command_type = OTHER_COMMAND; | |
6116 | break; | |
6117 | case CMD_CLOSE_XRI_CN: | |
6118 | case CMD_ABORT_XRI_CN: | |
6119 | case CMD_ABORT_XRI_CX: | |
6120 | /* words 0-2 memcpy should be 0 rserved */ | |
6121 | /* port will send abts */ | |
6122 | if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | |
6123 | /* | |
6124 | * The link is down so the fw does not need to send abts | |
6125 | * on the wire. | |
6126 | */ | |
6127 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | |
6128 | else | |
6129 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | |
6130 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | |
4f774513 JS |
6131 | wqe->words[5] = 0; |
6132 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, | |
6133 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | |
6134 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | |
4f774513 JS |
6135 | /* |
6136 | * The abort handler will send us CMD_ABORT_XRI_CN or | |
6137 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | |
6138 | */ | |
6139 | bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX); | |
6140 | cmnd = CMD_ABORT_XRI_CX; | |
6141 | command_type = OTHER_COMMAND; | |
6142 | xritag = 0; | |
6143 | break; | |
6669f9bb JS |
6144 | case CMD_XMIT_BLS_RSP64_CX: |
6145 | /* As BLS ABTS-ACC WQE is very different from other WQEs, | |
6146 | * we re-construct this WQE here based on information in | |
6147 | * iocbq from scratch. | |
6148 | */ | |
6149 | memset(wqe, 0, sizeof(union lpfc_wqe)); | |
5ffc266e | 6150 | /* OX_ID is invariable to who sent ABTS to CT exchange */ |
6669f9bb | 6151 | bf_set(xmit_bls_rsp64_oxid, &wqe->xmit_bls_rsp, |
5ffc266e JS |
6152 | bf_get(lpfc_abts_oxid, &iocbq->iocb.un.bls_acc)); |
6153 | if (bf_get(lpfc_abts_orig, &iocbq->iocb.un.bls_acc) == | |
6154 | LPFC_ABTS_UNSOL_INT) { | |
6155 | /* ABTS sent by initiator to CT exchange, the | |
6156 | * RX_ID field will be filled with the newly | |
6157 | * allocated responder XRI. | |
6158 | */ | |
6159 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6160 | iocbq->sli4_xritag); | |
6161 | } else { | |
6162 | /* ABTS sent by responder to CT exchange, the | |
6163 | * RX_ID field will be filled with the responder | |
6164 | * RX_ID from ABTS. | |
6165 | */ | |
6166 | bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp, | |
6167 | bf_get(lpfc_abts_rxid, &iocbq->iocb.un.bls_acc)); | |
6168 | } | |
6669f9bb JS |
6169 | bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff); |
6170 | bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1); | |
6171 | bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com, | |
6172 | iocbq->iocb.ulpContext); | |
6173 | /* Overwrite the pre-set comnd type with OTHER_COMMAND */ | |
6174 | command_type = OTHER_COMMAND; | |
6175 | break; | |
4f774513 JS |
6176 | case CMD_XRI_ABORTED_CX: |
6177 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | |
6178 | /* words0-2 are all 0's no bde */ | |
6179 | /* word3 and word4 are rsvrd */ | |
6180 | wqe->words[3] = 0; | |
6181 | wqe->words[4] = 0; | |
6182 | /* word5 iocb=rsvd wge=did */ | |
6183 | /* There is no remote port id in the IOCB? */ | |
6184 | /* Let this fall through and fail */ | |
6185 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ | |
6186 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | |
6187 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | |
6188 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | |
6189 | default: | |
6190 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6191 | "2014 Invalid command 0x%x\n", | |
6192 | iocbq->iocb.ulpCommand); | |
6193 | return IOCB_ERROR; | |
6194 | break; | |
6195 | ||
6196 | } | |
6197 | bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag); | |
6198 | bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag); | |
6199 | wqe->generic.abort_tag = abort_tag; | |
6200 | bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type); | |
6201 | bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd); | |
6202 | bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass); | |
6203 | bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT); | |
6204 | ||
6205 | return 0; | |
6206 | } | |
6207 | ||
6208 | /** | |
6209 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | |
6210 | * @phba: Pointer to HBA context object. | |
6211 | * @ring_number: SLI ring number to issue iocb on. | |
6212 | * @piocb: Pointer to command iocb. | |
6213 | * @flag: Flag indicating if this command can be put into txq. | |
6214 | * | |
6215 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | |
6216 | * an iocb command to an HBA with SLI-4 interface spec. | |
6217 | * | |
6218 | * This function is called with hbalock held. The function will return success | |
6219 | * after it successfully submit the iocb to firmware or after adding to the | |
6220 | * txq. | |
6221 | **/ | |
6222 | static int | |
6223 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | |
6224 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6225 | { | |
6226 | struct lpfc_sglq *sglq; | |
4f774513 JS |
6227 | union lpfc_wqe wqe; |
6228 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | |
4f774513 JS |
6229 | |
6230 | if (piocb->sli4_xritag == NO_XRI) { | |
6231 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | |
6669f9bb | 6232 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) |
4f774513 JS |
6233 | sglq = NULL; |
6234 | else { | |
2a9bf3d0 JS |
6235 | if (pring->txq_cnt) { |
6236 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6237 | __lpfc_sli_ringtx_put(phba, | |
6238 | pring, piocb); | |
6239 | return IOCB_SUCCESS; | |
6240 | } else { | |
6241 | return IOCB_BUSY; | |
6242 | } | |
6243 | } else { | |
4f774513 | 6244 | sglq = __lpfc_sli_get_sglq(phba); |
2a9bf3d0 JS |
6245 | if (!sglq) { |
6246 | if (!(flag & SLI_IOCB_RET_IOCB)) { | |
6247 | __lpfc_sli_ringtx_put(phba, | |
6248 | pring, | |
6249 | piocb); | |
6250 | return IOCB_SUCCESS; | |
6251 | } else | |
6252 | return IOCB_BUSY; | |
6253 | } | |
6254 | } | |
4f774513 JS |
6255 | } |
6256 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | |
6257 | sglq = NULL; /* These IO's already have an XRI and | |
6258 | * a mapped sgl. | |
6259 | */ | |
6260 | } else { | |
6261 | /* This is a continuation of a commandi,(CX) so this | |
6262 | * sglq is on the active list | |
6263 | */ | |
6264 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | |
6265 | if (!sglq) | |
6266 | return IOCB_ERROR; | |
6267 | } | |
6268 | ||
6269 | if (sglq) { | |
2a9bf3d0 JS |
6270 | piocb->sli4_xritag = sglq->sli4_xritag; |
6271 | ||
6272 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocb, sglq)) | |
4f774513 JS |
6273 | return IOCB_ERROR; |
6274 | } | |
6275 | ||
6276 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | |
6277 | return IOCB_ERROR; | |
6278 | ||
341af102 JS |
6279 | if ((piocb->iocb_flag & LPFC_IO_FCP) || |
6280 | (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) { | |
5ffc266e JS |
6281 | /* |
6282 | * For FCP command IOCB, get a new WQ index to distribute | |
6283 | * WQE across the WQsr. On the other hand, for abort IOCB, | |
6284 | * it carries the same WQ index to the original command | |
6285 | * IOCB. | |
6286 | */ | |
341af102 | 6287 | if (piocb->iocb_flag & LPFC_IO_FCP) |
5ffc266e JS |
6288 | piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); |
6289 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], | |
6290 | &wqe)) | |
4f774513 JS |
6291 | return IOCB_ERROR; |
6292 | } else { | |
6293 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
6294 | return IOCB_ERROR; | |
6295 | } | |
6296 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | |
6297 | ||
6298 | return 0; | |
6299 | } | |
6300 | ||
6301 | /** | |
6302 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | |
6303 | * | |
6304 | * This routine wraps the actual lockless version for issusing IOCB function | |
6305 | * pointer from the lpfc_hba struct. | |
6306 | * | |
6307 | * Return codes: | |
6308 | * IOCB_ERROR - Error | |
6309 | * IOCB_SUCCESS - Success | |
6310 | * IOCB_BUSY - Busy | |
6311 | **/ | |
2a9bf3d0 | 6312 | int |
4f774513 JS |
6313 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
6314 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6315 | { | |
6316 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6317 | } | |
6318 | ||
6319 | /** | |
6320 | * lpfc_sli_api_table_setup - Set up sli api fucntion jump table | |
6321 | * @phba: The hba struct for which this call is being executed. | |
6322 | * @dev_grp: The HBA PCI-Device group number. | |
6323 | * | |
6324 | * This routine sets up the SLI interface API function jump table in @phba | |
6325 | * struct. | |
6326 | * Returns: 0 - success, -ENODEV - failure. | |
6327 | **/ | |
6328 | int | |
6329 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6330 | { | |
6331 | ||
6332 | switch (dev_grp) { | |
6333 | case LPFC_PCI_DEV_LP: | |
6334 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | |
6335 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | |
6336 | break; | |
6337 | case LPFC_PCI_DEV_OC: | |
6338 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | |
6339 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | |
6340 | break; | |
6341 | default: | |
6342 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6343 | "1419 Invalid HBA PCI-device group: 0x%x\n", | |
6344 | dev_grp); | |
6345 | return -ENODEV; | |
6346 | break; | |
6347 | } | |
6348 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | |
6349 | return 0; | |
6350 | } | |
6351 | ||
6352 | /** | |
6353 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | |
6354 | * @phba: Pointer to HBA context object. | |
6355 | * @pring: Pointer to driver SLI ring object. | |
6356 | * @piocb: Pointer to command iocb. | |
6357 | * @flag: Flag indicating if this command can be put into txq. | |
6358 | * | |
6359 | * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb | |
6360 | * function. This function gets the hbalock and calls | |
6361 | * __lpfc_sli_issue_iocb function and will return the error returned | |
6362 | * by __lpfc_sli_issue_iocb function. This wrapper is used by | |
6363 | * functions which do not hold hbalock. | |
6364 | **/ | |
6365 | int | |
6366 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | |
6367 | struct lpfc_iocbq *piocb, uint32_t flag) | |
6368 | { | |
6369 | unsigned long iflags; | |
6370 | int rc; | |
6371 | ||
6372 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6373 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | |
6374 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6375 | ||
6376 | return rc; | |
6377 | } | |
6378 | ||
6379 | /** | |
6380 | * lpfc_extra_ring_setup - Extra ring setup function | |
6381 | * @phba: Pointer to HBA context object. | |
6382 | * | |
6383 | * This function is called while driver attaches with the | |
6384 | * HBA to setup the extra ring. The extra ring is used | |
6385 | * only when driver needs to support target mode functionality | |
6386 | * or IP over FC functionalities. | |
6387 | * | |
6388 | * This function is called with no lock held. | |
6389 | **/ | |
6390 | static int | |
6391 | lpfc_extra_ring_setup( struct lpfc_hba *phba) | |
6392 | { | |
6393 | struct lpfc_sli *psli; | |
6394 | struct lpfc_sli_ring *pring; | |
6395 | ||
6396 | psli = &phba->sli; | |
6397 | ||
6398 | /* Adjust cmd/rsp ring iocb entries more evenly */ | |
6399 | ||
6400 | /* Take some away from the FCP ring */ | |
6401 | pring = &psli->ring[psli->fcp_ring]; | |
6402 | pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
6403 | pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
cf5bf97e JW |
6404 | pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES; |
6405 | pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6406 | ||
a4bc3379 JS |
6407 | /* and give them to the extra ring */ |
6408 | pring = &psli->ring[psli->extra_ring]; | |
6409 | ||
cf5bf97e JW |
6410 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; |
6411 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
6412 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
6413 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
6414 | ||
6415 | /* Setup default profile for this ring */ | |
6416 | pring->iotag_max = 4096; | |
6417 | pring->num_mask = 1; | |
6418 | pring->prt[0].profile = 0; /* Mask 0 */ | |
a4bc3379 JS |
6419 | pring->prt[0].rctl = phba->cfg_multi_ring_rctl; |
6420 | pring->prt[0].type = phba->cfg_multi_ring_type; | |
cf5bf97e JW |
6421 | pring->prt[0].lpfc_sli_rcv_unsol_event = NULL; |
6422 | return 0; | |
6423 | } | |
6424 | ||
e59058c4 | 6425 | /** |
3621a710 | 6426 | * lpfc_sli_async_event_handler - ASYNC iocb handler function |
e59058c4 JS |
6427 | * @phba: Pointer to HBA context object. |
6428 | * @pring: Pointer to driver SLI ring object. | |
6429 | * @iocbq: Pointer to iocb object. | |
6430 | * | |
6431 | * This function is called by the slow ring event handler | |
6432 | * function when there is an ASYNC event iocb in the ring. | |
6433 | * This function is called with no lock held. | |
6434 | * Currently this function handles only temperature related | |
6435 | * ASYNC events. The function decodes the temperature sensor | |
6436 | * event message and posts events for the management applications. | |
6437 | **/ | |
98c9ea5c | 6438 | static void |
57127f15 JS |
6439 | lpfc_sli_async_event_handler(struct lpfc_hba * phba, |
6440 | struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) | |
6441 | { | |
6442 | IOCB_t *icmd; | |
6443 | uint16_t evt_code; | |
6444 | uint16_t temp; | |
6445 | struct temp_event temp_event_data; | |
6446 | struct Scsi_Host *shost; | |
a257bf90 | 6447 | uint32_t *iocb_w; |
57127f15 JS |
6448 | |
6449 | icmd = &iocbq->iocb; | |
6450 | evt_code = icmd->un.asyncstat.evt_code; | |
6451 | temp = icmd->ulpContext; | |
6452 | ||
6453 | if ((evt_code != ASYNC_TEMP_WARN) && | |
6454 | (evt_code != ASYNC_TEMP_SAFE)) { | |
a257bf90 | 6455 | iocb_w = (uint32_t *) icmd; |
57127f15 JS |
6456 | lpfc_printf_log(phba, |
6457 | KERN_ERR, | |
6458 | LOG_SLI, | |
76bb24ef | 6459 | "0346 Ring %d handler: unexpected ASYNC_STATUS" |
e4e74273 | 6460 | " evt_code 0x%x\n" |
a257bf90 JS |
6461 | "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n" |
6462 | "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n" | |
6463 | "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n" | |
6464 | "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n", | |
57127f15 | 6465 | pring->ringno, |
a257bf90 JS |
6466 | icmd->un.asyncstat.evt_code, |
6467 | iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3], | |
6468 | iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7], | |
6469 | iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11], | |
6470 | iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]); | |
6471 | ||
57127f15 JS |
6472 | return; |
6473 | } | |
6474 | temp_event_data.data = (uint32_t)temp; | |
6475 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
6476 | if (evt_code == ASYNC_TEMP_WARN) { | |
6477 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
6478 | lpfc_printf_log(phba, | |
09372820 | 6479 | KERN_ERR, |
57127f15 | 6480 | LOG_TEMP, |
76bb24ef | 6481 | "0347 Adapter is very hot, please take " |
57127f15 JS |
6482 | "corrective action. temperature : %d Celsius\n", |
6483 | temp); | |
6484 | } | |
6485 | if (evt_code == ASYNC_TEMP_SAFE) { | |
6486 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
6487 | lpfc_printf_log(phba, | |
09372820 | 6488 | KERN_ERR, |
57127f15 JS |
6489 | LOG_TEMP, |
6490 | "0340 Adapter temperature is OK now. " | |
6491 | "temperature : %d Celsius\n", | |
6492 | temp); | |
6493 | } | |
6494 | ||
6495 | /* Send temperature change event to applications */ | |
6496 | shost = lpfc_shost_from_vport(phba->pport); | |
6497 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
6498 | sizeof(temp_event_data), (char *) &temp_event_data, | |
ddcc50f0 | 6499 | LPFC_NL_VENDOR_ID); |
57127f15 JS |
6500 | |
6501 | } | |
6502 | ||
6503 | ||
e59058c4 | 6504 | /** |
3621a710 | 6505 | * lpfc_sli_setup - SLI ring setup function |
e59058c4 JS |
6506 | * @phba: Pointer to HBA context object. |
6507 | * | |
6508 | * lpfc_sli_setup sets up rings of the SLI interface with | |
6509 | * number of iocbs per ring and iotags. This function is | |
6510 | * called while driver attach to the HBA and before the | |
6511 | * interrupts are enabled. So there is no need for locking. | |
6512 | * | |
6513 | * This function always returns 0. | |
6514 | **/ | |
dea3101e JB |
6515 | int |
6516 | lpfc_sli_setup(struct lpfc_hba *phba) | |
6517 | { | |
ed957684 | 6518 | int i, totiocbsize = 0; |
dea3101e JB |
6519 | struct lpfc_sli *psli = &phba->sli; |
6520 | struct lpfc_sli_ring *pring; | |
6521 | ||
6522 | psli->num_rings = MAX_CONFIGURED_RINGS; | |
6523 | psli->sli_flag = 0; | |
6524 | psli->fcp_ring = LPFC_FCP_RING; | |
6525 | psli->next_ring = LPFC_FCP_NEXT_RING; | |
a4bc3379 | 6526 | psli->extra_ring = LPFC_EXTRA_RING; |
dea3101e | 6527 | |
604a3e30 JB |
6528 | psli->iocbq_lookup = NULL; |
6529 | psli->iocbq_lookup_len = 0; | |
6530 | psli->last_iotag = 0; | |
6531 | ||
dea3101e JB |
6532 | for (i = 0; i < psli->num_rings; i++) { |
6533 | pring = &psli->ring[i]; | |
6534 | switch (i) { | |
6535 | case LPFC_FCP_RING: /* ring 0 - FCP */ | |
6536 | /* numCiocb and numRiocb are used in config_port */ | |
6537 | pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES; | |
6538 | pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES; | |
6539 | pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES; | |
6540 | pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; | |
6541 | pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; | |
6542 | pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; | |
ed957684 | 6543 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
6544 | SLI3_IOCB_CMD_SIZE : |
6545 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 6546 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
6547 | SLI3_IOCB_RSP_SIZE : |
6548 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
6549 | pring->iotag_ctr = 0; |
6550 | pring->iotag_max = | |
92d7f7b0 | 6551 | (phba->cfg_hba_queue_depth * 2); |
dea3101e JB |
6552 | pring->fast_iotag = pring->iotag_max; |
6553 | pring->num_mask = 0; | |
6554 | break; | |
a4bc3379 | 6555 | case LPFC_EXTRA_RING: /* ring 1 - EXTRA */ |
dea3101e JB |
6556 | /* numCiocb and numRiocb are used in config_port */ |
6557 | pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; | |
6558 | pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; | |
ed957684 | 6559 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
6560 | SLI3_IOCB_CMD_SIZE : |
6561 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 6562 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
6563 | SLI3_IOCB_RSP_SIZE : |
6564 | SLI2_IOCB_RSP_SIZE; | |
2e0fef85 | 6565 | pring->iotag_max = phba->cfg_hba_queue_depth; |
dea3101e JB |
6566 | pring->num_mask = 0; |
6567 | break; | |
6568 | case LPFC_ELS_RING: /* ring 2 - ELS / CT */ | |
6569 | /* numCiocb and numRiocb are used in config_port */ | |
6570 | pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; | |
6571 | pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; | |
ed957684 | 6572 | pring->sizeCiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
6573 | SLI3_IOCB_CMD_SIZE : |
6574 | SLI2_IOCB_CMD_SIZE; | |
ed957684 | 6575 | pring->sizeRiocb = (phba->sli_rev == 3) ? |
92d7f7b0 JS |
6576 | SLI3_IOCB_RSP_SIZE : |
6577 | SLI2_IOCB_RSP_SIZE; | |
dea3101e JB |
6578 | pring->fast_iotag = 0; |
6579 | pring->iotag_ctr = 0; | |
6580 | pring->iotag_max = 4096; | |
57127f15 JS |
6581 | pring->lpfc_sli_rcv_async_status = |
6582 | lpfc_sli_async_event_handler; | |
6669f9bb | 6583 | pring->num_mask = LPFC_MAX_RING_MASK; |
dea3101e | 6584 | pring->prt[0].profile = 0; /* Mask 0 */ |
6a9c52cf JS |
6585 | pring->prt[0].rctl = FC_RCTL_ELS_REQ; |
6586 | pring->prt[0].type = FC_TYPE_ELS; | |
dea3101e | 6587 | pring->prt[0].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 6588 | lpfc_els_unsol_event; |
dea3101e | 6589 | pring->prt[1].profile = 0; /* Mask 1 */ |
6a9c52cf JS |
6590 | pring->prt[1].rctl = FC_RCTL_ELS_REP; |
6591 | pring->prt[1].type = FC_TYPE_ELS; | |
dea3101e | 6592 | pring->prt[1].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 6593 | lpfc_els_unsol_event; |
dea3101e JB |
6594 | pring->prt[2].profile = 0; /* Mask 2 */ |
6595 | /* NameServer Inquiry */ | |
6a9c52cf | 6596 | pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL; |
dea3101e | 6597 | /* NameServer */ |
6a9c52cf | 6598 | pring->prt[2].type = FC_TYPE_CT; |
dea3101e | 6599 | pring->prt[2].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 6600 | lpfc_ct_unsol_event; |
dea3101e JB |
6601 | pring->prt[3].profile = 0; /* Mask 3 */ |
6602 | /* NameServer response */ | |
6a9c52cf | 6603 | pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL; |
dea3101e | 6604 | /* NameServer */ |
6a9c52cf | 6605 | pring->prt[3].type = FC_TYPE_CT; |
dea3101e | 6606 | pring->prt[3].lpfc_sli_rcv_unsol_event = |
92d7f7b0 | 6607 | lpfc_ct_unsol_event; |
6669f9bb JS |
6608 | /* abort unsolicited sequence */ |
6609 | pring->prt[4].profile = 0; /* Mask 4 */ | |
6610 | pring->prt[4].rctl = FC_RCTL_BA_ABTS; | |
6611 | pring->prt[4].type = FC_TYPE_BLS; | |
6612 | pring->prt[4].lpfc_sli_rcv_unsol_event = | |
6613 | lpfc_sli4_ct_abort_unsol_event; | |
dea3101e JB |
6614 | break; |
6615 | } | |
ed957684 | 6616 | totiocbsize += (pring->numCiocb * pring->sizeCiocb) + |
92d7f7b0 | 6617 | (pring->numRiocb * pring->sizeRiocb); |
dea3101e | 6618 | } |
ed957684 | 6619 | if (totiocbsize > MAX_SLIM_IOCB_SIZE) { |
dea3101e | 6620 | /* Too many cmd / rsp ring entries in SLI2 SLIM */ |
e8b62011 JS |
6621 | printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in " |
6622 | "SLI2 SLIM Data: x%x x%lx\n", | |
6623 | phba->brd_no, totiocbsize, | |
6624 | (unsigned long) MAX_SLIM_IOCB_SIZE); | |
dea3101e | 6625 | } |
cf5bf97e JW |
6626 | if (phba->cfg_multi_ring_support == 2) |
6627 | lpfc_extra_ring_setup(phba); | |
dea3101e JB |
6628 | |
6629 | return 0; | |
6630 | } | |
6631 | ||
e59058c4 | 6632 | /** |
3621a710 | 6633 | * lpfc_sli_queue_setup - Queue initialization function |
e59058c4 JS |
6634 | * @phba: Pointer to HBA context object. |
6635 | * | |
6636 | * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each | |
6637 | * ring. This function also initializes ring indices of each ring. | |
6638 | * This function is called during the initialization of the SLI | |
6639 | * interface of an HBA. | |
6640 | * This function is called with no lock held and always returns | |
6641 | * 1. | |
6642 | **/ | |
dea3101e | 6643 | int |
2e0fef85 | 6644 | lpfc_sli_queue_setup(struct lpfc_hba *phba) |
dea3101e JB |
6645 | { |
6646 | struct lpfc_sli *psli; | |
6647 | struct lpfc_sli_ring *pring; | |
604a3e30 | 6648 | int i; |
dea3101e JB |
6649 | |
6650 | psli = &phba->sli; | |
2e0fef85 | 6651 | spin_lock_irq(&phba->hbalock); |
dea3101e | 6652 | INIT_LIST_HEAD(&psli->mboxq); |
92d7f7b0 | 6653 | INIT_LIST_HEAD(&psli->mboxq_cmpl); |
dea3101e JB |
6654 | /* Initialize list headers for txq and txcmplq as double linked lists */ |
6655 | for (i = 0; i < psli->num_rings; i++) { | |
6656 | pring = &psli->ring[i]; | |
6657 | pring->ringno = i; | |
6658 | pring->next_cmdidx = 0; | |
6659 | pring->local_getidx = 0; | |
6660 | pring->cmdidx = 0; | |
6661 | INIT_LIST_HEAD(&pring->txq); | |
6662 | INIT_LIST_HEAD(&pring->txcmplq); | |
6663 | INIT_LIST_HEAD(&pring->iocb_continueq); | |
9c2face6 | 6664 | INIT_LIST_HEAD(&pring->iocb_continue_saveq); |
dea3101e | 6665 | INIT_LIST_HEAD(&pring->postbufq); |
dea3101e | 6666 | } |
2e0fef85 JS |
6667 | spin_unlock_irq(&phba->hbalock); |
6668 | return 1; | |
dea3101e JB |
6669 | } |
6670 | ||
04c68496 JS |
6671 | /** |
6672 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | |
6673 | * @phba: Pointer to HBA context object. | |
6674 | * | |
6675 | * This routine flushes the mailbox command subsystem. It will unconditionally | |
6676 | * flush all the mailbox commands in the three possible stages in the mailbox | |
6677 | * command sub-system: pending mailbox command queue; the outstanding mailbox | |
6678 | * command; and completed mailbox command queue. It is caller's responsibility | |
6679 | * to make sure that the driver is in the proper state to flush the mailbox | |
6680 | * command sub-system. Namely, the posting of mailbox commands into the | |
6681 | * pending mailbox command queue from the various clients must be stopped; | |
6682 | * either the HBA is in a state that it will never works on the outstanding | |
6683 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | |
6684 | * mailbox command has been completed. | |
6685 | **/ | |
6686 | static void | |
6687 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | |
6688 | { | |
6689 | LIST_HEAD(completions); | |
6690 | struct lpfc_sli *psli = &phba->sli; | |
6691 | LPFC_MBOXQ_t *pmb; | |
6692 | unsigned long iflag; | |
6693 | ||
6694 | /* Flush all the mailbox commands in the mbox system */ | |
6695 | spin_lock_irqsave(&phba->hbalock, iflag); | |
6696 | /* The pending mailbox command queue */ | |
6697 | list_splice_init(&phba->sli.mboxq, &completions); | |
6698 | /* The outstanding active mailbox command */ | |
6699 | if (psli->mbox_active) { | |
6700 | list_add_tail(&psli->mbox_active->list, &completions); | |
6701 | psli->mbox_active = NULL; | |
6702 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
6703 | } | |
6704 | /* The completed mailbox command queue */ | |
6705 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | |
6706 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
6707 | ||
6708 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | |
6709 | while (!list_empty(&completions)) { | |
6710 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | |
6711 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
6712 | if (pmb->mbox_cmpl) | |
6713 | pmb->mbox_cmpl(phba, pmb); | |
6714 | } | |
6715 | } | |
6716 | ||
e59058c4 | 6717 | /** |
3621a710 | 6718 | * lpfc_sli_host_down - Vport cleanup function |
e59058c4 JS |
6719 | * @vport: Pointer to virtual port object. |
6720 | * | |
6721 | * lpfc_sli_host_down is called to clean up the resources | |
6722 | * associated with a vport before destroying virtual | |
6723 | * port data structures. | |
6724 | * This function does following operations: | |
6725 | * - Free discovery resources associated with this virtual | |
6726 | * port. | |
6727 | * - Free iocbs associated with this virtual port in | |
6728 | * the txq. | |
6729 | * - Send abort for all iocb commands associated with this | |
6730 | * vport in txcmplq. | |
6731 | * | |
6732 | * This function is called with no lock held and always returns 1. | |
6733 | **/ | |
92d7f7b0 JS |
6734 | int |
6735 | lpfc_sli_host_down(struct lpfc_vport *vport) | |
6736 | { | |
858c9f6c | 6737 | LIST_HEAD(completions); |
92d7f7b0 JS |
6738 | struct lpfc_hba *phba = vport->phba; |
6739 | struct lpfc_sli *psli = &phba->sli; | |
6740 | struct lpfc_sli_ring *pring; | |
6741 | struct lpfc_iocbq *iocb, *next_iocb; | |
92d7f7b0 JS |
6742 | int i; |
6743 | unsigned long flags = 0; | |
6744 | uint16_t prev_pring_flag; | |
6745 | ||
6746 | lpfc_cleanup_discovery_resources(vport); | |
6747 | ||
6748 | spin_lock_irqsave(&phba->hbalock, flags); | |
92d7f7b0 JS |
6749 | for (i = 0; i < psli->num_rings; i++) { |
6750 | pring = &psli->ring[i]; | |
6751 | prev_pring_flag = pring->flag; | |
5e9d9b82 JS |
6752 | /* Only slow rings */ |
6753 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 6754 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
6755 | /* Set the lpfc data pending flag */ |
6756 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
6757 | } | |
92d7f7b0 JS |
6758 | /* |
6759 | * Error everything on the txq since these iocbs have not been | |
6760 | * given to the FW yet. | |
6761 | */ | |
92d7f7b0 JS |
6762 | list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { |
6763 | if (iocb->vport != vport) | |
6764 | continue; | |
858c9f6c | 6765 | list_move_tail(&iocb->list, &completions); |
92d7f7b0 | 6766 | pring->txq_cnt--; |
92d7f7b0 JS |
6767 | } |
6768 | ||
6769 | /* Next issue ABTS for everything on the txcmplq */ | |
6770 | list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, | |
6771 | list) { | |
6772 | if (iocb->vport != vport) | |
6773 | continue; | |
6774 | lpfc_sli_issue_abort_iotag(phba, pring, iocb); | |
6775 | } | |
6776 | ||
6777 | pring->flag = prev_pring_flag; | |
6778 | } | |
6779 | ||
6780 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
6781 | ||
a257bf90 JS |
6782 | /* Cancel all the IOCBs from the completions list */ |
6783 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
6784 | IOERR_SLI_DOWN); | |
92d7f7b0 JS |
6785 | return 1; |
6786 | } | |
6787 | ||
e59058c4 | 6788 | /** |
3621a710 | 6789 | * lpfc_sli_hba_down - Resource cleanup function for the HBA |
e59058c4 JS |
6790 | * @phba: Pointer to HBA context object. |
6791 | * | |
6792 | * This function cleans up all iocb, buffers, mailbox commands | |
6793 | * while shutting down the HBA. This function is called with no | |
6794 | * lock held and always returns 1. | |
6795 | * This function does the following to cleanup driver resources: | |
6796 | * - Free discovery resources for each virtual port | |
6797 | * - Cleanup any pending fabric iocbs | |
6798 | * - Iterate through the iocb txq and free each entry | |
6799 | * in the list. | |
6800 | * - Free up any buffer posted to the HBA | |
6801 | * - Free mailbox commands in the mailbox queue. | |
6802 | **/ | |
dea3101e | 6803 | int |
2e0fef85 | 6804 | lpfc_sli_hba_down(struct lpfc_hba *phba) |
dea3101e | 6805 | { |
2534ba75 | 6806 | LIST_HEAD(completions); |
2e0fef85 | 6807 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 6808 | struct lpfc_sli_ring *pring; |
0ff10d46 | 6809 | struct lpfc_dmabuf *buf_ptr; |
dea3101e | 6810 | unsigned long flags = 0; |
04c68496 JS |
6811 | int i; |
6812 | ||
6813 | /* Shutdown the mailbox command sub-system */ | |
6814 | lpfc_sli_mbox_sys_shutdown(phba); | |
dea3101e | 6815 | |
dea3101e JB |
6816 | lpfc_hba_down_prep(phba); |
6817 | ||
92d7f7b0 JS |
6818 | lpfc_fabric_abort_hba(phba); |
6819 | ||
2e0fef85 | 6820 | spin_lock_irqsave(&phba->hbalock, flags); |
dea3101e JB |
6821 | for (i = 0; i < psli->num_rings; i++) { |
6822 | pring = &psli->ring[i]; | |
5e9d9b82 JS |
6823 | /* Only slow rings */ |
6824 | if (pring->ringno == LPFC_ELS_RING) { | |
858c9f6c | 6825 | pring->flag |= LPFC_DEFERRED_RING_EVENT; |
5e9d9b82 JS |
6826 | /* Set the lpfc data pending flag */ |
6827 | set_bit(LPFC_DATA_READY, &phba->data_flags); | |
6828 | } | |
dea3101e JB |
6829 | |
6830 | /* | |
6831 | * Error everything on the txq since these iocbs have not been | |
6832 | * given to the FW yet. | |
6833 | */ | |
2534ba75 | 6834 | list_splice_init(&pring->txq, &completions); |
dea3101e JB |
6835 | pring->txq_cnt = 0; |
6836 | ||
2534ba75 | 6837 | } |
2e0fef85 | 6838 | spin_unlock_irqrestore(&phba->hbalock, flags); |
dea3101e | 6839 | |
a257bf90 JS |
6840 | /* Cancel all the IOCBs from the completions list */ |
6841 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
6842 | IOERR_SLI_DOWN); | |
dea3101e | 6843 | |
0ff10d46 JS |
6844 | spin_lock_irqsave(&phba->hbalock, flags); |
6845 | list_splice_init(&phba->elsbuf, &completions); | |
6846 | phba->elsbuf_cnt = 0; | |
6847 | phba->elsbuf_prev_cnt = 0; | |
6848 | spin_unlock_irqrestore(&phba->hbalock, flags); | |
6849 | ||
6850 | while (!list_empty(&completions)) { | |
6851 | list_remove_head(&completions, buf_ptr, | |
6852 | struct lpfc_dmabuf, list); | |
6853 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
6854 | kfree(buf_ptr); | |
6855 | } | |
6856 | ||
dea3101e JB |
6857 | /* Return any active mbox cmds */ |
6858 | del_timer_sync(&psli->mbox_tmo); | |
2e0fef85 | 6859 | |
da0436e9 | 6860 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
2e0fef85 | 6861 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
da0436e9 | 6862 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
2e0fef85 | 6863 | |
da0436e9 JS |
6864 | return 1; |
6865 | } | |
6866 | ||
6867 | /** | |
6868 | * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA | |
6869 | * @phba: Pointer to HBA context object. | |
6870 | * | |
6871 | * This function cleans up all queues, iocb, buffers, mailbox commands while | |
6872 | * shutting down the SLI4 HBA FCoE function. This function is called with no | |
6873 | * lock held and always returns 1. | |
6874 | * | |
6875 | * This function does the following to cleanup driver FCoE function resources: | |
6876 | * - Free discovery resources for each virtual port | |
6877 | * - Cleanup any pending fabric iocbs | |
6878 | * - Iterate through the iocb txq and free each entry in the list. | |
6879 | * - Free up any buffer posted to the HBA. | |
6880 | * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc. | |
6881 | * - Free mailbox commands in the mailbox queue. | |
6882 | **/ | |
6883 | int | |
6884 | lpfc_sli4_hba_down(struct lpfc_hba *phba) | |
6885 | { | |
6886 | /* Stop the SLI4 device port */ | |
6887 | lpfc_stop_port(phba); | |
6888 | ||
6889 | /* Tear down the queues in the HBA */ | |
6890 | lpfc_sli4_queue_unset(phba); | |
6891 | ||
6892 | /* unregister default FCFI from the HBA */ | |
6893 | lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi); | |
92d7f7b0 | 6894 | |
dea3101e JB |
6895 | return 1; |
6896 | } | |
6897 | ||
e59058c4 | 6898 | /** |
3621a710 | 6899 | * lpfc_sli_pcimem_bcopy - SLI memory copy function |
e59058c4 JS |
6900 | * @srcp: Source memory pointer. |
6901 | * @destp: Destination memory pointer. | |
6902 | * @cnt: Number of words required to be copied. | |
6903 | * | |
6904 | * This function is used for copying data between driver memory | |
6905 | * and the SLI memory. This function also changes the endianness | |
6906 | * of each word if native endianness is different from SLI | |
6907 | * endianness. This function can be called with or without | |
6908 | * lock. | |
6909 | **/ | |
dea3101e JB |
6910 | void |
6911 | lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
6912 | { | |
6913 | uint32_t *src = srcp; | |
6914 | uint32_t *dest = destp; | |
6915 | uint32_t ldata; | |
6916 | int i; | |
6917 | ||
6918 | for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) { | |
6919 | ldata = *src; | |
6920 | ldata = le32_to_cpu(ldata); | |
6921 | *dest = ldata; | |
6922 | src++; | |
6923 | dest++; | |
6924 | } | |
6925 | } | |
6926 | ||
e59058c4 | 6927 | |
a0c87cbd JS |
6928 | /** |
6929 | * lpfc_sli_bemem_bcopy - SLI memory copy function | |
6930 | * @srcp: Source memory pointer. | |
6931 | * @destp: Destination memory pointer. | |
6932 | * @cnt: Number of words required to be copied. | |
6933 | * | |
6934 | * This function is used for copying data between a data structure | |
6935 | * with big endian representation to local endianness. | |
6936 | * This function can be called with or without lock. | |
6937 | **/ | |
6938 | void | |
6939 | lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt) | |
6940 | { | |
6941 | uint32_t *src = srcp; | |
6942 | uint32_t *dest = destp; | |
6943 | uint32_t ldata; | |
6944 | int i; | |
6945 | ||
6946 | for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) { | |
6947 | ldata = *src; | |
6948 | ldata = be32_to_cpu(ldata); | |
6949 | *dest = ldata; | |
6950 | src++; | |
6951 | dest++; | |
6952 | } | |
6953 | } | |
6954 | ||
e59058c4 | 6955 | /** |
3621a710 | 6956 | * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq |
e59058c4 JS |
6957 | * @phba: Pointer to HBA context object. |
6958 | * @pring: Pointer to driver SLI ring object. | |
6959 | * @mp: Pointer to driver buffer object. | |
6960 | * | |
6961 | * This function is called with no lock held. | |
6962 | * It always return zero after adding the buffer to the postbufq | |
6963 | * buffer list. | |
6964 | **/ | |
dea3101e | 6965 | int |
2e0fef85 JS |
6966 | lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
6967 | struct lpfc_dmabuf *mp) | |
dea3101e JB |
6968 | { |
6969 | /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up | |
6970 | later */ | |
2e0fef85 | 6971 | spin_lock_irq(&phba->hbalock); |
dea3101e | 6972 | list_add_tail(&mp->list, &pring->postbufq); |
dea3101e | 6973 | pring->postbufq_cnt++; |
2e0fef85 | 6974 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
6975 | return 0; |
6976 | } | |
6977 | ||
e59058c4 | 6978 | /** |
3621a710 | 6979 | * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer |
e59058c4 JS |
6980 | * @phba: Pointer to HBA context object. |
6981 | * | |
6982 | * When HBQ is enabled, buffers are searched based on tags. This function | |
6983 | * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The | |
6984 | * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag | |
6985 | * does not conflict with tags of buffer posted for unsolicited events. | |
6986 | * The function returns the allocated tag. The function is called with | |
6987 | * no locks held. | |
6988 | **/ | |
76bb24ef JS |
6989 | uint32_t |
6990 | lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) | |
6991 | { | |
6992 | spin_lock_irq(&phba->hbalock); | |
6993 | phba->buffer_tag_count++; | |
6994 | /* | |
6995 | * Always set the QUE_BUFTAG_BIT to distiguish between | |
6996 | * a tag assigned by HBQ. | |
6997 | */ | |
6998 | phba->buffer_tag_count |= QUE_BUFTAG_BIT; | |
6999 | spin_unlock_irq(&phba->hbalock); | |
7000 | return phba->buffer_tag_count; | |
7001 | } | |
7002 | ||
e59058c4 | 7003 | /** |
3621a710 | 7004 | * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag |
e59058c4 JS |
7005 | * @phba: Pointer to HBA context object. |
7006 | * @pring: Pointer to driver SLI ring object. | |
7007 | * @tag: Buffer tag. | |
7008 | * | |
7009 | * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq | |
7010 | * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX | |
7011 | * iocb is posted to the response ring with the tag of the buffer. | |
7012 | * This function searches the pring->postbufq list using the tag | |
7013 | * to find buffer associated with CMD_IOCB_RET_XRI64_CX | |
7014 | * iocb. If the buffer is found then lpfc_dmabuf object of the | |
7015 | * buffer is returned to the caller else NULL is returned. | |
7016 | * This function is called with no lock held. | |
7017 | **/ | |
76bb24ef JS |
7018 | struct lpfc_dmabuf * |
7019 | lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7020 | uint32_t tag) | |
7021 | { | |
7022 | struct lpfc_dmabuf *mp, *next_mp; | |
7023 | struct list_head *slp = &pring->postbufq; | |
7024 | ||
7025 | /* Search postbufq, from the begining, looking for a match on tag */ | |
7026 | spin_lock_irq(&phba->hbalock); | |
7027 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
7028 | if (mp->buffer_tag == tag) { | |
7029 | list_del_init(&mp->list); | |
7030 | pring->postbufq_cnt--; | |
7031 | spin_unlock_irq(&phba->hbalock); | |
7032 | return mp; | |
7033 | } | |
7034 | } | |
7035 | ||
7036 | spin_unlock_irq(&phba->hbalock); | |
7037 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 7038 | "0402 Cannot find virtual addr for buffer tag on " |
76bb24ef JS |
7039 | "ring %d Data x%lx x%p x%p x%x\n", |
7040 | pring->ringno, (unsigned long) tag, | |
7041 | slp->next, slp->prev, pring->postbufq_cnt); | |
7042 | ||
7043 | return NULL; | |
7044 | } | |
dea3101e | 7045 | |
e59058c4 | 7046 | /** |
3621a710 | 7047 | * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events |
e59058c4 JS |
7048 | * @phba: Pointer to HBA context object. |
7049 | * @pring: Pointer to driver SLI ring object. | |
7050 | * @phys: DMA address of the buffer. | |
7051 | * | |
7052 | * This function searches the buffer list using the dma_address | |
7053 | * of unsolicited event to find the driver's lpfc_dmabuf object | |
7054 | * corresponding to the dma_address. The function returns the | |
7055 | * lpfc_dmabuf object if a buffer is found else it returns NULL. | |
7056 | * This function is called by the ct and els unsolicited event | |
7057 | * handlers to get the buffer associated with the unsolicited | |
7058 | * event. | |
7059 | * | |
7060 | * This function is called with no lock held. | |
7061 | **/ | |
dea3101e JB |
7062 | struct lpfc_dmabuf * |
7063 | lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |
7064 | dma_addr_t phys) | |
7065 | { | |
7066 | struct lpfc_dmabuf *mp, *next_mp; | |
7067 | struct list_head *slp = &pring->postbufq; | |
7068 | ||
7069 | /* Search postbufq, from the begining, looking for a match on phys */ | |
2e0fef85 | 7070 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
7071 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
7072 | if (mp->phys == phys) { | |
7073 | list_del_init(&mp->list); | |
7074 | pring->postbufq_cnt--; | |
2e0fef85 | 7075 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
7076 | return mp; |
7077 | } | |
7078 | } | |
7079 | ||
2e0fef85 | 7080 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 7081 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 7082 | "0410 Cannot find virtual addr for mapped buf on " |
dea3101e | 7083 | "ring %d Data x%llx x%p x%p x%x\n", |
e8b62011 | 7084 | pring->ringno, (unsigned long long)phys, |
dea3101e JB |
7085 | slp->next, slp->prev, pring->postbufq_cnt); |
7086 | return NULL; | |
7087 | } | |
7088 | ||
e59058c4 | 7089 | /** |
3621a710 | 7090 | * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs |
e59058c4 JS |
7091 | * @phba: Pointer to HBA context object. |
7092 | * @cmdiocb: Pointer to driver command iocb object. | |
7093 | * @rspiocb: Pointer to driver response iocb object. | |
7094 | * | |
7095 | * This function is the completion handler for the abort iocbs for | |
7096 | * ELS commands. This function is called from the ELS ring event | |
7097 | * handler with no lock held. This function frees memory resources | |
7098 | * associated with the abort iocb. | |
7099 | **/ | |
dea3101e | 7100 | static void |
2e0fef85 JS |
7101 | lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7102 | struct lpfc_iocbq *rspiocb) | |
dea3101e | 7103 | { |
2e0fef85 | 7104 | IOCB_t *irsp = &rspiocb->iocb; |
2680eeaa | 7105 | uint16_t abort_iotag, abort_context; |
92d7f7b0 | 7106 | struct lpfc_iocbq *abort_iocb; |
2680eeaa JS |
7107 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
7108 | ||
7109 | abort_iocb = NULL; | |
2680eeaa JS |
7110 | |
7111 | if (irsp->ulpStatus) { | |
7112 | abort_context = cmdiocb->iocb.un.acxri.abortContextTag; | |
7113 | abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; | |
7114 | ||
2e0fef85 | 7115 | spin_lock_irq(&phba->hbalock); |
45ed1190 JS |
7116 | if (phba->sli_rev < LPFC_SLI_REV4) { |
7117 | if (abort_iotag != 0 && | |
7118 | abort_iotag <= phba->sli.last_iotag) | |
7119 | abort_iocb = | |
7120 | phba->sli.iocbq_lookup[abort_iotag]; | |
7121 | } else | |
7122 | /* For sli4 the abort_tag is the XRI, | |
7123 | * so the abort routine puts the iotag of the iocb | |
7124 | * being aborted in the context field of the abort | |
7125 | * IOCB. | |
7126 | */ | |
7127 | abort_iocb = phba->sli.iocbq_lookup[abort_context]; | |
2680eeaa | 7128 | |
58da1ffb JS |
7129 | /* |
7130 | * If the iocb is not found in Firmware queue the iocb | |
7131 | * might have completed already. Do not free it again. | |
7132 | */ | |
9b379605 | 7133 | if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) { |
45ed1190 JS |
7134 | if (irsp->un.ulpWord[4] != IOERR_NO_XRI) { |
7135 | spin_unlock_irq(&phba->hbalock); | |
7136 | lpfc_sli_release_iocbq(phba, cmdiocb); | |
7137 | return; | |
7138 | } | |
7139 | /* For SLI4 the ulpContext field for abort IOCB | |
7140 | * holds the iotag of the IOCB being aborted so | |
7141 | * the local abort_context needs to be reset to | |
7142 | * match the aborted IOCBs ulpContext. | |
7143 | */ | |
7144 | if (abort_iocb && phba->sli_rev == LPFC_SLI_REV4) | |
7145 | abort_context = abort_iocb->iocb.ulpContext; | |
58da1ffb | 7146 | } |
2a9bf3d0 JS |
7147 | |
7148 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI, | |
7149 | "0327 Cannot abort els iocb %p " | |
7150 | "with tag %x context %x, abort status %x, " | |
7151 | "abort code %x\n", | |
7152 | abort_iocb, abort_iotag, abort_context, | |
7153 | irsp->ulpStatus, irsp->un.ulpWord[4]); | |
2680eeaa JS |
7154 | /* |
7155 | * make sure we have the right iocbq before taking it | |
7156 | * off the txcmplq and try to call completion routine. | |
7157 | */ | |
2e0fef85 JS |
7158 | if (!abort_iocb || |
7159 | abort_iocb->iocb.ulpContext != abort_context || | |
7160 | (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) | |
7161 | spin_unlock_irq(&phba->hbalock); | |
341af102 JS |
7162 | else if (phba->sli_rev < LPFC_SLI_REV4) { |
7163 | /* | |
7164 | * leave the SLI4 aborted command on the txcmplq | |
7165 | * list and the command complete WCQE's XB bit | |
7166 | * will tell whether the SGL (XRI) can be released | |
7167 | * immediately or to the aborted SGL list for the | |
7168 | * following abort XRI from the HBA. | |
7169 | */ | |
92d7f7b0 | 7170 | list_del_init(&abort_iocb->list); |
2a9bf3d0 JS |
7171 | if (abort_iocb->iocb_flag & LPFC_IO_ON_Q) { |
7172 | abort_iocb->iocb_flag &= ~LPFC_IO_ON_Q; | |
7173 | pring->txcmplq_cnt--; | |
7174 | } | |
2680eeaa | 7175 | |
0ff10d46 JS |
7176 | /* Firmware could still be in progress of DMAing |
7177 | * payload, so don't free data buffer till after | |
7178 | * a hbeat. | |
7179 | */ | |
7180 | abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; | |
92d7f7b0 | 7181 | abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; |
341af102 JS |
7182 | spin_unlock_irq(&phba->hbalock); |
7183 | ||
92d7f7b0 | 7184 | abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; |
341af102 | 7185 | abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED; |
92d7f7b0 | 7186 | (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); |
49198b37 JS |
7187 | } else |
7188 | spin_unlock_irq(&phba->hbalock); | |
2680eeaa JS |
7189 | } |
7190 | ||
604a3e30 | 7191 | lpfc_sli_release_iocbq(phba, cmdiocb); |
dea3101e JB |
7192 | return; |
7193 | } | |
7194 | ||
e59058c4 | 7195 | /** |
3621a710 | 7196 | * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command |
e59058c4 JS |
7197 | * @phba: Pointer to HBA context object. |
7198 | * @cmdiocb: Pointer to driver command iocb object. | |
7199 | * @rspiocb: Pointer to driver response iocb object. | |
7200 | * | |
7201 | * The function is called from SLI ring event handler with no | |
7202 | * lock held. This function is the completion handler for ELS commands | |
7203 | * which are aborted. The function frees memory resources used for | |
7204 | * the aborted ELS commands. | |
7205 | **/ | |
92d7f7b0 JS |
7206 | static void |
7207 | lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, | |
7208 | struct lpfc_iocbq *rspiocb) | |
7209 | { | |
7210 | IOCB_t *irsp = &rspiocb->iocb; | |
7211 | ||
7212 | /* ELS cmd tag <ulpIoTag> completes */ | |
7213 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
d7c255b2 | 7214 | "0139 Ignoring ELS cmd tag x%x completion Data: " |
92d7f7b0 | 7215 | "x%x x%x x%x\n", |
e8b62011 | 7216 | irsp->ulpIoTag, irsp->ulpStatus, |
92d7f7b0 | 7217 | irsp->un.ulpWord[4], irsp->ulpTimeout); |
858c9f6c JS |
7218 | if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR) |
7219 | lpfc_ct_free_iocb(phba, cmdiocb); | |
7220 | else | |
7221 | lpfc_els_free_iocb(phba, cmdiocb); | |
92d7f7b0 JS |
7222 | return; |
7223 | } | |
7224 | ||
e59058c4 | 7225 | /** |
3621a710 | 7226 | * lpfc_sli_issue_abort_iotag - Abort function for a command iocb |
e59058c4 JS |
7227 | * @phba: Pointer to HBA context object. |
7228 | * @pring: Pointer to driver SLI ring object. | |
7229 | * @cmdiocb: Pointer to driver command iocb object. | |
7230 | * | |
7231 | * This function issues an abort iocb for the provided command | |
7232 | * iocb. This function is called with hbalock held. | |
7233 | * The function returns 0 when it fails due to memory allocation | |
7234 | * failure or when the command iocb is an abort request. | |
7235 | **/ | |
dea3101e | 7236 | int |
2e0fef85 JS |
7237 | lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, |
7238 | struct lpfc_iocbq *cmdiocb) | |
dea3101e | 7239 | { |
2e0fef85 | 7240 | struct lpfc_vport *vport = cmdiocb->vport; |
0bd4ca25 | 7241 | struct lpfc_iocbq *abtsiocbp; |
dea3101e JB |
7242 | IOCB_t *icmd = NULL; |
7243 | IOCB_t *iabt = NULL; | |
07951076 JS |
7244 | int retval = IOCB_ERROR; |
7245 | ||
92d7f7b0 JS |
7246 | /* |
7247 | * There are certain command types we don't want to abort. And we | |
7248 | * don't want to abort commands that are already in the process of | |
7249 | * being aborted. | |
07951076 JS |
7250 | */ |
7251 | icmd = &cmdiocb->iocb; | |
2e0fef85 | 7252 | if (icmd->ulpCommand == CMD_ABORT_XRI_CN || |
92d7f7b0 JS |
7253 | icmd->ulpCommand == CMD_CLOSE_XRI_CN || |
7254 | (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0) | |
07951076 JS |
7255 | return 0; |
7256 | ||
858c9f6c JS |
7257 | /* If we're unloading, don't abort iocb on the ELS ring, but change the |
7258 | * callback so that nothing happens when it finishes. | |
07951076 | 7259 | */ |
858c9f6c JS |
7260 | if ((vport->load_flag & FC_UNLOADING) && |
7261 | (pring->ringno == LPFC_ELS_RING)) { | |
92d7f7b0 JS |
7262 | if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) |
7263 | cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl; | |
7264 | else | |
7265 | cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl; | |
07951076 | 7266 | goto abort_iotag_exit; |
92d7f7b0 | 7267 | } |
dea3101e JB |
7268 | |
7269 | /* issue ABTS for this IOCB based on iotag */ | |
92d7f7b0 | 7270 | abtsiocbp = __lpfc_sli_get_iocbq(phba); |
dea3101e JB |
7271 | if (abtsiocbp == NULL) |
7272 | return 0; | |
dea3101e | 7273 | |
07951076 | 7274 | /* This signals the response to set the correct status |
341af102 | 7275 | * before calling the completion handler |
07951076 JS |
7276 | */ |
7277 | cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; | |
7278 | ||
dea3101e | 7279 | iabt = &abtsiocbp->iocb; |
07951076 JS |
7280 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
7281 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | |
45ed1190 | 7282 | if (phba->sli_rev == LPFC_SLI_REV4) { |
da0436e9 | 7283 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; |
45ed1190 JS |
7284 | iabt->un.acxri.abortContextTag = cmdiocb->iotag; |
7285 | } | |
da0436e9 JS |
7286 | else |
7287 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | |
07951076 JS |
7288 | iabt->ulpLe = 1; |
7289 | iabt->ulpClass = icmd->ulpClass; | |
dea3101e | 7290 | |
5ffc266e JS |
7291 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
7292 | abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; | |
341af102 JS |
7293 | if (cmdiocb->iocb_flag & LPFC_IO_FCP) |
7294 | abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 7295 | |
2e0fef85 | 7296 | if (phba->link_state >= LPFC_LINK_UP) |
07951076 JS |
7297 | iabt->ulpCommand = CMD_ABORT_XRI_CN; |
7298 | else | |
7299 | iabt->ulpCommand = CMD_CLOSE_XRI_CN; | |
dea3101e | 7300 | |
07951076 | 7301 | abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl; |
5b8bd0c9 | 7302 | |
e8b62011 JS |
7303 | lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, |
7304 | "0339 Abort xri x%x, original iotag x%x, " | |
7305 | "abort cmd iotag x%x\n", | |
2a9bf3d0 | 7306 | iabt->un.acxri.abortIoTag, |
e8b62011 | 7307 | iabt->un.acxri.abortContextTag, |
2a9bf3d0 | 7308 | abtsiocbp->iotag); |
da0436e9 | 7309 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
dea3101e | 7310 | |
d7c255b2 JS |
7311 | if (retval) |
7312 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | |
07951076 | 7313 | abort_iotag_exit: |
2e0fef85 JS |
7314 | /* |
7315 | * Caller to this routine should check for IOCB_ERROR | |
7316 | * and handle it properly. This routine no longer removes | |
7317 | * iocb off txcmplq and call compl in case of IOCB_ERROR. | |
07951076 | 7318 | */ |
2e0fef85 | 7319 | return retval; |
dea3101e JB |
7320 | } |
7321 | ||
e59058c4 | 7322 | /** |
3621a710 | 7323 | * lpfc_sli_validate_fcp_iocb - find commands associated with a vport or LUN |
e59058c4 JS |
7324 | * @iocbq: Pointer to driver iocb object. |
7325 | * @vport: Pointer to driver virtual port object. | |
7326 | * @tgt_id: SCSI ID of the target. | |
7327 | * @lun_id: LUN ID of the scsi device. | |
7328 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST | |
7329 | * | |
3621a710 | 7330 | * This function acts as an iocb filter for functions which abort or count |
e59058c4 JS |
7331 | * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return |
7332 | * 0 if the filtering criteria is met for the given iocb and will return | |
7333 | * 1 if the filtering criteria is not met. | |
7334 | * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the | |
7335 | * given iocb is for the SCSI device specified by vport, tgt_id and | |
7336 | * lun_id parameter. | |
7337 | * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the | |
7338 | * given iocb is for the SCSI target specified by vport and tgt_id | |
7339 | * parameters. | |
7340 | * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the | |
7341 | * given iocb is for the SCSI host associated with the given vport. | |
7342 | * This function is called with no locks held. | |
7343 | **/ | |
dea3101e | 7344 | static int |
51ef4c26 JS |
7345 | lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, |
7346 | uint16_t tgt_id, uint64_t lun_id, | |
0bd4ca25 | 7347 | lpfc_ctx_cmd ctx_cmd) |
dea3101e | 7348 | { |
0bd4ca25 | 7349 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e JB |
7350 | int rc = 1; |
7351 | ||
0bd4ca25 JSEC |
7352 | if (!(iocbq->iocb_flag & LPFC_IO_FCP)) |
7353 | return rc; | |
7354 | ||
51ef4c26 JS |
7355 | if (iocbq->vport != vport) |
7356 | return rc; | |
7357 | ||
0bd4ca25 | 7358 | lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq); |
0bd4ca25 | 7359 | |
495a714c | 7360 | if (lpfc_cmd->pCmd == NULL) |
dea3101e JB |
7361 | return rc; |
7362 | ||
7363 | switch (ctx_cmd) { | |
7364 | case LPFC_CTX_LUN: | |
495a714c JS |
7365 | if ((lpfc_cmd->rdata->pnode) && |
7366 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) && | |
7367 | (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id)) | |
dea3101e JB |
7368 | rc = 0; |
7369 | break; | |
7370 | case LPFC_CTX_TGT: | |
495a714c JS |
7371 | if ((lpfc_cmd->rdata->pnode) && |
7372 | (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id)) | |
dea3101e JB |
7373 | rc = 0; |
7374 | break; | |
dea3101e JB |
7375 | case LPFC_CTX_HOST: |
7376 | rc = 0; | |
7377 | break; | |
7378 | default: | |
7379 | printk(KERN_ERR "%s: Unknown context cmd type, value %d\n", | |
cadbd4a5 | 7380 | __func__, ctx_cmd); |
dea3101e JB |
7381 | break; |
7382 | } | |
7383 | ||
7384 | return rc; | |
7385 | } | |
7386 | ||
e59058c4 | 7387 | /** |
3621a710 | 7388 | * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending |
e59058c4 JS |
7389 | * @vport: Pointer to virtual port. |
7390 | * @tgt_id: SCSI ID of the target. | |
7391 | * @lun_id: LUN ID of the scsi device. | |
7392 | * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
7393 | * | |
7394 | * This function returns number of FCP commands pending for the vport. | |
7395 | * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP | |
7396 | * commands pending on the vport associated with SCSI device specified | |
7397 | * by tgt_id and lun_id parameters. | |
7398 | * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP | |
7399 | * commands pending on the vport associated with SCSI target specified | |
7400 | * by tgt_id parameter. | |
7401 | * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP | |
7402 | * commands pending on the vport. | |
7403 | * This function returns the number of iocbs which satisfy the filter. | |
7404 | * This function is called without any lock held. | |
7405 | **/ | |
dea3101e | 7406 | int |
51ef4c26 JS |
7407 | lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, |
7408 | lpfc_ctx_cmd ctx_cmd) | |
dea3101e | 7409 | { |
51ef4c26 | 7410 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
7411 | struct lpfc_iocbq *iocbq; |
7412 | int sum, i; | |
dea3101e | 7413 | |
0bd4ca25 JSEC |
7414 | for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) { |
7415 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 7416 | |
51ef4c26 JS |
7417 | if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id, |
7418 | ctx_cmd) == 0) | |
0bd4ca25 | 7419 | sum++; |
dea3101e | 7420 | } |
0bd4ca25 | 7421 | |
dea3101e JB |
7422 | return sum; |
7423 | } | |
7424 | ||
e59058c4 | 7425 | /** |
3621a710 | 7426 | * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs |
e59058c4 JS |
7427 | * @phba: Pointer to HBA context object |
7428 | * @cmdiocb: Pointer to command iocb object. | |
7429 | * @rspiocb: Pointer to response iocb object. | |
7430 | * | |
7431 | * This function is called when an aborted FCP iocb completes. This | |
7432 | * function is called by the ring event handler with no lock held. | |
7433 | * This function frees the iocb. | |
7434 | **/ | |
5eb95af0 | 7435 | void |
2e0fef85 JS |
7436 | lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, |
7437 | struct lpfc_iocbq *rspiocb) | |
5eb95af0 | 7438 | { |
604a3e30 | 7439 | lpfc_sli_release_iocbq(phba, cmdiocb); |
5eb95af0 JSEC |
7440 | return; |
7441 | } | |
7442 | ||
e59058c4 | 7443 | /** |
3621a710 | 7444 | * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN |
e59058c4 JS |
7445 | * @vport: Pointer to virtual port. |
7446 | * @pring: Pointer to driver SLI ring object. | |
7447 | * @tgt_id: SCSI ID of the target. | |
7448 | * @lun_id: LUN ID of the scsi device. | |
7449 | * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST. | |
7450 | * | |
7451 | * This function sends an abort command for every SCSI command | |
7452 | * associated with the given virtual port pending on the ring | |
7453 | * filtered by lpfc_sli_validate_fcp_iocb function. | |
7454 | * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the | |
7455 | * FCP iocbs associated with lun specified by tgt_id and lun_id | |
7456 | * parameters | |
7457 | * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the | |
7458 | * FCP iocbs associated with SCSI target specified by tgt_id parameter. | |
7459 | * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all | |
7460 | * FCP iocbs associated with virtual port. | |
7461 | * This function returns number of iocbs it failed to abort. | |
7462 | * This function is called with no locks held. | |
7463 | **/ | |
dea3101e | 7464 | int |
51ef4c26 JS |
7465 | lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, |
7466 | uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) | |
dea3101e | 7467 | { |
51ef4c26 | 7468 | struct lpfc_hba *phba = vport->phba; |
0bd4ca25 JSEC |
7469 | struct lpfc_iocbq *iocbq; |
7470 | struct lpfc_iocbq *abtsiocb; | |
dea3101e | 7471 | IOCB_t *cmd = NULL; |
dea3101e | 7472 | int errcnt = 0, ret_val = 0; |
0bd4ca25 | 7473 | int i; |
dea3101e | 7474 | |
0bd4ca25 JSEC |
7475 | for (i = 1; i <= phba->sli.last_iotag; i++) { |
7476 | iocbq = phba->sli.iocbq_lookup[i]; | |
dea3101e | 7477 | |
51ef4c26 | 7478 | if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id, |
2e0fef85 | 7479 | abort_cmd) != 0) |
dea3101e JB |
7480 | continue; |
7481 | ||
7482 | /* issue ABTS for this IOCB based on iotag */ | |
0bd4ca25 | 7483 | abtsiocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
7484 | if (abtsiocb == NULL) { |
7485 | errcnt++; | |
7486 | continue; | |
7487 | } | |
dea3101e | 7488 | |
0bd4ca25 | 7489 | cmd = &iocbq->iocb; |
dea3101e JB |
7490 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
7491 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | |
da0436e9 JS |
7492 | if (phba->sli_rev == LPFC_SLI_REV4) |
7493 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | |
7494 | else | |
7495 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | |
dea3101e JB |
7496 | abtsiocb->iocb.ulpLe = 1; |
7497 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | |
2e0fef85 | 7498 | abtsiocb->vport = phba->pport; |
dea3101e | 7499 | |
5ffc266e JS |
7500 | /* ABTS WQE must go to the same WQ as the WQE to be aborted */ |
7501 | abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; | |
341af102 JS |
7502 | if (iocbq->iocb_flag & LPFC_IO_FCP) |
7503 | abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX; | |
5ffc266e | 7504 | |
2e0fef85 | 7505 | if (lpfc_is_link_up(phba)) |
dea3101e JB |
7506 | abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; |
7507 | else | |
7508 | abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; | |
7509 | ||
5eb95af0 JSEC |
7510 | /* Setup callback routine and issue the command. */ |
7511 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | |
da0436e9 JS |
7512 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
7513 | abtsiocb, 0); | |
dea3101e | 7514 | if (ret_val == IOCB_ERROR) { |
604a3e30 | 7515 | lpfc_sli_release_iocbq(phba, abtsiocb); |
dea3101e JB |
7516 | errcnt++; |
7517 | continue; | |
7518 | } | |
7519 | } | |
7520 | ||
7521 | return errcnt; | |
7522 | } | |
7523 | ||
e59058c4 | 7524 | /** |
3621a710 | 7525 | * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler |
e59058c4 JS |
7526 | * @phba: Pointer to HBA context object. |
7527 | * @cmdiocbq: Pointer to command iocb. | |
7528 | * @rspiocbq: Pointer to response iocb. | |
7529 | * | |
7530 | * This function is the completion handler for iocbs issued using | |
7531 | * lpfc_sli_issue_iocb_wait function. This function is called by the | |
7532 | * ring event handler function without any lock held. This function | |
7533 | * can be called from both worker thread context and interrupt | |
7534 | * context. This function also can be called from other thread which | |
7535 | * cleans up the SLI layer objects. | |
7536 | * This function copy the contents of the response iocb to the | |
7537 | * response iocb memory object provided by the caller of | |
7538 | * lpfc_sli_issue_iocb_wait and then wakes up the thread which | |
7539 | * sleeps for the iocb completion. | |
7540 | **/ | |
68876920 JSEC |
7541 | static void |
7542 | lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |
7543 | struct lpfc_iocbq *cmdiocbq, | |
7544 | struct lpfc_iocbq *rspiocbq) | |
dea3101e | 7545 | { |
68876920 JSEC |
7546 | wait_queue_head_t *pdone_q; |
7547 | unsigned long iflags; | |
0f65ff68 | 7548 | struct lpfc_scsi_buf *lpfc_cmd; |
dea3101e | 7549 | |
2e0fef85 | 7550 | spin_lock_irqsave(&phba->hbalock, iflags); |
68876920 JSEC |
7551 | cmdiocbq->iocb_flag |= LPFC_IO_WAKE; |
7552 | if (cmdiocbq->context2 && rspiocbq) | |
7553 | memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, | |
7554 | &rspiocbq->iocb, sizeof(IOCB_t)); | |
7555 | ||
0f65ff68 JS |
7556 | /* Set the exchange busy flag for task management commands */ |
7557 | if ((cmdiocbq->iocb_flag & LPFC_IO_FCP) && | |
7558 | !(cmdiocbq->iocb_flag & LPFC_IO_LIBDFC)) { | |
7559 | lpfc_cmd = container_of(cmdiocbq, struct lpfc_scsi_buf, | |
7560 | cur_iocbq); | |
7561 | lpfc_cmd->exch_busy = rspiocbq->iocb_flag & LPFC_EXCHANGE_BUSY; | |
7562 | } | |
7563 | ||
68876920 | 7564 | pdone_q = cmdiocbq->context_un.wait_queue; |
68876920 JSEC |
7565 | if (pdone_q) |
7566 | wake_up(pdone_q); | |
858c9f6c | 7567 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
dea3101e JB |
7568 | return; |
7569 | } | |
7570 | ||
d11e31dd JS |
7571 | /** |
7572 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | |
7573 | * @phba: Pointer to HBA context object.. | |
7574 | * @piocbq: Pointer to command iocb. | |
7575 | * @flag: Flag to test. | |
7576 | * | |
7577 | * This routine grabs the hbalock and then test the iocb_flag to | |
7578 | * see if the passed in flag is set. | |
7579 | * Returns: | |
7580 | * 1 if flag is set. | |
7581 | * 0 if flag is not set. | |
7582 | **/ | |
7583 | static int | |
7584 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | |
7585 | struct lpfc_iocbq *piocbq, uint32_t flag) | |
7586 | { | |
7587 | unsigned long iflags; | |
7588 | int ret; | |
7589 | ||
7590 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7591 | ret = piocbq->iocb_flag & flag; | |
7592 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7593 | return ret; | |
7594 | ||
7595 | } | |
7596 | ||
e59058c4 | 7597 | /** |
3621a710 | 7598 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
e59058c4 JS |
7599 | * @phba: Pointer to HBA context object.. |
7600 | * @pring: Pointer to sli ring. | |
7601 | * @piocb: Pointer to command iocb. | |
7602 | * @prspiocbq: Pointer to response iocb. | |
7603 | * @timeout: Timeout in number of seconds. | |
7604 | * | |
7605 | * This function issues the iocb to firmware and waits for the | |
7606 | * iocb to complete. If the iocb command is not | |
7607 | * completed within timeout seconds, it returns IOCB_TIMEDOUT. | |
7608 | * Caller should not free the iocb resources if this function | |
7609 | * returns IOCB_TIMEDOUT. | |
7610 | * The function waits for the iocb completion using an | |
7611 | * non-interruptible wait. | |
7612 | * This function will sleep while waiting for iocb completion. | |
7613 | * So, this function should not be called from any context which | |
7614 | * does not allow sleeping. Due to the same reason, this function | |
7615 | * cannot be called with interrupt disabled. | |
7616 | * This function assumes that the iocb completions occur while | |
7617 | * this function sleep. So, this function cannot be called from | |
7618 | * the thread which process iocb completion for this ring. | |
7619 | * This function clears the iocb_flag of the iocb object before | |
7620 | * issuing the iocb and the iocb completion handler sets this | |
7621 | * flag and wakes this thread when the iocb completes. | |
7622 | * The contents of the response iocb will be copied to prspiocbq | |
7623 | * by the completion handler when the command completes. | |
7624 | * This function returns IOCB_SUCCESS when success. | |
7625 | * This function is called with no lock held. | |
7626 | **/ | |
dea3101e | 7627 | int |
2e0fef85 | 7628 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
da0436e9 | 7629 | uint32_t ring_number, |
2e0fef85 JS |
7630 | struct lpfc_iocbq *piocb, |
7631 | struct lpfc_iocbq *prspiocbq, | |
68876920 | 7632 | uint32_t timeout) |
dea3101e | 7633 | { |
7259f0d0 | 7634 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
68876920 JSEC |
7635 | long timeleft, timeout_req = 0; |
7636 | int retval = IOCB_SUCCESS; | |
875fbdfe | 7637 | uint32_t creg_val; |
2a9bf3d0 | 7638 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; |
dea3101e | 7639 | /* |
68876920 JSEC |
7640 | * If the caller has provided a response iocbq buffer, then context2 |
7641 | * is NULL or its an error. | |
dea3101e | 7642 | */ |
68876920 JSEC |
7643 | if (prspiocbq) { |
7644 | if (piocb->context2) | |
7645 | return IOCB_ERROR; | |
7646 | piocb->context2 = prspiocbq; | |
dea3101e JB |
7647 | } |
7648 | ||
68876920 JSEC |
7649 | piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait; |
7650 | piocb->context_un.wait_queue = &done_q; | |
7651 | piocb->iocb_flag &= ~LPFC_IO_WAKE; | |
dea3101e | 7652 | |
875fbdfe JSEC |
7653 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
7654 | creg_val = readl(phba->HCregaddr); | |
7655 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
7656 | writel(creg_val, phba->HCregaddr); | |
7657 | readl(phba->HCregaddr); /* flush */ | |
7658 | } | |
7659 | ||
2a9bf3d0 JS |
7660 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, |
7661 | SLI_IOCB_RET_IOCB); | |
68876920 JSEC |
7662 | if (retval == IOCB_SUCCESS) { |
7663 | timeout_req = timeout * HZ; | |
68876920 | 7664 | timeleft = wait_event_timeout(done_q, |
d11e31dd | 7665 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
68876920 | 7666 | timeout_req); |
dea3101e | 7667 | |
7054a606 JS |
7668 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
7669 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
e8b62011 | 7670 | "0331 IOCB wake signaled\n"); |
7054a606 | 7671 | } else if (timeleft == 0) { |
68876920 | 7672 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
7673 | "0338 IOCB wait timeout error - no " |
7674 | "wake response Data x%x\n", timeout); | |
68876920 | 7675 | retval = IOCB_TIMEDOUT; |
7054a606 | 7676 | } else { |
68876920 | 7677 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e8b62011 JS |
7678 | "0330 IOCB wake NOT set, " |
7679 | "Data x%x x%lx\n", | |
68876920 JSEC |
7680 | timeout, (timeleft / jiffies)); |
7681 | retval = IOCB_TIMEDOUT; | |
dea3101e | 7682 | } |
2a9bf3d0 JS |
7683 | } else if (retval == IOCB_BUSY) { |
7684 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
7685 | "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n", | |
7686 | phba->iocb_cnt, pring->txq_cnt, pring->txcmplq_cnt); | |
7687 | return retval; | |
68876920 JSEC |
7688 | } else { |
7689 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
d7c255b2 | 7690 | "0332 IOCB wait issue failed, Data x%x\n", |
e8b62011 | 7691 | retval); |
68876920 | 7692 | retval = IOCB_ERROR; |
dea3101e JB |
7693 | } |
7694 | ||
875fbdfe JSEC |
7695 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
7696 | creg_val = readl(phba->HCregaddr); | |
7697 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | |
7698 | writel(creg_val, phba->HCregaddr); | |
7699 | readl(phba->HCregaddr); /* flush */ | |
7700 | } | |
7701 | ||
68876920 JSEC |
7702 | if (prspiocbq) |
7703 | piocb->context2 = NULL; | |
7704 | ||
7705 | piocb->context_un.wait_queue = NULL; | |
7706 | piocb->iocb_cmpl = NULL; | |
dea3101e JB |
7707 | return retval; |
7708 | } | |
68876920 | 7709 | |
e59058c4 | 7710 | /** |
3621a710 | 7711 | * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox |
e59058c4 JS |
7712 | * @phba: Pointer to HBA context object. |
7713 | * @pmboxq: Pointer to driver mailbox object. | |
7714 | * @timeout: Timeout in number of seconds. | |
7715 | * | |
7716 | * This function issues the mailbox to firmware and waits for the | |
7717 | * mailbox command to complete. If the mailbox command is not | |
7718 | * completed within timeout seconds, it returns MBX_TIMEOUT. | |
7719 | * The function waits for the mailbox completion using an | |
7720 | * interruptible wait. If the thread is woken up due to a | |
7721 | * signal, MBX_TIMEOUT error is returned to the caller. Caller | |
7722 | * should not free the mailbox resources, if this function returns | |
7723 | * MBX_TIMEOUT. | |
7724 | * This function will sleep while waiting for mailbox completion. | |
7725 | * So, this function should not be called from any context which | |
7726 | * does not allow sleeping. Due to the same reason, this function | |
7727 | * cannot be called with interrupt disabled. | |
7728 | * This function assumes that the mailbox completion occurs while | |
7729 | * this function sleep. So, this function cannot be called from | |
7730 | * the worker thread which processes mailbox completion. | |
7731 | * This function is called in the context of HBA management | |
7732 | * applications. | |
7733 | * This function returns MBX_SUCCESS when successful. | |
7734 | * This function is called with no lock held. | |
7735 | **/ | |
dea3101e | 7736 | int |
2e0fef85 | 7737 | lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, |
dea3101e JB |
7738 | uint32_t timeout) |
7739 | { | |
7259f0d0 | 7740 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); |
dea3101e | 7741 | int retval; |
858c9f6c | 7742 | unsigned long flag; |
dea3101e JB |
7743 | |
7744 | /* The caller must leave context1 empty. */ | |
98c9ea5c | 7745 | if (pmboxq->context1) |
2e0fef85 | 7746 | return MBX_NOT_FINISHED; |
dea3101e | 7747 | |
495a714c | 7748 | pmboxq->mbox_flag &= ~LPFC_MBX_WAKE; |
dea3101e JB |
7749 | /* setup wake call as IOCB callback */ |
7750 | pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait; | |
7751 | /* setup context field to pass wait_queue pointer to wake function */ | |
7752 | pmboxq->context1 = &done_q; | |
7753 | ||
dea3101e JB |
7754 | /* now issue the command */ |
7755 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
7756 | ||
7757 | if (retval == MBX_BUSY || retval == MBX_SUCCESS) { | |
7054a606 JS |
7758 | wait_event_interruptible_timeout(done_q, |
7759 | pmboxq->mbox_flag & LPFC_MBX_WAKE, | |
7760 | timeout * HZ); | |
7761 | ||
858c9f6c | 7762 | spin_lock_irqsave(&phba->hbalock, flag); |
dea3101e | 7763 | pmboxq->context1 = NULL; |
7054a606 JS |
7764 | /* |
7765 | * if LPFC_MBX_WAKE flag is set the mailbox is completed | |
7766 | * else do not free the resources. | |
7767 | */ | |
7768 | if (pmboxq->mbox_flag & LPFC_MBX_WAKE) | |
dea3101e | 7769 | retval = MBX_SUCCESS; |
858c9f6c | 7770 | else { |
7054a606 | 7771 | retval = MBX_TIMEOUT; |
858c9f6c JS |
7772 | pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
7773 | } | |
7774 | spin_unlock_irqrestore(&phba->hbalock, flag); | |
dea3101e JB |
7775 | } |
7776 | ||
dea3101e JB |
7777 | return retval; |
7778 | } | |
7779 | ||
e59058c4 | 7780 | /** |
3772a991 | 7781 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
e59058c4 JS |
7782 | * @phba: Pointer to HBA context. |
7783 | * | |
3772a991 JS |
7784 | * This function is called to shutdown the driver's mailbox sub-system. |
7785 | * It first marks the mailbox sub-system is in a block state to prevent | |
7786 | * the asynchronous mailbox command from issued off the pending mailbox | |
7787 | * command queue. If the mailbox command sub-system shutdown is due to | |
7788 | * HBA error conditions such as EEH or ERATT, this routine shall invoke | |
7789 | * the mailbox sub-system flush routine to forcefully bring down the | |
7790 | * mailbox sub-system. Otherwise, if it is due to normal condition (such | |
7791 | * as with offline or HBA function reset), this routine will wait for the | |
7792 | * outstanding mailbox command to complete before invoking the mailbox | |
7793 | * sub-system flush routine to gracefully bring down mailbox sub-system. | |
e59058c4 | 7794 | **/ |
3772a991 JS |
7795 | void |
7796 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) | |
b4c02652 | 7797 | { |
3772a991 JS |
7798 | struct lpfc_sli *psli = &phba->sli; |
7799 | uint8_t actcmd = MBX_HEARTBEAT; | |
7800 | unsigned long timeout; | |
b4c02652 | 7801 | |
3772a991 JS |
7802 | spin_lock_irq(&phba->hbalock); |
7803 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
7804 | spin_unlock_irq(&phba->hbalock); | |
b4c02652 | 7805 | |
3772a991 | 7806 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
ed957684 | 7807 | spin_lock_irq(&phba->hbalock); |
3772a991 JS |
7808 | if (phba->sli.mbox_active) |
7809 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
ed957684 | 7810 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
7811 | /* Determine how long we might wait for the active mailbox |
7812 | * command to be gracefully completed by firmware. | |
7813 | */ | |
7814 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * | |
7815 | 1000) + jiffies; | |
7816 | while (phba->sli.mbox_active) { | |
7817 | /* Check active mailbox complete status every 2ms */ | |
7818 | msleep(2); | |
7819 | if (time_after(jiffies, timeout)) | |
7820 | /* Timeout, let the mailbox flush routine to | |
7821 | * forcefully release active mailbox command | |
7822 | */ | |
7823 | break; | |
7824 | } | |
7825 | } | |
7826 | lpfc_sli_mbox_sys_flush(phba); | |
7827 | } | |
ed957684 | 7828 | |
3772a991 JS |
7829 | /** |
7830 | * lpfc_sli_eratt_read - read sli-3 error attention events | |
7831 | * @phba: Pointer to HBA context. | |
7832 | * | |
7833 | * This function is called to read the SLI3 device error attention registers | |
7834 | * for possible error attention events. The caller must hold the hostlock | |
7835 | * with spin_lock_irq(). | |
7836 | * | |
7837 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
7838 | * Register and returns 0 otherwise. | |
7839 | **/ | |
7840 | static int | |
7841 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | |
7842 | { | |
7843 | uint32_t ha_copy; | |
b4c02652 | 7844 | |
3772a991 JS |
7845 | /* Read chip Host Attention (HA) register */ |
7846 | ha_copy = readl(phba->HAregaddr); | |
7847 | if (ha_copy & HA_ERATT) { | |
7848 | /* Read host status register to retrieve error event */ | |
7849 | lpfc_sli_read_hs(phba); | |
b4c02652 | 7850 | |
3772a991 JS |
7851 | /* Check if there is a deferred error condition is active */ |
7852 | if ((HS_FFER1 & phba->work_hs) && | |
7853 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
7854 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { | |
3772a991 | 7855 | phba->hba_flag |= DEFER_ERATT; |
3772a991 JS |
7856 | /* Clear all interrupt enable conditions */ |
7857 | writel(0, phba->HCregaddr); | |
7858 | readl(phba->HCregaddr); | |
7859 | } | |
7860 | ||
7861 | /* Set the driver HA work bitmap */ | |
3772a991 JS |
7862 | phba->work_ha |= HA_ERATT; |
7863 | /* Indicate polling handles this ERATT */ | |
7864 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
3772a991 JS |
7865 | return 1; |
7866 | } | |
7867 | return 0; | |
b4c02652 JS |
7868 | } |
7869 | ||
da0436e9 JS |
7870 | /** |
7871 | * lpfc_sli4_eratt_read - read sli-4 error attention events | |
7872 | * @phba: Pointer to HBA context. | |
7873 | * | |
7874 | * This function is called to read the SLI4 device error attention registers | |
7875 | * for possible error attention events. The caller must hold the hostlock | |
7876 | * with spin_lock_irq(). | |
7877 | * | |
7878 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
7879 | * Register and returns 0 otherwise. | |
7880 | **/ | |
7881 | static int | |
7882 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | |
7883 | { | |
7884 | uint32_t uerr_sta_hi, uerr_sta_lo; | |
da0436e9 JS |
7885 | |
7886 | /* For now, use the SLI4 device internal unrecoverable error | |
7887 | * registers for error attention. This can be changed later. | |
7888 | */ | |
a747c9ce JS |
7889 | uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr); |
7890 | uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr); | |
7891 | if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) || | |
7892 | (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) { | |
7893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7894 | "1423 HBA Unrecoverable error: " | |
7895 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
7896 | "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n", | |
7897 | uerr_sta_lo, uerr_sta_hi, | |
7898 | phba->sli4_hba.ue_mask_lo, | |
7899 | phba->sli4_hba.ue_mask_hi); | |
7900 | phba->work_status[0] = uerr_sta_lo; | |
7901 | phba->work_status[1] = uerr_sta_hi; | |
7902 | /* Set the driver HA work bitmap */ | |
7903 | phba->work_ha |= HA_ERATT; | |
7904 | /* Indicate polling handles this ERATT */ | |
7905 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
7906 | return 1; | |
da0436e9 JS |
7907 | } |
7908 | return 0; | |
7909 | } | |
7910 | ||
e59058c4 | 7911 | /** |
3621a710 | 7912 | * lpfc_sli_check_eratt - check error attention events |
9399627f JS |
7913 | * @phba: Pointer to HBA context. |
7914 | * | |
3772a991 | 7915 | * This function is called from timer soft interrupt context to check HBA's |
9399627f JS |
7916 | * error attention register bit for error attention events. |
7917 | * | |
7918 | * This fucntion returns 1 when there is Error Attention in the Host Attention | |
7919 | * Register and returns 0 otherwise. | |
7920 | **/ | |
7921 | int | |
7922 | lpfc_sli_check_eratt(struct lpfc_hba *phba) | |
7923 | { | |
7924 | uint32_t ha_copy; | |
7925 | ||
7926 | /* If somebody is waiting to handle an eratt, don't process it | |
7927 | * here. The brdkill function will do this. | |
7928 | */ | |
7929 | if (phba->link_flag & LS_IGNORE_ERATT) | |
7930 | return 0; | |
7931 | ||
7932 | /* Check if interrupt handler handles this ERATT */ | |
7933 | spin_lock_irq(&phba->hbalock); | |
7934 | if (phba->hba_flag & HBA_ERATT_HANDLED) { | |
7935 | /* Interrupt handler has handled ERATT */ | |
7936 | spin_unlock_irq(&phba->hbalock); | |
7937 | return 0; | |
7938 | } | |
7939 | ||
a257bf90 JS |
7940 | /* |
7941 | * If there is deferred error attention, do not check for error | |
7942 | * attention | |
7943 | */ | |
7944 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
7945 | spin_unlock_irq(&phba->hbalock); | |
7946 | return 0; | |
7947 | } | |
7948 | ||
3772a991 JS |
7949 | /* If PCI channel is offline, don't process it */ |
7950 | if (unlikely(pci_channel_offline(phba->pcidev))) { | |
9399627f | 7951 | spin_unlock_irq(&phba->hbalock); |
3772a991 JS |
7952 | return 0; |
7953 | } | |
7954 | ||
7955 | switch (phba->sli_rev) { | |
7956 | case LPFC_SLI_REV2: | |
7957 | case LPFC_SLI_REV3: | |
7958 | /* Read chip Host Attention (HA) register */ | |
7959 | ha_copy = lpfc_sli_eratt_read(phba); | |
7960 | break; | |
da0436e9 JS |
7961 | case LPFC_SLI_REV4: |
7962 | /* Read devcie Uncoverable Error (UERR) registers */ | |
7963 | ha_copy = lpfc_sli4_eratt_read(phba); | |
7964 | break; | |
3772a991 JS |
7965 | default: |
7966 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7967 | "0299 Invalid SLI revision (%d)\n", | |
7968 | phba->sli_rev); | |
7969 | ha_copy = 0; | |
7970 | break; | |
9399627f JS |
7971 | } |
7972 | spin_unlock_irq(&phba->hbalock); | |
3772a991 JS |
7973 | |
7974 | return ha_copy; | |
7975 | } | |
7976 | ||
7977 | /** | |
7978 | * lpfc_intr_state_check - Check device state for interrupt handling | |
7979 | * @phba: Pointer to HBA context. | |
7980 | * | |
7981 | * This inline routine checks whether a device or its PCI slot is in a state | |
7982 | * that the interrupt should be handled. | |
7983 | * | |
7984 | * This function returns 0 if the device or the PCI slot is in a state that | |
7985 | * interrupt should be handled, otherwise -EIO. | |
7986 | */ | |
7987 | static inline int | |
7988 | lpfc_intr_state_check(struct lpfc_hba *phba) | |
7989 | { | |
7990 | /* If the pci channel is offline, ignore all the interrupts */ | |
7991 | if (unlikely(pci_channel_offline(phba->pcidev))) | |
7992 | return -EIO; | |
7993 | ||
7994 | /* Update device level interrupt statistics */ | |
7995 | phba->sli.slistat.sli_intr++; | |
7996 | ||
7997 | /* Ignore all interrupts during initialization. */ | |
7998 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | |
7999 | return -EIO; | |
8000 | ||
9399627f JS |
8001 | return 0; |
8002 | } | |
8003 | ||
8004 | /** | |
3772a991 | 8005 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
e59058c4 JS |
8006 | * @irq: Interrupt number. |
8007 | * @dev_id: The device context pointer. | |
8008 | * | |
9399627f | 8009 | * This function is directly called from the PCI layer as an interrupt |
3772a991 JS |
8010 | * service routine when device with SLI-3 interface spec is enabled with |
8011 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
8012 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
8013 | * interrupt mode, this function is called as part of the device-level | |
8014 | * interrupt handler. When the PCI slot is in error recovery or the HBA | |
8015 | * is undergoing initialization, the interrupt handler will not process | |
8016 | * the interrupt. The link attention and ELS ring attention events are | |
8017 | * handled by the worker thread. The interrupt handler signals the worker | |
8018 | * thread and returns for these events. This function is called without | |
8019 | * any lock held. It gets the hbalock to access and update SLI data | |
9399627f JS |
8020 | * structures. |
8021 | * | |
8022 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8023 | * returns IRQ_NONE. | |
e59058c4 | 8024 | **/ |
dea3101e | 8025 | irqreturn_t |
3772a991 | 8026 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
dea3101e | 8027 | { |
2e0fef85 | 8028 | struct lpfc_hba *phba; |
a747c9ce | 8029 | uint32_t ha_copy, hc_copy; |
dea3101e JB |
8030 | uint32_t work_ha_copy; |
8031 | unsigned long status; | |
5b75da2f | 8032 | unsigned long iflag; |
dea3101e JB |
8033 | uint32_t control; |
8034 | ||
92d7f7b0 | 8035 | MAILBOX_t *mbox, *pmbox; |
858c9f6c JS |
8036 | struct lpfc_vport *vport; |
8037 | struct lpfc_nodelist *ndlp; | |
8038 | struct lpfc_dmabuf *mp; | |
92d7f7b0 JS |
8039 | LPFC_MBOXQ_t *pmb; |
8040 | int rc; | |
8041 | ||
dea3101e JB |
8042 | /* |
8043 | * Get the driver's phba structure from the dev_id and | |
8044 | * assume the HBA is not interrupting. | |
8045 | */ | |
9399627f | 8046 | phba = (struct lpfc_hba *)dev_id; |
dea3101e JB |
8047 | |
8048 | if (unlikely(!phba)) | |
8049 | return IRQ_NONE; | |
8050 | ||
dea3101e | 8051 | /* |
9399627f JS |
8052 | * Stuff needs to be attented to when this function is invoked as an |
8053 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
dea3101e | 8054 | */ |
9399627f | 8055 | if (phba->intr_type == MSIX) { |
3772a991 JS |
8056 | /* Check device state for handling interrupt */ |
8057 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8058 | return IRQ_NONE; |
8059 | /* Need to read HA REG for slow-path events */ | |
5b75da2f | 8060 | spin_lock_irqsave(&phba->hbalock, iflag); |
34b02dcd | 8061 | ha_copy = readl(phba->HAregaddr); |
9399627f JS |
8062 | /* If somebody is waiting to handle an eratt don't process it |
8063 | * here. The brdkill function will do this. | |
8064 | */ | |
8065 | if (phba->link_flag & LS_IGNORE_ERATT) | |
8066 | ha_copy &= ~HA_ERATT; | |
8067 | /* Check the need for handling ERATT in interrupt handler */ | |
8068 | if (ha_copy & HA_ERATT) { | |
8069 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8070 | /* ERATT polling has handled ERATT */ | |
8071 | ha_copy &= ~HA_ERATT; | |
8072 | else | |
8073 | /* Indicate interrupt handler handles ERATT */ | |
8074 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8075 | } | |
a257bf90 JS |
8076 | |
8077 | /* | |
8078 | * If there is deferred error attention, do not check for any | |
8079 | * interrupt. | |
8080 | */ | |
8081 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8082 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8083 | return IRQ_NONE; |
8084 | } | |
8085 | ||
9399627f | 8086 | /* Clear up only attention source related to slow-path */ |
a747c9ce JS |
8087 | hc_copy = readl(phba->HCregaddr); |
8088 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA | | |
8089 | HC_LAINT_ENA | HC_ERINT_ENA), | |
8090 | phba->HCregaddr); | |
9399627f JS |
8091 | writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)), |
8092 | phba->HAregaddr); | |
a747c9ce | 8093 | writel(hc_copy, phba->HCregaddr); |
9399627f | 8094 | readl(phba->HAregaddr); /* flush */ |
5b75da2f | 8095 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8096 | } else |
8097 | ha_copy = phba->ha_copy; | |
dea3101e | 8098 | |
dea3101e JB |
8099 | work_ha_copy = ha_copy & phba->work_ha_mask; |
8100 | ||
9399627f | 8101 | if (work_ha_copy) { |
dea3101e JB |
8102 | if (work_ha_copy & HA_LATT) { |
8103 | if (phba->sli.sli_flag & LPFC_PROCESS_LA) { | |
8104 | /* | |
8105 | * Turn off Link Attention interrupts | |
8106 | * until CLEAR_LA done | |
8107 | */ | |
5b75da2f | 8108 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e JB |
8109 | phba->sli.sli_flag &= ~LPFC_PROCESS_LA; |
8110 | control = readl(phba->HCregaddr); | |
8111 | control &= ~HC_LAINT_ENA; | |
8112 | writel(control, phba->HCregaddr); | |
8113 | readl(phba->HCregaddr); /* flush */ | |
5b75da2f | 8114 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
8115 | } |
8116 | else | |
8117 | work_ha_copy &= ~HA_LATT; | |
8118 | } | |
8119 | ||
9399627f | 8120 | if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) { |
858c9f6c JS |
8121 | /* |
8122 | * Turn off Slow Rings interrupts, LPFC_ELS_RING is | |
8123 | * the only slow ring. | |
8124 | */ | |
8125 | status = (work_ha_copy & | |
8126 | (HA_RXMASK << (4*LPFC_ELS_RING))); | |
8127 | status >>= (4*LPFC_ELS_RING); | |
8128 | if (status & HA_RXMASK) { | |
5b75da2f | 8129 | spin_lock_irqsave(&phba->hbalock, iflag); |
858c9f6c | 8130 | control = readl(phba->HCregaddr); |
a58cbd52 JS |
8131 | |
8132 | lpfc_debugfs_slow_ring_trc(phba, | |
8133 | "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x", | |
8134 | control, status, | |
8135 | (uint32_t)phba->sli.slistat.sli_intr); | |
8136 | ||
858c9f6c | 8137 | if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) { |
a58cbd52 JS |
8138 | lpfc_debugfs_slow_ring_trc(phba, |
8139 | "ISR Disable ring:" | |
8140 | "pwork:x%x hawork:x%x wait:x%x", | |
8141 | phba->work_ha, work_ha_copy, | |
8142 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8143 | &phba->work_waitq)); |
a58cbd52 | 8144 | |
858c9f6c JS |
8145 | control &= |
8146 | ~(HC_R0INT_ENA << LPFC_ELS_RING); | |
dea3101e JB |
8147 | writel(control, phba->HCregaddr); |
8148 | readl(phba->HCregaddr); /* flush */ | |
dea3101e | 8149 | } |
a58cbd52 JS |
8150 | else { |
8151 | lpfc_debugfs_slow_ring_trc(phba, | |
8152 | "ISR slow ring: pwork:" | |
8153 | "x%x hawork:x%x wait:x%x", | |
8154 | phba->work_ha, work_ha_copy, | |
8155 | (uint32_t)((unsigned long) | |
5e9d9b82 | 8156 | &phba->work_waitq)); |
a58cbd52 | 8157 | } |
5b75da2f | 8158 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
dea3101e JB |
8159 | } |
8160 | } | |
5b75da2f | 8161 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 | 8162 | if (work_ha_copy & HA_ERATT) { |
9399627f | 8163 | lpfc_sli_read_hs(phba); |
a257bf90 JS |
8164 | /* |
8165 | * Check if there is a deferred error condition | |
8166 | * is active | |
8167 | */ | |
8168 | if ((HS_FFER1 & phba->work_hs) && | |
8169 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | |
8170 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { | |
8171 | phba->hba_flag |= DEFER_ERATT; | |
8172 | /* Clear all interrupt enable conditions */ | |
8173 | writel(0, phba->HCregaddr); | |
8174 | readl(phba->HCregaddr); | |
8175 | } | |
8176 | } | |
8177 | ||
9399627f | 8178 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
92d7f7b0 | 8179 | pmb = phba->sli.mbox_active; |
04c68496 | 8180 | pmbox = &pmb->u.mb; |
34b02dcd | 8181 | mbox = phba->mbox; |
858c9f6c | 8182 | vport = pmb->vport; |
92d7f7b0 JS |
8183 | |
8184 | /* First check out the status word */ | |
8185 | lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t)); | |
8186 | if (pmbox->mbxOwner != OWN_HOST) { | |
5b75da2f | 8187 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
92d7f7b0 JS |
8188 | /* |
8189 | * Stray Mailbox Interrupt, mbxCommand <cmd> | |
8190 | * mbxStatus <status> | |
8191 | */ | |
09372820 | 8192 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | |
92d7f7b0 | 8193 | LOG_SLI, |
e8b62011 | 8194 | "(%d):0304 Stray Mailbox " |
92d7f7b0 JS |
8195 | "Interrupt mbxCommand x%x " |
8196 | "mbxStatus x%x\n", | |
e8b62011 | 8197 | (vport ? vport->vpi : 0), |
92d7f7b0 JS |
8198 | pmbox->mbxCommand, |
8199 | pmbox->mbxStatus); | |
09372820 JS |
8200 | /* clear mailbox attention bit */ |
8201 | work_ha_copy &= ~HA_MBATT; | |
8202 | } else { | |
97eab634 | 8203 | phba->sli.mbox_active = NULL; |
5b75da2f | 8204 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
09372820 JS |
8205 | phba->last_completion_time = jiffies; |
8206 | del_timer(&phba->sli.mbox_tmo); | |
09372820 JS |
8207 | if (pmb->mbox_cmpl) { |
8208 | lpfc_sli_pcimem_bcopy(mbox, pmbox, | |
8209 | MAILBOX_CMD_SIZE); | |
7a470277 JS |
8210 | if (pmb->out_ext_byte_len && |
8211 | pmb->context2) | |
8212 | lpfc_sli_pcimem_bcopy( | |
8213 | phba->mbox_ext, | |
8214 | pmb->context2, | |
8215 | pmb->out_ext_byte_len); | |
09372820 JS |
8216 | } |
8217 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
8218 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
8219 | ||
8220 | lpfc_debugfs_disc_trc(vport, | |
8221 | LPFC_DISC_TRC_MBOX_VPORT, | |
8222 | "MBOX dflt rpi: : " | |
8223 | "status:x%x rpi:x%x", | |
8224 | (uint32_t)pmbox->mbxStatus, | |
8225 | pmbox->un.varWords[0], 0); | |
8226 | ||
8227 | if (!pmbox->mbxStatus) { | |
8228 | mp = (struct lpfc_dmabuf *) | |
8229 | (pmb->context1); | |
8230 | ndlp = (struct lpfc_nodelist *) | |
8231 | pmb->context2; | |
8232 | ||
8233 | /* Reg_LOGIN of dflt RPI was | |
8234 | * successful. new lets get | |
8235 | * rid of the RPI using the | |
8236 | * same mbox buffer. | |
8237 | */ | |
8238 | lpfc_unreg_login(phba, | |
8239 | vport->vpi, | |
8240 | pmbox->un.varWords[0], | |
8241 | pmb); | |
8242 | pmb->mbox_cmpl = | |
8243 | lpfc_mbx_cmpl_dflt_rpi; | |
8244 | pmb->context1 = mp; | |
8245 | pmb->context2 = ndlp; | |
8246 | pmb->vport = vport; | |
58da1ffb JS |
8247 | rc = lpfc_sli_issue_mbox(phba, |
8248 | pmb, | |
8249 | MBX_NOWAIT); | |
8250 | if (rc != MBX_BUSY) | |
8251 | lpfc_printf_log(phba, | |
8252 | KERN_ERR, | |
8253 | LOG_MBOX | LOG_SLI, | |
d7c255b2 | 8254 | "0350 rc should have" |
6a9c52cf | 8255 | "been MBX_BUSY\n"); |
3772a991 JS |
8256 | if (rc != MBX_NOT_FINISHED) |
8257 | goto send_current_mbox; | |
09372820 | 8258 | } |
858c9f6c | 8259 | } |
5b75da2f JS |
8260 | spin_lock_irqsave( |
8261 | &phba->pport->work_port_lock, | |
8262 | iflag); | |
09372820 JS |
8263 | phba->pport->work_port_events &= |
8264 | ~WORKER_MBOX_TMO; | |
5b75da2f JS |
8265 | spin_unlock_irqrestore( |
8266 | &phba->pport->work_port_lock, | |
8267 | iflag); | |
09372820 | 8268 | lpfc_mbox_cmpl_put(phba, pmb); |
858c9f6c | 8269 | } |
97eab634 | 8270 | } else |
5b75da2f | 8271 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f | 8272 | |
92d7f7b0 JS |
8273 | if ((work_ha_copy & HA_MBATT) && |
8274 | (phba->sli.mbox_active == NULL)) { | |
858c9f6c | 8275 | send_current_mbox: |
92d7f7b0 | 8276 | /* Process next mailbox command if there is one */ |
58da1ffb JS |
8277 | do { |
8278 | rc = lpfc_sli_issue_mbox(phba, NULL, | |
8279 | MBX_NOWAIT); | |
8280 | } while (rc == MBX_NOT_FINISHED); | |
8281 | if (rc != MBX_SUCCESS) | |
8282 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
8283 | LOG_SLI, "0349 rc should be " | |
6a9c52cf | 8284 | "MBX_SUCCESS\n"); |
92d7f7b0 JS |
8285 | } |
8286 | ||
5b75da2f | 8287 | spin_lock_irqsave(&phba->hbalock, iflag); |
dea3101e | 8288 | phba->work_ha |= work_ha_copy; |
5b75da2f | 8289 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5e9d9b82 | 8290 | lpfc_worker_wake_up(phba); |
dea3101e | 8291 | } |
9399627f | 8292 | return IRQ_HANDLED; |
dea3101e | 8293 | |
3772a991 | 8294 | } /* lpfc_sli_sp_intr_handler */ |
9399627f JS |
8295 | |
8296 | /** | |
3772a991 | 8297 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
9399627f JS |
8298 | * @irq: Interrupt number. |
8299 | * @dev_id: The device context pointer. | |
8300 | * | |
8301 | * This function is directly called from the PCI layer as an interrupt | |
3772a991 JS |
8302 | * service routine when device with SLI-3 interface spec is enabled with |
8303 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
8304 | * ring event in the HBA. However, when the device is enabled with either | |
8305 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
8306 | * device-level interrupt handler. When the PCI slot is in error recovery | |
8307 | * or the HBA is undergoing initialization, the interrupt handler will not | |
8308 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
8309 | * the intrrupt context. This function is called without any lock held. | |
8310 | * It gets the hbalock to access and update SLI data structures. | |
9399627f JS |
8311 | * |
8312 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
8313 | * returns IRQ_NONE. | |
8314 | **/ | |
8315 | irqreturn_t | |
3772a991 | 8316 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
9399627f JS |
8317 | { |
8318 | struct lpfc_hba *phba; | |
8319 | uint32_t ha_copy; | |
8320 | unsigned long status; | |
5b75da2f | 8321 | unsigned long iflag; |
9399627f JS |
8322 | |
8323 | /* Get the driver's phba structure from the dev_id and | |
8324 | * assume the HBA is not interrupting. | |
8325 | */ | |
8326 | phba = (struct lpfc_hba *) dev_id; | |
8327 | ||
8328 | if (unlikely(!phba)) | |
8329 | return IRQ_NONE; | |
8330 | ||
8331 | /* | |
8332 | * Stuff needs to be attented to when this function is invoked as an | |
8333 | * individual interrupt handler in MSI-X multi-message interrupt mode | |
8334 | */ | |
8335 | if (phba->intr_type == MSIX) { | |
3772a991 JS |
8336 | /* Check device state for handling interrupt */ |
8337 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8338 | return IRQ_NONE; |
8339 | /* Need to read HA REG for FCP ring and other ring events */ | |
8340 | ha_copy = readl(phba->HAregaddr); | |
8341 | /* Clear up only attention source related to fast-path */ | |
5b75da2f | 8342 | spin_lock_irqsave(&phba->hbalock, iflag); |
a257bf90 JS |
8343 | /* |
8344 | * If there is deferred error attention, do not check for | |
8345 | * any interrupt. | |
8346 | */ | |
8347 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
3772a991 | 8348 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a257bf90 JS |
8349 | return IRQ_NONE; |
8350 | } | |
9399627f JS |
8351 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
8352 | phba->HAregaddr); | |
8353 | readl(phba->HAregaddr); /* flush */ | |
5b75da2f | 8354 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
9399627f JS |
8355 | } else |
8356 | ha_copy = phba->ha_copy; | |
dea3101e JB |
8357 | |
8358 | /* | |
9399627f | 8359 | * Process all events on FCP ring. Take the optimized path for FCP IO. |
dea3101e | 8360 | */ |
9399627f JS |
8361 | ha_copy &= ~(phba->work_ha_mask); |
8362 | ||
8363 | status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
dea3101e | 8364 | status >>= (4*LPFC_FCP_RING); |
858c9f6c | 8365 | if (status & HA_RXMASK) |
dea3101e JB |
8366 | lpfc_sli_handle_fast_ring_event(phba, |
8367 | &phba->sli.ring[LPFC_FCP_RING], | |
8368 | status); | |
a4bc3379 JS |
8369 | |
8370 | if (phba->cfg_multi_ring_support == 2) { | |
8371 | /* | |
9399627f JS |
8372 | * Process all events on extra ring. Take the optimized path |
8373 | * for extra ring IO. | |
a4bc3379 | 8374 | */ |
9399627f | 8375 | status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); |
a4bc3379 | 8376 | status >>= (4*LPFC_EXTRA_RING); |
858c9f6c | 8377 | if (status & HA_RXMASK) { |
a4bc3379 JS |
8378 | lpfc_sli_handle_fast_ring_event(phba, |
8379 | &phba->sli.ring[LPFC_EXTRA_RING], | |
8380 | status); | |
8381 | } | |
8382 | } | |
dea3101e | 8383 | return IRQ_HANDLED; |
3772a991 | 8384 | } /* lpfc_sli_fp_intr_handler */ |
9399627f JS |
8385 | |
8386 | /** | |
3772a991 | 8387 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
9399627f JS |
8388 | * @irq: Interrupt number. |
8389 | * @dev_id: The device context pointer. | |
8390 | * | |
3772a991 JS |
8391 | * This function is the HBA device-level interrupt handler to device with |
8392 | * SLI-3 interface spec, called from the PCI layer when either MSI or | |
8393 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which | |
8394 | * requires driver attention. This function invokes the slow-path interrupt | |
8395 | * attention handling function and fast-path interrupt attention handling | |
8396 | * function in turn to process the relevant HBA attention events. This | |
8397 | * function is called without any lock held. It gets the hbalock to access | |
8398 | * and update SLI data structures. | |
9399627f JS |
8399 | * |
8400 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
8401 | * returns IRQ_NONE. | |
8402 | **/ | |
8403 | irqreturn_t | |
3772a991 | 8404 | lpfc_sli_intr_handler(int irq, void *dev_id) |
9399627f JS |
8405 | { |
8406 | struct lpfc_hba *phba; | |
8407 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
8408 | unsigned long status1, status2; | |
a747c9ce | 8409 | uint32_t hc_copy; |
9399627f JS |
8410 | |
8411 | /* | |
8412 | * Get the driver's phba structure from the dev_id and | |
8413 | * assume the HBA is not interrupting. | |
8414 | */ | |
8415 | phba = (struct lpfc_hba *) dev_id; | |
8416 | ||
8417 | if (unlikely(!phba)) | |
8418 | return IRQ_NONE; | |
8419 | ||
3772a991 JS |
8420 | /* Check device state for handling interrupt */ |
8421 | if (lpfc_intr_state_check(phba)) | |
9399627f JS |
8422 | return IRQ_NONE; |
8423 | ||
8424 | spin_lock(&phba->hbalock); | |
8425 | phba->ha_copy = readl(phba->HAregaddr); | |
8426 | if (unlikely(!phba->ha_copy)) { | |
8427 | spin_unlock(&phba->hbalock); | |
8428 | return IRQ_NONE; | |
8429 | } else if (phba->ha_copy & HA_ERATT) { | |
8430 | if (phba->hba_flag & HBA_ERATT_HANDLED) | |
8431 | /* ERATT polling has handled ERATT */ | |
8432 | phba->ha_copy &= ~HA_ERATT; | |
8433 | else | |
8434 | /* Indicate interrupt handler handles ERATT */ | |
8435 | phba->hba_flag |= HBA_ERATT_HANDLED; | |
8436 | } | |
8437 | ||
a257bf90 JS |
8438 | /* |
8439 | * If there is deferred error attention, do not check for any interrupt. | |
8440 | */ | |
8441 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | |
8442 | spin_unlock_irq(&phba->hbalock); | |
8443 | return IRQ_NONE; | |
8444 | } | |
8445 | ||
9399627f | 8446 | /* Clear attention sources except link and error attentions */ |
a747c9ce JS |
8447 | hc_copy = readl(phba->HCregaddr); |
8448 | writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA | |
8449 | | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA), | |
8450 | phba->HCregaddr); | |
9399627f | 8451 | writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); |
a747c9ce | 8452 | writel(hc_copy, phba->HCregaddr); |
9399627f JS |
8453 | readl(phba->HAregaddr); /* flush */ |
8454 | spin_unlock(&phba->hbalock); | |
8455 | ||
8456 | /* | |
8457 | * Invokes slow-path host attention interrupt handling as appropriate. | |
8458 | */ | |
8459 | ||
8460 | /* status of events with mailbox and link attention */ | |
8461 | status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT); | |
8462 | ||
8463 | /* status of events with ELS ring */ | |
8464 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING))); | |
8465 | status2 >>= (4*LPFC_ELS_RING); | |
8466 | ||
8467 | if (status1 || (status2 & HA_RXMASK)) | |
3772a991 | 8468 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
9399627f JS |
8469 | else |
8470 | sp_irq_rc = IRQ_NONE; | |
8471 | ||
8472 | /* | |
8473 | * Invoke fast-path host attention interrupt handling as appropriate. | |
8474 | */ | |
8475 | ||
8476 | /* status of events with FCP ring */ | |
8477 | status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); | |
8478 | status1 >>= (4*LPFC_FCP_RING); | |
8479 | ||
8480 | /* status of events with extra ring */ | |
8481 | if (phba->cfg_multi_ring_support == 2) { | |
8482 | status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); | |
8483 | status2 >>= (4*LPFC_EXTRA_RING); | |
8484 | } else | |
8485 | status2 = 0; | |
8486 | ||
8487 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | |
3772a991 | 8488 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
9399627f JS |
8489 | else |
8490 | fp_irq_rc = IRQ_NONE; | |
dea3101e | 8491 | |
9399627f JS |
8492 | /* Return device-level interrupt handling status */ |
8493 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | |
3772a991 | 8494 | } /* lpfc_sli_intr_handler */ |
4f774513 JS |
8495 | |
8496 | /** | |
8497 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | |
8498 | * @phba: pointer to lpfc hba data structure. | |
8499 | * | |
8500 | * This routine is invoked by the worker thread to process all the pending | |
8501 | * SLI4 FCP abort XRI events. | |
8502 | **/ | |
8503 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | |
8504 | { | |
8505 | struct lpfc_cq_event *cq_event; | |
8506 | ||
8507 | /* First, declare the fcp xri abort event has been handled */ | |
8508 | spin_lock_irq(&phba->hbalock); | |
8509 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | |
8510 | spin_unlock_irq(&phba->hbalock); | |
8511 | /* Now, handle all the fcp xri abort events */ | |
8512 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | |
8513 | /* Get the first event from the head of the event queue */ | |
8514 | spin_lock_irq(&phba->hbalock); | |
8515 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
8516 | cq_event, struct lpfc_cq_event, list); | |
8517 | spin_unlock_irq(&phba->hbalock); | |
8518 | /* Notify aborted XRI for FCP work queue */ | |
8519 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
8520 | /* Free the event processed back to the free pool */ | |
8521 | lpfc_sli4_cq_event_release(phba, cq_event); | |
8522 | } | |
8523 | } | |
8524 | ||
8525 | /** | |
8526 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | |
8527 | * @phba: pointer to lpfc hba data structure. | |
8528 | * | |
8529 | * This routine is invoked by the worker thread to process all the pending | |
8530 | * SLI4 els abort xri events. | |
8531 | **/ | |
8532 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | |
8533 | { | |
8534 | struct lpfc_cq_event *cq_event; | |
8535 | ||
8536 | /* First, declare the els xri abort event has been handled */ | |
8537 | spin_lock_irq(&phba->hbalock); | |
8538 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | |
8539 | spin_unlock_irq(&phba->hbalock); | |
8540 | /* Now, handle all the els xri abort events */ | |
8541 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | |
8542 | /* Get the first event from the head of the event queue */ | |
8543 | spin_lock_irq(&phba->hbalock); | |
8544 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
8545 | cq_event, struct lpfc_cq_event, list); | |
8546 | spin_unlock_irq(&phba->hbalock); | |
8547 | /* Notify aborted XRI for ELS work queue */ | |
8548 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | |
8549 | /* Free the event processed back to the free pool */ | |
8550 | lpfc_sli4_cq_event_release(phba, cq_event); | |
8551 | } | |
8552 | } | |
8553 | ||
341af102 JS |
8554 | /** |
8555 | * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn | |
8556 | * @phba: pointer to lpfc hba data structure | |
8557 | * @pIocbIn: pointer to the rspiocbq | |
8558 | * @pIocbOut: pointer to the cmdiocbq | |
8559 | * @wcqe: pointer to the complete wcqe | |
8560 | * | |
8561 | * This routine transfers the fields of a command iocbq to a response iocbq | |
8562 | * by copying all the IOCB fields from command iocbq and transferring the | |
8563 | * completion status information from the complete wcqe. | |
8564 | **/ | |
4f774513 | 8565 | static void |
341af102 JS |
8566 | lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba, |
8567 | struct lpfc_iocbq *pIocbIn, | |
4f774513 JS |
8568 | struct lpfc_iocbq *pIocbOut, |
8569 | struct lpfc_wcqe_complete *wcqe) | |
8570 | { | |
341af102 | 8571 | unsigned long iflags; |
4f774513 JS |
8572 | size_t offset = offsetof(struct lpfc_iocbq, iocb); |
8573 | ||
8574 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | |
8575 | sizeof(struct lpfc_iocbq) - offset); | |
4f774513 JS |
8576 | /* Map WCQE parameters into irspiocb parameters */ |
8577 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | |
8578 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | |
8579 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | |
8580 | pIocbIn->iocb.un.fcpi.fcpi_parm = | |
8581 | pIocbOut->iocb.un.fcpi.fcpi_parm - | |
8582 | wcqe->total_data_placed; | |
8583 | else | |
8584 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | |
695a814e | 8585 | else { |
4f774513 | 8586 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; |
695a814e JS |
8587 | pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed; |
8588 | } | |
341af102 JS |
8589 | |
8590 | /* Pick up HBA exchange busy condition */ | |
8591 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) { | |
8592 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8593 | pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY; | |
8594 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8595 | } | |
4f774513 JS |
8596 | } |
8597 | ||
45ed1190 JS |
8598 | /** |
8599 | * lpfc_sli4_els_wcqe_to_rspiocbq - Get response iocbq from els wcqe | |
8600 | * @phba: Pointer to HBA context object. | |
8601 | * @wcqe: Pointer to work-queue completion queue entry. | |
8602 | * | |
8603 | * This routine handles an ELS work-queue completion event and construct | |
8604 | * a pseudo response ELS IODBQ from the SLI4 ELS WCQE for the common | |
8605 | * discovery engine to handle. | |
8606 | * | |
8607 | * Return: Pointer to the receive IOCBQ, NULL otherwise. | |
8608 | **/ | |
8609 | static struct lpfc_iocbq * | |
8610 | lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba, | |
8611 | struct lpfc_iocbq *irspiocbq) | |
8612 | { | |
8613 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
8614 | struct lpfc_iocbq *cmdiocbq; | |
8615 | struct lpfc_wcqe_complete *wcqe; | |
8616 | unsigned long iflags; | |
8617 | ||
8618 | wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl; | |
8619 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8620 | pring->stats.iocb_event++; | |
8621 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | |
8622 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
8623 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
8624 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8625 | ||
8626 | if (unlikely(!cmdiocbq)) { | |
8627 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8628 | "0386 ELS complete with no corresponding " | |
8629 | "cmdiocb: iotag (%d)\n", | |
8630 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
8631 | lpfc_sli_release_iocbq(phba, irspiocbq); | |
8632 | return NULL; | |
8633 | } | |
8634 | ||
8635 | /* Fake the irspiocbq and copy necessary response information */ | |
341af102 | 8636 | lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe); |
45ed1190 JS |
8637 | |
8638 | return irspiocbq; | |
8639 | } | |
8640 | ||
04c68496 JS |
8641 | /** |
8642 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | |
8643 | * @phba: Pointer to HBA context object. | |
8644 | * @cqe: Pointer to mailbox completion queue entry. | |
8645 | * | |
8646 | * This routine process a mailbox completion queue entry with asynchrous | |
8647 | * event. | |
8648 | * | |
8649 | * Return: true if work posted to worker thread, otherwise false. | |
8650 | **/ | |
8651 | static bool | |
8652 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
8653 | { | |
8654 | struct lpfc_cq_event *cq_event; | |
8655 | unsigned long iflags; | |
8656 | ||
8657 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
8658 | "0392 Async Event: word0:x%x, word1:x%x, " | |
8659 | "word2:x%x, word3:x%x\n", mcqe->word0, | |
8660 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | |
8661 | ||
8662 | /* Allocate a new internal CQ_EVENT entry */ | |
8663 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
8664 | if (!cq_event) { | |
8665 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8666 | "0394 Failed to allocate CQ_EVENT entry\n"); | |
8667 | return false; | |
8668 | } | |
8669 | ||
8670 | /* Move the CQE into an asynchronous event entry */ | |
8671 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | |
8672 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8673 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | |
8674 | /* Set the async event flag */ | |
8675 | phba->hba_flag |= ASYNC_EVENT; | |
8676 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8677 | ||
8678 | return true; | |
8679 | } | |
8680 | ||
8681 | /** | |
8682 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | |
8683 | * @phba: Pointer to HBA context object. | |
8684 | * @cqe: Pointer to mailbox completion queue entry. | |
8685 | * | |
8686 | * This routine process a mailbox completion queue entry with mailbox | |
8687 | * completion event. | |
8688 | * | |
8689 | * Return: true if work posted to worker thread, otherwise false. | |
8690 | **/ | |
8691 | static bool | |
8692 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | |
8693 | { | |
8694 | uint32_t mcqe_status; | |
8695 | MAILBOX_t *mbox, *pmbox; | |
8696 | struct lpfc_mqe *mqe; | |
8697 | struct lpfc_vport *vport; | |
8698 | struct lpfc_nodelist *ndlp; | |
8699 | struct lpfc_dmabuf *mp; | |
8700 | unsigned long iflags; | |
8701 | LPFC_MBOXQ_t *pmb; | |
8702 | bool workposted = false; | |
8703 | int rc; | |
8704 | ||
8705 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | |
8706 | if (!bf_get(lpfc_trailer_completed, mcqe)) | |
8707 | goto out_no_mqe_complete; | |
8708 | ||
8709 | /* Get the reference to the active mbox command */ | |
8710 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8711 | pmb = phba->sli.mbox_active; | |
8712 | if (unlikely(!pmb)) { | |
8713 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
8714 | "1832 No pending MBOX command to handle\n"); | |
8715 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8716 | goto out_no_mqe_complete; | |
8717 | } | |
8718 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8719 | mqe = &pmb->u.mqe; | |
8720 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | |
8721 | mbox = phba->mbox; | |
8722 | vport = pmb->vport; | |
8723 | ||
8724 | /* Reset heartbeat timer */ | |
8725 | phba->last_completion_time = jiffies; | |
8726 | del_timer(&phba->sli.mbox_tmo); | |
8727 | ||
8728 | /* Move mbox data to caller's mailbox region, do endian swapping */ | |
8729 | if (pmb->mbox_cmpl && mbox) | |
8730 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | |
8731 | /* Set the mailbox status with SLI4 range 0x4000 */ | |
8732 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | |
8733 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) | |
8734 | bf_set(lpfc_mqe_status, mqe, | |
8735 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | |
8736 | ||
8737 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | |
8738 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | |
8739 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | |
8740 | "MBOX dflt rpi: status:x%x rpi:x%x", | |
8741 | mcqe_status, | |
8742 | pmbox->un.varWords[0], 0); | |
8743 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | |
8744 | mp = (struct lpfc_dmabuf *)(pmb->context1); | |
8745 | ndlp = (struct lpfc_nodelist *)pmb->context2; | |
8746 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | |
8747 | * RID of the PPI using the same mbox buffer. | |
8748 | */ | |
8749 | lpfc_unreg_login(phba, vport->vpi, | |
8750 | pmbox->un.varWords[0], pmb); | |
8751 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | |
8752 | pmb->context1 = mp; | |
8753 | pmb->context2 = ndlp; | |
8754 | pmb->vport = vport; | |
8755 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
8756 | if (rc != MBX_BUSY) | |
8757 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | |
8758 | LOG_SLI, "0385 rc should " | |
8759 | "have been MBX_BUSY\n"); | |
8760 | if (rc != MBX_NOT_FINISHED) | |
8761 | goto send_current_mbox; | |
8762 | } | |
8763 | } | |
8764 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
8765 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | |
8766 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
8767 | ||
8768 | /* There is mailbox completion work to do */ | |
8769 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8770 | __lpfc_mbox_cmpl_put(phba, pmb); | |
8771 | phba->work_ha |= HA_MBATT; | |
8772 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8773 | workposted = true; | |
8774 | ||
8775 | send_current_mbox: | |
8776 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8777 | /* Release the mailbox command posting token */ | |
8778 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8779 | /* Setting active mailbox pointer need to be in sync to flag clear */ | |
8780 | phba->sli.mbox_active = NULL; | |
8781 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8782 | /* Wake up worker thread to post the next pending mailbox command */ | |
8783 | lpfc_worker_wake_up(phba); | |
8784 | out_no_mqe_complete: | |
8785 | if (bf_get(lpfc_trailer_consumed, mcqe)) | |
8786 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | |
8787 | return workposted; | |
8788 | } | |
8789 | ||
8790 | /** | |
8791 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | |
8792 | * @phba: Pointer to HBA context object. | |
8793 | * @cqe: Pointer to mailbox completion queue entry. | |
8794 | * | |
8795 | * This routine process a mailbox completion queue entry, it invokes the | |
8796 | * proper mailbox complete handling or asynchrous event handling routine | |
8797 | * according to the MCQE's async bit. | |
8798 | * | |
8799 | * Return: true if work posted to worker thread, otherwise false. | |
8800 | **/ | |
8801 | static bool | |
8802 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | |
8803 | { | |
8804 | struct lpfc_mcqe mcqe; | |
8805 | bool workposted; | |
8806 | ||
8807 | /* Copy the mailbox MCQE and convert endian order as needed */ | |
8808 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | |
8809 | ||
8810 | /* Invoke the proper event handling routine */ | |
8811 | if (!bf_get(lpfc_trailer_async, &mcqe)) | |
8812 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | |
8813 | else | |
8814 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | |
8815 | return workposted; | |
8816 | } | |
8817 | ||
4f774513 JS |
8818 | /** |
8819 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | |
8820 | * @phba: Pointer to HBA context object. | |
8821 | * @wcqe: Pointer to work-queue completion queue entry. | |
8822 | * | |
8823 | * This routine handles an ELS work-queue completion event. | |
8824 | * | |
8825 | * Return: true if work posted to worker thread, otherwise false. | |
8826 | **/ | |
8827 | static bool | |
8828 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | |
8829 | struct lpfc_wcqe_complete *wcqe) | |
8830 | { | |
4f774513 JS |
8831 | struct lpfc_iocbq *irspiocbq; |
8832 | unsigned long iflags; | |
2a9bf3d0 | 8833 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; |
4f774513 | 8834 | |
45ed1190 | 8835 | /* Get an irspiocbq for later ELS response processing use */ |
4f774513 JS |
8836 | irspiocbq = lpfc_sli_get_iocbq(phba); |
8837 | if (!irspiocbq) { | |
8838 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2a9bf3d0 JS |
8839 | "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d " |
8840 | "fcp_txcmplq_cnt=%d, els_txcmplq_cnt=%d\n", | |
8841 | pring->txq_cnt, phba->iocb_cnt, | |
8842 | phba->sli.ring[LPFC_FCP_RING].txcmplq_cnt, | |
8843 | phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt); | |
45ed1190 | 8844 | return false; |
4f774513 | 8845 | } |
4f774513 | 8846 | |
45ed1190 JS |
8847 | /* Save off the slow-path queue event for work thread to process */ |
8848 | memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe)); | |
4f774513 | 8849 | spin_lock_irqsave(&phba->hbalock, iflags); |
4d9ab994 | 8850 | list_add_tail(&irspiocbq->cq_event.list, |
45ed1190 JS |
8851 | &phba->sli4_hba.sp_queue_event); |
8852 | phba->hba_flag |= HBA_SP_QUEUE_EVT; | |
4f774513 | 8853 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
4f774513 | 8854 | |
45ed1190 | 8855 | return true; |
4f774513 JS |
8856 | } |
8857 | ||
8858 | /** | |
8859 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | |
8860 | * @phba: Pointer to HBA context object. | |
8861 | * @wcqe: Pointer to work-queue completion queue entry. | |
8862 | * | |
8863 | * This routine handles slow-path WQ entry comsumed event by invoking the | |
8864 | * proper WQ release routine to the slow-path WQ. | |
8865 | **/ | |
8866 | static void | |
8867 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | |
8868 | struct lpfc_wcqe_release *wcqe) | |
8869 | { | |
8870 | /* Check for the slow-path ELS work queue */ | |
8871 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | |
8872 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | |
8873 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
8874 | else | |
8875 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
8876 | "2579 Slow-path wqe consume event carries " | |
8877 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | |
8878 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | |
8879 | phba->sli4_hba.els_wq->queue_id); | |
8880 | } | |
8881 | ||
8882 | /** | |
8883 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | |
8884 | * @phba: Pointer to HBA context object. | |
8885 | * @cq: Pointer to a WQ completion queue. | |
8886 | * @wcqe: Pointer to work-queue completion queue entry. | |
8887 | * | |
8888 | * This routine handles an XRI abort event. | |
8889 | * | |
8890 | * Return: true if work posted to worker thread, otherwise false. | |
8891 | **/ | |
8892 | static bool | |
8893 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | |
8894 | struct lpfc_queue *cq, | |
8895 | struct sli4_wcqe_xri_aborted *wcqe) | |
8896 | { | |
8897 | bool workposted = false; | |
8898 | struct lpfc_cq_event *cq_event; | |
8899 | unsigned long iflags; | |
8900 | ||
8901 | /* Allocate a new internal CQ_EVENT entry */ | |
8902 | cq_event = lpfc_sli4_cq_event_alloc(phba); | |
8903 | if (!cq_event) { | |
8904 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8905 | "0602 Failed to allocate CQ_EVENT entry\n"); | |
8906 | return false; | |
8907 | } | |
8908 | ||
8909 | /* Move the CQE into the proper xri abort event list */ | |
8910 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | |
8911 | switch (cq->subtype) { | |
8912 | case LPFC_FCP: | |
8913 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8914 | list_add_tail(&cq_event->list, | |
8915 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
8916 | /* Set the fcp xri abort event flag */ | |
8917 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | |
8918 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8919 | workposted = true; | |
8920 | break; | |
8921 | case LPFC_ELS: | |
8922 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8923 | list_add_tail(&cq_event->list, | |
8924 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
8925 | /* Set the els xri abort event flag */ | |
8926 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | |
8927 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8928 | workposted = true; | |
8929 | break; | |
8930 | default: | |
8931 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8932 | "0603 Invalid work queue CQE subtype (x%x)\n", | |
8933 | cq->subtype); | |
8934 | workposted = false; | |
8935 | break; | |
8936 | } | |
8937 | return workposted; | |
8938 | } | |
8939 | ||
4f774513 JS |
8940 | /** |
8941 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | |
8942 | * @phba: Pointer to HBA context object. | |
8943 | * @rcqe: Pointer to receive-queue completion queue entry. | |
8944 | * | |
8945 | * This routine process a receive-queue completion queue entry. | |
8946 | * | |
8947 | * Return: true if work posted to worker thread, otherwise false. | |
8948 | **/ | |
8949 | static bool | |
4d9ab994 | 8950 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe) |
4f774513 | 8951 | { |
4f774513 JS |
8952 | bool workposted = false; |
8953 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | |
8954 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | |
8955 | struct hbq_dmabuf *dma_buf; | |
8956 | uint32_t status; | |
8957 | unsigned long iflags; | |
8958 | ||
4d9ab994 | 8959 | if (bf_get(lpfc_rcqe_rq_id, rcqe) != hrq->queue_id) |
4f774513 JS |
8960 | goto out; |
8961 | ||
4d9ab994 | 8962 | status = bf_get(lpfc_rcqe_status, rcqe); |
4f774513 JS |
8963 | switch (status) { |
8964 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | |
8965 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
8966 | "2537 Receive Frame Truncated!!\n"); | |
8967 | case FC_STATUS_RQ_SUCCESS: | |
5ffc266e | 8968 | lpfc_sli4_rq_release(hrq, drq); |
4f774513 JS |
8969 | spin_lock_irqsave(&phba->hbalock, iflags); |
8970 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | |
8971 | if (!dma_buf) { | |
8972 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8973 | goto out; | |
8974 | } | |
4d9ab994 | 8975 | memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe)); |
4f774513 | 8976 | /* save off the frame for the word thread to process */ |
4d9ab994 | 8977 | list_add_tail(&dma_buf->cq_event.list, |
45ed1190 | 8978 | &phba->sli4_hba.sp_queue_event); |
4f774513 | 8979 | /* Frame received */ |
45ed1190 | 8980 | phba->hba_flag |= HBA_SP_QUEUE_EVT; |
4f774513 JS |
8981 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
8982 | workposted = true; | |
8983 | break; | |
8984 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | |
8985 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | |
8986 | /* Post more buffers if possible */ | |
8987 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8988 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | |
8989 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8990 | workposted = true; | |
8991 | break; | |
8992 | } | |
8993 | out: | |
8994 | return workposted; | |
4f774513 JS |
8995 | } |
8996 | ||
4d9ab994 JS |
8997 | /** |
8998 | * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry | |
8999 | * @phba: Pointer to HBA context object. | |
9000 | * @cq: Pointer to the completion queue. | |
9001 | * @wcqe: Pointer to a completion queue entry. | |
9002 | * | |
9003 | * This routine process a slow-path work-queue or recieve queue completion queue | |
9004 | * entry. | |
9005 | * | |
9006 | * Return: true if work posted to worker thread, otherwise false. | |
9007 | **/ | |
9008 | static bool | |
9009 | lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9010 | struct lpfc_cqe *cqe) | |
9011 | { | |
45ed1190 | 9012 | struct lpfc_cqe cqevt; |
4d9ab994 JS |
9013 | bool workposted = false; |
9014 | ||
9015 | /* Copy the work queue CQE and convert endian order if needed */ | |
45ed1190 | 9016 | lpfc_sli_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe)); |
4d9ab994 JS |
9017 | |
9018 | /* Check and process for different type of WCQE and dispatch */ | |
45ed1190 | 9019 | switch (bf_get(lpfc_cqe_code, &cqevt)) { |
4d9ab994 | 9020 | case CQE_CODE_COMPL_WQE: |
45ed1190 | 9021 | /* Process the WQ/RQ complete event */ |
4d9ab994 | 9022 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, |
45ed1190 | 9023 | (struct lpfc_wcqe_complete *)&cqevt); |
4d9ab994 JS |
9024 | break; |
9025 | case CQE_CODE_RELEASE_WQE: | |
9026 | /* Process the WQ release event */ | |
9027 | lpfc_sli4_sp_handle_rel_wcqe(phba, | |
45ed1190 | 9028 | (struct lpfc_wcqe_release *)&cqevt); |
4d9ab994 JS |
9029 | break; |
9030 | case CQE_CODE_XRI_ABORTED: | |
9031 | /* Process the WQ XRI abort event */ | |
9032 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, | |
45ed1190 | 9033 | (struct sli4_wcqe_xri_aborted *)&cqevt); |
4d9ab994 JS |
9034 | break; |
9035 | case CQE_CODE_RECEIVE: | |
9036 | /* Process the RQ event */ | |
9037 | workposted = lpfc_sli4_sp_handle_rcqe(phba, | |
45ed1190 | 9038 | (struct lpfc_rcqe *)&cqevt); |
4d9ab994 JS |
9039 | break; |
9040 | default: | |
9041 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9042 | "0388 Not a valid WCQE code: x%x\n", | |
45ed1190 | 9043 | bf_get(lpfc_cqe_code, &cqevt)); |
4d9ab994 JS |
9044 | break; |
9045 | } | |
9046 | return workposted; | |
9047 | } | |
9048 | ||
4f774513 JS |
9049 | /** |
9050 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | |
9051 | * @phba: Pointer to HBA context object. | |
9052 | * @eqe: Pointer to fast-path event queue entry. | |
9053 | * | |
9054 | * This routine process a event queue entry from the slow-path event queue. | |
9055 | * It will check the MajorCode and MinorCode to determine this is for a | |
9056 | * completion event on a completion queue, if not, an error shall be logged | |
9057 | * and just return. Otherwise, it will get to the corresponding completion | |
9058 | * queue and process all the entries on that completion queue, rearm the | |
9059 | * completion queue, and then return. | |
9060 | * | |
9061 | **/ | |
9062 | static void | |
9063 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | |
9064 | { | |
9065 | struct lpfc_queue *cq = NULL, *childq, *speq; | |
9066 | struct lpfc_cqe *cqe; | |
9067 | bool workposted = false; | |
9068 | int ecount = 0; | |
9069 | uint16_t cqid; | |
9070 | ||
cb5172ea | 9071 | if (bf_get_le32(lpfc_eqe_major_code, eqe) != 0) { |
4f774513 JS |
9072 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9073 | "0359 Not a valid slow-path completion " | |
9074 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9075 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9076 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9077 | return; |
9078 | } | |
9079 | ||
9080 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9081 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9082 | |
9083 | /* Search for completion queue pointer matching this cqid */ | |
9084 | speq = phba->sli4_hba.sp_eq; | |
9085 | list_for_each_entry(childq, &speq->child_list, list) { | |
9086 | if (childq->queue_id == cqid) { | |
9087 | cq = childq; | |
9088 | break; | |
9089 | } | |
9090 | } | |
9091 | if (unlikely(!cq)) { | |
9092 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9093 | "0365 Slow-path CQ identifier (%d) does " | |
9094 | "not exist\n", cqid); | |
9095 | return; | |
9096 | } | |
9097 | ||
9098 | /* Process all the entries to the CQ */ | |
9099 | switch (cq->type) { | |
9100 | case LPFC_MCQ: | |
9101 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9102 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | |
9103 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9104 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9105 | } | |
9106 | break; | |
9107 | case LPFC_WCQ: | |
9108 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
4d9ab994 | 9109 | workposted |= lpfc_sli4_sp_handle_cqe(phba, cq, cqe); |
4f774513 JS |
9110 | if (!(++ecount % LPFC_GET_QE_REL_INT)) |
9111 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9112 | } | |
9113 | break; | |
9114 | default: | |
9115 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9116 | "0370 Invalid completion queue type (%d)\n", | |
9117 | cq->type); | |
9118 | return; | |
9119 | } | |
9120 | ||
9121 | /* Catch the no cq entry condition, log an error */ | |
9122 | if (unlikely(ecount == 0)) | |
9123 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9124 | "0371 No entry from the CQ: identifier " | |
9125 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | |
9126 | ||
9127 | /* In any case, flash and re-arm the RCQ */ | |
9128 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9129 | ||
9130 | /* wake up worker thread if there are works to be done */ | |
9131 | if (workposted) | |
9132 | lpfc_worker_wake_up(phba); | |
9133 | } | |
9134 | ||
9135 | /** | |
9136 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | |
9137 | * @eqe: Pointer to fast-path completion queue entry. | |
9138 | * | |
9139 | * This routine process a fast-path work queue completion entry from fast-path | |
9140 | * event queue for FCP command response completion. | |
9141 | **/ | |
9142 | static void | |
9143 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | |
9144 | struct lpfc_wcqe_complete *wcqe) | |
9145 | { | |
9146 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | |
9147 | struct lpfc_iocbq *cmdiocbq; | |
9148 | struct lpfc_iocbq irspiocbq; | |
9149 | unsigned long iflags; | |
9150 | ||
9151 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9152 | pring->stats.iocb_event++; | |
9153 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9154 | ||
9155 | /* Check for response status */ | |
9156 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | |
9157 | /* If resource errors reported from HBA, reduce queue | |
9158 | * depth of the SCSI device. | |
9159 | */ | |
9160 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | |
9161 | IOSTAT_LOCAL_REJECT) && | |
9162 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | |
9163 | phba->lpfc_rampdown_queue_depth(phba); | |
9164 | } | |
9165 | /* Log the error status */ | |
9166 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9167 | "0373 FCP complete error: status=x%x, " | |
9168 | "hw_status=x%x, total_data_specified=%d, " | |
9169 | "parameter=x%x, word3=x%x\n", | |
9170 | bf_get(lpfc_wcqe_c_status, wcqe), | |
9171 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | |
9172 | wcqe->total_data_placed, wcqe->parameter, | |
9173 | wcqe->word3); | |
9174 | } | |
9175 | ||
9176 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | |
9177 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9178 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | |
9179 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9180 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9181 | if (unlikely(!cmdiocbq)) { | |
9182 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9183 | "0374 FCP complete with no corresponding " | |
9184 | "cmdiocb: iotag (%d)\n", | |
9185 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9186 | return; | |
9187 | } | |
9188 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | |
9189 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9190 | "0375 FCP cmdiocb not callback function " | |
9191 | "iotag: (%d)\n", | |
9192 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | |
9193 | return; | |
9194 | } | |
9195 | ||
9196 | /* Fake the irspiocb and copy necessary response information */ | |
341af102 | 9197 | lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe); |
4f774513 | 9198 | |
0f65ff68 JS |
9199 | if (cmdiocbq->iocb_flag & LPFC_DRIVER_ABORTED) { |
9200 | spin_lock_irqsave(&phba->hbalock, iflags); | |
9201 | cmdiocbq->iocb_flag &= ~LPFC_DRIVER_ABORTED; | |
9202 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
9203 | } | |
9204 | ||
4f774513 JS |
9205 | /* Pass the cmd_iocb and the rsp state to the upper layer */ |
9206 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | |
9207 | } | |
9208 | ||
9209 | /** | |
9210 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | |
9211 | * @phba: Pointer to HBA context object. | |
9212 | * @cq: Pointer to completion queue. | |
9213 | * @wcqe: Pointer to work-queue completion queue entry. | |
9214 | * | |
9215 | * This routine handles an fast-path WQ entry comsumed event by invoking the | |
9216 | * proper WQ release routine to the slow-path WQ. | |
9217 | **/ | |
9218 | static void | |
9219 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9220 | struct lpfc_wcqe_release *wcqe) | |
9221 | { | |
9222 | struct lpfc_queue *childwq; | |
9223 | bool wqid_matched = false; | |
9224 | uint16_t fcp_wqid; | |
9225 | ||
9226 | /* Check for fast-path FCP work queue release */ | |
9227 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | |
9228 | list_for_each_entry(childwq, &cq->child_list, list) { | |
9229 | if (childwq->queue_id == fcp_wqid) { | |
9230 | lpfc_sli4_wq_release(childwq, | |
9231 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | |
9232 | wqid_matched = true; | |
9233 | break; | |
9234 | } | |
9235 | } | |
9236 | /* Report warning log message if no match found */ | |
9237 | if (wqid_matched != true) | |
9238 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9239 | "2580 Fast-path wqe consume event carries " | |
9240 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | |
9241 | } | |
9242 | ||
9243 | /** | |
9244 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | |
9245 | * @cq: Pointer to the completion queue. | |
9246 | * @eqe: Pointer to fast-path completion queue entry. | |
9247 | * | |
9248 | * This routine process a fast-path work queue completion entry from fast-path | |
9249 | * event queue for FCP command response completion. | |
9250 | **/ | |
9251 | static int | |
9252 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9253 | struct lpfc_cqe *cqe) | |
9254 | { | |
9255 | struct lpfc_wcqe_release wcqe; | |
9256 | bool workposted = false; | |
98fc5dd9 | 9257 | unsigned long iflag; |
4f774513 JS |
9258 | |
9259 | /* Copy the work queue CQE and convert endian order if needed */ | |
9260 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | |
9261 | ||
9262 | /* Check and process for different type of WCQE and dispatch */ | |
9263 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | |
9264 | case CQE_CODE_COMPL_WQE: | |
9265 | /* Process the WQ complete event */ | |
98fc5dd9 JS |
9266 | spin_lock_irqsave(&phba->hbalock, iflag); |
9267 | phba->last_completion_time = jiffies; | |
9268 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
4f774513 JS |
9269 | lpfc_sli4_fp_handle_fcp_wcqe(phba, |
9270 | (struct lpfc_wcqe_complete *)&wcqe); | |
9271 | break; | |
9272 | case CQE_CODE_RELEASE_WQE: | |
9273 | /* Process the WQ release event */ | |
9274 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | |
9275 | (struct lpfc_wcqe_release *)&wcqe); | |
9276 | break; | |
9277 | case CQE_CODE_XRI_ABORTED: | |
9278 | /* Process the WQ XRI abort event */ | |
9279 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, | |
9280 | (struct sli4_wcqe_xri_aborted *)&wcqe); | |
9281 | break; | |
9282 | default: | |
9283 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9284 | "0144 Not a valid WCQE code: x%x\n", | |
9285 | bf_get(lpfc_wcqe_c_code, &wcqe)); | |
9286 | break; | |
9287 | } | |
9288 | return workposted; | |
9289 | } | |
9290 | ||
9291 | /** | |
9292 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | |
9293 | * @phba: Pointer to HBA context object. | |
9294 | * @eqe: Pointer to fast-path event queue entry. | |
9295 | * | |
9296 | * This routine process a event queue entry from the fast-path event queue. | |
9297 | * It will check the MajorCode and MinorCode to determine this is for a | |
9298 | * completion event on a completion queue, if not, an error shall be logged | |
9299 | * and just return. Otherwise, it will get to the corresponding completion | |
9300 | * queue and process all the entries on the completion queue, rearm the | |
9301 | * completion queue, and then return. | |
9302 | **/ | |
9303 | static void | |
9304 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | |
9305 | uint32_t fcp_cqidx) | |
9306 | { | |
9307 | struct lpfc_queue *cq; | |
9308 | struct lpfc_cqe *cqe; | |
9309 | bool workposted = false; | |
9310 | uint16_t cqid; | |
9311 | int ecount = 0; | |
9312 | ||
cb5172ea | 9313 | if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) { |
4f774513 JS |
9314 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
9315 | "0366 Not a valid fast-path completion " | |
9316 | "event: majorcode=x%x, minorcode=x%x\n", | |
cb5172ea JS |
9317 | bf_get_le32(lpfc_eqe_major_code, eqe), |
9318 | bf_get_le32(lpfc_eqe_minor_code, eqe)); | |
4f774513 JS |
9319 | return; |
9320 | } | |
9321 | ||
9322 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | |
9323 | if (unlikely(!cq)) { | |
9324 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9325 | "0367 Fast-path completion queue does not " | |
9326 | "exist\n"); | |
9327 | return; | |
9328 | } | |
9329 | ||
9330 | /* Get the reference to the corresponding CQ */ | |
cb5172ea | 9331 | cqid = bf_get_le32(lpfc_eqe_resource_id, eqe); |
4f774513 JS |
9332 | if (unlikely(cqid != cq->queue_id)) { |
9333 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9334 | "0368 Miss-matched fast-path completion " | |
9335 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | |
9336 | cqid, cq->queue_id); | |
9337 | return; | |
9338 | } | |
9339 | ||
9340 | /* Process all the entries to the CQ */ | |
9341 | while ((cqe = lpfc_sli4_cq_get(cq))) { | |
9342 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | |
9343 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9344 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | |
9345 | } | |
9346 | ||
9347 | /* Catch the no cq entry condition */ | |
9348 | if (unlikely(ecount == 0)) | |
9349 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9350 | "0369 No entry from fast-path completion " | |
9351 | "queue fcpcqid=%d\n", cq->queue_id); | |
9352 | ||
9353 | /* In any case, flash and re-arm the CQ */ | |
9354 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | |
9355 | ||
9356 | /* wake up worker thread if there are works to be done */ | |
9357 | if (workposted) | |
9358 | lpfc_worker_wake_up(phba); | |
9359 | } | |
9360 | ||
9361 | static void | |
9362 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
9363 | { | |
9364 | struct lpfc_eqe *eqe; | |
9365 | ||
9366 | /* walk all the EQ entries and drop on the floor */ | |
9367 | while ((eqe = lpfc_sli4_eq_get(eq))) | |
9368 | ; | |
9369 | ||
9370 | /* Clear and re-arm the EQ */ | |
9371 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | |
9372 | } | |
9373 | ||
9374 | /** | |
9375 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | |
9376 | * @irq: Interrupt number. | |
9377 | * @dev_id: The device context pointer. | |
9378 | * | |
9379 | * This function is directly called from the PCI layer as an interrupt | |
9380 | * service routine when device with SLI-4 interface spec is enabled with | |
9381 | * MSI-X multi-message interrupt mode and there are slow-path events in | |
9382 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | |
9383 | * interrupt mode, this function is called as part of the device-level | |
9384 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | |
9385 | * undergoing initialization, the interrupt handler will not process the | |
9386 | * interrupt. The link attention and ELS ring attention events are handled | |
9387 | * by the worker thread. The interrupt handler signals the worker thread | |
9388 | * and returns for these events. This function is called without any lock | |
9389 | * held. It gets the hbalock to access and update SLI data structures. | |
9390 | * | |
9391 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
9392 | * returns IRQ_NONE. | |
9393 | **/ | |
9394 | irqreturn_t | |
9395 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | |
9396 | { | |
9397 | struct lpfc_hba *phba; | |
9398 | struct lpfc_queue *speq; | |
9399 | struct lpfc_eqe *eqe; | |
9400 | unsigned long iflag; | |
9401 | int ecount = 0; | |
9402 | ||
9403 | /* | |
9404 | * Get the driver's phba structure from the dev_id | |
9405 | */ | |
9406 | phba = (struct lpfc_hba *)dev_id; | |
9407 | ||
9408 | if (unlikely(!phba)) | |
9409 | return IRQ_NONE; | |
9410 | ||
9411 | /* Get to the EQ struct associated with this vector */ | |
9412 | speq = phba->sli4_hba.sp_eq; | |
9413 | ||
9414 | /* Check device state for handling interrupt */ | |
9415 | if (unlikely(lpfc_intr_state_check(phba))) { | |
9416 | /* Check again for link_state with lock held */ | |
9417 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9418 | if (phba->link_state < LPFC_LINK_DOWN) | |
9419 | /* Flush, clear interrupt, and rearm the EQ */ | |
9420 | lpfc_sli4_eq_flush(phba, speq); | |
9421 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9422 | return IRQ_NONE; | |
9423 | } | |
9424 | ||
9425 | /* | |
9426 | * Process all the event on FCP slow-path EQ | |
9427 | */ | |
9428 | while ((eqe = lpfc_sli4_eq_get(speq))) { | |
9429 | lpfc_sli4_sp_handle_eqe(phba, eqe); | |
9430 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9431 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); | |
9432 | } | |
9433 | ||
9434 | /* Always clear and re-arm the slow-path EQ */ | |
9435 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | |
9436 | ||
9437 | /* Catch the no cq entry condition */ | |
9438 | if (unlikely(ecount == 0)) { | |
9439 | if (phba->intr_type == MSIX) | |
9440 | /* MSI-X treated interrupt served as no EQ share INT */ | |
9441 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9442 | "0357 MSI-X interrupt with no EQE\n"); | |
9443 | else | |
9444 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
9445 | return IRQ_NONE; | |
9446 | } | |
9447 | ||
9448 | return IRQ_HANDLED; | |
9449 | } /* lpfc_sli4_sp_intr_handler */ | |
9450 | ||
9451 | /** | |
9452 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | |
9453 | * @irq: Interrupt number. | |
9454 | * @dev_id: The device context pointer. | |
9455 | * | |
9456 | * This function is directly called from the PCI layer as an interrupt | |
9457 | * service routine when device with SLI-4 interface spec is enabled with | |
9458 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | |
9459 | * ring event in the HBA. However, when the device is enabled with either | |
9460 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | |
9461 | * device-level interrupt handler. When the PCI slot is in error recovery | |
9462 | * or the HBA is undergoing initialization, the interrupt handler will not | |
9463 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | |
9464 | * the intrrupt context. This function is called without any lock held. | |
9465 | * It gets the hbalock to access and update SLI data structures. Note that, | |
9466 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | |
9467 | * equal to that of FCP CQ index. | |
9468 | * | |
9469 | * This function returns IRQ_HANDLED when interrupt is handled else it | |
9470 | * returns IRQ_NONE. | |
9471 | **/ | |
9472 | irqreturn_t | |
9473 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | |
9474 | { | |
9475 | struct lpfc_hba *phba; | |
9476 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | |
9477 | struct lpfc_queue *fpeq; | |
9478 | struct lpfc_eqe *eqe; | |
9479 | unsigned long iflag; | |
9480 | int ecount = 0; | |
9481 | uint32_t fcp_eqidx; | |
9482 | ||
9483 | /* Get the driver's phba structure from the dev_id */ | |
9484 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | |
9485 | phba = fcp_eq_hdl->phba; | |
9486 | fcp_eqidx = fcp_eq_hdl->idx; | |
9487 | ||
9488 | if (unlikely(!phba)) | |
9489 | return IRQ_NONE; | |
9490 | ||
9491 | /* Get to the EQ struct associated with this vector */ | |
9492 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | |
9493 | ||
9494 | /* Check device state for handling interrupt */ | |
9495 | if (unlikely(lpfc_intr_state_check(phba))) { | |
9496 | /* Check again for link_state with lock held */ | |
9497 | spin_lock_irqsave(&phba->hbalock, iflag); | |
9498 | if (phba->link_state < LPFC_LINK_DOWN) | |
9499 | /* Flush, clear interrupt, and rearm the EQ */ | |
9500 | lpfc_sli4_eq_flush(phba, fpeq); | |
9501 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
9502 | return IRQ_NONE; | |
9503 | } | |
9504 | ||
9505 | /* | |
9506 | * Process all the event on FCP fast-path EQ | |
9507 | */ | |
9508 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | |
9509 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | |
9510 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | |
9511 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); | |
9512 | } | |
9513 | ||
9514 | /* Always clear and re-arm the fast-path EQ */ | |
9515 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | |
9516 | ||
9517 | if (unlikely(ecount == 0)) { | |
9518 | if (phba->intr_type == MSIX) | |
9519 | /* MSI-X treated interrupt served as no EQ share INT */ | |
9520 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
9521 | "0358 MSI-X interrupt with no EQE\n"); | |
9522 | else | |
9523 | /* Non MSI-X treated on interrupt as EQ share INT */ | |
9524 | return IRQ_NONE; | |
9525 | } | |
9526 | ||
9527 | return IRQ_HANDLED; | |
9528 | } /* lpfc_sli4_fp_intr_handler */ | |
9529 | ||
9530 | /** | |
9531 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | |
9532 | * @irq: Interrupt number. | |
9533 | * @dev_id: The device context pointer. | |
9534 | * | |
9535 | * This function is the device-level interrupt handler to device with SLI-4 | |
9536 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | |
9537 | * interrupt mode is enabled and there is an event in the HBA which requires | |
9538 | * driver attention. This function invokes the slow-path interrupt attention | |
9539 | * handling function and fast-path interrupt attention handling function in | |
9540 | * turn to process the relevant HBA attention events. This function is called | |
9541 | * without any lock held. It gets the hbalock to access and update SLI data | |
9542 | * structures. | |
9543 | * | |
9544 | * This function returns IRQ_HANDLED when interrupt is handled, else it | |
9545 | * returns IRQ_NONE. | |
9546 | **/ | |
9547 | irqreturn_t | |
9548 | lpfc_sli4_intr_handler(int irq, void *dev_id) | |
9549 | { | |
9550 | struct lpfc_hba *phba; | |
9551 | irqreturn_t sp_irq_rc, fp_irq_rc; | |
9552 | bool fp_handled = false; | |
9553 | uint32_t fcp_eqidx; | |
9554 | ||
9555 | /* Get the driver's phba structure from the dev_id */ | |
9556 | phba = (struct lpfc_hba *)dev_id; | |
9557 | ||
9558 | if (unlikely(!phba)) | |
9559 | return IRQ_NONE; | |
9560 | ||
9561 | /* | |
9562 | * Invokes slow-path host attention interrupt handling as appropriate. | |
9563 | */ | |
9564 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | |
9565 | ||
9566 | /* | |
9567 | * Invoke fast-path host attention interrupt handling as appropriate. | |
9568 | */ | |
9569 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
9570 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | |
9571 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | |
9572 | if (fp_irq_rc == IRQ_HANDLED) | |
9573 | fp_handled |= true; | |
9574 | } | |
9575 | ||
9576 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | |
9577 | } /* lpfc_sli4_intr_handler */ | |
9578 | ||
9579 | /** | |
9580 | * lpfc_sli4_queue_free - free a queue structure and associated memory | |
9581 | * @queue: The queue structure to free. | |
9582 | * | |
9583 | * This function frees a queue structure and the DMAable memeory used for | |
9584 | * the host resident queue. This function must be called after destroying the | |
9585 | * queue on the HBA. | |
9586 | **/ | |
9587 | void | |
9588 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | |
9589 | { | |
9590 | struct lpfc_dmabuf *dmabuf; | |
9591 | ||
9592 | if (!queue) | |
9593 | return; | |
9594 | ||
9595 | while (!list_empty(&queue->page_list)) { | |
9596 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | |
9597 | list); | |
49198b37 | 9598 | dma_free_coherent(&queue->phba->pcidev->dev, SLI4_PAGE_SIZE, |
4f774513 JS |
9599 | dmabuf->virt, dmabuf->phys); |
9600 | kfree(dmabuf); | |
9601 | } | |
9602 | kfree(queue); | |
9603 | return; | |
9604 | } | |
9605 | ||
9606 | /** | |
9607 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | |
9608 | * @phba: The HBA that this queue is being created on. | |
9609 | * @entry_size: The size of each queue entry for this queue. | |
9610 | * @entry count: The number of entries that this queue will handle. | |
9611 | * | |
9612 | * This function allocates a queue structure and the DMAable memory used for | |
9613 | * the host resident queue. This function must be called before creating the | |
9614 | * queue on the HBA. | |
9615 | **/ | |
9616 | struct lpfc_queue * | |
9617 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | |
9618 | uint32_t entry_count) | |
9619 | { | |
9620 | struct lpfc_queue *queue; | |
9621 | struct lpfc_dmabuf *dmabuf; | |
9622 | int x, total_qe_count; | |
9623 | void *dma_pointer; | |
cb5172ea | 9624 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
4f774513 | 9625 | |
cb5172ea JS |
9626 | if (!phba->sli4_hba.pc_sli4_params.supported) |
9627 | hw_page_size = SLI4_PAGE_SIZE; | |
9628 | ||
4f774513 JS |
9629 | queue = kzalloc(sizeof(struct lpfc_queue) + |
9630 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | |
9631 | if (!queue) | |
9632 | return NULL; | |
cb5172ea JS |
9633 | queue->page_count = (ALIGN(entry_size * entry_count, |
9634 | hw_page_size))/hw_page_size; | |
4f774513 JS |
9635 | INIT_LIST_HEAD(&queue->list); |
9636 | INIT_LIST_HEAD(&queue->page_list); | |
9637 | INIT_LIST_HEAD(&queue->child_list); | |
9638 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | |
9639 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
9640 | if (!dmabuf) | |
9641 | goto out_fail; | |
9642 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
cb5172ea | 9643 | hw_page_size, &dmabuf->phys, |
4f774513 JS |
9644 | GFP_KERNEL); |
9645 | if (!dmabuf->virt) { | |
9646 | kfree(dmabuf); | |
9647 | goto out_fail; | |
9648 | } | |
cb5172ea | 9649 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
9650 | dmabuf->buffer_tag = x; |
9651 | list_add_tail(&dmabuf->list, &queue->page_list); | |
9652 | /* initialize queue's entry array */ | |
9653 | dma_pointer = dmabuf->virt; | |
9654 | for (; total_qe_count < entry_count && | |
cb5172ea | 9655 | dma_pointer < (hw_page_size + dmabuf->virt); |
4f774513 JS |
9656 | total_qe_count++, dma_pointer += entry_size) { |
9657 | queue->qe[total_qe_count].address = dma_pointer; | |
9658 | } | |
9659 | } | |
9660 | queue->entry_size = entry_size; | |
9661 | queue->entry_count = entry_count; | |
9662 | queue->phba = phba; | |
9663 | ||
9664 | return queue; | |
9665 | out_fail: | |
9666 | lpfc_sli4_queue_free(queue); | |
9667 | return NULL; | |
9668 | } | |
9669 | ||
9670 | /** | |
9671 | * lpfc_eq_create - Create an Event Queue on the HBA | |
9672 | * @phba: HBA structure that indicates port to create a queue on. | |
9673 | * @eq: The queue structure to use to create the event queue. | |
9674 | * @imax: The maximum interrupt per second limit. | |
9675 | * | |
9676 | * This function creates an event queue, as detailed in @eq, on a port, | |
9677 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | |
9678 | * | |
9679 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | |
9680 | * is used to get the entry count and entry size that are necessary to | |
9681 | * determine the number of pages to allocate and use for this queue. This | |
9682 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | |
9683 | * event queue. This function is asynchronous and will wait for the mailbox | |
9684 | * command to finish before continuing. | |
9685 | * | |
9686 | * On success this function will return a zero. If unable to allocate enough | |
9687 | * memory this function will return ENOMEM. If the queue create mailbox command | |
9688 | * fails this function will return ENXIO. | |
9689 | **/ | |
9690 | uint32_t | |
9691 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | |
9692 | { | |
9693 | struct lpfc_mbx_eq_create *eq_create; | |
9694 | LPFC_MBOXQ_t *mbox; | |
9695 | int rc, length, status = 0; | |
9696 | struct lpfc_dmabuf *dmabuf; | |
9697 | uint32_t shdr_status, shdr_add_status; | |
9698 | union lpfc_sli4_cfg_shdr *shdr; | |
9699 | uint16_t dmult; | |
49198b37 JS |
9700 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
9701 | ||
9702 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
9703 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
9704 | |
9705 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9706 | if (!mbox) | |
9707 | return -ENOMEM; | |
9708 | length = (sizeof(struct lpfc_mbx_eq_create) - | |
9709 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
9710 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
9711 | LPFC_MBOX_OPCODE_EQ_CREATE, | |
9712 | length, LPFC_SLI4_MBX_EMBED); | |
9713 | eq_create = &mbox->u.mqe.un.eq_create; | |
9714 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | |
9715 | eq->page_count); | |
9716 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | |
9717 | LPFC_EQE_SIZE); | |
9718 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | |
9719 | /* Calculate delay multiper from maximum interrupt per second */ | |
9720 | dmult = LPFC_DMULT_CONST/imax - 1; | |
9721 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | |
9722 | dmult); | |
9723 | switch (eq->entry_count) { | |
9724 | default: | |
9725 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9726 | "0360 Unsupported EQ count. (%d)\n", | |
9727 | eq->entry_count); | |
9728 | if (eq->entry_count < 256) | |
9729 | return -EINVAL; | |
9730 | /* otherwise default to smallest count (drop through) */ | |
9731 | case 256: | |
9732 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
9733 | LPFC_EQ_CNT_256); | |
9734 | break; | |
9735 | case 512: | |
9736 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
9737 | LPFC_EQ_CNT_512); | |
9738 | break; | |
9739 | case 1024: | |
9740 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
9741 | LPFC_EQ_CNT_1024); | |
9742 | break; | |
9743 | case 2048: | |
9744 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
9745 | LPFC_EQ_CNT_2048); | |
9746 | break; | |
9747 | case 4096: | |
9748 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | |
9749 | LPFC_EQ_CNT_4096); | |
9750 | break; | |
9751 | } | |
9752 | list_for_each_entry(dmabuf, &eq->page_list, list) { | |
49198b37 | 9753 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
9754 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
9755 | putPaddrLow(dmabuf->phys); | |
9756 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
9757 | putPaddrHigh(dmabuf->phys); | |
9758 | } | |
9759 | mbox->vport = phba->pport; | |
9760 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
9761 | mbox->context1 = NULL; | |
9762 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
9763 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | |
9764 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
9765 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
9766 | if (shdr_status || shdr_add_status || rc) { | |
9767 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9768 | "2500 EQ_CREATE mailbox failed with " | |
9769 | "status x%x add_status x%x, mbx status x%x\n", | |
9770 | shdr_status, shdr_add_status, rc); | |
9771 | status = -ENXIO; | |
9772 | } | |
9773 | eq->type = LPFC_EQ; | |
9774 | eq->subtype = LPFC_NONE; | |
9775 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | |
9776 | if (eq->queue_id == 0xFFFF) | |
9777 | status = -ENXIO; | |
9778 | eq->host_index = 0; | |
9779 | eq->hba_index = 0; | |
9780 | ||
8fa38513 | 9781 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
9782 | return status; |
9783 | } | |
9784 | ||
9785 | /** | |
9786 | * lpfc_cq_create - Create a Completion Queue on the HBA | |
9787 | * @phba: HBA structure that indicates port to create a queue on. | |
9788 | * @cq: The queue structure to use to create the completion queue. | |
9789 | * @eq: The event queue to bind this completion queue to. | |
9790 | * | |
9791 | * This function creates a completion queue, as detailed in @wq, on a port, | |
9792 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | |
9793 | * | |
9794 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
9795 | * is used to get the entry count and entry size that are necessary to | |
9796 | * determine the number of pages to allocate and use for this queue. The @eq | |
9797 | * is used to indicate which event queue to bind this completion queue to. This | |
9798 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | |
9799 | * completion queue. This function is asynchronous and will wait for the mailbox | |
9800 | * command to finish before continuing. | |
9801 | * | |
9802 | * On success this function will return a zero. If unable to allocate enough | |
9803 | * memory this function will return ENOMEM. If the queue create mailbox command | |
9804 | * fails this function will return ENXIO. | |
9805 | **/ | |
9806 | uint32_t | |
9807 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | |
9808 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | |
9809 | { | |
9810 | struct lpfc_mbx_cq_create *cq_create; | |
9811 | struct lpfc_dmabuf *dmabuf; | |
9812 | LPFC_MBOXQ_t *mbox; | |
9813 | int rc, length, status = 0; | |
9814 | uint32_t shdr_status, shdr_add_status; | |
9815 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
9816 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
9817 | ||
9818 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
9819 | hw_page_size = SLI4_PAGE_SIZE; | |
9820 | ||
4f774513 JS |
9821 | |
9822 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9823 | if (!mbox) | |
9824 | return -ENOMEM; | |
9825 | length = (sizeof(struct lpfc_mbx_cq_create) - | |
9826 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
9827 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
9828 | LPFC_MBOX_OPCODE_CQ_CREATE, | |
9829 | length, LPFC_SLI4_MBX_EMBED); | |
9830 | cq_create = &mbox->u.mqe.un.cq_create; | |
9831 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, | |
9832 | cq->page_count); | |
9833 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | |
9834 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | |
9835 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id); | |
9836 | switch (cq->entry_count) { | |
9837 | default: | |
9838 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
9839 | "0361 Unsupported CQ count. (%d)\n", | |
9840 | cq->entry_count); | |
9841 | if (cq->entry_count < 256) | |
9842 | return -EINVAL; | |
9843 | /* otherwise default to smallest count (drop through) */ | |
9844 | case 256: | |
9845 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
9846 | LPFC_CQ_CNT_256); | |
9847 | break; | |
9848 | case 512: | |
9849 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
9850 | LPFC_CQ_CNT_512); | |
9851 | break; | |
9852 | case 1024: | |
9853 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | |
9854 | LPFC_CQ_CNT_1024); | |
9855 | break; | |
9856 | } | |
9857 | list_for_each_entry(dmabuf, &cq->page_list, list) { | |
49198b37 | 9858 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
9859 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
9860 | putPaddrLow(dmabuf->phys); | |
9861 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
9862 | putPaddrHigh(dmabuf->phys); | |
9863 | } | |
9864 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
9865 | ||
9866 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
9867 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; | |
9868 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
9869 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
9870 | if (shdr_status || shdr_add_status || rc) { | |
9871 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9872 | "2501 CQ_CREATE mailbox failed with " | |
9873 | "status x%x add_status x%x, mbx status x%x\n", | |
9874 | shdr_status, shdr_add_status, rc); | |
9875 | status = -ENXIO; | |
9876 | goto out; | |
9877 | } | |
9878 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
9879 | if (cq->queue_id == 0xFFFF) { | |
9880 | status = -ENXIO; | |
9881 | goto out; | |
9882 | } | |
9883 | /* link the cq onto the parent eq child list */ | |
9884 | list_add_tail(&cq->list, &eq->child_list); | |
9885 | /* Set up completion queue's type and subtype */ | |
9886 | cq->type = type; | |
9887 | cq->subtype = subtype; | |
9888 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | |
9889 | cq->host_index = 0; | |
9890 | cq->hba_index = 0; | |
4f774513 | 9891 | |
8fa38513 JS |
9892 | out: |
9893 | mempool_free(mbox, phba->mbox_mem_pool); | |
4f774513 JS |
9894 | return status; |
9895 | } | |
9896 | ||
b19a061a JS |
9897 | /** |
9898 | * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration | |
9899 | * @phba: HBA structure that indicates port to create a queue on. | |
9900 | * @mq: The queue structure to use to create the mailbox queue. | |
9901 | * @mbox: An allocated pointer to type LPFC_MBOXQ_t | |
9902 | * @cq: The completion queue to associate with this cq. | |
9903 | * | |
9904 | * This function provides failback (fb) functionality when the | |
9905 | * mq_create_ext fails on older FW generations. It's purpose is identical | |
9906 | * to mq_create_ext otherwise. | |
9907 | * | |
9908 | * This routine cannot fail as all attributes were previously accessed and | |
9909 | * initialized in mq_create_ext. | |
9910 | **/ | |
9911 | static void | |
9912 | lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq, | |
9913 | LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq) | |
9914 | { | |
9915 | struct lpfc_mbx_mq_create *mq_create; | |
9916 | struct lpfc_dmabuf *dmabuf; | |
9917 | int length; | |
9918 | ||
9919 | length = (sizeof(struct lpfc_mbx_mq_create) - | |
9920 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
9921 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
9922 | LPFC_MBOX_OPCODE_MQ_CREATE, | |
9923 | length, LPFC_SLI4_MBX_EMBED); | |
9924 | mq_create = &mbox->u.mqe.un.mq_create; | |
9925 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | |
9926 | mq->page_count); | |
9927 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | |
9928 | cq->queue_id); | |
9929 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | |
9930 | switch (mq->entry_count) { | |
9931 | case 16: | |
9932 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
9933 | LPFC_MQ_CNT_16); | |
9934 | break; | |
9935 | case 32: | |
9936 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
9937 | LPFC_MQ_CNT_32); | |
9938 | break; | |
9939 | case 64: | |
9940 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
9941 | LPFC_MQ_CNT_64); | |
9942 | break; | |
9943 | case 128: | |
9944 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | |
9945 | LPFC_MQ_CNT_128); | |
9946 | break; | |
9947 | } | |
9948 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
9949 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
9950 | putPaddrLow(dmabuf->phys); | |
9951 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
9952 | putPaddrHigh(dmabuf->phys); | |
9953 | } | |
9954 | } | |
9955 | ||
04c68496 JS |
9956 | /** |
9957 | * lpfc_mq_create - Create a mailbox Queue on the HBA | |
9958 | * @phba: HBA structure that indicates port to create a queue on. | |
9959 | * @mq: The queue structure to use to create the mailbox queue. | |
b19a061a JS |
9960 | * @cq: The completion queue to associate with this cq. |
9961 | * @subtype: The queue's subtype. | |
04c68496 JS |
9962 | * |
9963 | * This function creates a mailbox queue, as detailed in @mq, on a port, | |
9964 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | |
9965 | * | |
9966 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | |
9967 | * is used to get the entry count and entry size that are necessary to | |
9968 | * determine the number of pages to allocate and use for this queue. This | |
9969 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | |
9970 | * mailbox queue. This function is asynchronous and will wait for the mailbox | |
9971 | * command to finish before continuing. | |
9972 | * | |
9973 | * On success this function will return a zero. If unable to allocate enough | |
9974 | * memory this function will return ENOMEM. If the queue create mailbox command | |
9975 | * fails this function will return ENXIO. | |
9976 | **/ | |
b19a061a | 9977 | int32_t |
04c68496 JS |
9978 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, |
9979 | struct lpfc_queue *cq, uint32_t subtype) | |
9980 | { | |
9981 | struct lpfc_mbx_mq_create *mq_create; | |
b19a061a | 9982 | struct lpfc_mbx_mq_create_ext *mq_create_ext; |
04c68496 JS |
9983 | struct lpfc_dmabuf *dmabuf; |
9984 | LPFC_MBOXQ_t *mbox; | |
9985 | int rc, length, status = 0; | |
9986 | uint32_t shdr_status, shdr_add_status; | |
9987 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 | 9988 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
04c68496 | 9989 | |
49198b37 JS |
9990 | if (!phba->sli4_hba.pc_sli4_params.supported) |
9991 | hw_page_size = SLI4_PAGE_SIZE; | |
b19a061a | 9992 | |
04c68496 JS |
9993 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9994 | if (!mbox) | |
9995 | return -ENOMEM; | |
b19a061a | 9996 | length = (sizeof(struct lpfc_mbx_mq_create_ext) - |
04c68496 JS |
9997 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
9998 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
b19a061a | 9999 | LPFC_MBOX_OPCODE_MQ_CREATE_EXT, |
04c68496 | 10000 | length, LPFC_SLI4_MBX_EMBED); |
b19a061a JS |
10001 | |
10002 | mq_create_ext = &mbox->u.mqe.un.mq_create_ext; | |
10003 | bf_set(lpfc_mbx_mq_create_ext_num_pages, &mq_create_ext->u.request, | |
04c68496 | 10004 | mq->page_count); |
b19a061a JS |
10005 | bf_set(lpfc_mbx_mq_create_ext_async_evt_link, &mq_create_ext->u.request, |
10006 | 1); | |
10007 | bf_set(lpfc_mbx_mq_create_ext_async_evt_fcfste, | |
10008 | &mq_create_ext->u.request, 1); | |
10009 | bf_set(lpfc_mbx_mq_create_ext_async_evt_group5, | |
10010 | &mq_create_ext->u.request, 1); | |
10011 | bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context, | |
10012 | cq->queue_id); | |
10013 | bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1); | |
04c68496 JS |
10014 | switch (mq->entry_count) { |
10015 | default: | |
10016 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10017 | "0362 Unsupported MQ count. (%d)\n", | |
10018 | mq->entry_count); | |
10019 | if (mq->entry_count < 16) | |
10020 | return -EINVAL; | |
10021 | /* otherwise default to smallest count (drop through) */ | |
10022 | case 16: | |
b19a061a | 10023 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10024 | LPFC_MQ_CNT_16); |
10025 | break; | |
10026 | case 32: | |
b19a061a | 10027 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10028 | LPFC_MQ_CNT_32); |
10029 | break; | |
10030 | case 64: | |
b19a061a | 10031 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10032 | LPFC_MQ_CNT_64); |
10033 | break; | |
10034 | case 128: | |
b19a061a | 10035 | bf_set(lpfc_mq_context_count, &mq_create_ext->u.request.context, |
04c68496 JS |
10036 | LPFC_MQ_CNT_128); |
10037 | break; | |
10038 | } | |
10039 | list_for_each_entry(dmabuf, &mq->page_list, list) { | |
49198b37 | 10040 | memset(dmabuf->virt, 0, hw_page_size); |
b19a061a | 10041 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo = |
04c68496 | 10042 | putPaddrLow(dmabuf->phys); |
b19a061a | 10043 | mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi = |
04c68496 JS |
10044 | putPaddrHigh(dmabuf->phys); |
10045 | } | |
10046 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
b19a061a JS |
10047 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr; |
10048 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10049 | &mq_create_ext->u.response); | |
10050 | if (rc != MBX_SUCCESS) { | |
10051 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10052 | "2795 MQ_CREATE_EXT failed with " | |
10053 | "status x%x. Failback to MQ_CREATE.\n", | |
10054 | rc); | |
10055 | lpfc_mq_create_fb_init(phba, mq, mbox, cq); | |
10056 | mq_create = &mbox->u.mqe.un.mq_create; | |
10057 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10058 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | |
10059 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, | |
10060 | &mq_create->u.response); | |
10061 | } | |
10062 | ||
04c68496 | 10063 | /* The IOCTL status is embedded in the mailbox subheader. */ |
04c68496 JS |
10064 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
10065 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10066 | if (shdr_status || shdr_add_status || rc) { | |
10067 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10068 | "2502 MQ_CREATE mailbox failed with " | |
10069 | "status x%x add_status x%x, mbx status x%x\n", | |
10070 | shdr_status, shdr_add_status, rc); | |
10071 | status = -ENXIO; | |
10072 | goto out; | |
10073 | } | |
04c68496 JS |
10074 | if (mq->queue_id == 0xFFFF) { |
10075 | status = -ENXIO; | |
10076 | goto out; | |
10077 | } | |
10078 | mq->type = LPFC_MQ; | |
10079 | mq->subtype = subtype; | |
10080 | mq->host_index = 0; | |
10081 | mq->hba_index = 0; | |
10082 | ||
10083 | /* link the mq onto the parent cq child list */ | |
10084 | list_add_tail(&mq->list, &cq->child_list); | |
10085 | out: | |
8fa38513 | 10086 | mempool_free(mbox, phba->mbox_mem_pool); |
04c68496 JS |
10087 | return status; |
10088 | } | |
10089 | ||
4f774513 JS |
10090 | /** |
10091 | * lpfc_wq_create - Create a Work Queue on the HBA | |
10092 | * @phba: HBA structure that indicates port to create a queue on. | |
10093 | * @wq: The queue structure to use to create the work queue. | |
10094 | * @cq: The completion queue to bind this work queue to. | |
10095 | * @subtype: The subtype of the work queue indicating its functionality. | |
10096 | * | |
10097 | * This function creates a work queue, as detailed in @wq, on a port, described | |
10098 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | |
10099 | * | |
10100 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | |
10101 | * is used to get the entry count and entry size that are necessary to | |
10102 | * determine the number of pages to allocate and use for this queue. The @cq | |
10103 | * is used to indicate which completion queue to bind this work queue to. This | |
10104 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | |
10105 | * work queue. This function is asynchronous and will wait for the mailbox | |
10106 | * command to finish before continuing. | |
10107 | * | |
10108 | * On success this function will return a zero. If unable to allocate enough | |
10109 | * memory this function will return ENOMEM. If the queue create mailbox command | |
10110 | * fails this function will return ENXIO. | |
10111 | **/ | |
10112 | uint32_t | |
10113 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | |
10114 | struct lpfc_queue *cq, uint32_t subtype) | |
10115 | { | |
10116 | struct lpfc_mbx_wq_create *wq_create; | |
10117 | struct lpfc_dmabuf *dmabuf; | |
10118 | LPFC_MBOXQ_t *mbox; | |
10119 | int rc, length, status = 0; | |
10120 | uint32_t shdr_status, shdr_add_status; | |
10121 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10122 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10123 | ||
10124 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10125 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10126 | |
10127 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10128 | if (!mbox) | |
10129 | return -ENOMEM; | |
10130 | length = (sizeof(struct lpfc_mbx_wq_create) - | |
10131 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10132 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10133 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | |
10134 | length, LPFC_SLI4_MBX_EMBED); | |
10135 | wq_create = &mbox->u.mqe.un.wq_create; | |
10136 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, | |
10137 | wq->page_count); | |
10138 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | |
10139 | cq->queue_id); | |
10140 | list_for_each_entry(dmabuf, &wq->page_list, list) { | |
49198b37 | 10141 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10142 | wq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10143 | putPaddrLow(dmabuf->phys); | |
10144 | wq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10145 | putPaddrHigh(dmabuf->phys); | |
10146 | } | |
10147 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10148 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10149 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; | |
10150 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10151 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10152 | if (shdr_status || shdr_add_status || rc) { | |
10153 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10154 | "2503 WQ_CREATE mailbox failed with " | |
10155 | "status x%x add_status x%x, mbx status x%x\n", | |
10156 | shdr_status, shdr_add_status, rc); | |
10157 | status = -ENXIO; | |
10158 | goto out; | |
10159 | } | |
10160 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | |
10161 | if (wq->queue_id == 0xFFFF) { | |
10162 | status = -ENXIO; | |
10163 | goto out; | |
10164 | } | |
10165 | wq->type = LPFC_WQ; | |
10166 | wq->subtype = subtype; | |
10167 | wq->host_index = 0; | |
10168 | wq->hba_index = 0; | |
10169 | ||
10170 | /* link the wq onto the parent cq child list */ | |
10171 | list_add_tail(&wq->list, &cq->child_list); | |
10172 | out: | |
8fa38513 | 10173 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10174 | return status; |
10175 | } | |
10176 | ||
10177 | /** | |
10178 | * lpfc_rq_create - Create a Receive Queue on the HBA | |
10179 | * @phba: HBA structure that indicates port to create a queue on. | |
10180 | * @hrq: The queue structure to use to create the header receive queue. | |
10181 | * @drq: The queue structure to use to create the data receive queue. | |
10182 | * @cq: The completion queue to bind this work queue to. | |
10183 | * | |
10184 | * This function creates a receive buffer queue pair , as detailed in @hrq and | |
10185 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | |
10186 | * to the HBA. | |
10187 | * | |
10188 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | |
10189 | * struct is used to get the entry count that is necessary to determine the | |
10190 | * number of pages to use for this queue. The @cq is used to indicate which | |
10191 | * completion queue to bind received buffers that are posted to these queues to. | |
10192 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | |
10193 | * receive queue pair. This function is asynchronous and will wait for the | |
10194 | * mailbox command to finish before continuing. | |
10195 | * | |
10196 | * On success this function will return a zero. If unable to allocate enough | |
10197 | * memory this function will return ENOMEM. If the queue create mailbox command | |
10198 | * fails this function will return ENXIO. | |
10199 | **/ | |
10200 | uint32_t | |
10201 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
10202 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | |
10203 | { | |
10204 | struct lpfc_mbx_rq_create *rq_create; | |
10205 | struct lpfc_dmabuf *dmabuf; | |
10206 | LPFC_MBOXQ_t *mbox; | |
10207 | int rc, length, status = 0; | |
10208 | uint32_t shdr_status, shdr_add_status; | |
10209 | union lpfc_sli4_cfg_shdr *shdr; | |
49198b37 JS |
10210 | uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz; |
10211 | ||
10212 | if (!phba->sli4_hba.pc_sli4_params.supported) | |
10213 | hw_page_size = SLI4_PAGE_SIZE; | |
4f774513 JS |
10214 | |
10215 | if (hrq->entry_count != drq->entry_count) | |
10216 | return -EINVAL; | |
10217 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10218 | if (!mbox) | |
10219 | return -ENOMEM; | |
10220 | length = (sizeof(struct lpfc_mbx_rq_create) - | |
10221 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10222 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10223 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10224 | length, LPFC_SLI4_MBX_EMBED); | |
10225 | rq_create = &mbox->u.mqe.un.rq_create; | |
10226 | switch (hrq->entry_count) { | |
10227 | default: | |
10228 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10229 | "2535 Unsupported RQ count. (%d)\n", | |
10230 | hrq->entry_count); | |
10231 | if (hrq->entry_count < 512) | |
10232 | return -EINVAL; | |
10233 | /* otherwise default to smallest count (drop through) */ | |
10234 | case 512: | |
10235 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10236 | LPFC_RQ_RING_SIZE_512); | |
10237 | break; | |
10238 | case 1024: | |
10239 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10240 | LPFC_RQ_RING_SIZE_1024); | |
10241 | break; | |
10242 | case 2048: | |
10243 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10244 | LPFC_RQ_RING_SIZE_2048); | |
10245 | break; | |
10246 | case 4096: | |
10247 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10248 | LPFC_RQ_RING_SIZE_4096); | |
10249 | break; | |
10250 | } | |
10251 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
10252 | cq->queue_id); | |
10253 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
10254 | hrq->page_count); | |
10255 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
10256 | LPFC_HDR_BUF_SIZE); | |
10257 | list_for_each_entry(dmabuf, &hrq->page_list, list) { | |
49198b37 | 10258 | memset(dmabuf->virt, 0, hw_page_size); |
4f774513 JS |
10259 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = |
10260 | putPaddrLow(dmabuf->phys); | |
10261 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10262 | putPaddrHigh(dmabuf->phys); | |
10263 | } | |
10264 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10265 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10266 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
10267 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10268 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10269 | if (shdr_status || shdr_add_status || rc) { | |
10270 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10271 | "2504 RQ_CREATE mailbox failed with " | |
10272 | "status x%x add_status x%x, mbx status x%x\n", | |
10273 | shdr_status, shdr_add_status, rc); | |
10274 | status = -ENXIO; | |
10275 | goto out; | |
10276 | } | |
10277 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
10278 | if (hrq->queue_id == 0xFFFF) { | |
10279 | status = -ENXIO; | |
10280 | goto out; | |
10281 | } | |
10282 | hrq->type = LPFC_HRQ; | |
10283 | hrq->subtype = subtype; | |
10284 | hrq->host_index = 0; | |
10285 | hrq->hba_index = 0; | |
10286 | ||
10287 | /* now create the data queue */ | |
10288 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10289 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | |
10290 | length, LPFC_SLI4_MBX_EMBED); | |
10291 | switch (drq->entry_count) { | |
10292 | default: | |
10293 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10294 | "2536 Unsupported RQ count. (%d)\n", | |
10295 | drq->entry_count); | |
10296 | if (drq->entry_count < 512) | |
10297 | return -EINVAL; | |
10298 | /* otherwise default to smallest count (drop through) */ | |
10299 | case 512: | |
10300 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10301 | LPFC_RQ_RING_SIZE_512); | |
10302 | break; | |
10303 | case 1024: | |
10304 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10305 | LPFC_RQ_RING_SIZE_1024); | |
10306 | break; | |
10307 | case 2048: | |
10308 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10309 | LPFC_RQ_RING_SIZE_2048); | |
10310 | break; | |
10311 | case 4096: | |
10312 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | |
10313 | LPFC_RQ_RING_SIZE_4096); | |
10314 | break; | |
10315 | } | |
10316 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | |
10317 | cq->queue_id); | |
10318 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | |
10319 | drq->page_count); | |
10320 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | |
10321 | LPFC_DATA_BUF_SIZE); | |
10322 | list_for_each_entry(dmabuf, &drq->page_list, list) { | |
10323 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | |
10324 | putPaddrLow(dmabuf->phys); | |
10325 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | |
10326 | putPaddrHigh(dmabuf->phys); | |
10327 | } | |
10328 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10329 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10330 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | |
10331 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10332 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10333 | if (shdr_status || shdr_add_status || rc) { | |
10334 | status = -ENXIO; | |
10335 | goto out; | |
10336 | } | |
10337 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | |
10338 | if (drq->queue_id == 0xFFFF) { | |
10339 | status = -ENXIO; | |
10340 | goto out; | |
10341 | } | |
10342 | drq->type = LPFC_DRQ; | |
10343 | drq->subtype = subtype; | |
10344 | drq->host_index = 0; | |
10345 | drq->hba_index = 0; | |
10346 | ||
10347 | /* link the header and data RQs onto the parent cq child list */ | |
10348 | list_add_tail(&hrq->list, &cq->child_list); | |
10349 | list_add_tail(&drq->list, &cq->child_list); | |
10350 | ||
10351 | out: | |
8fa38513 | 10352 | mempool_free(mbox, phba->mbox_mem_pool); |
4f774513 JS |
10353 | return status; |
10354 | } | |
10355 | ||
10356 | /** | |
10357 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | |
10358 | * @eq: The queue structure associated with the queue to destroy. | |
10359 | * | |
10360 | * This function destroys a queue, as detailed in @eq by sending an mailbox | |
10361 | * command, specific to the type of queue, to the HBA. | |
10362 | * | |
10363 | * The @eq struct is used to get the queue ID of the queue to destroy. | |
10364 | * | |
10365 | * On success this function will return a zero. If the queue destroy mailbox | |
10366 | * command fails this function will return ENXIO. | |
10367 | **/ | |
10368 | uint32_t | |
10369 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | |
10370 | { | |
10371 | LPFC_MBOXQ_t *mbox; | |
10372 | int rc, length, status = 0; | |
10373 | uint32_t shdr_status, shdr_add_status; | |
10374 | union lpfc_sli4_cfg_shdr *shdr; | |
10375 | ||
10376 | if (!eq) | |
10377 | return -ENODEV; | |
10378 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | |
10379 | if (!mbox) | |
10380 | return -ENOMEM; | |
10381 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | |
10382 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10383 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10384 | LPFC_MBOX_OPCODE_EQ_DESTROY, | |
10385 | length, LPFC_SLI4_MBX_EMBED); | |
10386 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | |
10387 | eq->queue_id); | |
10388 | mbox->vport = eq->phba->pport; | |
10389 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10390 | ||
10391 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | |
10392 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10393 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10394 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | |
10395 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10396 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10397 | if (shdr_status || shdr_add_status || rc) { | |
10398 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10399 | "2505 EQ_DESTROY mailbox failed with " | |
10400 | "status x%x add_status x%x, mbx status x%x\n", | |
10401 | shdr_status, shdr_add_status, rc); | |
10402 | status = -ENXIO; | |
10403 | } | |
10404 | ||
10405 | /* Remove eq from any list */ | |
10406 | list_del_init(&eq->list); | |
8fa38513 | 10407 | mempool_free(mbox, eq->phba->mbox_mem_pool); |
4f774513 JS |
10408 | return status; |
10409 | } | |
10410 | ||
10411 | /** | |
10412 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | |
10413 | * @cq: The queue structure associated with the queue to destroy. | |
10414 | * | |
10415 | * This function destroys a queue, as detailed in @cq by sending an mailbox | |
10416 | * command, specific to the type of queue, to the HBA. | |
10417 | * | |
10418 | * The @cq struct is used to get the queue ID of the queue to destroy. | |
10419 | * | |
10420 | * On success this function will return a zero. If the queue destroy mailbox | |
10421 | * command fails this function will return ENXIO. | |
10422 | **/ | |
10423 | uint32_t | |
10424 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | |
10425 | { | |
10426 | LPFC_MBOXQ_t *mbox; | |
10427 | int rc, length, status = 0; | |
10428 | uint32_t shdr_status, shdr_add_status; | |
10429 | union lpfc_sli4_cfg_shdr *shdr; | |
10430 | ||
10431 | if (!cq) | |
10432 | return -ENODEV; | |
10433 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | |
10434 | if (!mbox) | |
10435 | return -ENOMEM; | |
10436 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | |
10437 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10438 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10439 | LPFC_MBOX_OPCODE_CQ_DESTROY, | |
10440 | length, LPFC_SLI4_MBX_EMBED); | |
10441 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | |
10442 | cq->queue_id); | |
10443 | mbox->vport = cq->phba->pport; | |
10444 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10445 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | |
10446 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10447 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10448 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | |
10449 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10450 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10451 | if (shdr_status || shdr_add_status || rc) { | |
10452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10453 | "2506 CQ_DESTROY mailbox failed with " | |
10454 | "status x%x add_status x%x, mbx status x%x\n", | |
10455 | shdr_status, shdr_add_status, rc); | |
10456 | status = -ENXIO; | |
10457 | } | |
10458 | /* Remove cq from any list */ | |
10459 | list_del_init(&cq->list); | |
8fa38513 | 10460 | mempool_free(mbox, cq->phba->mbox_mem_pool); |
4f774513 JS |
10461 | return status; |
10462 | } | |
10463 | ||
04c68496 JS |
10464 | /** |
10465 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | |
10466 | * @qm: The queue structure associated with the queue to destroy. | |
10467 | * | |
10468 | * This function destroys a queue, as detailed in @mq by sending an mailbox | |
10469 | * command, specific to the type of queue, to the HBA. | |
10470 | * | |
10471 | * The @mq struct is used to get the queue ID of the queue to destroy. | |
10472 | * | |
10473 | * On success this function will return a zero. If the queue destroy mailbox | |
10474 | * command fails this function will return ENXIO. | |
10475 | **/ | |
10476 | uint32_t | |
10477 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | |
10478 | { | |
10479 | LPFC_MBOXQ_t *mbox; | |
10480 | int rc, length, status = 0; | |
10481 | uint32_t shdr_status, shdr_add_status; | |
10482 | union lpfc_sli4_cfg_shdr *shdr; | |
10483 | ||
10484 | if (!mq) | |
10485 | return -ENODEV; | |
10486 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | |
10487 | if (!mbox) | |
10488 | return -ENOMEM; | |
10489 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | |
10490 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10491 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | |
10492 | LPFC_MBOX_OPCODE_MQ_DESTROY, | |
10493 | length, LPFC_SLI4_MBX_EMBED); | |
10494 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | |
10495 | mq->queue_id); | |
10496 | mbox->vport = mq->phba->pport; | |
10497 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10498 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | |
10499 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10500 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10501 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | |
10502 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10503 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10504 | if (shdr_status || shdr_add_status || rc) { | |
10505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10506 | "2507 MQ_DESTROY mailbox failed with " | |
10507 | "status x%x add_status x%x, mbx status x%x\n", | |
10508 | shdr_status, shdr_add_status, rc); | |
10509 | status = -ENXIO; | |
10510 | } | |
10511 | /* Remove mq from any list */ | |
10512 | list_del_init(&mq->list); | |
8fa38513 | 10513 | mempool_free(mbox, mq->phba->mbox_mem_pool); |
04c68496 JS |
10514 | return status; |
10515 | } | |
10516 | ||
4f774513 JS |
10517 | /** |
10518 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | |
10519 | * @wq: The queue structure associated with the queue to destroy. | |
10520 | * | |
10521 | * This function destroys a queue, as detailed in @wq by sending an mailbox | |
10522 | * command, specific to the type of queue, to the HBA. | |
10523 | * | |
10524 | * The @wq struct is used to get the queue ID of the queue to destroy. | |
10525 | * | |
10526 | * On success this function will return a zero. If the queue destroy mailbox | |
10527 | * command fails this function will return ENXIO. | |
10528 | **/ | |
10529 | uint32_t | |
10530 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | |
10531 | { | |
10532 | LPFC_MBOXQ_t *mbox; | |
10533 | int rc, length, status = 0; | |
10534 | uint32_t shdr_status, shdr_add_status; | |
10535 | union lpfc_sli4_cfg_shdr *shdr; | |
10536 | ||
10537 | if (!wq) | |
10538 | return -ENODEV; | |
10539 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | |
10540 | if (!mbox) | |
10541 | return -ENOMEM; | |
10542 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | |
10543 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
10544 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10545 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | |
10546 | length, LPFC_SLI4_MBX_EMBED); | |
10547 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | |
10548 | wq->queue_id); | |
10549 | mbox->vport = wq->phba->pport; | |
10550 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10551 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | |
10552 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10553 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | |
10554 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10555 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10556 | if (shdr_status || shdr_add_status || rc) { | |
10557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10558 | "2508 WQ_DESTROY mailbox failed with " | |
10559 | "status x%x add_status x%x, mbx status x%x\n", | |
10560 | shdr_status, shdr_add_status, rc); | |
10561 | status = -ENXIO; | |
10562 | } | |
10563 | /* Remove wq from any list */ | |
10564 | list_del_init(&wq->list); | |
8fa38513 | 10565 | mempool_free(mbox, wq->phba->mbox_mem_pool); |
4f774513 JS |
10566 | return status; |
10567 | } | |
10568 | ||
10569 | /** | |
10570 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | |
10571 | * @rq: The queue structure associated with the queue to destroy. | |
10572 | * | |
10573 | * This function destroys a queue, as detailed in @rq by sending an mailbox | |
10574 | * command, specific to the type of queue, to the HBA. | |
10575 | * | |
10576 | * The @rq struct is used to get the queue ID of the queue to destroy. | |
10577 | * | |
10578 | * On success this function will return a zero. If the queue destroy mailbox | |
10579 | * command fails this function will return ENXIO. | |
10580 | **/ | |
10581 | uint32_t | |
10582 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
10583 | struct lpfc_queue *drq) | |
10584 | { | |
10585 | LPFC_MBOXQ_t *mbox; | |
10586 | int rc, length, status = 0; | |
10587 | uint32_t shdr_status, shdr_add_status; | |
10588 | union lpfc_sli4_cfg_shdr *shdr; | |
10589 | ||
10590 | if (!hrq || !drq) | |
10591 | return -ENODEV; | |
10592 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | |
10593 | if (!mbox) | |
10594 | return -ENOMEM; | |
10595 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | |
10596 | sizeof(struct mbox_header)); | |
10597 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10598 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | |
10599 | length, LPFC_SLI4_MBX_EMBED); | |
10600 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
10601 | hrq->queue_id); | |
10602 | mbox->vport = hrq->phba->pport; | |
10603 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
10604 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | |
10605 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10606 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10607 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
10608 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10609 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10610 | if (shdr_status || shdr_add_status || rc) { | |
10611 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10612 | "2509 RQ_DESTROY mailbox failed with " | |
10613 | "status x%x add_status x%x, mbx status x%x\n", | |
10614 | shdr_status, shdr_add_status, rc); | |
10615 | if (rc != MBX_TIMEOUT) | |
10616 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | |
10617 | return -ENXIO; | |
10618 | } | |
10619 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | |
10620 | drq->queue_id); | |
10621 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | |
10622 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10623 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | |
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 | "2510 RQ_DESTROY 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 | } | |
10633 | list_del_init(&hrq->list); | |
10634 | list_del_init(&drq->list); | |
8fa38513 | 10635 | mempool_free(mbox, hrq->phba->mbox_mem_pool); |
4f774513 JS |
10636 | return status; |
10637 | } | |
10638 | ||
10639 | /** | |
10640 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | |
10641 | * @phba: The virtual port for which this call being executed. | |
10642 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | |
10643 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | |
10644 | * @xritag: the xritag that ties this io to the SGL pages. | |
10645 | * | |
10646 | * This routine will post the sgl pages for the IO that has the xritag | |
10647 | * that is in the iocbq structure. The xritag is assigned during iocbq | |
10648 | * creation and persists for as long as the driver is loaded. | |
10649 | * if the caller has fewer than 256 scatter gather segments to map then | |
10650 | * pdma_phys_addr1 should be 0. | |
10651 | * If the caller needs to map more than 256 scatter gather segment then | |
10652 | * pdma_phys_addr1 should be a valid physical address. | |
10653 | * physical address for SGLs must be 64 byte aligned. | |
10654 | * If you are going to map 2 SGL's then the first one must have 256 entries | |
10655 | * the second sgl can have between 1 and 256 entries. | |
10656 | * | |
10657 | * Return codes: | |
10658 | * 0 - Success | |
10659 | * -ENXIO, -ENOMEM - Failure | |
10660 | **/ | |
10661 | int | |
10662 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | |
10663 | dma_addr_t pdma_phys_addr0, | |
10664 | dma_addr_t pdma_phys_addr1, | |
10665 | uint16_t xritag) | |
10666 | { | |
10667 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | |
10668 | LPFC_MBOXQ_t *mbox; | |
10669 | int rc; | |
10670 | uint32_t shdr_status, shdr_add_status; | |
10671 | union lpfc_sli4_cfg_shdr *shdr; | |
10672 | ||
10673 | if (xritag == NO_XRI) { | |
10674 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10675 | "0364 Invalid param:\n"); | |
10676 | return -EINVAL; | |
10677 | } | |
10678 | ||
10679 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10680 | if (!mbox) | |
10681 | return -ENOMEM; | |
10682 | ||
10683 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10684 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | |
10685 | sizeof(struct lpfc_mbx_post_sgl_pages) - | |
10686 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | |
10687 | ||
10688 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | |
10689 | &mbox->u.mqe.un.post_sgl_pages; | |
10690 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | |
10691 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | |
10692 | ||
10693 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | |
10694 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | |
10695 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | |
10696 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | |
10697 | ||
10698 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | |
10699 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | |
10700 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | |
10701 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | |
10702 | if (!phba->sli4_hba.intr_enable) | |
10703 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10704 | else | |
10705 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
10706 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10707 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | |
10708 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10709 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10710 | if (rc != MBX_TIMEOUT) | |
10711 | mempool_free(mbox, phba->mbox_mem_pool); | |
10712 | if (shdr_status || shdr_add_status || rc) { | |
10713 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10714 | "2511 POST_SGL mailbox failed with " | |
10715 | "status x%x add_status x%x, mbx status x%x\n", | |
10716 | shdr_status, shdr_add_status, rc); | |
10717 | rc = -ENXIO; | |
10718 | } | |
10719 | return 0; | |
10720 | } | |
10721 | /** | |
10722 | * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA | |
10723 | * @phba: The virtual port for which this call being executed. | |
10724 | * | |
10725 | * This routine will remove all of the sgl pages registered with the hba. | |
10726 | * | |
10727 | * Return codes: | |
10728 | * 0 - Success | |
10729 | * -ENXIO, -ENOMEM - Failure | |
10730 | **/ | |
10731 | int | |
10732 | lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba) | |
10733 | { | |
10734 | LPFC_MBOXQ_t *mbox; | |
10735 | int rc; | |
10736 | uint32_t shdr_status, shdr_add_status; | |
10737 | union lpfc_sli4_cfg_shdr *shdr; | |
10738 | ||
10739 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10740 | if (!mbox) | |
10741 | return -ENOMEM; | |
10742 | ||
10743 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10744 | LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0, | |
10745 | LPFC_SLI4_MBX_EMBED); | |
10746 | if (!phba->sli4_hba.intr_enable) | |
10747 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10748 | else | |
10749 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | |
10750 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
10751 | shdr = (union lpfc_sli4_cfg_shdr *) | |
10752 | &mbox->u.mqe.un.sli4_config.header.cfg_shdr; | |
10753 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10754 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10755 | if (rc != MBX_TIMEOUT) | |
10756 | mempool_free(mbox, phba->mbox_mem_pool); | |
10757 | if (shdr_status || shdr_add_status || rc) { | |
10758 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10759 | "2512 REMOVE_ALL_SGL_PAGES mailbox failed with " | |
10760 | "status x%x add_status x%x, mbx status x%x\n", | |
10761 | shdr_status, shdr_add_status, rc); | |
10762 | rc = -ENXIO; | |
10763 | } | |
10764 | return rc; | |
10765 | } | |
10766 | ||
10767 | /** | |
10768 | * lpfc_sli4_next_xritag - Get an xritag for the io | |
10769 | * @phba: Pointer to HBA context object. | |
10770 | * | |
10771 | * This function gets an xritag for the iocb. If there is no unused xritag | |
10772 | * it will return 0xffff. | |
10773 | * The function returns the allocated xritag if successful, else returns zero. | |
10774 | * Zero is not a valid xritag. | |
10775 | * The caller is not required to hold any lock. | |
10776 | **/ | |
10777 | uint16_t | |
10778 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | |
10779 | { | |
10780 | uint16_t xritag; | |
10781 | ||
10782 | spin_lock_irq(&phba->hbalock); | |
10783 | xritag = phba->sli4_hba.next_xri; | |
10784 | if ((xritag != (uint16_t) -1) && xritag < | |
10785 | (phba->sli4_hba.max_cfg_param.max_xri | |
10786 | + phba->sli4_hba.max_cfg_param.xri_base)) { | |
10787 | phba->sli4_hba.next_xri++; | |
10788 | phba->sli4_hba.max_cfg_param.xri_used++; | |
10789 | spin_unlock_irq(&phba->hbalock); | |
10790 | return xritag; | |
10791 | } | |
10792 | spin_unlock_irq(&phba->hbalock); | |
6a9c52cf | 10793 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
4f774513 JS |
10794 | "2004 Failed to allocate XRI.last XRITAG is %d" |
10795 | " Max XRI is %d, Used XRI is %d\n", | |
10796 | phba->sli4_hba.next_xri, | |
10797 | phba->sli4_hba.max_cfg_param.max_xri, | |
10798 | phba->sli4_hba.max_cfg_param.xri_used); | |
10799 | return -1; | |
10800 | } | |
10801 | ||
10802 | /** | |
10803 | * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware. | |
10804 | * @phba: pointer to lpfc hba data structure. | |
10805 | * | |
10806 | * This routine is invoked to post a block of driver's sgl pages to the | |
10807 | * HBA using non-embedded mailbox command. No Lock is held. This routine | |
10808 | * is only called when the driver is loading and after all IO has been | |
10809 | * stopped. | |
10810 | **/ | |
10811 | int | |
10812 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba) | |
10813 | { | |
10814 | struct lpfc_sglq *sglq_entry; | |
10815 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
10816 | struct sgl_page_pairs *sgl_pg_pairs; | |
10817 | void *viraddr; | |
10818 | LPFC_MBOXQ_t *mbox; | |
10819 | uint32_t reqlen, alloclen, pg_pairs; | |
10820 | uint32_t mbox_tmo; | |
10821 | uint16_t xritag_start = 0; | |
10822 | int els_xri_cnt, rc = 0; | |
10823 | uint32_t shdr_status, shdr_add_status; | |
10824 | union lpfc_sli4_cfg_shdr *shdr; | |
10825 | ||
10826 | /* The number of sgls to be posted */ | |
10827 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
10828 | ||
10829 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | |
10830 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 10831 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
10832 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
10833 | "2559 Block sgl registration required DMA " | |
10834 | "size (%d) great than a page\n", reqlen); | |
10835 | return -ENOMEM; | |
10836 | } | |
10837 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10838 | if (!mbox) { | |
10839 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10840 | "2560 Failed to allocate mbox cmd memory\n"); | |
10841 | return -ENOMEM; | |
10842 | } | |
10843 | ||
10844 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
10845 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10846 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
10847 | LPFC_SLI4_MBX_NEMBED); | |
10848 | ||
10849 | if (alloclen < reqlen) { | |
10850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10851 | "0285 Allocated DMA memory size (%d) is " | |
10852 | "less than the requested DMA memory " | |
10853 | "size (%d)\n", alloclen, reqlen); | |
10854 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
10855 | return -ENOMEM; | |
10856 | } | |
4f774513 | 10857 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
10858 | viraddr = mbox->sge_array->addr[0]; |
10859 | ||
10860 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
10861 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
10862 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
10863 | ||
10864 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | |
10865 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | |
10866 | /* Set up the sge entry */ | |
10867 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
10868 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | |
10869 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
10870 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | |
10871 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
10872 | cpu_to_le32(putPaddrLow(0)); | |
10873 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
10874 | cpu_to_le32(putPaddrHigh(0)); | |
10875 | /* Keep the first xritag on the list */ | |
10876 | if (pg_pairs == 0) | |
10877 | xritag_start = sglq_entry->sli4_xritag; | |
10878 | sgl_pg_pairs++; | |
10879 | } | |
10880 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
6a9c52cf | 10881 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, els_xri_cnt); |
4f774513 JS |
10882 | /* Perform endian conversion if necessary */ |
10883 | sgl->word0 = cpu_to_le32(sgl->word0); | |
10884 | ||
10885 | if (!phba->sli4_hba.intr_enable) | |
10886 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10887 | else { | |
10888 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
10889 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
10890 | } | |
10891 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
10892 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
10893 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
10894 | if (rc != MBX_TIMEOUT) | |
10895 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
10896 | if (shdr_status || shdr_add_status || rc) { | |
10897 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
10898 | "2513 POST_SGL_BLOCK mailbox command failed " | |
10899 | "status x%x add_status x%x mbx status x%x\n", | |
10900 | shdr_status, shdr_add_status, rc); | |
10901 | rc = -ENXIO; | |
10902 | } | |
10903 | return rc; | |
10904 | } | |
10905 | ||
10906 | /** | |
10907 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | |
10908 | * @phba: pointer to lpfc hba data structure. | |
10909 | * @sblist: pointer to scsi buffer list. | |
10910 | * @count: number of scsi buffers on the list. | |
10911 | * | |
10912 | * This routine is invoked to post a block of @count scsi sgl pages from a | |
10913 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | |
10914 | * No Lock is held. | |
10915 | * | |
10916 | **/ | |
10917 | int | |
10918 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | |
10919 | int cnt) | |
10920 | { | |
10921 | struct lpfc_scsi_buf *psb; | |
10922 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | |
10923 | struct sgl_page_pairs *sgl_pg_pairs; | |
10924 | void *viraddr; | |
10925 | LPFC_MBOXQ_t *mbox; | |
10926 | uint32_t reqlen, alloclen, pg_pairs; | |
10927 | uint32_t mbox_tmo; | |
10928 | uint16_t xritag_start = 0; | |
10929 | int rc = 0; | |
10930 | uint32_t shdr_status, shdr_add_status; | |
10931 | dma_addr_t pdma_phys_bpl1; | |
10932 | union lpfc_sli4_cfg_shdr *shdr; | |
10933 | ||
10934 | /* Calculate the requested length of the dma memory */ | |
10935 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | |
10936 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | |
49198b37 | 10937 | if (reqlen > SLI4_PAGE_SIZE) { |
4f774513 JS |
10938 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
10939 | "0217 Block sgl registration required DMA " | |
10940 | "size (%d) great than a page\n", reqlen); | |
10941 | return -ENOMEM; | |
10942 | } | |
10943 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
10944 | if (!mbox) { | |
10945 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10946 | "0283 Failed to allocate mbox cmd memory\n"); | |
10947 | return -ENOMEM; | |
10948 | } | |
10949 | ||
10950 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
10951 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
10952 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | |
10953 | LPFC_SLI4_MBX_NEMBED); | |
10954 | ||
10955 | if (alloclen < reqlen) { | |
10956 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10957 | "2561 Allocated DMA memory size (%d) is " | |
10958 | "less than the requested DMA memory " | |
10959 | "size (%d)\n", alloclen, reqlen); | |
10960 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
10961 | return -ENOMEM; | |
10962 | } | |
4f774513 | 10963 | /* Get the first SGE entry from the non-embedded DMA memory */ |
4f774513 JS |
10964 | viraddr = mbox->sge_array->addr[0]; |
10965 | ||
10966 | /* Set up the SGL pages in the non-embedded DMA pages */ | |
10967 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | |
10968 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | |
10969 | ||
10970 | pg_pairs = 0; | |
10971 | list_for_each_entry(psb, sblist, list) { | |
10972 | /* Set up the sge entry */ | |
10973 | sgl_pg_pairs->sgl_pg0_addr_lo = | |
10974 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | |
10975 | sgl_pg_pairs->sgl_pg0_addr_hi = | |
10976 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | |
10977 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | |
10978 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | |
10979 | else | |
10980 | pdma_phys_bpl1 = 0; | |
10981 | sgl_pg_pairs->sgl_pg1_addr_lo = | |
10982 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | |
10983 | sgl_pg_pairs->sgl_pg1_addr_hi = | |
10984 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | |
10985 | /* Keep the first xritag on the list */ | |
10986 | if (pg_pairs == 0) | |
10987 | xritag_start = psb->cur_iocbq.sli4_xritag; | |
10988 | sgl_pg_pairs++; | |
10989 | pg_pairs++; | |
10990 | } | |
10991 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | |
10992 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | |
10993 | /* Perform endian conversion if necessary */ | |
10994 | sgl->word0 = cpu_to_le32(sgl->word0); | |
10995 | ||
10996 | if (!phba->sli4_hba.intr_enable) | |
10997 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
10998 | else { | |
10999 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11000 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
11001 | } | |
11002 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | |
11003 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11004 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11005 | if (rc != MBX_TIMEOUT) | |
11006 | lpfc_sli4_mbox_cmd_free(phba, mbox); | |
11007 | if (shdr_status || shdr_add_status || rc) { | |
11008 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11009 | "2564 POST_SGL_BLOCK mailbox command failed " | |
11010 | "status x%x add_status x%x mbx status x%x\n", | |
11011 | shdr_status, shdr_add_status, rc); | |
11012 | rc = -ENXIO; | |
11013 | } | |
11014 | return rc; | |
11015 | } | |
11016 | ||
11017 | /** | |
11018 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | |
11019 | * @phba: pointer to lpfc_hba struct that the frame was received on | |
11020 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11021 | * | |
11022 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | |
11023 | * valid type of frame that the LPFC driver will handle. This function will | |
11024 | * return a zero if the frame is a valid frame or a non zero value when the | |
11025 | * frame does not pass the check. | |
11026 | **/ | |
11027 | static int | |
11028 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | |
11029 | { | |
11030 | char *rctl_names[] = FC_RCTL_NAMES_INIT; | |
11031 | char *type_names[] = FC_TYPE_NAMES_INIT; | |
11032 | struct fc_vft_header *fc_vft_hdr; | |
11033 | ||
11034 | switch (fc_hdr->fh_r_ctl) { | |
11035 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | |
11036 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | |
11037 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | |
11038 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | |
11039 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | |
11040 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | |
11041 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | |
11042 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | |
11043 | case FC_RCTL_ELS_REQ: /* extended link services request */ | |
11044 | case FC_RCTL_ELS_REP: /* extended link services reply */ | |
11045 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | |
11046 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | |
11047 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | |
11048 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | |
11049 | case FC_RCTL_BA_RMC: /* remove connection */ | |
11050 | case FC_RCTL_BA_ACC: /* basic accept */ | |
11051 | case FC_RCTL_BA_RJT: /* basic reject */ | |
11052 | case FC_RCTL_BA_PRMT: | |
11053 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | |
11054 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | |
11055 | case FC_RCTL_P_RJT: /* port reject */ | |
11056 | case FC_RCTL_F_RJT: /* fabric reject */ | |
11057 | case FC_RCTL_P_BSY: /* port busy */ | |
11058 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | |
11059 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | |
11060 | case FC_RCTL_LCR: /* link credit reset */ | |
11061 | case FC_RCTL_END: /* end */ | |
11062 | break; | |
11063 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | |
11064 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11065 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | |
11066 | return lpfc_fc_frame_check(phba, fc_hdr); | |
11067 | default: | |
11068 | goto drop; | |
11069 | } | |
11070 | switch (fc_hdr->fh_type) { | |
11071 | case FC_TYPE_BLS: | |
11072 | case FC_TYPE_ELS: | |
11073 | case FC_TYPE_FCP: | |
11074 | case FC_TYPE_CT: | |
11075 | break; | |
11076 | case FC_TYPE_IP: | |
11077 | case FC_TYPE_ILS: | |
11078 | default: | |
11079 | goto drop; | |
11080 | } | |
11081 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
11082 | "2538 Received frame rctl:%s type:%s\n", | |
11083 | rctl_names[fc_hdr->fh_r_ctl], | |
11084 | type_names[fc_hdr->fh_type]); | |
11085 | return 0; | |
11086 | drop: | |
11087 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11088 | "2539 Dropped frame rctl:%s type:%s\n", | |
11089 | rctl_names[fc_hdr->fh_r_ctl], | |
11090 | type_names[fc_hdr->fh_type]); | |
11091 | return 1; | |
11092 | } | |
11093 | ||
11094 | /** | |
11095 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | |
11096 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11097 | * | |
11098 | * This function processes the FC header to retrieve the VFI from the VF | |
11099 | * header, if one exists. This function will return the VFI if one exists | |
11100 | * or 0 if no VSAN Header exists. | |
11101 | **/ | |
11102 | static uint32_t | |
11103 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | |
11104 | { | |
11105 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | |
11106 | ||
11107 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | |
11108 | return 0; | |
11109 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | |
11110 | } | |
11111 | ||
11112 | /** | |
11113 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | |
11114 | * @phba: Pointer to the HBA structure to search for the vport on | |
11115 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | |
11116 | * @fcfi: The FC Fabric ID that the frame came from | |
11117 | * | |
11118 | * This function searches the @phba for a vport that matches the content of the | |
11119 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | |
11120 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | |
11121 | * returns the matching vport pointer or NULL if unable to match frame to a | |
11122 | * vport. | |
11123 | **/ | |
11124 | static struct lpfc_vport * | |
11125 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | |
11126 | uint16_t fcfi) | |
11127 | { | |
11128 | struct lpfc_vport **vports; | |
11129 | struct lpfc_vport *vport = NULL; | |
11130 | int i; | |
11131 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | |
11132 | fc_hdr->fh_d_id[1] << 8 | | |
11133 | fc_hdr->fh_d_id[2]); | |
11134 | ||
11135 | vports = lpfc_create_vport_work_array(phba); | |
11136 | if (vports != NULL) | |
11137 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | |
11138 | if (phba->fcf.fcfi == fcfi && | |
11139 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | |
11140 | vports[i]->fc_myDID == did) { | |
11141 | vport = vports[i]; | |
11142 | break; | |
11143 | } | |
11144 | } | |
11145 | lpfc_destroy_vport_work_array(phba, vports); | |
11146 | return vport; | |
11147 | } | |
11148 | ||
45ed1190 JS |
11149 | /** |
11150 | * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp | |
11151 | * @vport: The vport to work on. | |
11152 | * | |
11153 | * This function updates the receive sequence time stamp for this vport. The | |
11154 | * receive sequence time stamp indicates the time that the last frame of the | |
11155 | * the sequence that has been idle for the longest amount of time was received. | |
11156 | * the driver uses this time stamp to indicate if any received sequences have | |
11157 | * timed out. | |
11158 | **/ | |
11159 | void | |
11160 | lpfc_update_rcv_time_stamp(struct lpfc_vport *vport) | |
11161 | { | |
11162 | struct lpfc_dmabuf *h_buf; | |
11163 | struct hbq_dmabuf *dmabuf = NULL; | |
11164 | ||
11165 | /* get the oldest sequence on the rcv list */ | |
11166 | h_buf = list_get_first(&vport->rcv_buffer_list, | |
11167 | struct lpfc_dmabuf, list); | |
11168 | if (!h_buf) | |
11169 | return; | |
11170 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11171 | vport->rcv_buffer_time_stamp = dmabuf->time_stamp; | |
11172 | } | |
11173 | ||
11174 | /** | |
11175 | * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences. | |
11176 | * @vport: The vport that the received sequences were sent to. | |
11177 | * | |
11178 | * This function cleans up all outstanding received sequences. This is called | |
11179 | * by the driver when a link event or user action invalidates all the received | |
11180 | * sequences. | |
11181 | **/ | |
11182 | void | |
11183 | lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport) | |
11184 | { | |
11185 | struct lpfc_dmabuf *h_buf, *hnext; | |
11186 | struct lpfc_dmabuf *d_buf, *dnext; | |
11187 | struct hbq_dmabuf *dmabuf = NULL; | |
11188 | ||
11189 | /* start with the oldest sequence on the rcv list */ | |
11190 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11191 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11192 | list_del_init(&dmabuf->hbuf.list); | |
11193 | list_for_each_entry_safe(d_buf, dnext, | |
11194 | &dmabuf->dbuf.list, list) { | |
11195 | list_del_init(&d_buf->list); | |
11196 | lpfc_in_buf_free(vport->phba, d_buf); | |
11197 | } | |
11198 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11199 | } | |
11200 | } | |
11201 | ||
11202 | /** | |
11203 | * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences. | |
11204 | * @vport: The vport that the received sequences were sent to. | |
11205 | * | |
11206 | * This function determines whether any received sequences have timed out by | |
11207 | * first checking the vport's rcv_buffer_time_stamp. If this time_stamp | |
11208 | * indicates that there is at least one timed out sequence this routine will | |
11209 | * go through the received sequences one at a time from most inactive to most | |
11210 | * active to determine which ones need to be cleaned up. Once it has determined | |
11211 | * that a sequence needs to be cleaned up it will simply free up the resources | |
11212 | * without sending an abort. | |
11213 | **/ | |
11214 | void | |
11215 | lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport) | |
11216 | { | |
11217 | struct lpfc_dmabuf *h_buf, *hnext; | |
11218 | struct lpfc_dmabuf *d_buf, *dnext; | |
11219 | struct hbq_dmabuf *dmabuf = NULL; | |
11220 | unsigned long timeout; | |
11221 | int abort_count = 0; | |
11222 | ||
11223 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11224 | vport->rcv_buffer_time_stamp); | |
11225 | if (list_empty(&vport->rcv_buffer_list) || | |
11226 | time_before(jiffies, timeout)) | |
11227 | return; | |
11228 | /* start with the oldest sequence on the rcv list */ | |
11229 | list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) { | |
11230 | dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11231 | timeout = (msecs_to_jiffies(vport->phba->fc_edtov) + | |
11232 | dmabuf->time_stamp); | |
11233 | if (time_before(jiffies, timeout)) | |
11234 | break; | |
11235 | abort_count++; | |
11236 | list_del_init(&dmabuf->hbuf.list); | |
11237 | list_for_each_entry_safe(d_buf, dnext, | |
11238 | &dmabuf->dbuf.list, list) { | |
11239 | list_del_init(&d_buf->list); | |
11240 | lpfc_in_buf_free(vport->phba, d_buf); | |
11241 | } | |
11242 | lpfc_in_buf_free(vport->phba, &dmabuf->dbuf); | |
11243 | } | |
11244 | if (abort_count) | |
11245 | lpfc_update_rcv_time_stamp(vport); | |
11246 | } | |
11247 | ||
4f774513 JS |
11248 | /** |
11249 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | |
11250 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | |
11251 | * | |
11252 | * This function searches through the existing incomplete sequences that have | |
11253 | * been sent to this @vport. If the frame matches one of the incomplete | |
11254 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | |
11255 | * make up that sequence. If no sequence is found that matches this frame then | |
11256 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | |
11257 | * This function returns a pointer to the first dmabuf in the sequence list that | |
11258 | * the frame was linked to. | |
11259 | **/ | |
11260 | static struct hbq_dmabuf * | |
11261 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | |
11262 | { | |
11263 | struct fc_frame_header *new_hdr; | |
11264 | struct fc_frame_header *temp_hdr; | |
11265 | struct lpfc_dmabuf *d_buf; | |
11266 | struct lpfc_dmabuf *h_buf; | |
11267 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
11268 | struct hbq_dmabuf *temp_dmabuf = NULL; | |
11269 | ||
4d9ab994 | 11270 | INIT_LIST_HEAD(&dmabuf->dbuf.list); |
45ed1190 | 11271 | dmabuf->time_stamp = jiffies; |
4f774513 JS |
11272 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
11273 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | |
11274 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
11275 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
11276 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
11277 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
11278 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
11279 | continue; | |
11280 | /* found a pending sequence that matches this frame */ | |
11281 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11282 | break; | |
11283 | } | |
11284 | if (!seq_dmabuf) { | |
11285 | /* | |
11286 | * This indicates first frame received for this sequence. | |
11287 | * Queue the buffer on the vport's rcv_buffer_list. | |
11288 | */ | |
11289 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
45ed1190 | 11290 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
11291 | return dmabuf; |
11292 | } | |
11293 | temp_hdr = seq_dmabuf->hbuf.virt; | |
eeead811 JS |
11294 | if (be16_to_cpu(new_hdr->fh_seq_cnt) < |
11295 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4d9ab994 JS |
11296 | list_del_init(&seq_dmabuf->hbuf.list); |
11297 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
11298 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
45ed1190 | 11299 | lpfc_update_rcv_time_stamp(vport); |
4f774513 JS |
11300 | return dmabuf; |
11301 | } | |
45ed1190 JS |
11302 | /* move this sequence to the tail to indicate a young sequence */ |
11303 | list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list); | |
11304 | seq_dmabuf->time_stamp = jiffies; | |
11305 | lpfc_update_rcv_time_stamp(vport); | |
eeead811 JS |
11306 | if (list_empty(&seq_dmabuf->dbuf.list)) { |
11307 | temp_hdr = dmabuf->hbuf.virt; | |
11308 | list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list); | |
11309 | return seq_dmabuf; | |
11310 | } | |
4f774513 JS |
11311 | /* find the correct place in the sequence to insert this frame */ |
11312 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | |
11313 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
11314 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | |
11315 | /* | |
11316 | * If the frame's sequence count is greater than the frame on | |
11317 | * the list then insert the frame right after this frame | |
11318 | */ | |
eeead811 JS |
11319 | if (be16_to_cpu(new_hdr->fh_seq_cnt) > |
11320 | be16_to_cpu(temp_hdr->fh_seq_cnt)) { | |
4f774513 JS |
11321 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); |
11322 | return seq_dmabuf; | |
11323 | } | |
11324 | } | |
11325 | return NULL; | |
11326 | } | |
11327 | ||
6669f9bb JS |
11328 | /** |
11329 | * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence | |
11330 | * @vport: pointer to a vitural port | |
11331 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
11332 | * | |
11333 | * This function tries to abort from the partially assembed sequence, described | |
11334 | * by the information from basic abbort @dmabuf. It checks to see whether such | |
11335 | * partially assembled sequence held by the driver. If so, it shall free up all | |
11336 | * the frames from the partially assembled sequence. | |
11337 | * | |
11338 | * Return | |
11339 | * true -- if there is matching partially assembled sequence present and all | |
11340 | * the frames freed with the sequence; | |
11341 | * false -- if there is no matching partially assembled sequence present so | |
11342 | * nothing got aborted in the lower layer driver | |
11343 | **/ | |
11344 | static bool | |
11345 | lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport, | |
11346 | struct hbq_dmabuf *dmabuf) | |
11347 | { | |
11348 | struct fc_frame_header *new_hdr; | |
11349 | struct fc_frame_header *temp_hdr; | |
11350 | struct lpfc_dmabuf *d_buf, *n_buf, *h_buf; | |
11351 | struct hbq_dmabuf *seq_dmabuf = NULL; | |
11352 | ||
11353 | /* Use the hdr_buf to find the sequence that matches this frame */ | |
11354 | INIT_LIST_HEAD(&dmabuf->dbuf.list); | |
11355 | INIT_LIST_HEAD(&dmabuf->hbuf.list); | |
11356 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
11357 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | |
11358 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | |
11359 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | |
11360 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | |
11361 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | |
11362 | continue; | |
11363 | /* found a pending sequence that matches this frame */ | |
11364 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | |
11365 | break; | |
11366 | } | |
11367 | ||
11368 | /* Free up all the frames from the partially assembled sequence */ | |
11369 | if (seq_dmabuf) { | |
11370 | list_for_each_entry_safe(d_buf, n_buf, | |
11371 | &seq_dmabuf->dbuf.list, list) { | |
11372 | list_del_init(&d_buf->list); | |
11373 | lpfc_in_buf_free(vport->phba, d_buf); | |
11374 | } | |
11375 | return true; | |
11376 | } | |
11377 | return false; | |
11378 | } | |
11379 | ||
11380 | /** | |
11381 | * lpfc_sli4_seq_abort_acc_cmpl - Accept seq abort iocb complete handler | |
11382 | * @phba: Pointer to HBA context object. | |
11383 | * @cmd_iocbq: pointer to the command iocbq structure. | |
11384 | * @rsp_iocbq: pointer to the response iocbq structure. | |
11385 | * | |
11386 | * This function handles the sequence abort accept iocb command complete | |
11387 | * event. It properly releases the memory allocated to the sequence abort | |
11388 | * accept iocb. | |
11389 | **/ | |
11390 | static void | |
11391 | lpfc_sli4_seq_abort_acc_cmpl(struct lpfc_hba *phba, | |
11392 | struct lpfc_iocbq *cmd_iocbq, | |
11393 | struct lpfc_iocbq *rsp_iocbq) | |
11394 | { | |
11395 | if (cmd_iocbq) | |
11396 | lpfc_sli_release_iocbq(phba, cmd_iocbq); | |
11397 | } | |
11398 | ||
11399 | /** | |
11400 | * lpfc_sli4_seq_abort_acc - Accept sequence abort | |
11401 | * @phba: Pointer to HBA context object. | |
11402 | * @fc_hdr: pointer to a FC frame header. | |
11403 | * | |
11404 | * This function sends a basic accept to a previous unsol sequence abort | |
11405 | * event after aborting the sequence handling. | |
11406 | **/ | |
11407 | static void | |
11408 | lpfc_sli4_seq_abort_acc(struct lpfc_hba *phba, | |
11409 | struct fc_frame_header *fc_hdr) | |
11410 | { | |
11411 | struct lpfc_iocbq *ctiocb = NULL; | |
11412 | struct lpfc_nodelist *ndlp; | |
5ffc266e JS |
11413 | uint16_t oxid, rxid; |
11414 | uint32_t sid, fctl; | |
6669f9bb JS |
11415 | IOCB_t *icmd; |
11416 | ||
11417 | if (!lpfc_is_link_up(phba)) | |
11418 | return; | |
11419 | ||
11420 | sid = sli4_sid_from_fc_hdr(fc_hdr); | |
11421 | oxid = be16_to_cpu(fc_hdr->fh_ox_id); | |
5ffc266e | 11422 | rxid = be16_to_cpu(fc_hdr->fh_rx_id); |
6669f9bb JS |
11423 | |
11424 | ndlp = lpfc_findnode_did(phba->pport, sid); | |
11425 | if (!ndlp) { | |
11426 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | |
11427 | "1268 Find ndlp returned NULL for oxid:x%x " | |
11428 | "SID:x%x\n", oxid, sid); | |
11429 | return; | |
11430 | } | |
11431 | ||
11432 | /* Allocate buffer for acc iocb */ | |
11433 | ctiocb = lpfc_sli_get_iocbq(phba); | |
11434 | if (!ctiocb) | |
11435 | return; | |
11436 | ||
5ffc266e JS |
11437 | /* Extract the F_CTL field from FC_HDR */ |
11438 | fctl = sli4_fctl_from_fc_hdr(fc_hdr); | |
11439 | ||
6669f9bb | 11440 | icmd = &ctiocb->iocb; |
6669f9bb | 11441 | icmd->un.xseq64.bdl.bdeSize = 0; |
5ffc266e | 11442 | icmd->un.xseq64.bdl.ulpIoTag32 = 0; |
6669f9bb JS |
11443 | icmd->un.xseq64.w5.hcsw.Dfctl = 0; |
11444 | icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_BA_ACC; | |
11445 | icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_BLS; | |
11446 | ||
11447 | /* Fill in the rest of iocb fields */ | |
11448 | icmd->ulpCommand = CMD_XMIT_BLS_RSP64_CX; | |
11449 | icmd->ulpBdeCount = 0; | |
11450 | icmd->ulpLe = 1; | |
11451 | icmd->ulpClass = CLASS3; | |
11452 | icmd->ulpContext = ndlp->nlp_rpi; | |
6669f9bb | 11453 | |
6669f9bb JS |
11454 | ctiocb->iocb_cmpl = NULL; |
11455 | ctiocb->vport = phba->pport; | |
11456 | ctiocb->iocb_cmpl = lpfc_sli4_seq_abort_acc_cmpl; | |
11457 | ||
5ffc266e JS |
11458 | if (fctl & FC_FC_EX_CTX) { |
11459 | /* ABTS sent by responder to CT exchange, construction | |
11460 | * of BA_ACC will use OX_ID from ABTS for the XRI_TAG | |
11461 | * field and RX_ID from ABTS for RX_ID field. | |
11462 | */ | |
11463 | bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_RSP); | |
11464 | bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, rxid); | |
11465 | ctiocb->sli4_xritag = oxid; | |
11466 | } else { | |
11467 | /* ABTS sent by initiator to CT exchange, construction | |
11468 | * of BA_ACC will need to allocate a new XRI as for the | |
11469 | * XRI_TAG and RX_ID fields. | |
11470 | */ | |
11471 | bf_set(lpfc_abts_orig, &icmd->un.bls_acc, LPFC_ABTS_UNSOL_INT); | |
11472 | bf_set(lpfc_abts_rxid, &icmd->un.bls_acc, NO_XRI); | |
11473 | ctiocb->sli4_xritag = NO_XRI; | |
11474 | } | |
11475 | bf_set(lpfc_abts_oxid, &icmd->un.bls_acc, oxid); | |
11476 | ||
6669f9bb JS |
11477 | /* Xmit CT abts accept on exchange <xid> */ |
11478 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | |
11479 | "1200 Xmit CT ABTS ACC on exchange x%x Data: x%x\n", | |
11480 | CMD_XMIT_BLS_RSP64_CX, phba->link_state); | |
11481 | lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0); | |
11482 | } | |
11483 | ||
11484 | /** | |
11485 | * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event | |
11486 | * @vport: Pointer to the vport on which this sequence was received | |
11487 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
11488 | * | |
11489 | * This function handles an SLI-4 unsolicited abort event. If the unsolicited | |
11490 | * receive sequence is only partially assembed by the driver, it shall abort | |
11491 | * the partially assembled frames for the sequence. Otherwise, if the | |
11492 | * unsolicited receive sequence has been completely assembled and passed to | |
11493 | * the Upper Layer Protocol (UPL), it then mark the per oxid status for the | |
11494 | * unsolicited sequence has been aborted. After that, it will issue a basic | |
11495 | * accept to accept the abort. | |
11496 | **/ | |
11497 | void | |
11498 | lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport, | |
11499 | struct hbq_dmabuf *dmabuf) | |
11500 | { | |
11501 | struct lpfc_hba *phba = vport->phba; | |
11502 | struct fc_frame_header fc_hdr; | |
5ffc266e | 11503 | uint32_t fctl; |
6669f9bb JS |
11504 | bool abts_par; |
11505 | ||
6669f9bb JS |
11506 | /* Make a copy of fc_hdr before the dmabuf being released */ |
11507 | memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header)); | |
5ffc266e | 11508 | fctl = sli4_fctl_from_fc_hdr(&fc_hdr); |
6669f9bb | 11509 | |
5ffc266e JS |
11510 | if (fctl & FC_FC_EX_CTX) { |
11511 | /* | |
11512 | * ABTS sent by responder to exchange, just free the buffer | |
11513 | */ | |
6669f9bb | 11514 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
5ffc266e JS |
11515 | } else { |
11516 | /* | |
11517 | * ABTS sent by initiator to exchange, need to do cleanup | |
11518 | */ | |
11519 | /* Try to abort partially assembled seq */ | |
11520 | abts_par = lpfc_sli4_abort_partial_seq(vport, dmabuf); | |
11521 | ||
11522 | /* Send abort to ULP if partially seq abort failed */ | |
11523 | if (abts_par == false) | |
11524 | lpfc_sli4_send_seq_to_ulp(vport, dmabuf); | |
11525 | else | |
11526 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
11527 | } | |
6669f9bb JS |
11528 | /* Send basic accept (BA_ACC) to the abort requester */ |
11529 | lpfc_sli4_seq_abort_acc(phba, &fc_hdr); | |
11530 | } | |
11531 | ||
4f774513 JS |
11532 | /** |
11533 | * lpfc_seq_complete - Indicates if a sequence is complete | |
11534 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
11535 | * | |
11536 | * This function checks the sequence, starting with the frame described by | |
11537 | * @dmabuf, to see if all the frames associated with this sequence are present. | |
11538 | * the frames associated with this sequence are linked to the @dmabuf using the | |
11539 | * dbuf list. This function looks for two major things. 1) That the first frame | |
11540 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | |
11541 | * set. 3) That there are no holes in the sequence count. The function will | |
11542 | * return 1 when the sequence is complete, otherwise it will return 0. | |
11543 | **/ | |
11544 | static int | |
11545 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | |
11546 | { | |
11547 | struct fc_frame_header *hdr; | |
11548 | struct lpfc_dmabuf *d_buf; | |
11549 | struct hbq_dmabuf *seq_dmabuf; | |
11550 | uint32_t fctl; | |
11551 | int seq_count = 0; | |
11552 | ||
11553 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | |
11554 | /* make sure first fame of sequence has a sequence count of zero */ | |
11555 | if (hdr->fh_seq_cnt != seq_count) | |
11556 | return 0; | |
11557 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
11558 | hdr->fh_f_ctl[1] << 8 | | |
11559 | hdr->fh_f_ctl[2]); | |
11560 | /* If last frame of sequence we can return success. */ | |
11561 | if (fctl & FC_FC_END_SEQ) | |
11562 | return 1; | |
11563 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | |
11564 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | |
11565 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
11566 | /* If there is a hole in the sequence count then fail. */ | |
eeead811 | 11567 | if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt)) |
4f774513 JS |
11568 | return 0; |
11569 | fctl = (hdr->fh_f_ctl[0] << 16 | | |
11570 | hdr->fh_f_ctl[1] << 8 | | |
11571 | hdr->fh_f_ctl[2]); | |
11572 | /* If last frame of sequence we can return success. */ | |
11573 | if (fctl & FC_FC_END_SEQ) | |
11574 | return 1; | |
11575 | } | |
11576 | return 0; | |
11577 | } | |
11578 | ||
11579 | /** | |
11580 | * lpfc_prep_seq - Prep sequence for ULP processing | |
11581 | * @vport: Pointer to the vport on which this sequence was received | |
11582 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | |
11583 | * | |
11584 | * This function takes a sequence, described by a list of frames, and creates | |
11585 | * a list of iocbq structures to describe the sequence. This iocbq list will be | |
11586 | * used to issue to the generic unsolicited sequence handler. This routine | |
11587 | * returns a pointer to the first iocbq in the list. If the function is unable | |
11588 | * to allocate an iocbq then it throw out the received frames that were not | |
11589 | * able to be described and return a pointer to the first iocbq. If unable to | |
11590 | * allocate any iocbqs (including the first) this function will return NULL. | |
11591 | **/ | |
11592 | static struct lpfc_iocbq * | |
11593 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | |
11594 | { | |
11595 | struct lpfc_dmabuf *d_buf, *n_buf; | |
11596 | struct lpfc_iocbq *first_iocbq, *iocbq; | |
11597 | struct fc_frame_header *fc_hdr; | |
11598 | uint32_t sid; | |
eeead811 | 11599 | struct ulp_bde64 *pbde; |
4f774513 JS |
11600 | |
11601 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
11602 | /* remove from receive buffer list */ | |
11603 | list_del_init(&seq_dmabuf->hbuf.list); | |
45ed1190 | 11604 | lpfc_update_rcv_time_stamp(vport); |
4f774513 | 11605 | /* get the Remote Port's SID */ |
6669f9bb | 11606 | sid = sli4_sid_from_fc_hdr(fc_hdr); |
4f774513 JS |
11607 | /* Get an iocbq struct to fill in. */ |
11608 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | |
11609 | if (first_iocbq) { | |
11610 | /* Initialize the first IOCB. */ | |
8fa38513 | 11611 | first_iocbq->iocb.unsli3.rcvsli3.acc_len = 0; |
4f774513 JS |
11612 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; |
11613 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | |
11614 | first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id); | |
11615 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | |
11616 | vport->vpi + vport->phba->vpi_base; | |
11617 | /* put the first buffer into the first IOCBq */ | |
11618 | first_iocbq->context2 = &seq_dmabuf->dbuf; | |
11619 | first_iocbq->context3 = NULL; | |
11620 | first_iocbq->iocb.ulpBdeCount = 1; | |
11621 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
11622 | LPFC_DATA_BUF_SIZE; | |
11623 | first_iocbq->iocb.un.rcvels.remoteID = sid; | |
8fa38513 | 11624 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
11625 | bf_get(lpfc_rcqe_length, |
11626 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
11627 | } |
11628 | iocbq = first_iocbq; | |
11629 | /* | |
11630 | * Each IOCBq can have two Buffers assigned, so go through the list | |
11631 | * of buffers for this sequence and save two buffers in each IOCBq | |
11632 | */ | |
11633 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | |
11634 | if (!iocbq) { | |
11635 | lpfc_in_buf_free(vport->phba, d_buf); | |
11636 | continue; | |
11637 | } | |
11638 | if (!iocbq->context3) { | |
11639 | iocbq->context3 = d_buf; | |
11640 | iocbq->iocb.ulpBdeCount++; | |
eeead811 JS |
11641 | pbde = (struct ulp_bde64 *) |
11642 | &iocbq->iocb.unsli3.sli3Words[4]; | |
11643 | pbde->tus.f.bdeSize = LPFC_DATA_BUF_SIZE; | |
8fa38513 | 11644 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
11645 | bf_get(lpfc_rcqe_length, |
11646 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
11647 | } else { |
11648 | iocbq = lpfc_sli_get_iocbq(vport->phba); | |
11649 | if (!iocbq) { | |
11650 | if (first_iocbq) { | |
11651 | first_iocbq->iocb.ulpStatus = | |
11652 | IOSTAT_FCP_RSP_ERROR; | |
11653 | first_iocbq->iocb.un.ulpWord[4] = | |
11654 | IOERR_NO_RESOURCES; | |
11655 | } | |
11656 | lpfc_in_buf_free(vport->phba, d_buf); | |
11657 | continue; | |
11658 | } | |
11659 | iocbq->context2 = d_buf; | |
11660 | iocbq->context3 = NULL; | |
11661 | iocbq->iocb.ulpBdeCount = 1; | |
11662 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | |
11663 | LPFC_DATA_BUF_SIZE; | |
8fa38513 | 11664 | first_iocbq->iocb.unsli3.rcvsli3.acc_len += |
4d9ab994 JS |
11665 | bf_get(lpfc_rcqe_length, |
11666 | &seq_dmabuf->cq_event.cqe.rcqe_cmpl); | |
4f774513 JS |
11667 | iocbq->iocb.un.rcvels.remoteID = sid; |
11668 | list_add_tail(&iocbq->list, &first_iocbq->list); | |
11669 | } | |
11670 | } | |
11671 | return first_iocbq; | |
11672 | } | |
11673 | ||
6669f9bb JS |
11674 | static void |
11675 | lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport, | |
11676 | struct hbq_dmabuf *seq_dmabuf) | |
11677 | { | |
11678 | struct fc_frame_header *fc_hdr; | |
11679 | struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb; | |
11680 | struct lpfc_hba *phba = vport->phba; | |
11681 | ||
11682 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | |
11683 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | |
11684 | if (!iocbq) { | |
11685 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11686 | "2707 Ring %d handler: Failed to allocate " | |
11687 | "iocb Rctl x%x Type x%x received\n", | |
11688 | LPFC_ELS_RING, | |
11689 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
11690 | return; | |
11691 | } | |
11692 | if (!lpfc_complete_unsol_iocb(phba, | |
11693 | &phba->sli.ring[LPFC_ELS_RING], | |
11694 | iocbq, fc_hdr->fh_r_ctl, | |
11695 | fc_hdr->fh_type)) | |
11696 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
11697 | "2540 Ring %d handler: unexpected Rctl " | |
11698 | "x%x Type x%x received\n", | |
11699 | LPFC_ELS_RING, | |
11700 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | |
11701 | ||
11702 | /* Free iocb created in lpfc_prep_seq */ | |
11703 | list_for_each_entry_safe(curr_iocb, next_iocb, | |
11704 | &iocbq->list, list) { | |
11705 | list_del_init(&curr_iocb->list); | |
11706 | lpfc_sli_release_iocbq(phba, curr_iocb); | |
11707 | } | |
11708 | lpfc_sli_release_iocbq(phba, iocbq); | |
11709 | } | |
11710 | ||
4f774513 JS |
11711 | /** |
11712 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | |
11713 | * @phba: Pointer to HBA context object. | |
11714 | * | |
11715 | * This function is called with no lock held. This function processes all | |
11716 | * the received buffers and gives it to upper layers when a received buffer | |
11717 | * indicates that it is the final frame in the sequence. The interrupt | |
11718 | * service routine processes received buffers at interrupt contexts and adds | |
11719 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | |
11720 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | |
11721 | * appropriate receive function when the final frame in a sequence is received. | |
11722 | **/ | |
4d9ab994 JS |
11723 | void |
11724 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba, | |
11725 | struct hbq_dmabuf *dmabuf) | |
4f774513 | 11726 | { |
4d9ab994 | 11727 | struct hbq_dmabuf *seq_dmabuf; |
4f774513 JS |
11728 | struct fc_frame_header *fc_hdr; |
11729 | struct lpfc_vport *vport; | |
11730 | uint32_t fcfi; | |
4f774513 | 11731 | |
4f774513 | 11732 | /* Process each received buffer */ |
4d9ab994 JS |
11733 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; |
11734 | /* check to see if this a valid type of frame */ | |
11735 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | |
11736 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
11737 | return; | |
11738 | } | |
11739 | fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->cq_event.cqe.rcqe_cmpl); | |
11740 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); | |
c868595d | 11741 | if (!vport || !(vport->vpi_state & LPFC_VPI_REGISTERED)) { |
4d9ab994 JS |
11742 | /* throw out the frame */ |
11743 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
11744 | return; | |
11745 | } | |
6669f9bb JS |
11746 | /* Handle the basic abort sequence (BA_ABTS) event */ |
11747 | if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
11748 | lpfc_sli4_handle_unsol_abort(vport, dmabuf); | |
11749 | return; | |
11750 | } | |
11751 | ||
4d9ab994 JS |
11752 | /* Link this frame */ |
11753 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | |
11754 | if (!seq_dmabuf) { | |
11755 | /* unable to add frame to vport - throw it out */ | |
11756 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
11757 | return; | |
11758 | } | |
11759 | /* If not last frame in sequence continue processing frames. */ | |
def9c7a9 | 11760 | if (!lpfc_seq_complete(seq_dmabuf)) |
4d9ab994 | 11761 | return; |
def9c7a9 | 11762 | |
6669f9bb JS |
11763 | /* Send the complete sequence to the upper layer protocol */ |
11764 | lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf); | |
4f774513 | 11765 | } |
6fb120a7 JS |
11766 | |
11767 | /** | |
11768 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | |
11769 | * @phba: pointer to lpfc hba data structure. | |
11770 | * | |
11771 | * This routine is invoked to post rpi header templates to the | |
11772 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
11773 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
11774 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
11775 | * |
11776 | * This routine does not require any locks. It's usage is expected | |
11777 | * to be driver load or reset recovery when the driver is | |
11778 | * sequential. | |
11779 | * | |
11780 | * Return codes | |
af901ca1 | 11781 | * 0 - successful |
6fb120a7 JS |
11782 | * EIO - The mailbox failed to complete successfully. |
11783 | * When this error occurs, the driver is not guaranteed | |
11784 | * to have any rpi regions posted to the device and | |
11785 | * must either attempt to repost the regions or take a | |
11786 | * fatal error. | |
11787 | **/ | |
11788 | int | |
11789 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | |
11790 | { | |
11791 | struct lpfc_rpi_hdr *rpi_page; | |
11792 | uint32_t rc = 0; | |
11793 | ||
11794 | /* Post all rpi memory regions to the port. */ | |
11795 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
11796 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); | |
11797 | if (rc != MBX_SUCCESS) { | |
11798 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11799 | "2008 Error %d posting all rpi " | |
11800 | "headers\n", rc); | |
11801 | rc = -EIO; | |
11802 | break; | |
11803 | } | |
11804 | } | |
11805 | ||
11806 | return rc; | |
11807 | } | |
11808 | ||
11809 | /** | |
11810 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | |
11811 | * @phba: pointer to lpfc hba data structure. | |
11812 | * @rpi_page: pointer to the rpi memory region. | |
11813 | * | |
11814 | * This routine is invoked to post a single rpi header to the | |
11815 | * HBA consistent with the SLI-4 interface spec. This memory region | |
11816 | * maps up to 64 rpi context regions. | |
11817 | * | |
11818 | * Return codes | |
af901ca1 | 11819 | * 0 - successful |
6fb120a7 JS |
11820 | * ENOMEM - No available memory |
11821 | * EIO - The mailbox failed to complete successfully. | |
11822 | **/ | |
11823 | int | |
11824 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | |
11825 | { | |
11826 | LPFC_MBOXQ_t *mboxq; | |
11827 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | |
11828 | uint32_t rc = 0; | |
11829 | uint32_t mbox_tmo; | |
11830 | uint32_t shdr_status, shdr_add_status; | |
11831 | union lpfc_sli4_cfg_shdr *shdr; | |
11832 | ||
11833 | /* The port is notified of the header region via a mailbox command. */ | |
11834 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11835 | if (!mboxq) { | |
11836 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11837 | "2001 Unable to allocate memory for issuing " | |
11838 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
11839 | return -ENOMEM; | |
11840 | } | |
11841 | ||
11842 | /* Post all rpi memory regions to the port. */ | |
11843 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | |
11844 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
11845 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
11846 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | |
11847 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | |
11848 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | |
11849 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, | |
11850 | hdr_tmpl, rpi_page->page_count); | |
11851 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, | |
11852 | rpi_page->start_rpi); | |
11853 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); | |
11854 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | |
f1126688 | 11855 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
6fb120a7 JS |
11856 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; |
11857 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
11858 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
11859 | if (rc != MBX_TIMEOUT) | |
11860 | mempool_free(mboxq, phba->mbox_mem_pool); | |
11861 | if (shdr_status || shdr_add_status || rc) { | |
11862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11863 | "2514 POST_RPI_HDR mailbox failed with " | |
11864 | "status x%x add_status x%x, mbx status x%x\n", | |
11865 | shdr_status, shdr_add_status, rc); | |
11866 | rc = -ENXIO; | |
11867 | } | |
11868 | return rc; | |
11869 | } | |
11870 | ||
11871 | /** | |
11872 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | |
11873 | * @phba: pointer to lpfc hba data structure. | |
11874 | * | |
11875 | * This routine is invoked to post rpi header templates to the | |
11876 | * HBA consistent with the SLI-4 interface spec. This routine | |
49198b37 JS |
11877 | * posts a SLI4_PAGE_SIZE memory region to the port to hold up to |
11878 | * SLI4_PAGE_SIZE modulo 64 rpi context headers. | |
6fb120a7 JS |
11879 | * |
11880 | * Returns | |
af901ca1 | 11881 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful |
6fb120a7 JS |
11882 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. |
11883 | **/ | |
11884 | int | |
11885 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | |
11886 | { | |
11887 | int rpi; | |
11888 | uint16_t max_rpi, rpi_base, rpi_limit; | |
11889 | uint16_t rpi_remaining; | |
11890 | struct lpfc_rpi_hdr *rpi_hdr; | |
11891 | ||
11892 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | |
11893 | rpi_base = phba->sli4_hba.max_cfg_param.rpi_base; | |
11894 | rpi_limit = phba->sli4_hba.next_rpi; | |
11895 | ||
11896 | /* | |
11897 | * The valid rpi range is not guaranteed to be zero-based. Start | |
11898 | * the search at the rpi_base as reported by the port. | |
11899 | */ | |
11900 | spin_lock_irq(&phba->hbalock); | |
11901 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base); | |
11902 | if (rpi >= rpi_limit || rpi < rpi_base) | |
11903 | rpi = LPFC_RPI_ALLOC_ERROR; | |
11904 | else { | |
11905 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | |
11906 | phba->sli4_hba.max_cfg_param.rpi_used++; | |
11907 | phba->sli4_hba.rpi_count++; | |
11908 | } | |
11909 | ||
11910 | /* | |
11911 | * Don't try to allocate more rpi header regions if the device limit | |
11912 | * on available rpis max has been exhausted. | |
11913 | */ | |
11914 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | |
11915 | (phba->sli4_hba.rpi_count >= max_rpi)) { | |
11916 | spin_unlock_irq(&phba->hbalock); | |
11917 | return rpi; | |
11918 | } | |
11919 | ||
11920 | /* | |
11921 | * If the driver is running low on rpi resources, allocate another | |
11922 | * page now. Note that the next_rpi value is used because | |
11923 | * it represents how many are actually in use whereas max_rpi notes | |
11924 | * how many are supported max by the device. | |
11925 | */ | |
11926 | rpi_remaining = phba->sli4_hba.next_rpi - rpi_base - | |
11927 | phba->sli4_hba.rpi_count; | |
11928 | spin_unlock_irq(&phba->hbalock); | |
11929 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | |
11930 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
11931 | if (!rpi_hdr) { | |
11932 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11933 | "2002 Error Could not grow rpi " | |
11934 | "count\n"); | |
11935 | } else { | |
11936 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); | |
11937 | } | |
11938 | } | |
11939 | ||
11940 | return rpi; | |
11941 | } | |
11942 | ||
11943 | /** | |
11944 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | |
11945 | * @phba: pointer to lpfc hba data structure. | |
11946 | * | |
11947 | * This routine is invoked to release an rpi to the pool of | |
11948 | * available rpis maintained by the driver. | |
11949 | **/ | |
11950 | void | |
11951 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | |
11952 | { | |
11953 | spin_lock_irq(&phba->hbalock); | |
11954 | clear_bit(rpi, phba->sli4_hba.rpi_bmask); | |
11955 | phba->sli4_hba.rpi_count--; | |
11956 | phba->sli4_hba.max_cfg_param.rpi_used--; | |
11957 | spin_unlock_irq(&phba->hbalock); | |
11958 | } | |
11959 | ||
11960 | /** | |
11961 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | |
11962 | * @phba: pointer to lpfc hba data structure. | |
11963 | * | |
11964 | * This routine is invoked to remove the memory region that | |
11965 | * provided rpi via a bitmask. | |
11966 | **/ | |
11967 | void | |
11968 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | |
11969 | { | |
11970 | kfree(phba->sli4_hba.rpi_bmask); | |
11971 | } | |
11972 | ||
11973 | /** | |
11974 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | |
11975 | * @phba: pointer to lpfc hba data structure. | |
11976 | * | |
11977 | * This routine is invoked to remove the memory region that | |
11978 | * provided rpi via a bitmask. | |
11979 | **/ | |
11980 | int | |
11981 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | |
11982 | { | |
11983 | LPFC_MBOXQ_t *mboxq; | |
11984 | struct lpfc_hba *phba = ndlp->phba; | |
11985 | int rc; | |
11986 | ||
11987 | /* The port is notified of the header region via a mailbox command. */ | |
11988 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
11989 | if (!mboxq) | |
11990 | return -ENOMEM; | |
11991 | ||
11992 | /* Post all rpi memory regions to the port. */ | |
11993 | lpfc_resume_rpi(mboxq, ndlp); | |
11994 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
11995 | if (rc == MBX_NOT_FINISHED) { | |
11996 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
11997 | "2010 Resume RPI Mailbox failed " | |
11998 | "status %d, mbxStatus x%x\n", rc, | |
11999 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
12000 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12001 | return -EIO; | |
12002 | } | |
12003 | return 0; | |
12004 | } | |
12005 | ||
12006 | /** | |
12007 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | |
12008 | * @phba: pointer to lpfc hba data structure. | |
12009 | * @vpi: vpi value to activate with the port. | |
12010 | * | |
12011 | * This routine is invoked to activate a vpi with the | |
12012 | * port when the host intends to use vports with a | |
12013 | * nonzero vpi. | |
12014 | * | |
12015 | * Returns: | |
12016 | * 0 success | |
12017 | * -Evalue otherwise | |
12018 | **/ | |
12019 | int | |
12020 | lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi) | |
12021 | { | |
12022 | LPFC_MBOXQ_t *mboxq; | |
12023 | int rc = 0; | |
6a9c52cf | 12024 | int retval = MBX_SUCCESS; |
6fb120a7 JS |
12025 | uint32_t mbox_tmo; |
12026 | ||
12027 | if (vpi == 0) | |
12028 | return -EINVAL; | |
12029 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12030 | if (!mboxq) | |
12031 | return -ENOMEM; | |
1c6834a7 | 12032 | lpfc_init_vpi(phba, mboxq, vpi); |
6fb120a7 JS |
12033 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI); |
12034 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6fb120a7 JS |
12035 | if (rc != MBX_SUCCESS) { |
12036 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12037 | "2022 INIT VPI Mailbox failed " | |
12038 | "status %d, mbxStatus x%x\n", rc, | |
12039 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
6a9c52cf | 12040 | retval = -EIO; |
6fb120a7 | 12041 | } |
6a9c52cf JS |
12042 | if (rc != MBX_TIMEOUT) |
12043 | mempool_free(mboxq, phba->mbox_mem_pool); | |
12044 | ||
12045 | return retval; | |
6fb120a7 JS |
12046 | } |
12047 | ||
12048 | /** | |
12049 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | |
12050 | * @phba: pointer to lpfc hba data structure. | |
12051 | * @mboxq: Pointer to mailbox object. | |
12052 | * | |
12053 | * This routine is invoked to manually add a single FCF record. The caller | |
12054 | * must pass a completely initialized FCF_Record. This routine takes | |
12055 | * care of the nonembedded mailbox operations. | |
12056 | **/ | |
12057 | static void | |
12058 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
12059 | { | |
12060 | void *virt_addr; | |
12061 | union lpfc_sli4_cfg_shdr *shdr; | |
12062 | uint32_t shdr_status, shdr_add_status; | |
12063 | ||
12064 | virt_addr = mboxq->sge_array->addr[0]; | |
12065 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
12066 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | |
12067 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
12068 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
12069 | ||
12070 | if ((shdr_status || shdr_add_status) && | |
12071 | (shdr_status != STATUS_FCF_IN_USE)) | |
12072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12073 | "2558 ADD_FCF_RECORD mailbox failed with " | |
12074 | "status x%x add_status x%x\n", | |
12075 | shdr_status, shdr_add_status); | |
12076 | ||
12077 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12078 | } | |
12079 | ||
12080 | /** | |
12081 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | |
12082 | * @phba: pointer to lpfc hba data structure. | |
12083 | * @fcf_record: pointer to the initialized fcf record to add. | |
12084 | * | |
12085 | * This routine is invoked to manually add a single FCF record. The caller | |
12086 | * must pass a completely initialized FCF_Record. This routine takes | |
12087 | * care of the nonembedded mailbox operations. | |
12088 | **/ | |
12089 | int | |
12090 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | |
12091 | { | |
12092 | int rc = 0; | |
12093 | LPFC_MBOXQ_t *mboxq; | |
12094 | uint8_t *bytep; | |
12095 | void *virt_addr; | |
12096 | dma_addr_t phys_addr; | |
12097 | struct lpfc_mbx_sge sge; | |
12098 | uint32_t alloc_len, req_len; | |
12099 | uint32_t fcfindex; | |
12100 | ||
12101 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12102 | if (!mboxq) { | |
12103 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12104 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | |
12105 | return -ENOMEM; | |
12106 | } | |
12107 | ||
12108 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | |
12109 | sizeof(uint32_t); | |
12110 | ||
12111 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | |
12112 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12113 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | |
12114 | req_len, LPFC_SLI4_MBX_NEMBED); | |
12115 | if (alloc_len < req_len) { | |
12116 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12117 | "2523 Allocated DMA memory size (x%x) is " | |
12118 | "less than the requested DMA memory " | |
12119 | "size (x%x)\n", alloc_len, req_len); | |
12120 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12121 | return -ENOMEM; | |
12122 | } | |
12123 | ||
12124 | /* | |
12125 | * Get the first SGE entry from the non-embedded DMA memory. This | |
12126 | * routine only uses a single SGE. | |
12127 | */ | |
12128 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | |
12129 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | |
6fb120a7 JS |
12130 | virt_addr = mboxq->sge_array->addr[0]; |
12131 | /* | |
12132 | * Configure the FCF record for FCFI 0. This is the driver's | |
12133 | * hardcoded default and gets used in nonFIP mode. | |
12134 | */ | |
12135 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | |
12136 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | |
12137 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | |
12138 | ||
12139 | /* | |
12140 | * Copy the fcf_index and the FCF Record Data. The data starts after | |
12141 | * the FCoE header plus word10. The data copy needs to be endian | |
12142 | * correct. | |
12143 | */ | |
12144 | bytep += sizeof(uint32_t); | |
12145 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | |
12146 | mboxq->vport = phba->pport; | |
12147 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | |
12148 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12149 | if (rc == MBX_NOT_FINISHED) { | |
12150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12151 | "2515 ADD_FCF_RECORD mailbox failed with " | |
12152 | "status 0x%x\n", rc); | |
12153 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12154 | rc = -EIO; | |
12155 | } else | |
12156 | rc = 0; | |
12157 | ||
12158 | return rc; | |
12159 | } | |
12160 | ||
12161 | /** | |
12162 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | |
12163 | * @phba: pointer to lpfc hba data structure. | |
12164 | * @fcf_record: pointer to the fcf record to write the default data. | |
12165 | * @fcf_index: FCF table entry index. | |
12166 | * | |
12167 | * This routine is invoked to build the driver's default FCF record. The | |
12168 | * values used are hardcoded. This routine handles memory initialization. | |
12169 | * | |
12170 | **/ | |
12171 | void | |
12172 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | |
12173 | struct fcf_record *fcf_record, | |
12174 | uint16_t fcf_index) | |
12175 | { | |
12176 | memset(fcf_record, 0, sizeof(struct fcf_record)); | |
12177 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | |
12178 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | |
12179 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | |
12180 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | |
12181 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | |
12182 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | |
12183 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | |
12184 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | |
12185 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | |
12186 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | |
12187 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | |
12188 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | |
12189 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | |
0c287589 | 12190 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); |
6fb120a7 JS |
12191 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); |
12192 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | |
12193 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | |
12194 | /* Set the VLAN bit map */ | |
12195 | if (phba->valid_vlan) { | |
12196 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | |
12197 | = 1 << (phba->vlan_id % 8); | |
12198 | } | |
12199 | } | |
12200 | ||
12201 | /** | |
0c9ab6f5 | 12202 | * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan. |
6fb120a7 JS |
12203 | * @phba: pointer to lpfc hba data structure. |
12204 | * @fcf_index: FCF table entry offset. | |
12205 | * | |
0c9ab6f5 JS |
12206 | * This routine is invoked to scan the entire FCF table by reading FCF |
12207 | * record and processing it one at a time starting from the @fcf_index | |
12208 | * for initial FCF discovery or fast FCF failover rediscovery. | |
12209 | * | |
12210 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12211 | * otherwise. | |
6fb120a7 JS |
12212 | **/ |
12213 | int | |
0c9ab6f5 | 12214 | lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) |
6fb120a7 JS |
12215 | { |
12216 | int rc = 0, error; | |
12217 | LPFC_MBOXQ_t *mboxq; | |
6fb120a7 | 12218 | |
32b9793f | 12219 | phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; |
6fb120a7 JS |
12220 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12221 | if (!mboxq) { | |
12222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12223 | "2000 Failed to allocate mbox for " | |
12224 | "READ_FCF cmd\n"); | |
4d9ab994 | 12225 | error = -ENOMEM; |
0c9ab6f5 | 12226 | goto fail_fcf_scan; |
6fb120a7 | 12227 | } |
ecfd03c6 | 12228 | /* Construct the read FCF record mailbox command */ |
0c9ab6f5 | 12229 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); |
ecfd03c6 JS |
12230 | if (rc) { |
12231 | error = -EINVAL; | |
0c9ab6f5 | 12232 | goto fail_fcf_scan; |
6fb120a7 | 12233 | } |
ecfd03c6 | 12234 | /* Issue the mailbox command asynchronously */ |
6fb120a7 | 12235 | mboxq->vport = phba->pport; |
0c9ab6f5 | 12236 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec; |
6fb120a7 | 12237 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); |
ecfd03c6 | 12238 | if (rc == MBX_NOT_FINISHED) |
6fb120a7 | 12239 | error = -EIO; |
ecfd03c6 | 12240 | else { |
32b9793f JS |
12241 | spin_lock_irq(&phba->hbalock); |
12242 | phba->hba_flag |= FCF_DISC_INPROGRESS; | |
12243 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 12244 | /* Reset FCF round robin index bmask for new scan */ |
999d813f | 12245 | if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) { |
0c9ab6f5 JS |
12246 | memset(phba->fcf.fcf_rr_bmask, 0, |
12247 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
999d813f JS |
12248 | phba->fcf.eligible_fcf_cnt = 0; |
12249 | } | |
6fb120a7 | 12250 | error = 0; |
32b9793f | 12251 | } |
0c9ab6f5 | 12252 | fail_fcf_scan: |
4d9ab994 JS |
12253 | if (error) { |
12254 | if (mboxq) | |
12255 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12256 | /* FCF scan failed, clear FCF_DISC_INPROGRESS flag */ | |
12257 | spin_lock_irq(&phba->hbalock); | |
12258 | phba->hba_flag &= ~FCF_DISC_INPROGRESS; | |
12259 | spin_unlock_irq(&phba->hbalock); | |
12260 | } | |
6fb120a7 JS |
12261 | return error; |
12262 | } | |
a0c87cbd | 12263 | |
0c9ab6f5 JS |
12264 | /** |
12265 | * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for round robin fcf. | |
12266 | * @phba: pointer to lpfc hba data structure. | |
12267 | * @fcf_index: FCF table entry offset. | |
12268 | * | |
12269 | * This routine is invoked to read an FCF record indicated by @fcf_index | |
12270 | * and to use it for FLOGI round robin FCF failover. | |
12271 | * | |
12272 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12273 | * otherwise. | |
12274 | **/ | |
12275 | int | |
12276 | lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
12277 | { | |
12278 | int rc = 0, error; | |
12279 | LPFC_MBOXQ_t *mboxq; | |
12280 | ||
12281 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12282 | if (!mboxq) { | |
12283 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
12284 | "2763 Failed to allocate mbox for " | |
12285 | "READ_FCF cmd\n"); | |
12286 | error = -ENOMEM; | |
12287 | goto fail_fcf_read; | |
12288 | } | |
12289 | /* Construct the read FCF record mailbox command */ | |
12290 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
12291 | if (rc) { | |
12292 | error = -EINVAL; | |
12293 | goto fail_fcf_read; | |
12294 | } | |
12295 | /* Issue the mailbox command asynchronously */ | |
12296 | mboxq->vport = phba->pport; | |
12297 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec; | |
12298 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12299 | if (rc == MBX_NOT_FINISHED) | |
12300 | error = -EIO; | |
12301 | else | |
12302 | error = 0; | |
12303 | ||
12304 | fail_fcf_read: | |
12305 | if (error && mboxq) | |
12306 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12307 | return error; | |
12308 | } | |
12309 | ||
12310 | /** | |
12311 | * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask. | |
12312 | * @phba: pointer to lpfc hba data structure. | |
12313 | * @fcf_index: FCF table entry offset. | |
12314 | * | |
12315 | * This routine is invoked to read an FCF record indicated by @fcf_index to | |
12316 | * determine whether it's eligible for FLOGI round robin failover list. | |
12317 | * | |
12318 | * Return 0 if the mailbox command is submitted sucessfully, none 0 | |
12319 | * otherwise. | |
12320 | **/ | |
12321 | int | |
12322 | lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index) | |
12323 | { | |
12324 | int rc = 0, error; | |
12325 | LPFC_MBOXQ_t *mboxq; | |
12326 | ||
12327 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12328 | if (!mboxq) { | |
12329 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT, | |
12330 | "2758 Failed to allocate mbox for " | |
12331 | "READ_FCF cmd\n"); | |
12332 | error = -ENOMEM; | |
12333 | goto fail_fcf_read; | |
12334 | } | |
12335 | /* Construct the read FCF record mailbox command */ | |
12336 | rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index); | |
12337 | if (rc) { | |
12338 | error = -EINVAL; | |
12339 | goto fail_fcf_read; | |
12340 | } | |
12341 | /* Issue the mailbox command asynchronously */ | |
12342 | mboxq->vport = phba->pport; | |
12343 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec; | |
12344 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | |
12345 | if (rc == MBX_NOT_FINISHED) | |
12346 | error = -EIO; | |
12347 | else | |
12348 | error = 0; | |
12349 | ||
12350 | fail_fcf_read: | |
12351 | if (error && mboxq) | |
12352 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | |
12353 | return error; | |
12354 | } | |
12355 | ||
12356 | /** | |
12357 | * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index | |
12358 | * @phba: pointer to lpfc hba data structure. | |
12359 | * | |
12360 | * This routine is to get the next eligible FCF record index in a round | |
12361 | * robin fashion. If the next eligible FCF record index equals to the | |
12362 | * initial round robin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF) | |
12363 | * shall be returned, otherwise, the next eligible FCF record's index | |
12364 | * shall be returned. | |
12365 | **/ | |
12366 | uint16_t | |
12367 | lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba) | |
12368 | { | |
12369 | uint16_t next_fcf_index; | |
12370 | ||
12371 | /* Search from the currently registered FCF index */ | |
12372 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, | |
12373 | LPFC_SLI4_FCF_TBL_INDX_MAX, | |
12374 | phba->fcf.current_rec.fcf_indx); | |
12375 | /* Wrap around condition on phba->fcf.fcf_rr_bmask */ | |
12376 | if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) | |
12377 | next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask, | |
12378 | LPFC_SLI4_FCF_TBL_INDX_MAX, 0); | |
12379 | /* Round robin failover stop condition */ | |
12380 | if (next_fcf_index == phba->fcf.fcf_rr_init_indx) | |
12381 | return LPFC_FCOE_FCF_NEXT_NONE; | |
12382 | ||
12383 | return next_fcf_index; | |
12384 | } | |
12385 | ||
12386 | /** | |
12387 | * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index | |
12388 | * @phba: pointer to lpfc hba data structure. | |
12389 | * | |
12390 | * This routine sets the FCF record index in to the eligible bmask for | |
12391 | * round robin failover search. It checks to make sure that the index | |
12392 | * does not go beyond the range of the driver allocated bmask dimension | |
12393 | * before setting the bit. | |
12394 | * | |
12395 | * Returns 0 if the index bit successfully set, otherwise, it returns | |
12396 | * -EINVAL. | |
12397 | **/ | |
12398 | int | |
12399 | lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index) | |
12400 | { | |
12401 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12402 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
12403 | "2610 HBA FCF index reached driver's " | |
12404 | "book keeping dimension: fcf_index:%d, " | |
12405 | "driver_bmask_max:%d\n", | |
12406 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); | |
12407 | return -EINVAL; | |
12408 | } | |
12409 | /* Set the eligible FCF record index bmask */ | |
12410 | set_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
12411 | ||
12412 | return 0; | |
12413 | } | |
12414 | ||
12415 | /** | |
12416 | * lpfc_sli4_fcf_rr_index_set - Clear bmask from eligible fcf record index | |
12417 | * @phba: pointer to lpfc hba data structure. | |
12418 | * | |
12419 | * This routine clears the FCF record index from the eligible bmask for | |
12420 | * round robin failover search. It checks to make sure that the index | |
12421 | * does not go beyond the range of the driver allocated bmask dimension | |
12422 | * before clearing the bit. | |
12423 | **/ | |
12424 | void | |
12425 | lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index) | |
12426 | { | |
12427 | if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) { | |
12428 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, | |
12429 | "2762 HBA FCF index goes beyond driver's " | |
12430 | "book keeping dimension: fcf_index:%d, " | |
12431 | "driver_bmask_max:%d\n", | |
12432 | fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX); | |
12433 | return; | |
12434 | } | |
12435 | /* Clear the eligible FCF record index bmask */ | |
12436 | clear_bit(fcf_index, phba->fcf.fcf_rr_bmask); | |
12437 | } | |
12438 | ||
ecfd03c6 JS |
12439 | /** |
12440 | * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table | |
12441 | * @phba: pointer to lpfc hba data structure. | |
12442 | * | |
12443 | * This routine is the completion routine for the rediscover FCF table mailbox | |
12444 | * command. If the mailbox command returned failure, it will try to stop the | |
12445 | * FCF rediscover wait timer. | |
12446 | **/ | |
12447 | void | |
12448 | lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) | |
12449 | { | |
12450 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
12451 | uint32_t shdr_status, shdr_add_status; | |
12452 | ||
12453 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
12454 | ||
12455 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
12456 | &redisc_fcf->header.cfg_shdr.response); | |
12457 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
12458 | &redisc_fcf->header.cfg_shdr.response); | |
12459 | if (shdr_status || shdr_add_status) { | |
0c9ab6f5 | 12460 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP, |
ecfd03c6 JS |
12461 | "2746 Requesting for FCF rediscovery failed " |
12462 | "status x%x add_status x%x\n", | |
12463 | shdr_status, shdr_add_status); | |
0c9ab6f5 | 12464 | if (phba->fcf.fcf_flag & FCF_ACVL_DISC) { |
fc2b989b | 12465 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 12466 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b JS |
12467 | spin_unlock_irq(&phba->hbalock); |
12468 | /* | |
12469 | * CVL event triggered FCF rediscover request failed, | |
12470 | * last resort to re-try current registered FCF entry. | |
12471 | */ | |
12472 | lpfc_retry_pport_discovery(phba); | |
12473 | } else { | |
12474 | spin_lock_irq(&phba->hbalock); | |
0c9ab6f5 | 12475 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
12476 | spin_unlock_irq(&phba->hbalock); |
12477 | /* | |
12478 | * DEAD FCF event triggered FCF rediscover request | |
12479 | * failed, last resort to fail over as a link down | |
12480 | * to FCF registration. | |
12481 | */ | |
12482 | lpfc_sli4_fcf_dead_failthrough(phba); | |
12483 | } | |
0c9ab6f5 JS |
12484 | } else { |
12485 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, | |
12486 | "2775 Start FCF rediscovery quiescent period " | |
12487 | "wait timer before scaning FCF table\n"); | |
ecfd03c6 JS |
12488 | /* |
12489 | * Start FCF rediscovery wait timer for pending FCF | |
12490 | * before rescan FCF record table. | |
12491 | */ | |
12492 | lpfc_fcf_redisc_wait_start_timer(phba); | |
0c9ab6f5 | 12493 | } |
ecfd03c6 JS |
12494 | |
12495 | mempool_free(mbox, phba->mbox_mem_pool); | |
12496 | } | |
12497 | ||
12498 | /** | |
12499 | * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port. | |
12500 | * @phba: pointer to lpfc hba data structure. | |
12501 | * | |
12502 | * This routine is invoked to request for rediscovery of the entire FCF table | |
12503 | * by the port. | |
12504 | **/ | |
12505 | int | |
12506 | lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba) | |
12507 | { | |
12508 | LPFC_MBOXQ_t *mbox; | |
12509 | struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf; | |
12510 | int rc, length; | |
12511 | ||
0c9ab6f5 JS |
12512 | /* Cancel retry delay timers to all vports before FCF rediscover */ |
12513 | lpfc_cancel_all_vport_retry_delay_timer(phba); | |
12514 | ||
ecfd03c6 JS |
12515 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
12516 | if (!mbox) { | |
12517 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12518 | "2745 Failed to allocate mbox for " | |
12519 | "requesting FCF rediscover.\n"); | |
12520 | return -ENOMEM; | |
12521 | } | |
12522 | ||
12523 | length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) - | |
12524 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
12525 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | |
12526 | LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF, | |
12527 | length, LPFC_SLI4_MBX_EMBED); | |
12528 | ||
12529 | redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl; | |
12530 | /* Set count to 0 for invalidating the entire FCF database */ | |
12531 | bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0); | |
12532 | ||
12533 | /* Issue the mailbox command asynchronously */ | |
12534 | mbox->vport = phba->pport; | |
12535 | mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table; | |
12536 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); | |
12537 | ||
12538 | if (rc == MBX_NOT_FINISHED) { | |
12539 | mempool_free(mbox, phba->mbox_mem_pool); | |
12540 | return -EIO; | |
12541 | } | |
12542 | return 0; | |
12543 | } | |
12544 | ||
fc2b989b JS |
12545 | /** |
12546 | * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event | |
12547 | * @phba: pointer to lpfc hba data structure. | |
12548 | * | |
12549 | * This function is the failover routine as a last resort to the FCF DEAD | |
12550 | * event when driver failed to perform fast FCF failover. | |
12551 | **/ | |
12552 | void | |
12553 | lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba) | |
12554 | { | |
12555 | uint32_t link_state; | |
12556 | ||
12557 | /* | |
12558 | * Last resort as FCF DEAD event failover will treat this as | |
12559 | * a link down, but save the link state because we don't want | |
12560 | * it to be changed to Link Down unless it is already down. | |
12561 | */ | |
12562 | link_state = phba->link_state; | |
12563 | lpfc_linkdown(phba); | |
12564 | phba->link_state = link_state; | |
12565 | ||
12566 | /* Unregister FCF if no devices connected to it */ | |
12567 | lpfc_unregister_unused_fcf(phba); | |
12568 | } | |
12569 | ||
a0c87cbd JS |
12570 | /** |
12571 | * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. | |
12572 | * @phba: pointer to lpfc hba data structure. | |
12573 | * | |
12574 | * This function read region 23 and parse TLV for port status to | |
12575 | * decide if the user disaled the port. If the TLV indicates the | |
12576 | * port is disabled, the hba_flag is set accordingly. | |
12577 | **/ | |
12578 | void | |
12579 | lpfc_sli_read_link_ste(struct lpfc_hba *phba) | |
12580 | { | |
12581 | LPFC_MBOXQ_t *pmb = NULL; | |
12582 | MAILBOX_t *mb; | |
12583 | uint8_t *rgn23_data = NULL; | |
12584 | uint32_t offset = 0, data_size, sub_tlv_len, tlv_offset; | |
12585 | int rc; | |
12586 | ||
12587 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
12588 | if (!pmb) { | |
12589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12590 | "2600 lpfc_sli_read_serdes_param failed to" | |
12591 | " allocate mailbox memory\n"); | |
12592 | goto out; | |
12593 | } | |
12594 | mb = &pmb->u.mb; | |
12595 | ||
12596 | /* Get adapter Region 23 data */ | |
12597 | rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL); | |
12598 | if (!rgn23_data) | |
12599 | goto out; | |
12600 | ||
12601 | do { | |
12602 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23); | |
12603 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
12604 | ||
12605 | if (rc != MBX_SUCCESS) { | |
12606 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
12607 | "2601 lpfc_sli_read_link_ste failed to" | |
12608 | " read config region 23 rc 0x%x Status 0x%x\n", | |
12609 | rc, mb->mbxStatus); | |
12610 | mb->un.varDmp.word_cnt = 0; | |
12611 | } | |
12612 | /* | |
12613 | * dump mem may return a zero when finished or we got a | |
12614 | * mailbox error, either way we are done. | |
12615 | */ | |
12616 | if (mb->un.varDmp.word_cnt == 0) | |
12617 | break; | |
12618 | if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset) | |
12619 | mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset; | |
12620 | ||
12621 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | |
12622 | rgn23_data + offset, | |
12623 | mb->un.varDmp.word_cnt); | |
12624 | offset += mb->un.varDmp.word_cnt; | |
12625 | } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE); | |
12626 | ||
12627 | data_size = offset; | |
12628 | offset = 0; | |
12629 | ||
12630 | if (!data_size) | |
12631 | goto out; | |
12632 | ||
12633 | /* Check the region signature first */ | |
12634 | if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) { | |
12635 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12636 | "2619 Config region 23 has bad signature\n"); | |
12637 | goto out; | |
12638 | } | |
12639 | offset += 4; | |
12640 | ||
12641 | /* Check the data structure version */ | |
12642 | if (rgn23_data[offset] != LPFC_REGION23_VERSION) { | |
12643 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
12644 | "2620 Config region 23 has bad version\n"); | |
12645 | goto out; | |
12646 | } | |
12647 | offset += 4; | |
12648 | ||
12649 | /* Parse TLV entries in the region */ | |
12650 | while (offset < data_size) { | |
12651 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) | |
12652 | break; | |
12653 | /* | |
12654 | * If the TLV is not driver specific TLV or driver id is | |
12655 | * not linux driver id, skip the record. | |
12656 | */ | |
12657 | if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) || | |
12658 | (rgn23_data[offset + 2] != LINUX_DRIVER_ID) || | |
12659 | (rgn23_data[offset + 3] != 0)) { | |
12660 | offset += rgn23_data[offset + 1] * 4 + 4; | |
12661 | continue; | |
12662 | } | |
12663 | ||
12664 | /* Driver found a driver specific TLV in the config region */ | |
12665 | sub_tlv_len = rgn23_data[offset + 1] * 4; | |
12666 | offset += 4; | |
12667 | tlv_offset = 0; | |
12668 | ||
12669 | /* | |
12670 | * Search for configured port state sub-TLV. | |
12671 | */ | |
12672 | while ((offset < data_size) && | |
12673 | (tlv_offset < sub_tlv_len)) { | |
12674 | if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) { | |
12675 | offset += 4; | |
12676 | tlv_offset += 4; | |
12677 | break; | |
12678 | } | |
12679 | if (rgn23_data[offset] != PORT_STE_TYPE) { | |
12680 | offset += rgn23_data[offset + 1] * 4 + 4; | |
12681 | tlv_offset += rgn23_data[offset + 1] * 4 + 4; | |
12682 | continue; | |
12683 | } | |
12684 | ||
12685 | /* This HBA contains PORT_STE configured */ | |
12686 | if (!rgn23_data[offset + 2]) | |
12687 | phba->hba_flag |= LINK_DISABLED; | |
12688 | ||
12689 | goto out; | |
12690 | } | |
12691 | } | |
12692 | out: | |
12693 | if (pmb) | |
12694 | mempool_free(pmb, phba->mbox_mem_pool); | |
12695 | kfree(rgn23_data); | |
12696 | return; | |
12697 | } | |
695a814e JS |
12698 | |
12699 | /** | |
12700 | * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands. | |
12701 | * @vport: pointer to vport data structure. | |
12702 | * | |
12703 | * This function iterate through the mailboxq and clean up all REG_LOGIN | |
12704 | * and REG_VPI mailbox commands associated with the vport. This function | |
12705 | * is called when driver want to restart discovery of the vport due to | |
12706 | * a Clear Virtual Link event. | |
12707 | **/ | |
12708 | void | |
12709 | lpfc_cleanup_pending_mbox(struct lpfc_vport *vport) | |
12710 | { | |
12711 | struct lpfc_hba *phba = vport->phba; | |
12712 | LPFC_MBOXQ_t *mb, *nextmb; | |
12713 | struct lpfc_dmabuf *mp; | |
78730cfe | 12714 | struct lpfc_nodelist *ndlp; |
695a814e JS |
12715 | |
12716 | spin_lock_irq(&phba->hbalock); | |
12717 | list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) { | |
12718 | if (mb->vport != vport) | |
12719 | continue; | |
12720 | ||
12721 | if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) && | |
12722 | (mb->u.mb.mbxCommand != MBX_REG_VPI)) | |
12723 | continue; | |
12724 | ||
12725 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { | |
12726 | mp = (struct lpfc_dmabuf *) (mb->context1); | |
12727 | if (mp) { | |
12728 | __lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
12729 | kfree(mp); | |
12730 | } | |
78730cfe JS |
12731 | ndlp = (struct lpfc_nodelist *) mb->context2; |
12732 | if (ndlp) { | |
12733 | lpfc_nlp_put(ndlp); | |
12734 | mb->context2 = NULL; | |
12735 | } | |
695a814e JS |
12736 | } |
12737 | list_del(&mb->list); | |
12738 | mempool_free(mb, phba->mbox_mem_pool); | |
12739 | } | |
12740 | mb = phba->sli.mbox_active; | |
12741 | if (mb && (mb->vport == vport)) { | |
12742 | if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) || | |
12743 | (mb->u.mb.mbxCommand == MBX_REG_VPI)) | |
12744 | mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
78730cfe JS |
12745 | if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) { |
12746 | ndlp = (struct lpfc_nodelist *) mb->context2; | |
12747 | if (ndlp) { | |
12748 | lpfc_nlp_put(ndlp); | |
12749 | mb->context2 = NULL; | |
12750 | } | |
12751 | /* Unregister the RPI when mailbox complete */ | |
12752 | mb->mbox_flag |= LPFC_MBX_IMED_UNREG; | |
12753 | } | |
695a814e JS |
12754 | } |
12755 | spin_unlock_irq(&phba->hbalock); | |
12756 | } | |
12757 | ||
2a9bf3d0 JS |
12758 | /** |
12759 | * lpfc_drain_txq - Drain the txq | |
12760 | * @phba: Pointer to HBA context object. | |
12761 | * | |
12762 | * This function attempt to submit IOCBs on the txq | |
12763 | * to the adapter. For SLI4 adapters, the txq contains | |
12764 | * ELS IOCBs that have been deferred because the there | |
12765 | * are no SGLs. This congestion can occur with large | |
12766 | * vport counts during node discovery. | |
12767 | **/ | |
12768 | ||
12769 | uint32_t | |
12770 | lpfc_drain_txq(struct lpfc_hba *phba) | |
12771 | { | |
12772 | LIST_HEAD(completions); | |
12773 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | |
12774 | struct lpfc_iocbq *piocbq = 0; | |
12775 | unsigned long iflags = 0; | |
12776 | char *fail_msg = NULL; | |
12777 | struct lpfc_sglq *sglq; | |
12778 | union lpfc_wqe wqe; | |
12779 | ||
12780 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12781 | if (pring->txq_cnt > pring->txq_max) | |
12782 | pring->txq_max = pring->txq_cnt; | |
12783 | ||
12784 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12785 | ||
12786 | while (pring->txq_cnt) { | |
12787 | spin_lock_irqsave(&phba->hbalock, iflags); | |
12788 | ||
12789 | sglq = __lpfc_sli_get_sglq(phba); | |
12790 | if (!sglq) { | |
12791 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12792 | break; | |
12793 | } else { | |
12794 | piocbq = lpfc_sli_ringtx_get(phba, pring); | |
12795 | if (!piocbq) { | |
12796 | /* The txq_cnt out of sync. This should | |
12797 | * never happen | |
12798 | */ | |
12799 | sglq = __lpfc_clear_active_sglq(phba, | |
12800 | sglq->sli4_xritag); | |
12801 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12802 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12803 | "2823 txq empty and txq_cnt is %d\n ", | |
12804 | pring->txq_cnt); | |
12805 | break; | |
12806 | } | |
12807 | } | |
12808 | ||
12809 | /* The xri and iocb resources secured, | |
12810 | * attempt to issue request | |
12811 | */ | |
12812 | piocbq->sli4_xritag = sglq->sli4_xritag; | |
12813 | if (NO_XRI == lpfc_sli4_bpl2sgl(phba, piocbq, sglq)) | |
12814 | fail_msg = "to convert bpl to sgl"; | |
12815 | else if (lpfc_sli4_iocb2wqe(phba, piocbq, &wqe)) | |
12816 | fail_msg = "to convert iocb to wqe"; | |
12817 | else if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | |
12818 | fail_msg = " - Wq is full"; | |
12819 | else | |
12820 | lpfc_sli_ringtxcmpl_put(phba, pring, piocbq); | |
12821 | ||
12822 | if (fail_msg) { | |
12823 | /* Failed means we can't issue and need to cancel */ | |
12824 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
12825 | "2822 IOCB failed %s iotag 0x%x " | |
12826 | "xri 0x%x\n", | |
12827 | fail_msg, | |
12828 | piocbq->iotag, piocbq->sli4_xritag); | |
12829 | list_add_tail(&piocbq->list, &completions); | |
12830 | } | |
12831 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
12832 | } | |
12833 | ||
12834 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | |
12835 | phba->pport->work_port_events &= ~WORKER_SERVICE_TXQ; | |
12836 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | |
12837 | ||
12838 | /* Cancel all the IOCBs that cannot be issued */ | |
12839 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
12840 | IOERR_SLI_ABORTED); | |
12841 | ||
12842 | return pring->txq_cnt; | |
12843 | } |