diff options
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_sli.c')
-rw-r--r-- | drivers/scsi/lpfc/lpfc_sli.c | 6811 |
1 files changed, 6354 insertions, 457 deletions
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c index eb5c75c45ba4..acc43b061ba1 100644 --- a/drivers/scsi/lpfc/lpfc_sli.c +++ b/drivers/scsi/lpfc/lpfc_sli.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /******************************************************************* | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | 2 | * This file is part of the Emulex Linux Device Driver for * |
3 | * Fibre Channel Host Bus Adapters. * | 3 | * Fibre Channel Host Bus Adapters. * |
4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
5 | * EMULEX and SLI are trademarks of Emulex. * | 5 | * EMULEX and SLI are trademarks of Emulex. * |
6 | * www.emulex.com * | 6 | * www.emulex.com * |
7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
@@ -29,9 +29,12 @@ | |||
29 | #include <scsi/scsi_device.h> | 29 | #include <scsi/scsi_device.h> |
30 | #include <scsi/scsi_host.h> | 30 | #include <scsi/scsi_host.h> |
31 | #include <scsi/scsi_transport_fc.h> | 31 | #include <scsi/scsi_transport_fc.h> |
32 | #include <scsi/fc/fc_fs.h> | ||
32 | 33 | ||
34 | #include "lpfc_hw4.h" | ||
33 | #include "lpfc_hw.h" | 35 | #include "lpfc_hw.h" |
34 | #include "lpfc_sli.h" | 36 | #include "lpfc_sli.h" |
37 | #include "lpfc_sli4.h" | ||
35 | #include "lpfc_nl.h" | 38 | #include "lpfc_nl.h" |
36 | #include "lpfc_disc.h" | 39 | #include "lpfc_disc.h" |
37 | #include "lpfc_scsi.h" | 40 | #include "lpfc_scsi.h" |
@@ -40,24 +43,7 @@ | |||
40 | #include "lpfc_logmsg.h" | 43 | #include "lpfc_logmsg.h" |
41 | #include "lpfc_compat.h" | 44 | #include "lpfc_compat.h" |
42 | #include "lpfc_debugfs.h" | 45 | #include "lpfc_debugfs.h" |
43 | 46 | #include "lpfc_vport.h" | |
44 | /* | ||
45 | * Define macro to log: Mailbox command x%x cannot issue Data | ||
46 | * This allows multiple uses of lpfc_msgBlk0311 | ||
47 | * w/o perturbing log msg utility. | ||
48 | */ | ||
49 | #define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \ | ||
50 | lpfc_printf_log(phba, \ | ||
51 | KERN_INFO, \ | ||
52 | LOG_MBOX | LOG_SLI, \ | ||
53 | "(%d):0311 Mailbox command x%x cannot " \ | ||
54 | "issue Data: x%x x%x x%x\n", \ | ||
55 | pmbox->vport ? pmbox->vport->vpi : 0, \ | ||
56 | pmbox->mb.mbxCommand, \ | ||
57 | phba->pport->port_state, \ | ||
58 | psli->sli_flag, \ | ||
59 | flag) | ||
60 | |||
61 | 47 | ||
62 | /* There are only four IOCB completion types. */ | 48 | /* There are only four IOCB completion types. */ |
63 | typedef enum _lpfc_iocb_type { | 49 | typedef enum _lpfc_iocb_type { |
@@ -67,6 +53,350 @@ typedef enum _lpfc_iocb_type { | |||
67 | LPFC_ABORT_IOCB | 53 | LPFC_ABORT_IOCB |
68 | } lpfc_iocb_type; | 54 | } lpfc_iocb_type; |
69 | 55 | ||
56 | |||
57 | /* Provide function prototypes local to this module. */ | ||
58 | static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *, | ||
59 | uint32_t); | ||
60 | static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *, | ||
61 | uint8_t *, uint32_t *); | ||
62 | |||
63 | static IOCB_t * | ||
64 | lpfc_get_iocb_from_iocbq(struct lpfc_iocbq *iocbq) | ||
65 | { | ||
66 | return &iocbq->iocb; | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue | ||
71 | * @q: The Work Queue to operate on. | ||
72 | * @wqe: The work Queue Entry to put on the Work queue. | ||
73 | * | ||
74 | * This routine will copy the contents of @wqe to the next available entry on | ||
75 | * the @q. This function will then ring the Work Queue Doorbell to signal the | ||
76 | * HBA to start processing the Work Queue Entry. This function returns 0 if | ||
77 | * successful. If no entries are available on @q then this function will return | ||
78 | * -ENOMEM. | ||
79 | * The caller is expected to hold the hbalock when calling this routine. | ||
80 | **/ | ||
81 | static uint32_t | ||
82 | lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe *wqe) | ||
83 | { | ||
84 | union lpfc_wqe *temp_wqe = q->qe[q->host_index].wqe; | ||
85 | struct lpfc_register doorbell; | ||
86 | uint32_t host_index; | ||
87 | |||
88 | /* If the host has not yet processed the next entry then we are done */ | ||
89 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | ||
90 | return -ENOMEM; | ||
91 | /* set consumption flag every once in a while */ | ||
92 | if (!((q->host_index + 1) % LPFC_RELEASE_NOTIFICATION_INTERVAL)) | ||
93 | bf_set(lpfc_wqe_gen_wqec, &wqe->generic, 1); | ||
94 | |||
95 | lpfc_sli_pcimem_bcopy(wqe, temp_wqe, q->entry_size); | ||
96 | |||
97 | /* Update the host index before invoking device */ | ||
98 | host_index = q->host_index; | ||
99 | q->host_index = ((q->host_index + 1) % q->entry_count); | ||
100 | |||
101 | /* Ring Doorbell */ | ||
102 | doorbell.word0 = 0; | ||
103 | bf_set(lpfc_wq_doorbell_num_posted, &doorbell, 1); | ||
104 | bf_set(lpfc_wq_doorbell_index, &doorbell, host_index); | ||
105 | bf_set(lpfc_wq_doorbell_id, &doorbell, q->queue_id); | ||
106 | writel(doorbell.word0, q->phba->sli4_hba.WQDBregaddr); | ||
107 | readl(q->phba->sli4_hba.WQDBregaddr); /* Flush */ | ||
108 | |||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * lpfc_sli4_wq_release - Updates internal hba index for WQ | ||
114 | * @q: The Work Queue to operate on. | ||
115 | * @index: The index to advance the hba index to. | ||
116 | * | ||
117 | * This routine will update the HBA index of a queue to reflect consumption of | ||
118 | * Work Queue Entries by the HBA. When the HBA indicates that it has consumed | ||
119 | * an entry the host calls this function to update the queue's internal | ||
120 | * pointers. This routine returns the number of entries that were consumed by | ||
121 | * the HBA. | ||
122 | **/ | ||
123 | static uint32_t | ||
124 | lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index) | ||
125 | { | ||
126 | uint32_t released = 0; | ||
127 | |||
128 | if (q->hba_index == index) | ||
129 | return 0; | ||
130 | do { | ||
131 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | ||
132 | released++; | ||
133 | } while (q->hba_index != index); | ||
134 | return released; | ||
135 | } | ||
136 | |||
137 | /** | ||
138 | * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue | ||
139 | * @q: The Mailbox Queue to operate on. | ||
140 | * @wqe: The Mailbox Queue Entry to put on the Work queue. | ||
141 | * | ||
142 | * This routine will copy the contents of @mqe to the next available entry on | ||
143 | * the @q. This function will then ring the Work Queue Doorbell to signal the | ||
144 | * HBA to start processing the Work Queue Entry. This function returns 0 if | ||
145 | * successful. If no entries are available on @q then this function will return | ||
146 | * -ENOMEM. | ||
147 | * The caller is expected to hold the hbalock when calling this routine. | ||
148 | **/ | ||
149 | static uint32_t | ||
150 | lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe) | ||
151 | { | ||
152 | struct lpfc_mqe *temp_mqe = q->qe[q->host_index].mqe; | ||
153 | struct lpfc_register doorbell; | ||
154 | uint32_t host_index; | ||
155 | |||
156 | /* If the host has not yet processed the next entry then we are done */ | ||
157 | if (((q->host_index + 1) % q->entry_count) == q->hba_index) | ||
158 | return -ENOMEM; | ||
159 | lpfc_sli_pcimem_bcopy(mqe, temp_mqe, q->entry_size); | ||
160 | /* Save off the mailbox pointer for completion */ | ||
161 | q->phba->mbox = (MAILBOX_t *)temp_mqe; | ||
162 | |||
163 | /* Update the host index before invoking device */ | ||
164 | host_index = q->host_index; | ||
165 | q->host_index = ((q->host_index + 1) % q->entry_count); | ||
166 | |||
167 | /* Ring Doorbell */ | ||
168 | doorbell.word0 = 0; | ||
169 | bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1); | ||
170 | bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id); | ||
171 | writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr); | ||
172 | readl(q->phba->sli4_hba.MQDBregaddr); /* Flush */ | ||
173 | return 0; | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * lpfc_sli4_mq_release - Updates internal hba index for MQ | ||
178 | * @q: The Mailbox Queue to operate on. | ||
179 | * | ||
180 | * This routine will update the HBA index of a queue to reflect consumption of | ||
181 | * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed | ||
182 | * an entry the host calls this function to update the queue's internal | ||
183 | * pointers. This routine returns the number of entries that were consumed by | ||
184 | * the HBA. | ||
185 | **/ | ||
186 | static uint32_t | ||
187 | lpfc_sli4_mq_release(struct lpfc_queue *q) | ||
188 | { | ||
189 | /* Clear the mailbox pointer for completion */ | ||
190 | q->phba->mbox = NULL; | ||
191 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | ||
192 | return 1; | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ | ||
197 | * @q: The Event Queue to get the first valid EQE from | ||
198 | * | ||
199 | * This routine will get the first valid Event Queue Entry from @q, update | ||
200 | * the queue's internal hba index, and return the EQE. If no valid EQEs are in | ||
201 | * the Queue (no more work to do), or the Queue is full of EQEs that have been | ||
202 | * processed, but not popped back to the HBA then this routine will return NULL. | ||
203 | **/ | ||
204 | static struct lpfc_eqe * | ||
205 | lpfc_sli4_eq_get(struct lpfc_queue *q) | ||
206 | { | ||
207 | struct lpfc_eqe *eqe = q->qe[q->hba_index].eqe; | ||
208 | |||
209 | /* If the next EQE is not valid then we are done */ | ||
210 | if (!bf_get(lpfc_eqe_valid, eqe)) | ||
211 | return NULL; | ||
212 | /* If the host has not yet processed the next entry then we are done */ | ||
213 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | ||
214 | return NULL; | ||
215 | |||
216 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | ||
217 | return eqe; | ||
218 | } | ||
219 | |||
220 | /** | ||
221 | * lpfc_sli4_eq_release - Indicates the host has finished processing an EQ | ||
222 | * @q: The Event Queue that the host has completed processing for. | ||
223 | * @arm: Indicates whether the host wants to arms this CQ. | ||
224 | * | ||
225 | * This routine will mark all Event Queue Entries on @q, from the last | ||
226 | * known completed entry to the last entry that was processed, as completed | ||
227 | * by clearing the valid bit for each completion queue entry. Then it will | ||
228 | * notify the HBA, by ringing the doorbell, that the EQEs have been processed. | ||
229 | * The internal host index in the @q will be updated by this routine to indicate | ||
230 | * that the host has finished processing the entries. The @arm parameter | ||
231 | * indicates that the queue should be rearmed when ringing the doorbell. | ||
232 | * | ||
233 | * This function will return the number of EQEs that were popped. | ||
234 | **/ | ||
235 | uint32_t | ||
236 | lpfc_sli4_eq_release(struct lpfc_queue *q, bool arm) | ||
237 | { | ||
238 | uint32_t released = 0; | ||
239 | struct lpfc_eqe *temp_eqe; | ||
240 | struct lpfc_register doorbell; | ||
241 | |||
242 | /* while there are valid entries */ | ||
243 | while (q->hba_index != q->host_index) { | ||
244 | temp_eqe = q->qe[q->host_index].eqe; | ||
245 | bf_set(lpfc_eqe_valid, temp_eqe, 0); | ||
246 | released++; | ||
247 | q->host_index = ((q->host_index + 1) % q->entry_count); | ||
248 | } | ||
249 | if (unlikely(released == 0 && !arm)) | ||
250 | return 0; | ||
251 | |||
252 | /* ring doorbell for number popped */ | ||
253 | doorbell.word0 = 0; | ||
254 | if (arm) { | ||
255 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | ||
256 | bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1); | ||
257 | } | ||
258 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | ||
259 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT); | ||
260 | bf_set(lpfc_eqcq_doorbell_eqid, &doorbell, q->queue_id); | ||
261 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | ||
262 | return released; | ||
263 | } | ||
264 | |||
265 | /** | ||
266 | * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ | ||
267 | * @q: The Completion Queue to get the first valid CQE from | ||
268 | * | ||
269 | * This routine will get the first valid Completion Queue Entry from @q, update | ||
270 | * the queue's internal hba index, and return the CQE. If no valid CQEs are in | ||
271 | * the Queue (no more work to do), or the Queue is full of CQEs that have been | ||
272 | * processed, but not popped back to the HBA then this routine will return NULL. | ||
273 | **/ | ||
274 | static struct lpfc_cqe * | ||
275 | lpfc_sli4_cq_get(struct lpfc_queue *q) | ||
276 | { | ||
277 | struct lpfc_cqe *cqe; | ||
278 | |||
279 | /* If the next CQE is not valid then we are done */ | ||
280 | if (!bf_get(lpfc_cqe_valid, q->qe[q->hba_index].cqe)) | ||
281 | return NULL; | ||
282 | /* If the host has not yet processed the next entry then we are done */ | ||
283 | if (((q->hba_index + 1) % q->entry_count) == q->host_index) | ||
284 | return NULL; | ||
285 | |||
286 | cqe = q->qe[q->hba_index].cqe; | ||
287 | q->hba_index = ((q->hba_index + 1) % q->entry_count); | ||
288 | return cqe; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * lpfc_sli4_cq_release - Indicates the host has finished processing a CQ | ||
293 | * @q: The Completion Queue that the host has completed processing for. | ||
294 | * @arm: Indicates whether the host wants to arms this CQ. | ||
295 | * | ||
296 | * This routine will mark all Completion queue entries on @q, from the last | ||
297 | * known completed entry to the last entry that was processed, as completed | ||
298 | * by clearing the valid bit for each completion queue entry. Then it will | ||
299 | * notify the HBA, by ringing the doorbell, that the CQEs have been processed. | ||
300 | * The internal host index in the @q will be updated by this routine to indicate | ||
301 | * that the host has finished processing the entries. The @arm parameter | ||
302 | * indicates that the queue should be rearmed when ringing the doorbell. | ||
303 | * | ||
304 | * This function will return the number of CQEs that were released. | ||
305 | **/ | ||
306 | uint32_t | ||
307 | lpfc_sli4_cq_release(struct lpfc_queue *q, bool arm) | ||
308 | { | ||
309 | uint32_t released = 0; | ||
310 | struct lpfc_cqe *temp_qe; | ||
311 | struct lpfc_register doorbell; | ||
312 | |||
313 | /* while there are valid entries */ | ||
314 | while (q->hba_index != q->host_index) { | ||
315 | temp_qe = q->qe[q->host_index].cqe; | ||
316 | bf_set(lpfc_cqe_valid, temp_qe, 0); | ||
317 | released++; | ||
318 | q->host_index = ((q->host_index + 1) % q->entry_count); | ||
319 | } | ||
320 | if (unlikely(released == 0 && !arm)) | ||
321 | return 0; | ||
322 | |||
323 | /* ring doorbell for number popped */ | ||
324 | doorbell.word0 = 0; | ||
325 | if (arm) | ||
326 | bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1); | ||
327 | bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, released); | ||
328 | bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION); | ||
329 | bf_set(lpfc_eqcq_doorbell_cqid, &doorbell, q->queue_id); | ||
330 | writel(doorbell.word0, q->phba->sli4_hba.EQCQDBregaddr); | ||
331 | return released; | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue | ||
336 | * @q: The Header Receive Queue to operate on. | ||
337 | * @wqe: The Receive Queue Entry to put on the Receive queue. | ||
338 | * | ||
339 | * This routine will copy the contents of @wqe to the next available entry on | ||
340 | * the @q. This function will then ring the Receive Queue Doorbell to signal the | ||
341 | * HBA to start processing the Receive Queue Entry. This function returns the | ||
342 | * index that the rqe was copied to if successful. If no entries are available | ||
343 | * on @q then this function will return -ENOMEM. | ||
344 | * The caller is expected to hold the hbalock when calling this routine. | ||
345 | **/ | ||
346 | static int | ||
347 | lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq, | ||
348 | struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe) | ||
349 | { | ||
350 | struct lpfc_rqe *temp_hrqe = hq->qe[hq->host_index].rqe; | ||
351 | struct lpfc_rqe *temp_drqe = dq->qe[dq->host_index].rqe; | ||
352 | struct lpfc_register doorbell; | ||
353 | int put_index = hq->host_index; | ||
354 | |||
355 | if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ) | ||
356 | return -EINVAL; | ||
357 | if (hq->host_index != dq->host_index) | ||
358 | return -EINVAL; | ||
359 | /* If the host has not yet processed the next entry then we are done */ | ||
360 | if (((hq->host_index + 1) % hq->entry_count) == hq->hba_index) | ||
361 | return -EBUSY; | ||
362 | lpfc_sli_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size); | ||
363 | lpfc_sli_pcimem_bcopy(drqe, temp_drqe, dq->entry_size); | ||
364 | |||
365 | /* Update the host index to point to the next slot */ | ||
366 | hq->host_index = ((hq->host_index + 1) % hq->entry_count); | ||
367 | dq->host_index = ((dq->host_index + 1) % dq->entry_count); | ||
368 | |||
369 | /* Ring The Header Receive Queue Doorbell */ | ||
370 | if (!(hq->host_index % LPFC_RQ_POST_BATCH)) { | ||
371 | doorbell.word0 = 0; | ||
372 | bf_set(lpfc_rq_doorbell_num_posted, &doorbell, | ||
373 | LPFC_RQ_POST_BATCH); | ||
374 | bf_set(lpfc_rq_doorbell_id, &doorbell, hq->queue_id); | ||
375 | writel(doorbell.word0, hq->phba->sli4_hba.RQDBregaddr); | ||
376 | } | ||
377 | return put_index; | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * lpfc_sli4_rq_release - Updates internal hba index for RQ | ||
382 | * @q: The Header Receive Queue to operate on. | ||
383 | * | ||
384 | * This routine will update the HBA index of a queue to reflect consumption of | ||
385 | * one Receive Queue Entry by the HBA. When the HBA indicates that it has | ||
386 | * consumed an entry the host calls this function to update the queue's | ||
387 | * internal pointers. This routine returns the number of entries that were | ||
388 | * consumed by the HBA. | ||
389 | **/ | ||
390 | static uint32_t | ||
391 | lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq) | ||
392 | { | ||
393 | if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ)) | ||
394 | return 0; | ||
395 | hq->hba_index = ((hq->hba_index + 1) % hq->entry_count); | ||
396 | dq->hba_index = ((dq->hba_index + 1) % dq->entry_count); | ||
397 | return 1; | ||
398 | } | ||
399 | |||
70 | /** | 400 | /** |
71 | * lpfc_cmd_iocb - Get next command iocb entry in the ring | 401 | * lpfc_cmd_iocb - Get next command iocb entry in the ring |
72 | * @phba: Pointer to HBA context object. | 402 | * @phba: Pointer to HBA context object. |
@@ -121,6 +451,76 @@ __lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |||
121 | } | 451 | } |
122 | 452 | ||
123 | /** | 453 | /** |
454 | * __lpfc_clear_active_sglq - Remove the active sglq for this XRI. | ||
455 | * @phba: Pointer to HBA context object. | ||
456 | * @xritag: XRI value. | ||
457 | * | ||
458 | * This function clears the sglq pointer from the array of acive | ||
459 | * sglq's. The xritag that is passed in is used to index into the | ||
460 | * array. Before the xritag can be used it needs to be adjusted | ||
461 | * by subtracting the xribase. | ||
462 | * | ||
463 | * Returns sglq ponter = success, NULL = Failure. | ||
464 | **/ | ||
465 | static struct lpfc_sglq * | ||
466 | __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | ||
467 | { | ||
468 | uint16_t adj_xri; | ||
469 | struct lpfc_sglq *sglq; | ||
470 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | ||
471 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) | ||
472 | return NULL; | ||
473 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; | ||
474 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = NULL; | ||
475 | return sglq; | ||
476 | } | ||
477 | |||
478 | /** | ||
479 | * __lpfc_get_active_sglq - Get the active sglq for this XRI. | ||
480 | * @phba: Pointer to HBA context object. | ||
481 | * @xritag: XRI value. | ||
482 | * | ||
483 | * This function returns the sglq pointer from the array of acive | ||
484 | * sglq's. The xritag that is passed in is used to index into the | ||
485 | * array. Before the xritag can be used it needs to be adjusted | ||
486 | * by subtracting the xribase. | ||
487 | * | ||
488 | * Returns sglq ponter = success, NULL = Failure. | ||
489 | **/ | ||
490 | static struct lpfc_sglq * | ||
491 | __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag) | ||
492 | { | ||
493 | uint16_t adj_xri; | ||
494 | struct lpfc_sglq *sglq; | ||
495 | adj_xri = xritag - phba->sli4_hba.max_cfg_param.xri_base; | ||
496 | if (adj_xri > phba->sli4_hba.max_cfg_param.max_xri) | ||
497 | return NULL; | ||
498 | sglq = phba->sli4_hba.lpfc_sglq_active_list[adj_xri]; | ||
499 | return sglq; | ||
500 | } | ||
501 | |||
502 | /** | ||
503 | * __lpfc_sli_get_sglq - Allocates an iocb object from sgl pool | ||
504 | * @phba: Pointer to HBA context object. | ||
505 | * | ||
506 | * This function is called with hbalock held. This function | ||
507 | * Gets a new driver sglq object from the sglq list. If the | ||
508 | * list is not empty then it is successful, it returns pointer to the newly | ||
509 | * allocated sglq object else it returns NULL. | ||
510 | **/ | ||
511 | static struct lpfc_sglq * | ||
512 | __lpfc_sli_get_sglq(struct lpfc_hba *phba) | ||
513 | { | ||
514 | struct list_head *lpfc_sgl_list = &phba->sli4_hba.lpfc_sgl_list; | ||
515 | struct lpfc_sglq *sglq = NULL; | ||
516 | uint16_t adj_xri; | ||
517 | list_remove_head(lpfc_sgl_list, sglq, struct lpfc_sglq, list); | ||
518 | adj_xri = sglq->sli4_xritag - phba->sli4_hba.max_cfg_param.xri_base; | ||
519 | phba->sli4_hba.lpfc_sglq_active_list[adj_xri] = sglq; | ||
520 | return sglq; | ||
521 | } | ||
522 | |||
523 | /** | ||
124 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool | 524 | * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool |
125 | * @phba: Pointer to HBA context object. | 525 | * @phba: Pointer to HBA context object. |
126 | * | 526 | * |
@@ -142,7 +542,7 @@ lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |||
142 | } | 542 | } |
143 | 543 | ||
144 | /** | 544 | /** |
145 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | 545 | * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool |
146 | * @phba: Pointer to HBA context object. | 546 | * @phba: Pointer to HBA context object. |
147 | * @iocbq: Pointer to driver iocb object. | 547 | * @iocbq: Pointer to driver iocb object. |
148 | * | 548 | * |
@@ -150,9 +550,62 @@ lpfc_sli_get_iocbq(struct lpfc_hba *phba) | |||
150 | * iocb object to the iocb pool. The iotag in the iocb object | 550 | * iocb object to the iocb pool. The iotag in the iocb object |
151 | * does not change for each use of the iocb object. This function | 551 | * does not change for each use of the iocb object. This function |
152 | * clears all other fields of the iocb object when it is freed. | 552 | * clears all other fields of the iocb object when it is freed. |
553 | * The sqlq structure that holds the xritag and phys and virtual | ||
554 | * mappings for the scatter gather list is retrieved from the | ||
555 | * active array of sglq. The get of the sglq pointer also clears | ||
556 | * the entry in the array. If the status of the IO indiactes that | ||
557 | * this IO was aborted then the sglq entry it put on the | ||
558 | * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the | ||
559 | * IO has good status or fails for any other reason then the sglq | ||
560 | * entry is added to the free list (lpfc_sgl_list). | ||
153 | **/ | 561 | **/ |
154 | static void | 562 | static void |
155 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | 563 | __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) |
564 | { | ||
565 | struct lpfc_sglq *sglq; | ||
566 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | ||
567 | unsigned long iflag; | ||
568 | |||
569 | if (iocbq->sli4_xritag == NO_XRI) | ||
570 | sglq = NULL; | ||
571 | else | ||
572 | sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag); | ||
573 | if (sglq) { | ||
574 | if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED | ||
575 | || ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT) | ||
576 | && (iocbq->iocb.un.ulpWord[4] | ||
577 | == IOERR_SLI_ABORTED))) { | ||
578 | spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, | ||
579 | iflag); | ||
580 | list_add(&sglq->list, | ||
581 | &phba->sli4_hba.lpfc_abts_els_sgl_list); | ||
582 | spin_unlock_irqrestore( | ||
583 | &phba->sli4_hba.abts_sgl_list_lock, iflag); | ||
584 | } else | ||
585 | list_add(&sglq->list, &phba->sli4_hba.lpfc_sgl_list); | ||
586 | } | ||
587 | |||
588 | |||
589 | /* | ||
590 | * Clean all volatile data fields, preserve iotag and node struct. | ||
591 | */ | ||
592 | memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | ||
593 | iocbq->sli4_xritag = NO_XRI; | ||
594 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool | ||
599 | * @phba: Pointer to HBA context object. | ||
600 | * @iocbq: Pointer to driver iocb object. | ||
601 | * | ||
602 | * This function is called with hbalock held to release driver | ||
603 | * iocb object to the iocb pool. The iotag in the iocb object | ||
604 | * does not change for each use of the iocb object. This function | ||
605 | * clears all other fields of the iocb object when it is freed. | ||
606 | **/ | ||
607 | static void | ||
608 | __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | ||
156 | { | 609 | { |
157 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); | 610 | size_t start_clean = offsetof(struct lpfc_iocbq, iocb); |
158 | 611 | ||
@@ -160,10 +613,27 @@ __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | |||
160 | * Clean all volatile data fields, preserve iotag and node struct. | 613 | * Clean all volatile data fields, preserve iotag and node struct. |
161 | */ | 614 | */ |
162 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); | 615 | memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean); |
616 | iocbq->sli4_xritag = NO_XRI; | ||
163 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); | 617 | list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); |
164 | } | 618 | } |
165 | 619 | ||
166 | /** | 620 | /** |
621 | * __lpfc_sli_release_iocbq - Release iocb to the iocb pool | ||
622 | * @phba: Pointer to HBA context object. | ||
623 | * @iocbq: Pointer to driver iocb object. | ||
624 | * | ||
625 | * This function is called with hbalock held to release driver | ||
626 | * iocb object to the iocb pool. The iotag in the iocb object | ||
627 | * does not change for each use of the iocb object. This function | ||
628 | * clears all other fields of the iocb object when it is freed. | ||
629 | **/ | ||
630 | static void | ||
631 | __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) | ||
632 | { | ||
633 | phba->__lpfc_sli_release_iocbq(phba, iocbq); | ||
634 | } | ||
635 | |||
636 | /** | ||
167 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool | 637 | * lpfc_sli_release_iocbq - Release iocb to the iocb pool |
168 | * @phba: Pointer to HBA context object. | 638 | * @phba: Pointer to HBA context object. |
169 | * @iocbq: Pointer to driver iocb object. | 639 | * @iocbq: Pointer to driver iocb object. |
@@ -281,6 +751,14 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) | |||
281 | case CMD_GEN_REQUEST64_CR: | 751 | case CMD_GEN_REQUEST64_CR: |
282 | case CMD_GEN_REQUEST64_CX: | 752 | case CMD_GEN_REQUEST64_CX: |
283 | case CMD_XMIT_ELS_RSP64_CX: | 753 | case CMD_XMIT_ELS_RSP64_CX: |
754 | case DSSCMD_IWRITE64_CR: | ||
755 | case DSSCMD_IWRITE64_CX: | ||
756 | case DSSCMD_IREAD64_CR: | ||
757 | case DSSCMD_IREAD64_CX: | ||
758 | case DSSCMD_INVALIDATE_DEK: | ||
759 | case DSSCMD_SET_KEK: | ||
760 | case DSSCMD_GET_KEK_ID: | ||
761 | case DSSCMD_GEN_XFER: | ||
284 | type = LPFC_SOL_IOCB; | 762 | type = LPFC_SOL_IOCB; |
285 | break; | 763 | break; |
286 | case CMD_ABORT_XRI_CN: | 764 | case CMD_ABORT_XRI_CN: |
@@ -348,7 +826,7 @@ lpfc_sli_ring_map(struct lpfc_hba *phba) | |||
348 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | 826 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
349 | if (!pmb) | 827 | if (!pmb) |
350 | return -ENOMEM; | 828 | return -ENOMEM; |
351 | pmbox = &pmb->mb; | 829 | pmbox = &pmb->u.mb; |
352 | phba->link_state = LPFC_INIT_MBX_CMDS; | 830 | phba->link_state = LPFC_INIT_MBX_CMDS; |
353 | for (i = 0; i < psli->num_rings; i++) { | 831 | for (i = 0; i < psli->num_rings; i++) { |
354 | lpfc_config_ring(phba, i, pmb); | 832 | lpfc_config_ring(phba, i, pmb); |
@@ -779,8 +1257,8 @@ lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |||
779 | phba->hbqs[i].buffer_count = 0; | 1257 | phba->hbqs[i].buffer_count = 0; |
780 | } | 1258 | } |
781 | /* Return all HBQ buffer that are in-fly */ | 1259 | /* Return all HBQ buffer that are in-fly */ |
782 | list_for_each_entry_safe(dmabuf, next_dmabuf, | 1260 | list_for_each_entry_safe(dmabuf, next_dmabuf, &phba->rb_pend_list, |
783 | &phba->hbqbuf_in_list, list) { | 1261 | list) { |
784 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); | 1262 | hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf); |
785 | list_del(&hbq_buf->dbuf.list); | 1263 | list_del(&hbq_buf->dbuf.list); |
786 | if (hbq_buf->tag == -1) { | 1264 | if (hbq_buf->tag == -1) { |
@@ -814,10 +1292,28 @@ lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) | |||
814 | * pointer to the hbq entry if it successfully post the buffer | 1292 | * pointer to the hbq entry if it successfully post the buffer |
815 | * else it will return NULL. | 1293 | * else it will return NULL. |
816 | **/ | 1294 | **/ |
817 | static struct lpfc_hbq_entry * | 1295 | static int |
818 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, | 1296 | lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, |
819 | struct hbq_dmabuf *hbq_buf) | 1297 | struct hbq_dmabuf *hbq_buf) |
820 | { | 1298 | { |
1299 | return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf); | ||
1300 | } | ||
1301 | |||
1302 | /** | ||
1303 | * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware | ||
1304 | * @phba: Pointer to HBA context object. | ||
1305 | * @hbqno: HBQ number. | ||
1306 | * @hbq_buf: Pointer to HBQ buffer. | ||
1307 | * | ||
1308 | * This function is called with the hbalock held to post a hbq buffer to the | ||
1309 | * firmware. If the function finds an empty slot in the HBQ, it will post the | ||
1310 | * buffer and place it on the hbq_buffer_list. The function will return zero if | ||
1311 | * it successfully post the buffer else it will return an error. | ||
1312 | **/ | ||
1313 | static int | ||
1314 | lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno, | ||
1315 | struct hbq_dmabuf *hbq_buf) | ||
1316 | { | ||
821 | struct lpfc_hbq_entry *hbqe; | 1317 | struct lpfc_hbq_entry *hbqe; |
822 | dma_addr_t physaddr = hbq_buf->dbuf.phys; | 1318 | dma_addr_t physaddr = hbq_buf->dbuf.phys; |
823 | 1319 | ||
@@ -838,8 +1334,40 @@ lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, | |||
838 | /* flush */ | 1334 | /* flush */ |
839 | readl(phba->hbq_put + hbqno); | 1335 | readl(phba->hbq_put + hbqno); |
840 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); | 1336 | list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list); |
841 | } | 1337 | return 0; |
842 | return hbqe; | 1338 | } else |
1339 | return -ENOMEM; | ||
1340 | } | ||
1341 | |||
1342 | /** | ||
1343 | * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware | ||
1344 | * @phba: Pointer to HBA context object. | ||
1345 | * @hbqno: HBQ number. | ||
1346 | * @hbq_buf: Pointer to HBQ buffer. | ||
1347 | * | ||
1348 | * This function is called with the hbalock held to post an RQE to the SLI4 | ||
1349 | * firmware. If able to post the RQE to the RQ it will queue the hbq entry to | ||
1350 | * the hbq_buffer_list and return zero, otherwise it will return an error. | ||
1351 | **/ | ||
1352 | static int | ||
1353 | lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno, | ||
1354 | struct hbq_dmabuf *hbq_buf) | ||
1355 | { | ||
1356 | int rc; | ||
1357 | struct lpfc_rqe hrqe; | ||
1358 | struct lpfc_rqe drqe; | ||
1359 | |||
1360 | hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys); | ||
1361 | hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys); | ||
1362 | drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys); | ||
1363 | drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys); | ||
1364 | rc = lpfc_sli4_rq_put(phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | ||
1365 | &hrqe, &drqe); | ||
1366 | if (rc < 0) | ||
1367 | return rc; | ||
1368 | hbq_buf->tag = rc; | ||
1369 | list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list); | ||
1370 | return 0; | ||
843 | } | 1371 | } |
844 | 1372 | ||
845 | /* HBQ for ELS and CT traffic. */ | 1373 | /* HBQ for ELS and CT traffic. */ |
@@ -914,7 +1442,7 @@ lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) | |||
914 | dbuf.list); | 1442 | dbuf.list); |
915 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | | 1443 | hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count | |
916 | (hbqno << 16)); | 1444 | (hbqno << 16)); |
917 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { | 1445 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { |
918 | phba->hbqs[hbqno].buffer_count++; | 1446 | phba->hbqs[hbqno].buffer_count++; |
919 | posted++; | 1447 | posted++; |
920 | } else | 1448 | } else |
@@ -965,6 +1493,25 @@ lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) | |||
965 | } | 1493 | } |
966 | 1494 | ||
967 | /** | 1495 | /** |
1496 | * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list | ||
1497 | * @phba: Pointer to HBA context object. | ||
1498 | * @hbqno: HBQ number. | ||
1499 | * | ||
1500 | * This function removes the first hbq buffer on an hbq list and returns a | ||
1501 | * pointer to that buffer. If it finds no buffers on the list it returns NULL. | ||
1502 | **/ | ||
1503 | static struct hbq_dmabuf * | ||
1504 | lpfc_sli_hbqbuf_get(struct list_head *rb_list) | ||
1505 | { | ||
1506 | struct lpfc_dmabuf *d_buf; | ||
1507 | |||
1508 | list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list); | ||
1509 | if (!d_buf) | ||
1510 | return NULL; | ||
1511 | return container_of(d_buf, struct hbq_dmabuf, dbuf); | ||
1512 | } | ||
1513 | |||
1514 | /** | ||
968 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag | 1515 | * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag |
969 | * @phba: Pointer to HBA context object. | 1516 | * @phba: Pointer to HBA context object. |
970 | * @tag: Tag of the hbq buffer. | 1517 | * @tag: Tag of the hbq buffer. |
@@ -985,12 +1532,15 @@ lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) | |||
985 | if (hbqno >= LPFC_MAX_HBQS) | 1532 | if (hbqno >= LPFC_MAX_HBQS) |
986 | return NULL; | 1533 | return NULL; |
987 | 1534 | ||
1535 | spin_lock_irq(&phba->hbalock); | ||
988 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { | 1536 | list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) { |
989 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); | 1537 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
990 | if (hbq_buf->tag == tag) { | 1538 | if (hbq_buf->tag == tag) { |
1539 | spin_unlock_irq(&phba->hbalock); | ||
991 | return hbq_buf; | 1540 | return hbq_buf; |
992 | } | 1541 | } |
993 | } | 1542 | } |
1543 | spin_unlock_irq(&phba->hbalock); | ||
994 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, | 1544 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT, |
995 | "1803 Bad hbq tag. Data: x%x x%x\n", | 1545 | "1803 Bad hbq tag. Data: x%x x%x\n", |
996 | tag, phba->hbqs[tag >> 16].buffer_count); | 1546 | tag, phba->hbqs[tag >> 16].buffer_count); |
@@ -1013,9 +1563,8 @@ lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) | |||
1013 | 1563 | ||
1014 | if (hbq_buffer) { | 1564 | if (hbq_buffer) { |
1015 | hbqno = hbq_buffer->tag >> 16; | 1565 | hbqno = hbq_buffer->tag >> 16; |
1016 | if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) { | 1566 | if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) |
1017 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); | 1567 | (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); |
1018 | } | ||
1019 | } | 1568 | } |
1020 | } | 1569 | } |
1021 | 1570 | ||
@@ -1086,6 +1635,15 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |||
1086 | case MBX_HEARTBEAT: | 1635 | case MBX_HEARTBEAT: |
1087 | case MBX_PORT_CAPABILITIES: | 1636 | case MBX_PORT_CAPABILITIES: |
1088 | case MBX_PORT_IOV_CONTROL: | 1637 | case MBX_PORT_IOV_CONTROL: |
1638 | case MBX_SLI4_CONFIG: | ||
1639 | case MBX_SLI4_REQ_FTRS: | ||
1640 | case MBX_REG_FCFI: | ||
1641 | case MBX_UNREG_FCFI: | ||
1642 | case MBX_REG_VFI: | ||
1643 | case MBX_UNREG_VFI: | ||
1644 | case MBX_INIT_VPI: | ||
1645 | case MBX_INIT_VFI: | ||
1646 | case MBX_RESUME_RPI: | ||
1089 | ret = mbxCommand; | 1647 | ret = mbxCommand; |
1090 | break; | 1648 | break; |
1091 | default: | 1649 | default: |
@@ -1106,7 +1664,7 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand) | |||
1106 | * will wake up thread waiting on the wait queue pointed by context1 | 1664 | * will wake up thread waiting on the wait queue pointed by context1 |
1107 | * of the mailbox. | 1665 | * of the mailbox. |
1108 | **/ | 1666 | **/ |
1109 | static void | 1667 | void |
1110 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | 1668 | lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
1111 | { | 1669 | { |
1112 | wait_queue_head_t *pdone_q; | 1670 | wait_queue_head_t *pdone_q; |
@@ -1140,7 +1698,7 @@ void | |||
1140 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | 1698 | lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
1141 | { | 1699 | { |
1142 | struct lpfc_dmabuf *mp; | 1700 | struct lpfc_dmabuf *mp; |
1143 | uint16_t rpi; | 1701 | uint16_t rpi, vpi; |
1144 | int rc; | 1702 | int rc; |
1145 | 1703 | ||
1146 | mp = (struct lpfc_dmabuf *) (pmb->context1); | 1704 | mp = (struct lpfc_dmabuf *) (pmb->context1); |
@@ -1150,24 +1708,30 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) | |||
1150 | kfree(mp); | 1708 | kfree(mp); |
1151 | } | 1709 | } |
1152 | 1710 | ||
1711 | if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) && | ||
1712 | (phba->sli_rev == LPFC_SLI_REV4)) | ||
1713 | lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi); | ||
1714 | |||
1153 | /* | 1715 | /* |
1154 | * If a REG_LOGIN succeeded after node is destroyed or node | 1716 | * If a REG_LOGIN succeeded after node is destroyed or node |
1155 | * is in re-discovery driver need to cleanup the RPI. | 1717 | * is in re-discovery driver need to cleanup the RPI. |
1156 | */ | 1718 | */ |
1157 | if (!(phba->pport->load_flag & FC_UNLOADING) && | 1719 | if (!(phba->pport->load_flag & FC_UNLOADING) && |
1158 | pmb->mb.mbxCommand == MBX_REG_LOGIN64 && | 1720 | pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 && |
1159 | !pmb->mb.mbxStatus) { | 1721 | !pmb->u.mb.mbxStatus) { |
1160 | 1722 | rpi = pmb->u.mb.un.varWords[0]; | |
1161 | rpi = pmb->mb.un.varWords[0]; | 1723 | vpi = pmb->u.mb.un.varRegLogin.vpi - phba->vpi_base; |
1162 | lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb); | 1724 | lpfc_unreg_login(phba, vpi, rpi, pmb); |
1163 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | 1725 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
1164 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | 1726 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
1165 | if (rc != MBX_NOT_FINISHED) | 1727 | if (rc != MBX_NOT_FINISHED) |
1166 | return; | 1728 | return; |
1167 | } | 1729 | } |
1168 | 1730 | ||
1169 | mempool_free(pmb, phba->mbox_mem_pool); | 1731 | if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) |
1170 | return; | 1732 | lpfc_sli4_mbox_cmd_free(phba, pmb); |
1733 | else | ||
1734 | mempool_free(pmb, phba->mbox_mem_pool); | ||
1171 | } | 1735 | } |
1172 | 1736 | ||
1173 | /** | 1737 | /** |
@@ -1204,7 +1768,7 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba) | |||
1204 | if (pmb == NULL) | 1768 | if (pmb == NULL) |
1205 | break; | 1769 | break; |
1206 | 1770 | ||
1207 | pmbox = &pmb->mb; | 1771 | pmbox = &pmb->u.mb; |
1208 | 1772 | ||
1209 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { | 1773 | if (pmbox->mbxCommand != MBX_HEARTBEAT) { |
1210 | if (pmb->vport) { | 1774 | if (pmb->vport) { |
@@ -1233,9 +1797,10 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba) | |||
1233 | /* Unknow mailbox command compl */ | 1797 | /* Unknow mailbox command compl */ |
1234 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | 1798 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
1235 | "(%d):0323 Unknown Mailbox command " | 1799 | "(%d):0323 Unknown Mailbox command " |
1236 | "%x Cmpl\n", | 1800 | "x%x (x%x) Cmpl\n", |
1237 | pmb->vport ? pmb->vport->vpi : 0, | 1801 | pmb->vport ? pmb->vport->vpi : 0, |
1238 | pmbox->mbxCommand); | 1802 | pmbox->mbxCommand, |
1803 | lpfc_sli4_mbox_opcode_get(phba, pmb)); | ||
1239 | phba->link_state = LPFC_HBA_ERROR; | 1804 | phba->link_state = LPFC_HBA_ERROR; |
1240 | phba->work_hs = HS_FFER3; | 1805 | phba->work_hs = HS_FFER3; |
1241 | lpfc_handle_eratt(phba); | 1806 | lpfc_handle_eratt(phba); |
@@ -1250,29 +1815,29 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba) | |||
1250 | LOG_MBOX | LOG_SLI, | 1815 | LOG_MBOX | LOG_SLI, |
1251 | "(%d):0305 Mbox cmd cmpl " | 1816 | "(%d):0305 Mbox cmd cmpl " |
1252 | "error - RETRYing Data: x%x " | 1817 | "error - RETRYing Data: x%x " |
1253 | "x%x x%x x%x\n", | 1818 | "(x%x) x%x x%x x%x\n", |
1254 | pmb->vport ? pmb->vport->vpi :0, | 1819 | pmb->vport ? pmb->vport->vpi :0, |
1255 | pmbox->mbxCommand, | 1820 | pmbox->mbxCommand, |
1821 | lpfc_sli4_mbox_opcode_get(phba, | ||
1822 | pmb), | ||
1256 | pmbox->mbxStatus, | 1823 | pmbox->mbxStatus, |
1257 | pmbox->un.varWords[0], | 1824 | pmbox->un.varWords[0], |
1258 | pmb->vport->port_state); | 1825 | pmb->vport->port_state); |
1259 | pmbox->mbxStatus = 0; | 1826 | pmbox->mbxStatus = 0; |
1260 | pmbox->mbxOwner = OWN_HOST; | 1827 | pmbox->mbxOwner = OWN_HOST; |
1261 | spin_lock_irq(&phba->hbalock); | ||
1262 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
1263 | spin_unlock_irq(&phba->hbalock); | ||
1264 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | 1828 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
1265 | if (rc == MBX_SUCCESS) | 1829 | if (rc != MBX_NOT_FINISHED) |
1266 | continue; | 1830 | continue; |
1267 | } | 1831 | } |
1268 | } | 1832 | } |
1269 | 1833 | ||
1270 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ | 1834 | /* Mailbox cmd <cmd> Cmpl <cmpl> */ |
1271 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | 1835 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, |
1272 | "(%d):0307 Mailbox cmd x%x Cmpl x%p " | 1836 | "(%d):0307 Mailbox cmd x%x (x%x) Cmpl x%p " |
1273 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", | 1837 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n", |
1274 | pmb->vport ? pmb->vport->vpi : 0, | 1838 | pmb->vport ? pmb->vport->vpi : 0, |
1275 | pmbox->mbxCommand, | 1839 | pmbox->mbxCommand, |
1840 | lpfc_sli4_mbox_opcode_get(phba, pmb), | ||
1276 | pmb->mbox_cmpl, | 1841 | pmb->mbox_cmpl, |
1277 | *((uint32_t *) pmbox), | 1842 | *((uint32_t *) pmbox), |
1278 | pmbox->un.varWords[0], | 1843 | pmbox->un.varWords[0], |
@@ -1317,6 +1882,45 @@ lpfc_sli_get_buff(struct lpfc_hba *phba, | |||
1317 | return &hbq_entry->dbuf; | 1882 | return &hbq_entry->dbuf; |
1318 | } | 1883 | } |
1319 | 1884 | ||
1885 | /** | ||
1886 | * lpfc_complete_unsol_iocb - Complete an unsolicited sequence | ||
1887 | * @phba: Pointer to HBA context object. | ||
1888 | * @pring: Pointer to driver SLI ring object. | ||
1889 | * @saveq: Pointer to the iocbq struct representing the sequence starting frame. | ||
1890 | * @fch_r_ctl: the r_ctl for the first frame of the sequence. | ||
1891 | * @fch_type: the type for the first frame of the sequence. | ||
1892 | * | ||
1893 | * This function is called with no lock held. This function uses the r_ctl and | ||
1894 | * type of the received sequence to find the correct callback function to call | ||
1895 | * to process the sequence. | ||
1896 | **/ | ||
1897 | static int | ||
1898 | lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | ||
1899 | struct lpfc_iocbq *saveq, uint32_t fch_r_ctl, | ||
1900 | uint32_t fch_type) | ||
1901 | { | ||
1902 | int i; | ||
1903 | |||
1904 | /* unSolicited Responses */ | ||
1905 | if (pring->prt[0].profile) { | ||
1906 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | ||
1907 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | ||
1908 | saveq); | ||
1909 | return 1; | ||
1910 | } | ||
1911 | /* We must search, based on rctl / type | ||
1912 | for the right routine */ | ||
1913 | for (i = 0; i < pring->num_mask; i++) { | ||
1914 | if ((pring->prt[i].rctl == fch_r_ctl) && | ||
1915 | (pring->prt[i].type == fch_type)) { | ||
1916 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | ||
1917 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | ||
1918 | (phba, pring, saveq); | ||
1919 | return 1; | ||
1920 | } | ||
1921 | } | ||
1922 | return 0; | ||
1923 | } | ||
1320 | 1924 | ||
1321 | /** | 1925 | /** |
1322 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler | 1926 | * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler |
@@ -1339,7 +1943,7 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
1339 | IOCB_t * irsp; | 1943 | IOCB_t * irsp; |
1340 | WORD5 * w5p; | 1944 | WORD5 * w5p; |
1341 | uint32_t Rctl, Type; | 1945 | uint32_t Rctl, Type; |
1342 | uint32_t match, i; | 1946 | uint32_t match; |
1343 | struct lpfc_iocbq *iocbq; | 1947 | struct lpfc_iocbq *iocbq; |
1344 | struct lpfc_dmabuf *dmzbuf; | 1948 | struct lpfc_dmabuf *dmzbuf; |
1345 | 1949 | ||
@@ -1482,35 +2086,12 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
1482 | } | 2086 | } |
1483 | } | 2087 | } |
1484 | 2088 | ||
1485 | /* unSolicited Responses */ | 2089 | if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type)) |
1486 | if (pring->prt[0].profile) { | ||
1487 | if (pring->prt[0].lpfc_sli_rcv_unsol_event) | ||
1488 | (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring, | ||
1489 | saveq); | ||
1490 | match = 1; | ||
1491 | } else { | ||
1492 | /* We must search, based on rctl / type | ||
1493 | for the right routine */ | ||
1494 | for (i = 0; i < pring->num_mask; i++) { | ||
1495 | if ((pring->prt[i].rctl == Rctl) | ||
1496 | && (pring->prt[i].type == Type)) { | ||
1497 | if (pring->prt[i].lpfc_sli_rcv_unsol_event) | ||
1498 | (pring->prt[i].lpfc_sli_rcv_unsol_event) | ||
1499 | (phba, pring, saveq); | ||
1500 | match = 1; | ||
1501 | break; | ||
1502 | } | ||
1503 | } | ||
1504 | } | ||
1505 | if (match == 0) { | ||
1506 | /* Unexpected Rctl / Type received */ | ||
1507 | /* Ring <ringno> handler: unexpected | ||
1508 | Rctl <Rctl> Type <Type> received */ | ||
1509 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | 2090 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
1510 | "0313 Ring %d handler: unexpected Rctl x%x " | 2091 | "0313 Ring %d handler: unexpected Rctl x%x " |
1511 | "Type x%x received\n", | 2092 | "Type x%x received\n", |
1512 | pring->ringno, Rctl, Type); | 2093 | pring->ringno, Rctl, Type); |
1513 | } | 2094 | |
1514 | return 1; | 2095 | return 1; |
1515 | } | 2096 | } |
1516 | 2097 | ||
@@ -1552,6 +2133,37 @@ lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, | |||
1552 | } | 2133 | } |
1553 | 2134 | ||
1554 | /** | 2135 | /** |
2136 | * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag | ||
2137 | * @phba: Pointer to HBA context object. | ||
2138 | * @pring: Pointer to driver SLI ring object. | ||
2139 | * @iotag: IOCB tag. | ||
2140 | * | ||
2141 | * This function looks up the iocb_lookup table to get the command iocb | ||
2142 | * corresponding to the given iotag. This function is called with the | ||
2143 | * hbalock held. | ||
2144 | * This function returns the command iocb object if it finds the command | ||
2145 | * iocb else returns NULL. | ||
2146 | **/ | ||
2147 | static struct lpfc_iocbq * | ||
2148 | lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba, | ||
2149 | struct lpfc_sli_ring *pring, uint16_t iotag) | ||
2150 | { | ||
2151 | struct lpfc_iocbq *cmd_iocb; | ||
2152 | |||
2153 | if (iotag != 0 && iotag <= phba->sli.last_iotag) { | ||
2154 | cmd_iocb = phba->sli.iocbq_lookup[iotag]; | ||
2155 | list_del_init(&cmd_iocb->list); | ||
2156 | pring->txcmplq_cnt--; | ||
2157 | return cmd_iocb; | ||
2158 | } | ||
2159 | |||
2160 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2161 | "0372 iotag x%x is out off range: max iotag (x%x)\n", | ||
2162 | iotag, phba->sli.last_iotag); | ||
2163 | return NULL; | ||
2164 | } | ||
2165 | |||
2166 | /** | ||
1555 | * lpfc_sli_process_sol_iocb - process solicited iocb completion | 2167 | * lpfc_sli_process_sol_iocb - process solicited iocb completion |
1556 | * @phba: Pointer to HBA context object. | 2168 | * @phba: Pointer to HBA context object. |
1557 | * @pring: Pointer to driver SLI ring object. | 2169 | * @pring: Pointer to driver SLI ring object. |
@@ -1954,7 +2566,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, | |||
1954 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | 2566 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && |
1955 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | 2567 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { |
1956 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 2568 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
1957 | lpfc_rampdown_queue_depth(phba); | 2569 | phba->lpfc_rampdown_queue_depth(phba); |
1958 | spin_lock_irqsave(&phba->hbalock, iflag); | 2570 | spin_lock_irqsave(&phba->hbalock, iflag); |
1959 | } | 2571 | } |
1960 | 2572 | ||
@@ -2068,39 +2680,215 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, | |||
2068 | } | 2680 | } |
2069 | 2681 | ||
2070 | /** | 2682 | /** |
2071 | * lpfc_sli_handle_slow_ring_event - Handle ring events for non-FCP rings | 2683 | * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb |
2684 | * @phba: Pointer to HBA context object. | ||
2685 | * @pring: Pointer to driver SLI ring object. | ||
2686 | * @rspiocbp: Pointer to driver response IOCB object. | ||
2687 | * | ||
2688 | * This function is called from the worker thread when there is a slow-path | ||
2689 | * response IOCB to process. This function chains all the response iocbs until | ||
2690 | * seeing the iocb with the LE bit set. The function will call | ||
2691 | * lpfc_sli_process_sol_iocb function if the response iocb indicates a | ||
2692 | * completion of a command iocb. The function will call the | ||
2693 | * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb. | ||
2694 | * The function frees the resources or calls the completion handler if this | ||
2695 | * iocb is an abort completion. The function returns NULL when the response | ||
2696 | * iocb has the LE bit set and all the chained iocbs are processed, otherwise | ||
2697 | * this function shall chain the iocb on to the iocb_continueq and return the | ||
2698 | * response iocb passed in. | ||
2699 | **/ | ||
2700 | static struct lpfc_iocbq * | ||
2701 | lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | ||
2702 | struct lpfc_iocbq *rspiocbp) | ||
2703 | { | ||
2704 | struct lpfc_iocbq *saveq; | ||
2705 | struct lpfc_iocbq *cmdiocbp; | ||
2706 | struct lpfc_iocbq *next_iocb; | ||
2707 | IOCB_t *irsp = NULL; | ||
2708 | uint32_t free_saveq; | ||
2709 | uint8_t iocb_cmd_type; | ||
2710 | lpfc_iocb_type type; | ||
2711 | unsigned long iflag; | ||
2712 | int rc; | ||
2713 | |||
2714 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2715 | /* First add the response iocb to the countinueq list */ | ||
2716 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | ||
2717 | pring->iocb_continueq_cnt++; | ||
2718 | |||
2719 | /* Now, determine whetehr the list is completed for processing */ | ||
2720 | irsp = &rspiocbp->iocb; | ||
2721 | if (irsp->ulpLe) { | ||
2722 | /* | ||
2723 | * By default, the driver expects to free all resources | ||
2724 | * associated with this iocb completion. | ||
2725 | */ | ||
2726 | free_saveq = 1; | ||
2727 | saveq = list_get_first(&pring->iocb_continueq, | ||
2728 | struct lpfc_iocbq, list); | ||
2729 | irsp = &(saveq->iocb); | ||
2730 | list_del_init(&pring->iocb_continueq); | ||
2731 | pring->iocb_continueq_cnt = 0; | ||
2732 | |||
2733 | pring->stats.iocb_rsp++; | ||
2734 | |||
2735 | /* | ||
2736 | * If resource errors reported from HBA, reduce | ||
2737 | * queuedepths of the SCSI device. | ||
2738 | */ | ||
2739 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | ||
2740 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | ||
2741 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2742 | phba->lpfc_rampdown_queue_depth(phba); | ||
2743 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2744 | } | ||
2745 | |||
2746 | if (irsp->ulpStatus) { | ||
2747 | /* Rsp ring <ringno> error: IOCB */ | ||
2748 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
2749 | "0328 Rsp Ring %d error: " | ||
2750 | "IOCB Data: " | ||
2751 | "x%x x%x x%x x%x " | ||
2752 | "x%x x%x x%x x%x " | ||
2753 | "x%x x%x x%x x%x " | ||
2754 | "x%x x%x x%x x%x\n", | ||
2755 | pring->ringno, | ||
2756 | irsp->un.ulpWord[0], | ||
2757 | irsp->un.ulpWord[1], | ||
2758 | irsp->un.ulpWord[2], | ||
2759 | irsp->un.ulpWord[3], | ||
2760 | irsp->un.ulpWord[4], | ||
2761 | irsp->un.ulpWord[5], | ||
2762 | *(((uint32_t *) irsp) + 6), | ||
2763 | *(((uint32_t *) irsp) + 7), | ||
2764 | *(((uint32_t *) irsp) + 8), | ||
2765 | *(((uint32_t *) irsp) + 9), | ||
2766 | *(((uint32_t *) irsp) + 10), | ||
2767 | *(((uint32_t *) irsp) + 11), | ||
2768 | *(((uint32_t *) irsp) + 12), | ||
2769 | *(((uint32_t *) irsp) + 13), | ||
2770 | *(((uint32_t *) irsp) + 14), | ||
2771 | *(((uint32_t *) irsp) + 15)); | ||
2772 | } | ||
2773 | |||
2774 | /* | ||
2775 | * Fetch the IOCB command type and call the correct completion | ||
2776 | * routine. Solicited and Unsolicited IOCBs on the ELS ring | ||
2777 | * get freed back to the lpfc_iocb_list by the discovery | ||
2778 | * kernel thread. | ||
2779 | */ | ||
2780 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | ||
2781 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | ||
2782 | switch (type) { | ||
2783 | case LPFC_SOL_IOCB: | ||
2784 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2785 | rc = lpfc_sli_process_sol_iocb(phba, pring, saveq); | ||
2786 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2787 | break; | ||
2788 | |||
2789 | case LPFC_UNSOL_IOCB: | ||
2790 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2791 | rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq); | ||
2792 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2793 | if (!rc) | ||
2794 | free_saveq = 0; | ||
2795 | break; | ||
2796 | |||
2797 | case LPFC_ABORT_IOCB: | ||
2798 | cmdiocbp = NULL; | ||
2799 | if (irsp->ulpCommand != CMD_XRI_ABORTED_CX) | ||
2800 | cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, | ||
2801 | saveq); | ||
2802 | if (cmdiocbp) { | ||
2803 | /* Call the specified completion routine */ | ||
2804 | if (cmdiocbp->iocb_cmpl) { | ||
2805 | spin_unlock_irqrestore(&phba->hbalock, | ||
2806 | iflag); | ||
2807 | (cmdiocbp->iocb_cmpl)(phba, cmdiocbp, | ||
2808 | saveq); | ||
2809 | spin_lock_irqsave(&phba->hbalock, | ||
2810 | iflag); | ||
2811 | } else | ||
2812 | __lpfc_sli_release_iocbq(phba, | ||
2813 | cmdiocbp); | ||
2814 | } | ||
2815 | break; | ||
2816 | |||
2817 | case LPFC_UNKNOWN_IOCB: | ||
2818 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | ||
2819 | char adaptermsg[LPFC_MAX_ADPTMSG]; | ||
2820 | memset(adaptermsg, 0, LPFC_MAX_ADPTMSG); | ||
2821 | memcpy(&adaptermsg[0], (uint8_t *)irsp, | ||
2822 | MAX_MSG_DATA); | ||
2823 | dev_warn(&((phba->pcidev)->dev), | ||
2824 | "lpfc%d: %s\n", | ||
2825 | phba->brd_no, adaptermsg); | ||
2826 | } else { | ||
2827 | /* Unknown IOCB command */ | ||
2828 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2829 | "0335 Unknown IOCB " | ||
2830 | "command Data: x%x " | ||
2831 | "x%x x%x x%x\n", | ||
2832 | irsp->ulpCommand, | ||
2833 | irsp->ulpStatus, | ||
2834 | irsp->ulpIoTag, | ||
2835 | irsp->ulpContext); | ||
2836 | } | ||
2837 | break; | ||
2838 | } | ||
2839 | |||
2840 | if (free_saveq) { | ||
2841 | list_for_each_entry_safe(rspiocbp, next_iocb, | ||
2842 | &saveq->list, list) { | ||
2843 | list_del(&rspiocbp->list); | ||
2844 | __lpfc_sli_release_iocbq(phba, rspiocbp); | ||
2845 | } | ||
2846 | __lpfc_sli_release_iocbq(phba, saveq); | ||
2847 | } | ||
2848 | rspiocbp = NULL; | ||
2849 | } | ||
2850 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2851 | return rspiocbp; | ||
2852 | } | ||
2853 | |||
2854 | /** | ||
2855 | * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs | ||
2072 | * @phba: Pointer to HBA context object. | 2856 | * @phba: Pointer to HBA context object. |
2073 | * @pring: Pointer to driver SLI ring object. | 2857 | * @pring: Pointer to driver SLI ring object. |
2074 | * @mask: Host attention register mask for this ring. | 2858 | * @mask: Host attention register mask for this ring. |
2075 | * | 2859 | * |
2076 | * This function is called from the worker thread when there is a ring | 2860 | * This routine wraps the actual slow_ring event process routine from the |
2077 | * event for non-fcp rings. The caller does not hold any lock . | 2861 | * API jump table function pointer from the lpfc_hba struct. |
2078 | * The function processes each response iocb in the response ring until it | ||
2079 | * finds an iocb with LE bit set and chains all the iocbs upto the iocb with | ||
2080 | * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the | ||
2081 | * response iocb indicates a completion of a command iocb. The function | ||
2082 | * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited | ||
2083 | * iocb. The function frees the resources or calls the completion handler if | ||
2084 | * this iocb is an abort completion. The function returns 0 when the allocated | ||
2085 | * iocbs are not freed, otherwise returns 1. | ||
2086 | **/ | 2862 | **/ |
2087 | int | 2863 | void |
2088 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, | 2864 | lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, |
2089 | struct lpfc_sli_ring *pring, uint32_t mask) | 2865 | struct lpfc_sli_ring *pring, uint32_t mask) |
2090 | { | 2866 | { |
2867 | phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask); | ||
2868 | } | ||
2869 | |||
2870 | /** | ||
2871 | * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings | ||
2872 | * @phba: Pointer to HBA context object. | ||
2873 | * @pring: Pointer to driver SLI ring object. | ||
2874 | * @mask: Host attention register mask for this ring. | ||
2875 | * | ||
2876 | * This function is called from the worker thread when there is a ring event | ||
2877 | * for non-fcp rings. The caller does not hold any lock. The function will | ||
2878 | * remove each response iocb in the response ring and calls the handle | ||
2879 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | ||
2880 | **/ | ||
2881 | static void | ||
2882 | lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba, | ||
2883 | struct lpfc_sli_ring *pring, uint32_t mask) | ||
2884 | { | ||
2091 | struct lpfc_pgp *pgp; | 2885 | struct lpfc_pgp *pgp; |
2092 | IOCB_t *entry; | 2886 | IOCB_t *entry; |
2093 | IOCB_t *irsp = NULL; | 2887 | IOCB_t *irsp = NULL; |
2094 | struct lpfc_iocbq *rspiocbp = NULL; | 2888 | struct lpfc_iocbq *rspiocbp = NULL; |
2095 | struct lpfc_iocbq *next_iocb; | ||
2096 | struct lpfc_iocbq *cmdiocbp; | ||
2097 | struct lpfc_iocbq *saveq; | ||
2098 | uint8_t iocb_cmd_type; | ||
2099 | lpfc_iocb_type type; | ||
2100 | uint32_t status, free_saveq; | ||
2101 | uint32_t portRspPut, portRspMax; | 2889 | uint32_t portRspPut, portRspMax; |
2102 | int rc = 1; | ||
2103 | unsigned long iflag; | 2890 | unsigned long iflag; |
2891 | uint32_t status; | ||
2104 | 2892 | ||
2105 | pgp = &phba->port_gp[pring->ringno]; | 2893 | pgp = &phba->port_gp[pring->ringno]; |
2106 | spin_lock_irqsave(&phba->hbalock, iflag); | 2894 | spin_lock_irqsave(&phba->hbalock, iflag); |
@@ -2128,7 +2916,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, | |||
2128 | phba->work_hs = HS_FFER3; | 2916 | phba->work_hs = HS_FFER3; |
2129 | lpfc_handle_eratt(phba); | 2917 | lpfc_handle_eratt(phba); |
2130 | 2918 | ||
2131 | return 1; | 2919 | return; |
2132 | } | 2920 | } |
2133 | 2921 | ||
2134 | rmb(); | 2922 | rmb(); |
@@ -2173,138 +2961,10 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, | |||
2173 | 2961 | ||
2174 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); | 2962 | writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx); |
2175 | 2963 | ||
2176 | list_add_tail(&rspiocbp->list, &(pring->iocb_continueq)); | 2964 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2177 | 2965 | /* Handle the response IOCB */ | |
2178 | pring->iocb_continueq_cnt++; | 2966 | rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp); |
2179 | if (irsp->ulpLe) { | 2967 | spin_lock_irqsave(&phba->hbalock, iflag); |
2180 | /* | ||
2181 | * By default, the driver expects to free all resources | ||
2182 | * associated with this iocb completion. | ||
2183 | */ | ||
2184 | free_saveq = 1; | ||
2185 | saveq = list_get_first(&pring->iocb_continueq, | ||
2186 | struct lpfc_iocbq, list); | ||
2187 | irsp = &(saveq->iocb); | ||
2188 | list_del_init(&pring->iocb_continueq); | ||
2189 | pring->iocb_continueq_cnt = 0; | ||
2190 | |||
2191 | pring->stats.iocb_rsp++; | ||
2192 | |||
2193 | /* | ||
2194 | * If resource errors reported from HBA, reduce | ||
2195 | * queuedepths of the SCSI device. | ||
2196 | */ | ||
2197 | if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) && | ||
2198 | (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) { | ||
2199 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2200 | lpfc_rampdown_queue_depth(phba); | ||
2201 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2202 | } | ||
2203 | |||
2204 | if (irsp->ulpStatus) { | ||
2205 | /* Rsp ring <ringno> error: IOCB */ | ||
2206 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
2207 | "0328 Rsp Ring %d error: " | ||
2208 | "IOCB Data: " | ||
2209 | "x%x x%x x%x x%x " | ||
2210 | "x%x x%x x%x x%x " | ||
2211 | "x%x x%x x%x x%x " | ||
2212 | "x%x x%x x%x x%x\n", | ||
2213 | pring->ringno, | ||
2214 | irsp->un.ulpWord[0], | ||
2215 | irsp->un.ulpWord[1], | ||
2216 | irsp->un.ulpWord[2], | ||
2217 | irsp->un.ulpWord[3], | ||
2218 | irsp->un.ulpWord[4], | ||
2219 | irsp->un.ulpWord[5], | ||
2220 | *(((uint32_t *) irsp) + 6), | ||
2221 | *(((uint32_t *) irsp) + 7), | ||
2222 | *(((uint32_t *) irsp) + 8), | ||
2223 | *(((uint32_t *) irsp) + 9), | ||
2224 | *(((uint32_t *) irsp) + 10), | ||
2225 | *(((uint32_t *) irsp) + 11), | ||
2226 | *(((uint32_t *) irsp) + 12), | ||
2227 | *(((uint32_t *) irsp) + 13), | ||
2228 | *(((uint32_t *) irsp) + 14), | ||
2229 | *(((uint32_t *) irsp) + 15)); | ||
2230 | } | ||
2231 | |||
2232 | /* | ||
2233 | * Fetch the IOCB command type and call the correct | ||
2234 | * completion routine. Solicited and Unsolicited | ||
2235 | * IOCBs on the ELS ring get freed back to the | ||
2236 | * lpfc_iocb_list by the discovery kernel thread. | ||
2237 | */ | ||
2238 | iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; | ||
2239 | type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); | ||
2240 | if (type == LPFC_SOL_IOCB) { | ||
2241 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2242 | rc = lpfc_sli_process_sol_iocb(phba, pring, | ||
2243 | saveq); | ||
2244 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2245 | } else if (type == LPFC_UNSOL_IOCB) { | ||
2246 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
2247 | rc = lpfc_sli_process_unsol_iocb(phba, pring, | ||
2248 | saveq); | ||
2249 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
2250 | if (!rc) | ||
2251 | free_saveq = 0; | ||
2252 | } else if (type == LPFC_ABORT_IOCB) { | ||
2253 | if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && | ||
2254 | ((cmdiocbp = | ||
2255 | lpfc_sli_iocbq_lookup(phba, pring, | ||
2256 | saveq)))) { | ||
2257 | /* Call the specified completion | ||
2258 | routine */ | ||
2259 | if (cmdiocbp->iocb_cmpl) { | ||
2260 | spin_unlock_irqrestore( | ||
2261 | &phba->hbalock, | ||
2262 | iflag); | ||
2263 | (cmdiocbp->iocb_cmpl) (phba, | ||
2264 | cmdiocbp, saveq); | ||
2265 | spin_lock_irqsave( | ||
2266 | &phba->hbalock, | ||
2267 | iflag); | ||
2268 | } else | ||
2269 | __lpfc_sli_release_iocbq(phba, | ||
2270 | cmdiocbp); | ||
2271 | } | ||
2272 | } else if (type == LPFC_UNKNOWN_IOCB) { | ||
2273 | if (irsp->ulpCommand == CMD_ADAPTER_MSG) { | ||
2274 | |||
2275 | char adaptermsg[LPFC_MAX_ADPTMSG]; | ||
2276 | |||
2277 | memset(adaptermsg, 0, | ||
2278 | LPFC_MAX_ADPTMSG); | ||
2279 | memcpy(&adaptermsg[0], (uint8_t *) irsp, | ||
2280 | MAX_MSG_DATA); | ||
2281 | dev_warn(&((phba->pcidev)->dev), | ||
2282 | "lpfc%d: %s\n", | ||
2283 | phba->brd_no, adaptermsg); | ||
2284 | } else { | ||
2285 | /* Unknown IOCB command */ | ||
2286 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2287 | "0335 Unknown IOCB " | ||
2288 | "command Data: x%x " | ||
2289 | "x%x x%x x%x\n", | ||
2290 | irsp->ulpCommand, | ||
2291 | irsp->ulpStatus, | ||
2292 | irsp->ulpIoTag, | ||
2293 | irsp->ulpContext); | ||
2294 | } | ||
2295 | } | ||
2296 | |||
2297 | if (free_saveq) { | ||
2298 | list_for_each_entry_safe(rspiocbp, next_iocb, | ||
2299 | &saveq->list, list) { | ||
2300 | list_del(&rspiocbp->list); | ||
2301 | __lpfc_sli_release_iocbq(phba, | ||
2302 | rspiocbp); | ||
2303 | } | ||
2304 | __lpfc_sli_release_iocbq(phba, saveq); | ||
2305 | } | ||
2306 | rspiocbp = NULL; | ||
2307 | } | ||
2308 | 2968 | ||
2309 | /* | 2969 | /* |
2310 | * If the port response put pointer has not been updated, sync | 2970 | * If the port response put pointer has not been updated, sync |
@@ -2338,7 +2998,37 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, | |||
2338 | } | 2998 | } |
2339 | 2999 | ||
2340 | spin_unlock_irqrestore(&phba->hbalock, iflag); | 3000 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2341 | return rc; | 3001 | return; |
3002 | } | ||
3003 | |||
3004 | /** | ||
3005 | * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events | ||
3006 | * @phba: Pointer to HBA context object. | ||
3007 | * @pring: Pointer to driver SLI ring object. | ||
3008 | * @mask: Host attention register mask for this ring. | ||
3009 | * | ||
3010 | * This function is called from the worker thread when there is a pending | ||
3011 | * ELS response iocb on the driver internal slow-path response iocb worker | ||
3012 | * queue. The caller does not hold any lock. The function will remove each | ||
3013 | * response iocb from the response worker queue and calls the handle | ||
3014 | * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it. | ||
3015 | **/ | ||
3016 | static void | ||
3017 | lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba, | ||
3018 | struct lpfc_sli_ring *pring, uint32_t mask) | ||
3019 | { | ||
3020 | struct lpfc_iocbq *irspiocbq; | ||
3021 | unsigned long iflag; | ||
3022 | |||
3023 | while (!list_empty(&phba->sli4_hba.sp_rspiocb_work_queue)) { | ||
3024 | /* Get the response iocb from the head of work queue */ | ||
3025 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
3026 | list_remove_head(&phba->sli4_hba.sp_rspiocb_work_queue, | ||
3027 | irspiocbq, struct lpfc_iocbq, list); | ||
3028 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
3029 | /* Process the response iocb */ | ||
3030 | lpfc_sli_sp_handle_rspiocb(phba, pring, irspiocbq); | ||
3031 | } | ||
2342 | } | 3032 | } |
2343 | 3033 | ||
2344 | /** | 3034 | /** |
@@ -2420,7 +3110,7 @@ lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |||
2420 | } | 3110 | } |
2421 | 3111 | ||
2422 | /** | 3112 | /** |
2423 | * lpfc_sli_brdready - Check for host status bits | 3113 | * lpfc_sli_brdready_s3 - Check for sli3 host ready status |
2424 | * @phba: Pointer to HBA context object. | 3114 | * @phba: Pointer to HBA context object. |
2425 | * @mask: Bit mask to be checked. | 3115 | * @mask: Bit mask to be checked. |
2426 | * | 3116 | * |
@@ -2432,8 +3122,8 @@ lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba) | |||
2432 | * function returns 1 when HBA fail to restart otherwise returns | 3122 | * function returns 1 when HBA fail to restart otherwise returns |
2433 | * zero. | 3123 | * zero. |
2434 | **/ | 3124 | **/ |
2435 | int | 3125 | static int |
2436 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | 3126 | lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask) |
2437 | { | 3127 | { |
2438 | uint32_t status; | 3128 | uint32_t status; |
2439 | int i = 0; | 3129 | int i = 0; |
@@ -2477,6 +3167,56 @@ lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | |||
2477 | return retval; | 3167 | return retval; |
2478 | } | 3168 | } |
2479 | 3169 | ||
3170 | /** | ||
3171 | * lpfc_sli_brdready_s4 - Check for sli4 host ready status | ||
3172 | * @phba: Pointer to HBA context object. | ||
3173 | * @mask: Bit mask to be checked. | ||
3174 | * | ||
3175 | * This function checks the host status register to check if HBA is | ||
3176 | * ready. This function will wait in a loop for the HBA to be ready | ||
3177 | * If the HBA is not ready , the function will will reset the HBA PCI | ||
3178 | * function again. The function returns 1 when HBA fail to be ready | ||
3179 | * otherwise returns zero. | ||
3180 | **/ | ||
3181 | static int | ||
3182 | lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask) | ||
3183 | { | ||
3184 | uint32_t status; | ||
3185 | int retval = 0; | ||
3186 | |||
3187 | /* Read the HBA Host Status Register */ | ||
3188 | status = lpfc_sli4_post_status_check(phba); | ||
3189 | |||
3190 | if (status) { | ||
3191 | phba->pport->port_state = LPFC_VPORT_UNKNOWN; | ||
3192 | lpfc_sli_brdrestart(phba); | ||
3193 | status = lpfc_sli4_post_status_check(phba); | ||
3194 | } | ||
3195 | |||
3196 | /* Check to see if any errors occurred during init */ | ||
3197 | if (status) { | ||
3198 | phba->link_state = LPFC_HBA_ERROR; | ||
3199 | retval = 1; | ||
3200 | } else | ||
3201 | phba->sli4_hba.intr_enable = 0; | ||
3202 | |||
3203 | return retval; | ||
3204 | } | ||
3205 | |||
3206 | /** | ||
3207 | * lpfc_sli_brdready - Wrapper func for checking the hba readyness | ||
3208 | * @phba: Pointer to HBA context object. | ||
3209 | * @mask: Bit mask to be checked. | ||
3210 | * | ||
3211 | * This routine wraps the actual SLI3 or SLI4 hba readyness check routine | ||
3212 | * from the API jump table function pointer from the lpfc_hba struct. | ||
3213 | **/ | ||
3214 | int | ||
3215 | lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) | ||
3216 | { | ||
3217 | return phba->lpfc_sli_brdready(phba, mask); | ||
3218 | } | ||
3219 | |||
2480 | #define BARRIER_TEST_PATTERN (0xdeadbeef) | 3220 | #define BARRIER_TEST_PATTERN (0xdeadbeef) |
2481 | 3221 | ||
2482 | /** | 3222 | /** |
@@ -2532,7 +3272,7 @@ void lpfc_reset_barrier(struct lpfc_hba *phba) | |||
2532 | mdelay(1); | 3272 | mdelay(1); |
2533 | 3273 | ||
2534 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { | 3274 | if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { |
2535 | if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || | 3275 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE || |
2536 | phba->pport->stopped) | 3276 | phba->pport->stopped) |
2537 | goto restore_hc; | 3277 | goto restore_hc; |
2538 | else | 3278 | else |
@@ -2613,7 +3353,9 @@ lpfc_sli_brdkill(struct lpfc_hba *phba) | |||
2613 | return 1; | 3353 | return 1; |
2614 | } | 3354 | } |
2615 | 3355 | ||
2616 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 3356 | spin_lock_irq(&phba->hbalock); |
3357 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | ||
3358 | spin_unlock_irq(&phba->hbalock); | ||
2617 | 3359 | ||
2618 | mempool_free(pmb, phba->mbox_mem_pool); | 3360 | mempool_free(pmb, phba->mbox_mem_pool); |
2619 | 3361 | ||
@@ -2636,10 +3378,10 @@ lpfc_sli_brdkill(struct lpfc_hba *phba) | |||
2636 | } | 3378 | } |
2637 | spin_lock_irq(&phba->hbalock); | 3379 | spin_lock_irq(&phba->hbalock); |
2638 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 3380 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
3381 | psli->mbox_active = NULL; | ||
2639 | phba->link_flag &= ~LS_IGNORE_ERATT; | 3382 | phba->link_flag &= ~LS_IGNORE_ERATT; |
2640 | spin_unlock_irq(&phba->hbalock); | 3383 | spin_unlock_irq(&phba->hbalock); |
2641 | 3384 | ||
2642 | psli->mbox_active = NULL; | ||
2643 | lpfc_hba_down_post(phba); | 3385 | lpfc_hba_down_post(phba); |
2644 | phba->link_state = LPFC_HBA_ERROR; | 3386 | phba->link_state = LPFC_HBA_ERROR; |
2645 | 3387 | ||
@@ -2647,7 +3389,7 @@ lpfc_sli_brdkill(struct lpfc_hba *phba) | |||
2647 | } | 3389 | } |
2648 | 3390 | ||
2649 | /** | 3391 | /** |
2650 | * lpfc_sli_brdreset - Reset the HBA | 3392 | * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA |
2651 | * @phba: Pointer to HBA context object. | 3393 | * @phba: Pointer to HBA context object. |
2652 | * | 3394 | * |
2653 | * This function resets the HBA by writing HC_INITFF to the control | 3395 | * This function resets the HBA by writing HC_INITFF to the control |
@@ -2683,7 +3425,8 @@ lpfc_sli_brdreset(struct lpfc_hba *phba) | |||
2683 | (cfg_value & | 3425 | (cfg_value & |
2684 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | 3426 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); |
2685 | 3427 | ||
2686 | psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA); | 3428 | psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA); |
3429 | |||
2687 | /* Now toggle INITFF bit in the Host Control Register */ | 3430 | /* Now toggle INITFF bit in the Host Control Register */ |
2688 | writel(HC_INITFF, phba->HCregaddr); | 3431 | writel(HC_INITFF, phba->HCregaddr); |
2689 | mdelay(1); | 3432 | mdelay(1); |
@@ -2710,7 +3453,66 @@ lpfc_sli_brdreset(struct lpfc_hba *phba) | |||
2710 | } | 3453 | } |
2711 | 3454 | ||
2712 | /** | 3455 | /** |
2713 | * lpfc_sli_brdrestart - Restart the HBA | 3456 | * lpfc_sli4_brdreset - Reset a sli-4 HBA |
3457 | * @phba: Pointer to HBA context object. | ||
3458 | * | ||
3459 | * This function resets a SLI4 HBA. This function disables PCI layer parity | ||
3460 | * checking during resets the device. The caller is not required to hold | ||
3461 | * any locks. | ||
3462 | * | ||
3463 | * This function returns 0 always. | ||
3464 | **/ | ||
3465 | int | ||
3466 | lpfc_sli4_brdreset(struct lpfc_hba *phba) | ||
3467 | { | ||
3468 | struct lpfc_sli *psli = &phba->sli; | ||
3469 | uint16_t cfg_value; | ||
3470 | uint8_t qindx; | ||
3471 | |||
3472 | /* Reset HBA */ | ||
3473 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | ||
3474 | "0295 Reset HBA Data: x%x x%x\n", | ||
3475 | phba->pport->port_state, psli->sli_flag); | ||
3476 | |||
3477 | /* perform board reset */ | ||
3478 | phba->fc_eventTag = 0; | ||
3479 | phba->pport->fc_myDID = 0; | ||
3480 | phba->pport->fc_prevDID = 0; | ||
3481 | |||
3482 | /* Turn off parity checking and serr during the physical reset */ | ||
3483 | pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); | ||
3484 | pci_write_config_word(phba->pcidev, PCI_COMMAND, | ||
3485 | (cfg_value & | ||
3486 | ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR))); | ||
3487 | |||
3488 | spin_lock_irq(&phba->hbalock); | ||
3489 | psli->sli_flag &= ~(LPFC_PROCESS_LA); | ||
3490 | phba->fcf.fcf_flag = 0; | ||
3491 | /* Clean up the child queue list for the CQs */ | ||
3492 | list_del_init(&phba->sli4_hba.mbx_wq->list); | ||
3493 | list_del_init(&phba->sli4_hba.els_wq->list); | ||
3494 | list_del_init(&phba->sli4_hba.hdr_rq->list); | ||
3495 | list_del_init(&phba->sli4_hba.dat_rq->list); | ||
3496 | list_del_init(&phba->sli4_hba.mbx_cq->list); | ||
3497 | list_del_init(&phba->sli4_hba.els_cq->list); | ||
3498 | list_del_init(&phba->sli4_hba.rxq_cq->list); | ||
3499 | for (qindx = 0; qindx < phba->cfg_fcp_wq_count; qindx++) | ||
3500 | list_del_init(&phba->sli4_hba.fcp_wq[qindx]->list); | ||
3501 | for (qindx = 0; qindx < phba->cfg_fcp_eq_count; qindx++) | ||
3502 | list_del_init(&phba->sli4_hba.fcp_cq[qindx]->list); | ||
3503 | spin_unlock_irq(&phba->hbalock); | ||
3504 | |||
3505 | /* Now physically reset the device */ | ||
3506 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3507 | "0389 Performing PCI function reset!\n"); | ||
3508 | /* Perform FCoE PCI function reset */ | ||
3509 | lpfc_pci_function_reset(phba); | ||
3510 | |||
3511 | return 0; | ||
3512 | } | ||
3513 | |||
3514 | /** | ||
3515 | * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba | ||
2714 | * @phba: Pointer to HBA context object. | 3516 | * @phba: Pointer to HBA context object. |
2715 | * | 3517 | * |
2716 | * This function is called in the SLI initialization code path to | 3518 | * This function is called in the SLI initialization code path to |
@@ -2722,8 +3524,8 @@ lpfc_sli_brdreset(struct lpfc_hba *phba) | |||
2722 | * The function does not guarantee completion of MBX_RESTART mailbox | 3524 | * The function does not guarantee completion of MBX_RESTART mailbox |
2723 | * command before the return of this function. | 3525 | * command before the return of this function. |
2724 | **/ | 3526 | **/ |
2725 | int | 3527 | static int |
2726 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | 3528 | lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) |
2727 | { | 3529 | { |
2728 | MAILBOX_t *mb; | 3530 | MAILBOX_t *mb; |
2729 | struct lpfc_sli *psli; | 3531 | struct lpfc_sli *psli; |
@@ -2762,7 +3564,7 @@ lpfc_sli_brdrestart(struct lpfc_hba *phba) | |||
2762 | lpfc_sli_brdreset(phba); | 3564 | lpfc_sli_brdreset(phba); |
2763 | phba->pport->stopped = 0; | 3565 | phba->pport->stopped = 0; |
2764 | phba->link_state = LPFC_INIT_START; | 3566 | phba->link_state = LPFC_INIT_START; |
2765 | 3567 | phba->hba_flag = 0; | |
2766 | spin_unlock_irq(&phba->hbalock); | 3568 | spin_unlock_irq(&phba->hbalock); |
2767 | 3569 | ||
2768 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | 3570 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); |
@@ -2777,6 +3579,55 @@ lpfc_sli_brdrestart(struct lpfc_hba *phba) | |||
2777 | } | 3579 | } |
2778 | 3580 | ||
2779 | /** | 3581 | /** |
3582 | * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba | ||
3583 | * @phba: Pointer to HBA context object. | ||
3584 | * | ||
3585 | * This function is called in the SLI initialization code path to restart | ||
3586 | * a SLI4 HBA. The caller is not required to hold any lock. | ||
3587 | * At the end of the function, it calls lpfc_hba_down_post function to | ||
3588 | * free any pending commands. | ||
3589 | **/ | ||
3590 | static int | ||
3591 | lpfc_sli_brdrestart_s4(struct lpfc_hba *phba) | ||
3592 | { | ||
3593 | struct lpfc_sli *psli = &phba->sli; | ||
3594 | |||
3595 | |||
3596 | /* Restart HBA */ | ||
3597 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | ||
3598 | "0296 Restart HBA Data: x%x x%x\n", | ||
3599 | phba->pport->port_state, psli->sli_flag); | ||
3600 | |||
3601 | lpfc_sli4_brdreset(phba); | ||
3602 | |||
3603 | spin_lock_irq(&phba->hbalock); | ||
3604 | phba->pport->stopped = 0; | ||
3605 | phba->link_state = LPFC_INIT_START; | ||
3606 | phba->hba_flag = 0; | ||
3607 | spin_unlock_irq(&phba->hbalock); | ||
3608 | |||
3609 | memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); | ||
3610 | psli->stats_start = get_seconds(); | ||
3611 | |||
3612 | lpfc_hba_down_post(phba); | ||
3613 | |||
3614 | return 0; | ||
3615 | } | ||
3616 | |||
3617 | /** | ||
3618 | * lpfc_sli_brdrestart - Wrapper func for restarting hba | ||
3619 | * @phba: Pointer to HBA context object. | ||
3620 | * | ||
3621 | * This routine wraps the actual SLI3 or SLI4 hba restart routine from the | ||
3622 | * API jump table function pointer from the lpfc_hba struct. | ||
3623 | **/ | ||
3624 | int | ||
3625 | lpfc_sli_brdrestart(struct lpfc_hba *phba) | ||
3626 | { | ||
3627 | return phba->lpfc_sli_brdrestart(phba); | ||
3628 | } | ||
3629 | |||
3630 | /** | ||
2780 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart | 3631 | * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart |
2781 | * @phba: Pointer to HBA context object. | 3632 | * @phba: Pointer to HBA context object. |
2782 | * | 3633 | * |
@@ -2940,7 +3791,7 @@ lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |||
2940 | if (!pmb) | 3791 | if (!pmb) |
2941 | return -ENOMEM; | 3792 | return -ENOMEM; |
2942 | 3793 | ||
2943 | pmbox = &pmb->mb; | 3794 | pmbox = &pmb->u.mb; |
2944 | 3795 | ||
2945 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ | 3796 | /* Initialize the struct lpfc_sli_hbq structure for each hbq */ |
2946 | phba->link_state = LPFC_INIT_MBX_CMDS; | 3797 | phba->link_state = LPFC_INIT_MBX_CMDS; |
@@ -2984,6 +3835,26 @@ lpfc_sli_hbq_setup(struct lpfc_hba *phba) | |||
2984 | } | 3835 | } |
2985 | 3836 | ||
2986 | /** | 3837 | /** |
3838 | * lpfc_sli4_rb_setup - Initialize and post RBs to HBA | ||
3839 | * @phba: Pointer to HBA context object. | ||
3840 | * | ||
3841 | * This function is called during the SLI initialization to configure | ||
3842 | * all the HBQs and post buffers to the HBQ. The caller is not | ||
3843 | * required to hold any locks. This function will return zero if successful | ||
3844 | * else it will return negative error code. | ||
3845 | **/ | ||
3846 | static int | ||
3847 | lpfc_sli4_rb_setup(struct lpfc_hba *phba) | ||
3848 | { | ||
3849 | phba->hbq_in_use = 1; | ||
3850 | phba->hbqs[0].entry_count = lpfc_hbq_defs[0]->entry_count; | ||
3851 | phba->hbq_count = 1; | ||
3852 | /* Initially populate or replenish the HBQs */ | ||
3853 | lpfc_sli_hbqbuf_init_hbqs(phba, 0); | ||
3854 | return 0; | ||
3855 | } | ||
3856 | |||
3857 | /** | ||
2987 | * lpfc_sli_config_port - Issue config port mailbox command | 3858 | * lpfc_sli_config_port - Issue config port mailbox command |
2988 | * @phba: Pointer to HBA context object. | 3859 | * @phba: Pointer to HBA context object. |
2989 | * @sli_mode: sli mode - 2/3 | 3860 | * @sli_mode: sli mode - 2/3 |
@@ -3047,33 +3918,43 @@ lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |||
3047 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 3918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3048 | "0442 Adapter failed to init, mbxCmd x%x " | 3919 | "0442 Adapter failed to init, mbxCmd x%x " |
3049 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", | 3920 | "CONFIG_PORT, mbxStatus x%x Data: x%x\n", |
3050 | pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0); | 3921 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0); |
3051 | spin_lock_irq(&phba->hbalock); | 3922 | spin_lock_irq(&phba->hbalock); |
3052 | phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; | 3923 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
3053 | spin_unlock_irq(&phba->hbalock); | 3924 | spin_unlock_irq(&phba->hbalock); |
3054 | rc = -ENXIO; | 3925 | rc = -ENXIO; |
3055 | } else | 3926 | } else { |
3927 | /* Allow asynchronous mailbox command to go through */ | ||
3928 | spin_lock_irq(&phba->hbalock); | ||
3929 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | ||
3930 | spin_unlock_irq(&phba->hbalock); | ||
3056 | done = 1; | 3931 | done = 1; |
3932 | } | ||
3057 | } | 3933 | } |
3058 | if (!done) { | 3934 | if (!done) { |
3059 | rc = -EINVAL; | 3935 | rc = -EINVAL; |
3060 | goto do_prep_failed; | 3936 | goto do_prep_failed; |
3061 | } | 3937 | } |
3062 | if (pmb->mb.un.varCfgPort.sli_mode == 3) { | 3938 | if (pmb->u.mb.un.varCfgPort.sli_mode == 3) { |
3063 | if (!pmb->mb.un.varCfgPort.cMA) { | 3939 | if (!pmb->u.mb.un.varCfgPort.cMA) { |
3064 | rc = -ENXIO; | 3940 | rc = -ENXIO; |
3065 | goto do_prep_failed; | 3941 | goto do_prep_failed; |
3066 | } | 3942 | } |
3067 | if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) { | 3943 | if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) { |
3068 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; | 3944 | phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED; |
3069 | phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi; | 3945 | phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi; |
3946 | phba->max_vports = (phba->max_vpi > phba->max_vports) ? | ||
3947 | phba->max_vpi : phba->max_vports; | ||
3948 | |||
3070 | } else | 3949 | } else |
3071 | phba->max_vpi = 0; | 3950 | phba->max_vpi = 0; |
3072 | if (pmb->mb.un.varCfgPort.gerbm) | 3951 | if (pmb->u.mb.un.varCfgPort.gdss) |
3952 | phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; | ||
3953 | if (pmb->u.mb.un.varCfgPort.gerbm) | ||
3073 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; | 3954 | phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; |
3074 | if (pmb->mb.un.varCfgPort.gcrp) | 3955 | if (pmb->u.mb.un.varCfgPort.gcrp) |
3075 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; | 3956 | phba->sli3_options |= LPFC_SLI3_CRP_ENABLED; |
3076 | if (pmb->mb.un.varCfgPort.ginb) { | 3957 | if (pmb->u.mb.un.varCfgPort.ginb) { |
3077 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; | 3958 | phba->sli3_options |= LPFC_SLI3_INB_ENABLED; |
3078 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; | 3959 | phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get; |
3079 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; | 3960 | phba->port_gp = phba->mbox->us.s3_inb_pgp.port; |
@@ -3089,7 +3970,7 @@ lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode) | |||
3089 | } | 3970 | } |
3090 | 3971 | ||
3091 | if (phba->cfg_enable_bg) { | 3972 | if (phba->cfg_enable_bg) { |
3092 | if (pmb->mb.un.varCfgPort.gbg) | 3973 | if (pmb->u.mb.un.varCfgPort.gbg) |
3093 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; | 3974 | phba->sli3_options |= LPFC_SLI3_BG_ENABLED; |
3094 | else | 3975 | else |
3095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 3976 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
@@ -3184,8 +4065,9 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba) | |||
3184 | if (rc) | 4065 | if (rc) |
3185 | goto lpfc_sli_hba_setup_error; | 4066 | goto lpfc_sli_hba_setup_error; |
3186 | } | 4067 | } |
3187 | 4068 | spin_lock_irq(&phba->hbalock); | |
3188 | phba->sli.sli_flag |= LPFC_PROCESS_LA; | 4069 | phba->sli.sli_flag |= LPFC_PROCESS_LA; |
4070 | spin_unlock_irq(&phba->hbalock); | ||
3189 | 4071 | ||
3190 | rc = lpfc_config_port_post(phba); | 4072 | rc = lpfc_config_port_post(phba); |
3191 | if (rc) | 4073 | if (rc) |
@@ -3200,6 +4082,493 @@ lpfc_sli_hba_setup_error: | |||
3200 | return rc; | 4082 | return rc; |
3201 | } | 4083 | } |
3202 | 4084 | ||
4085 | /** | ||
4086 | * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region | ||
4087 | * @phba: Pointer to HBA context object. | ||
4088 | * @mboxq: mailbox pointer. | ||
4089 | * This function issue a dump mailbox command to read config region | ||
4090 | * 23 and parse the records in the region and populate driver | ||
4091 | * data structure. | ||
4092 | **/ | ||
4093 | static int | ||
4094 | lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba, | ||
4095 | LPFC_MBOXQ_t *mboxq) | ||
4096 | { | ||
4097 | struct lpfc_dmabuf *mp; | ||
4098 | struct lpfc_mqe *mqe; | ||
4099 | uint32_t data_length; | ||
4100 | int rc; | ||
4101 | |||
4102 | /* Program the default value of vlan_id and fc_map */ | ||
4103 | phba->valid_vlan = 0; | ||
4104 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | ||
4105 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | ||
4106 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | ||
4107 | |||
4108 | mqe = &mboxq->u.mqe; | ||
4109 | if (lpfc_dump_fcoe_param(phba, mboxq)) | ||
4110 | return -ENOMEM; | ||
4111 | |||
4112 | mp = (struct lpfc_dmabuf *) mboxq->context1; | ||
4113 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
4114 | |||
4115 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | ||
4116 | "(%d):2571 Mailbox cmd x%x Status x%x " | ||
4117 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x " | ||
4118 | "x%x x%x x%x x%x x%x x%x x%x x%x x%x " | ||
4119 | "CQ: x%x x%x x%x x%x\n", | ||
4120 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
4121 | bf_get(lpfc_mqe_command, mqe), | ||
4122 | bf_get(lpfc_mqe_status, mqe), | ||
4123 | mqe->un.mb_words[0], mqe->un.mb_words[1], | ||
4124 | mqe->un.mb_words[2], mqe->un.mb_words[3], | ||
4125 | mqe->un.mb_words[4], mqe->un.mb_words[5], | ||
4126 | mqe->un.mb_words[6], mqe->un.mb_words[7], | ||
4127 | mqe->un.mb_words[8], mqe->un.mb_words[9], | ||
4128 | mqe->un.mb_words[10], mqe->un.mb_words[11], | ||
4129 | mqe->un.mb_words[12], mqe->un.mb_words[13], | ||
4130 | mqe->un.mb_words[14], mqe->un.mb_words[15], | ||
4131 | mqe->un.mb_words[16], mqe->un.mb_words[50], | ||
4132 | mboxq->mcqe.word0, | ||
4133 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | ||
4134 | mboxq->mcqe.trailer); | ||
4135 | |||
4136 | if (rc) { | ||
4137 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | ||
4138 | kfree(mp); | ||
4139 | return -EIO; | ||
4140 | } | ||
4141 | data_length = mqe->un.mb_words[5]; | ||
4142 | if (data_length > DMP_FCOEPARAM_RGN_SIZE) { | ||
4143 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | ||
4144 | kfree(mp); | ||
4145 | return -EIO; | ||
4146 | } | ||
4147 | |||
4148 | lpfc_parse_fcoe_conf(phba, mp->virt, data_length); | ||
4149 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | ||
4150 | kfree(mp); | ||
4151 | return 0; | ||
4152 | } | ||
4153 | |||
4154 | /** | ||
4155 | * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data | ||
4156 | * @phba: pointer to lpfc hba data structure. | ||
4157 | * @mboxq: pointer to the LPFC_MBOXQ_t structure. | ||
4158 | * @vpd: pointer to the memory to hold resulting port vpd data. | ||
4159 | * @vpd_size: On input, the number of bytes allocated to @vpd. | ||
4160 | * On output, the number of data bytes in @vpd. | ||
4161 | * | ||
4162 | * This routine executes a READ_REV SLI4 mailbox command. In | ||
4163 | * addition, this routine gets the port vpd data. | ||
4164 | * | ||
4165 | * Return codes | ||
4166 | * 0 - sucessful | ||
4167 | * ENOMEM - could not allocated memory. | ||
4168 | **/ | ||
4169 | static int | ||
4170 | lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | ||
4171 | uint8_t *vpd, uint32_t *vpd_size) | ||
4172 | { | ||
4173 | int rc = 0; | ||
4174 | uint32_t dma_size; | ||
4175 | struct lpfc_dmabuf *dmabuf; | ||
4176 | struct lpfc_mqe *mqe; | ||
4177 | |||
4178 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | ||
4179 | if (!dmabuf) | ||
4180 | return -ENOMEM; | ||
4181 | |||
4182 | /* | ||
4183 | * Get a DMA buffer for the vpd data resulting from the READ_REV | ||
4184 | * mailbox command. | ||
4185 | */ | ||
4186 | dma_size = *vpd_size; | ||
4187 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | ||
4188 | dma_size, | ||
4189 | &dmabuf->phys, | ||
4190 | GFP_KERNEL); | ||
4191 | if (!dmabuf->virt) { | ||
4192 | kfree(dmabuf); | ||
4193 | return -ENOMEM; | ||
4194 | } | ||
4195 | memset(dmabuf->virt, 0, dma_size); | ||
4196 | |||
4197 | /* | ||
4198 | * The SLI4 implementation of READ_REV conflicts at word1, | ||
4199 | * bits 31:16 and SLI4 adds vpd functionality not present | ||
4200 | * in SLI3. This code corrects the conflicts. | ||
4201 | */ | ||
4202 | lpfc_read_rev(phba, mboxq); | ||
4203 | mqe = &mboxq->u.mqe; | ||
4204 | mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys); | ||
4205 | mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys); | ||
4206 | mqe->un.read_rev.word1 &= 0x0000FFFF; | ||
4207 | bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1); | ||
4208 | bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size); | ||
4209 | |||
4210 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
4211 | if (rc) { | ||
4212 | dma_free_coherent(&phba->pcidev->dev, dma_size, | ||
4213 | dmabuf->virt, dmabuf->phys); | ||
4214 | return -EIO; | ||
4215 | } | ||
4216 | |||
4217 | /* | ||
4218 | * The available vpd length cannot be bigger than the | ||
4219 | * DMA buffer passed to the port. Catch the less than | ||
4220 | * case and update the caller's size. | ||
4221 | */ | ||
4222 | if (mqe->un.read_rev.avail_vpd_len < *vpd_size) | ||
4223 | *vpd_size = mqe->un.read_rev.avail_vpd_len; | ||
4224 | |||
4225 | lpfc_sli_pcimem_bcopy(dmabuf->virt, vpd, *vpd_size); | ||
4226 | dma_free_coherent(&phba->pcidev->dev, dma_size, | ||
4227 | dmabuf->virt, dmabuf->phys); | ||
4228 | kfree(dmabuf); | ||
4229 | return 0; | ||
4230 | } | ||
4231 | |||
4232 | /** | ||
4233 | * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues | ||
4234 | * @phba: pointer to lpfc hba data structure. | ||
4235 | * | ||
4236 | * This routine is called to explicitly arm the SLI4 device's completion and | ||
4237 | * event queues | ||
4238 | **/ | ||
4239 | static void | ||
4240 | lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba) | ||
4241 | { | ||
4242 | uint8_t fcp_eqidx; | ||
4243 | |||
4244 | lpfc_sli4_cq_release(phba->sli4_hba.mbx_cq, LPFC_QUEUE_REARM); | ||
4245 | lpfc_sli4_cq_release(phba->sli4_hba.els_cq, LPFC_QUEUE_REARM); | ||
4246 | lpfc_sli4_cq_release(phba->sli4_hba.rxq_cq, LPFC_QUEUE_REARM); | ||
4247 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | ||
4248 | lpfc_sli4_cq_release(phba->sli4_hba.fcp_cq[fcp_eqidx], | ||
4249 | LPFC_QUEUE_REARM); | ||
4250 | lpfc_sli4_eq_release(phba->sli4_hba.sp_eq, LPFC_QUEUE_REARM); | ||
4251 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) | ||
4252 | lpfc_sli4_eq_release(phba->sli4_hba.fp_eq[fcp_eqidx], | ||
4253 | LPFC_QUEUE_REARM); | ||
4254 | } | ||
4255 | |||
4256 | /** | ||
4257 | * lpfc_sli4_hba_setup - SLI4 device intialization PCI function | ||
4258 | * @phba: Pointer to HBA context object. | ||
4259 | * | ||
4260 | * This function is the main SLI4 device intialization PCI function. This | ||
4261 | * function is called by the HBA intialization code, HBA reset code and | ||
4262 | * HBA error attention handler code. Caller is not required to hold any | ||
4263 | * locks. | ||
4264 | **/ | ||
4265 | int | ||
4266 | lpfc_sli4_hba_setup(struct lpfc_hba *phba) | ||
4267 | { | ||
4268 | int rc; | ||
4269 | LPFC_MBOXQ_t *mboxq; | ||
4270 | struct lpfc_mqe *mqe; | ||
4271 | uint8_t *vpd; | ||
4272 | uint32_t vpd_size; | ||
4273 | uint32_t ftr_rsp = 0; | ||
4274 | struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport); | ||
4275 | struct lpfc_vport *vport = phba->pport; | ||
4276 | struct lpfc_dmabuf *mp; | ||
4277 | |||
4278 | /* Perform a PCI function reset to start from clean */ | ||
4279 | rc = lpfc_pci_function_reset(phba); | ||
4280 | if (unlikely(rc)) | ||
4281 | return -ENODEV; | ||
4282 | |||
4283 | /* Check the HBA Host Status Register for readyness */ | ||
4284 | rc = lpfc_sli4_post_status_check(phba); | ||
4285 | if (unlikely(rc)) | ||
4286 | return -ENODEV; | ||
4287 | else { | ||
4288 | spin_lock_irq(&phba->hbalock); | ||
4289 | phba->sli.sli_flag |= LPFC_SLI_ACTIVE; | ||
4290 | spin_unlock_irq(&phba->hbalock); | ||
4291 | } | ||
4292 | |||
4293 | /* | ||
4294 | * Allocate a single mailbox container for initializing the | ||
4295 | * port. | ||
4296 | */ | ||
4297 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
4298 | if (!mboxq) | ||
4299 | return -ENOMEM; | ||
4300 | |||
4301 | /* | ||
4302 | * Continue initialization with default values even if driver failed | ||
4303 | * to read FCoE param config regions | ||
4304 | */ | ||
4305 | if (lpfc_sli4_read_fcoe_params(phba, mboxq)) | ||
4306 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT, | ||
4307 | "2570 Failed to read FCoE parameters \n"); | ||
4308 | |||
4309 | /* Issue READ_REV to collect vpd and FW information. */ | ||
4310 | vpd_size = PAGE_SIZE; | ||
4311 | vpd = kzalloc(vpd_size, GFP_KERNEL); | ||
4312 | if (!vpd) { | ||
4313 | rc = -ENOMEM; | ||
4314 | goto out_free_mbox; | ||
4315 | } | ||
4316 | |||
4317 | rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size); | ||
4318 | if (unlikely(rc)) | ||
4319 | goto out_free_vpd; | ||
4320 | |||
4321 | mqe = &mboxq->u.mqe; | ||
4322 | phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev); | ||
4323 | if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) | ||
4324 | phba->hba_flag |= HBA_FCOE_SUPPORT; | ||
4325 | if (phba->sli_rev != LPFC_SLI_REV4 || | ||
4326 | !(phba->hba_flag & HBA_FCOE_SUPPORT)) { | ||
4327 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
4328 | "0376 READ_REV Error. SLI Level %d " | ||
4329 | "FCoE enabled %d\n", | ||
4330 | phba->sli_rev, phba->hba_flag & HBA_FCOE_SUPPORT); | ||
4331 | rc = -EIO; | ||
4332 | goto out_free_vpd; | ||
4333 | } | ||
4334 | /* | ||
4335 | * Evaluate the read rev and vpd data. Populate the driver | ||
4336 | * state with the results. If this routine fails, the failure | ||
4337 | * is not fatal as the driver will use generic values. | ||
4338 | */ | ||
4339 | rc = lpfc_parse_vpd(phba, vpd, vpd_size); | ||
4340 | if (unlikely(!rc)) { | ||
4341 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
4342 | "0377 Error %d parsing vpd. " | ||
4343 | "Using defaults.\n", rc); | ||
4344 | rc = 0; | ||
4345 | } | ||
4346 | |||
4347 | /* Save information as VPD data */ | ||
4348 | phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev; | ||
4349 | phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev; | ||
4350 | phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev; | ||
4351 | phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high, | ||
4352 | &mqe->un.read_rev); | ||
4353 | phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low, | ||
4354 | &mqe->un.read_rev); | ||
4355 | phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high, | ||
4356 | &mqe->un.read_rev); | ||
4357 | phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low, | ||
4358 | &mqe->un.read_rev); | ||
4359 | phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev; | ||
4360 | memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16); | ||
4361 | phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev; | ||
4362 | memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16); | ||
4363 | phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev; | ||
4364 | memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16); | ||
4365 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | ||
4366 | "(%d):0380 READ_REV Status x%x " | ||
4367 | "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n", | ||
4368 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
4369 | bf_get(lpfc_mqe_status, mqe), | ||
4370 | phba->vpd.rev.opFwName, | ||
4371 | phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow, | ||
4372 | phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow); | ||
4373 | |||
4374 | /* | ||
4375 | * Discover the port's supported feature set and match it against the | ||
4376 | * hosts requests. | ||
4377 | */ | ||
4378 | lpfc_request_features(phba, mboxq); | ||
4379 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
4380 | if (unlikely(rc)) { | ||
4381 | rc = -EIO; | ||
4382 | goto out_free_vpd; | ||
4383 | } | ||
4384 | |||
4385 | /* | ||
4386 | * The port must support FCP initiator mode as this is the | ||
4387 | * only mode running in the host. | ||
4388 | */ | ||
4389 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) { | ||
4390 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | ||
4391 | "0378 No support for fcpi mode.\n"); | ||
4392 | ftr_rsp++; | ||
4393 | } | ||
4394 | |||
4395 | /* | ||
4396 | * If the port cannot support the host's requested features | ||
4397 | * then turn off the global config parameters to disable the | ||
4398 | * feature in the driver. This is not a fatal error. | ||
4399 | */ | ||
4400 | if ((phba->cfg_enable_bg) && | ||
4401 | !(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | ||
4402 | ftr_rsp++; | ||
4403 | |||
4404 | if (phba->max_vpi && phba->cfg_enable_npiv && | ||
4405 | !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | ||
4406 | ftr_rsp++; | ||
4407 | |||
4408 | if (ftr_rsp) { | ||
4409 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | ||
4410 | "0379 Feature Mismatch Data: x%08x %08x " | ||
4411 | "x%x x%x x%x\n", mqe->un.req_ftrs.word2, | ||
4412 | mqe->un.req_ftrs.word3, phba->cfg_enable_bg, | ||
4413 | phba->cfg_enable_npiv, phba->max_vpi); | ||
4414 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) | ||
4415 | phba->cfg_enable_bg = 0; | ||
4416 | if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs))) | ||
4417 | phba->cfg_enable_npiv = 0; | ||
4418 | } | ||
4419 | |||
4420 | /* These SLI3 features are assumed in SLI4 */ | ||
4421 | spin_lock_irq(&phba->hbalock); | ||
4422 | phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED); | ||
4423 | spin_unlock_irq(&phba->hbalock); | ||
4424 | |||
4425 | /* Read the port's service parameters. */ | ||
4426 | lpfc_read_sparam(phba, mboxq, vport->vpi); | ||
4427 | mboxq->vport = vport; | ||
4428 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
4429 | mp = (struct lpfc_dmabuf *) mboxq->context1; | ||
4430 | if (rc == MBX_SUCCESS) { | ||
4431 | memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm)); | ||
4432 | rc = 0; | ||
4433 | } | ||
4434 | |||
4435 | /* | ||
4436 | * This memory was allocated by the lpfc_read_sparam routine. Release | ||
4437 | * it to the mbuf pool. | ||
4438 | */ | ||
4439 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | ||
4440 | kfree(mp); | ||
4441 | mboxq->context1 = NULL; | ||
4442 | if (unlikely(rc)) { | ||
4443 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
4444 | "0382 READ_SPARAM command failed " | ||
4445 | "status %d, mbxStatus x%x\n", | ||
4446 | rc, bf_get(lpfc_mqe_status, mqe)); | ||
4447 | phba->link_state = LPFC_HBA_ERROR; | ||
4448 | rc = -EIO; | ||
4449 | goto out_free_vpd; | ||
4450 | } | ||
4451 | |||
4452 | if (phba->cfg_soft_wwnn) | ||
4453 | u64_to_wwn(phba->cfg_soft_wwnn, | ||
4454 | vport->fc_sparam.nodeName.u.wwn); | ||
4455 | if (phba->cfg_soft_wwpn) | ||
4456 | u64_to_wwn(phba->cfg_soft_wwpn, | ||
4457 | vport->fc_sparam.portName.u.wwn); | ||
4458 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | ||
4459 | sizeof(struct lpfc_name)); | ||
4460 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | ||
4461 | sizeof(struct lpfc_name)); | ||
4462 | |||
4463 | /* Update the fc_host data structures with new wwn. */ | ||
4464 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | ||
4465 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | ||
4466 | |||
4467 | /* Register SGL pool to the device using non-embedded mailbox command */ | ||
4468 | rc = lpfc_sli4_post_sgl_list(phba); | ||
4469 | if (unlikely(rc)) { | ||
4470 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
4471 | "0582 Error %d during sgl post operation", rc); | ||
4472 | rc = -ENODEV; | ||
4473 | goto out_free_vpd; | ||
4474 | } | ||
4475 | |||
4476 | /* Register SCSI SGL pool to the device */ | ||
4477 | rc = lpfc_sli4_repost_scsi_sgl_list(phba); | ||
4478 | if (unlikely(rc)) { | ||
4479 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | ||
4480 | "0383 Error %d during scsi sgl post opeation", | ||
4481 | rc); | ||
4482 | /* Some Scsi buffers were moved to the abort scsi list */ | ||
4483 | /* A pci function reset will repost them */ | ||
4484 | rc = -ENODEV; | ||
4485 | goto out_free_vpd; | ||
4486 | } | ||
4487 | |||
4488 | /* Post the rpi header region to the device. */ | ||
4489 | rc = lpfc_sli4_post_all_rpi_hdrs(phba); | ||
4490 | if (unlikely(rc)) { | ||
4491 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
4492 | "0393 Error %d during rpi post operation\n", | ||
4493 | rc); | ||
4494 | rc = -ENODEV; | ||
4495 | goto out_free_vpd; | ||
4496 | } | ||
4497 | if (phba->cfg_enable_fip) | ||
4498 | bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 1); | ||
4499 | else | ||
4500 | bf_set(lpfc_fip_flag, &phba->sli4_hba.sli4_flags, 0); | ||
4501 | |||
4502 | /* Set up all the queues to the device */ | ||
4503 | rc = lpfc_sli4_queue_setup(phba); | ||
4504 | if (unlikely(rc)) { | ||
4505 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
4506 | "0381 Error %d during queue setup.\n ", rc); | ||
4507 | goto out_stop_timers; | ||
4508 | } | ||
4509 | |||
4510 | /* Arm the CQs and then EQs on device */ | ||
4511 | lpfc_sli4_arm_cqeq_intr(phba); | ||
4512 | |||
4513 | /* Indicate device interrupt mode */ | ||
4514 | phba->sli4_hba.intr_enable = 1; | ||
4515 | |||
4516 | /* Allow asynchronous mailbox command to go through */ | ||
4517 | spin_lock_irq(&phba->hbalock); | ||
4518 | phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | ||
4519 | spin_unlock_irq(&phba->hbalock); | ||
4520 | |||
4521 | /* Post receive buffers to the device */ | ||
4522 | lpfc_sli4_rb_setup(phba); | ||
4523 | |||
4524 | /* Start the ELS watchdog timer */ | ||
4525 | /* | ||
4526 | * The driver for SLI4 is not yet ready to process timeouts | ||
4527 | * or interrupts. Once it is, the comment bars can be removed. | ||
4528 | */ | ||
4529 | /* mod_timer(&vport->els_tmofunc, | ||
4530 | * jiffies + HZ * (phba->fc_ratov*2)); */ | ||
4531 | |||
4532 | /* Start heart beat timer */ | ||
4533 | mod_timer(&phba->hb_tmofunc, | ||
4534 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | ||
4535 | phba->hb_outstanding = 0; | ||
4536 | phba->last_completion_time = jiffies; | ||
4537 | |||
4538 | /* Start error attention (ERATT) polling timer */ | ||
4539 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | ||
4540 | |||
4541 | /* | ||
4542 | * The port is ready, set the host's link state to LINK_DOWN | ||
4543 | * in preparation for link interrupts. | ||
4544 | */ | ||
4545 | lpfc_init_link(phba, mboxq, phba->cfg_topology, phba->cfg_link_speed); | ||
4546 | mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
4547 | lpfc_set_loopback_flag(phba); | ||
4548 | /* Change driver state to LPFC_LINK_DOWN right before init link */ | ||
4549 | spin_lock_irq(&phba->hbalock); | ||
4550 | phba->link_state = LPFC_LINK_DOWN; | ||
4551 | spin_unlock_irq(&phba->hbalock); | ||
4552 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | ||
4553 | if (unlikely(rc != MBX_NOT_FINISHED)) { | ||
4554 | kfree(vpd); | ||
4555 | return 0; | ||
4556 | } else | ||
4557 | rc = -EIO; | ||
4558 | |||
4559 | /* Unset all the queues set up in this routine when error out */ | ||
4560 | if (rc) | ||
4561 | lpfc_sli4_queue_unset(phba); | ||
4562 | |||
4563 | out_stop_timers: | ||
4564 | if (rc) | ||
4565 | lpfc_stop_hba_timers(phba); | ||
4566 | out_free_vpd: | ||
4567 | kfree(vpd); | ||
4568 | out_free_mbox: | ||
4569 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
4570 | return rc; | ||
4571 | } | ||
3203 | 4572 | ||
3204 | /** | 4573 | /** |
3205 | * lpfc_mbox_timeout - Timeout call back function for mbox timer | 4574 | * lpfc_mbox_timeout - Timeout call back function for mbox timer |
@@ -3244,7 +4613,7 @@ void | |||
3244 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | 4613 | lpfc_mbox_timeout_handler(struct lpfc_hba *phba) |
3245 | { | 4614 | { |
3246 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; | 4615 | LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active; |
3247 | MAILBOX_t *mb = &pmbox->mb; | 4616 | MAILBOX_t *mb = &pmbox->u.mb; |
3248 | struct lpfc_sli *psli = &phba->sli; | 4617 | struct lpfc_sli *psli = &phba->sli; |
3249 | struct lpfc_sli_ring *pring; | 4618 | struct lpfc_sli_ring *pring; |
3250 | 4619 | ||
@@ -3281,7 +4650,7 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |||
3281 | spin_unlock_irq(&phba->pport->work_port_lock); | 4650 | spin_unlock_irq(&phba->pport->work_port_lock); |
3282 | spin_lock_irq(&phba->hbalock); | 4651 | spin_lock_irq(&phba->hbalock); |
3283 | phba->link_state = LPFC_LINK_UNKNOWN; | 4652 | phba->link_state = LPFC_LINK_UNKNOWN; |
3284 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 4653 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
3285 | spin_unlock_irq(&phba->hbalock); | 4654 | spin_unlock_irq(&phba->hbalock); |
3286 | 4655 | ||
3287 | pring = &psli->ring[psli->fcp_ring]; | 4656 | pring = &psli->ring[psli->fcp_ring]; |
@@ -3289,32 +4658,20 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |||
3289 | 4658 | ||
3290 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | 4659 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
3291 | "0345 Resetting board due to mailbox timeout\n"); | 4660 | "0345 Resetting board due to mailbox timeout\n"); |
3292 | /* | 4661 | |
3293 | * lpfc_offline calls lpfc_sli_hba_down which will clean up | 4662 | /* Reset the HBA device */ |
3294 | * on oustanding mailbox commands. | 4663 | lpfc_reset_hba(phba); |
3295 | */ | ||
3296 | /* If resets are disabled then set error state and return. */ | ||
3297 | if (!phba->cfg_enable_hba_reset) { | ||
3298 | phba->link_state = LPFC_HBA_ERROR; | ||
3299 | return; | ||
3300 | } | ||
3301 | lpfc_offline_prep(phba); | ||
3302 | lpfc_offline(phba); | ||
3303 | lpfc_sli_brdrestart(phba); | ||
3304 | lpfc_online(phba); | ||
3305 | lpfc_unblock_mgmt_io(phba); | ||
3306 | return; | ||
3307 | } | 4664 | } |
3308 | 4665 | ||
3309 | /** | 4666 | /** |
3310 | * lpfc_sli_issue_mbox - Issue a mailbox command to firmware | 4667 | * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware |
3311 | * @phba: Pointer to HBA context object. | 4668 | * @phba: Pointer to HBA context object. |
3312 | * @pmbox: Pointer to mailbox object. | 4669 | * @pmbox: Pointer to mailbox object. |
3313 | * @flag: Flag indicating how the mailbox need to be processed. | 4670 | * @flag: Flag indicating how the mailbox need to be processed. |
3314 | * | 4671 | * |
3315 | * This function is called by discovery code and HBA management code | 4672 | * This function is called by discovery code and HBA management code |
3316 | * to submit a mailbox command to firmware. This function gets the | 4673 | * to submit a mailbox command to firmware with SLI-3 interface spec. This |
3317 | * hbalock to protect the data structures. | 4674 | * function gets the hbalock to protect the data structures. |
3318 | * The mailbox command can be submitted in polling mode, in which case | 4675 | * The mailbox command can be submitted in polling mode, in which case |
3319 | * this function will wait in a polling loop for the completion of the | 4676 | * this function will wait in a polling loop for the completion of the |
3320 | * mailbox. | 4677 | * mailbox. |
@@ -3332,8 +4689,9 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba) | |||
3332 | * return codes the caller owns the mailbox command after the return of | 4689 | * return codes the caller owns the mailbox command after the return of |
3333 | * the function. | 4690 | * the function. |
3334 | **/ | 4691 | **/ |
3335 | int | 4692 | static int |
3336 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | 4693 | lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, |
4694 | uint32_t flag) | ||
3337 | { | 4695 | { |
3338 | MAILBOX_t *mb; | 4696 | MAILBOX_t *mb; |
3339 | struct lpfc_sli *psli = &phba->sli; | 4697 | struct lpfc_sli *psli = &phba->sli; |
@@ -3349,6 +4707,10 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3349 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | 4707 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
3350 | if (!pmbox) { | 4708 | if (!pmbox) { |
3351 | /* processing mbox queue from intr_handler */ | 4709 | /* processing mbox queue from intr_handler */ |
4710 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | ||
4711 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | ||
4712 | return MBX_SUCCESS; | ||
4713 | } | ||
3352 | processing_queue = 1; | 4714 | processing_queue = 1; |
3353 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 4715 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
3354 | pmbox = lpfc_mbox_get(phba); | 4716 | pmbox = lpfc_mbox_get(phba); |
@@ -3365,7 +4727,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3365 | lpfc_printf_log(phba, KERN_ERR, | 4727 | lpfc_printf_log(phba, KERN_ERR, |
3366 | LOG_MBOX | LOG_VPORT, | 4728 | LOG_MBOX | LOG_VPORT, |
3367 | "1806 Mbox x%x failed. No vport\n", | 4729 | "1806 Mbox x%x failed. No vport\n", |
3368 | pmbox->mb.mbxCommand); | 4730 | pmbox->u.mb.mbxCommand); |
3369 | dump_stack(); | 4731 | dump_stack(); |
3370 | goto out_not_finished; | 4732 | goto out_not_finished; |
3371 | } | 4733 | } |
@@ -3385,21 +4747,29 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3385 | 4747 | ||
3386 | psli = &phba->sli; | 4748 | psli = &phba->sli; |
3387 | 4749 | ||
3388 | mb = &pmbox->mb; | 4750 | mb = &pmbox->u.mb; |
3389 | status = MBX_SUCCESS; | 4751 | status = MBX_SUCCESS; |
3390 | 4752 | ||
3391 | if (phba->link_state == LPFC_HBA_ERROR) { | 4753 | if (phba->link_state == LPFC_HBA_ERROR) { |
3392 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 4754 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3393 | 4755 | ||
3394 | /* Mbox command <mbxCommand> cannot issue */ | 4756 | /* Mbox command <mbxCommand> cannot issue */ |
3395 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 4757 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4758 | "(%d):0311 Mailbox command x%x cannot " | ||
4759 | "issue Data: x%x x%x\n", | ||
4760 | pmbox->vport ? pmbox->vport->vpi : 0, | ||
4761 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | ||
3396 | goto out_not_finished; | 4762 | goto out_not_finished; |
3397 | } | 4763 | } |
3398 | 4764 | ||
3399 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && | 4765 | if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && |
3400 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { | 4766 | !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { |
3401 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 4767 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3402 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 4768 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4769 | "(%d):2528 Mailbox command x%x cannot " | ||
4770 | "issue Data: x%x x%x\n", | ||
4771 | pmbox->vport ? pmbox->vport->vpi : 0, | ||
4772 | pmbox->u.mb.mbxCommand, psli->sli_flag, flag); | ||
3403 | goto out_not_finished; | 4773 | goto out_not_finished; |
3404 | } | 4774 | } |
3405 | 4775 | ||
@@ -3413,14 +4783,24 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3413 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 4783 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3414 | 4784 | ||
3415 | /* Mbox command <mbxCommand> cannot issue */ | 4785 | /* Mbox command <mbxCommand> cannot issue */ |
3416 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 4786 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4787 | "(%d):2529 Mailbox command x%x " | ||
4788 | "cannot issue Data: x%x x%x\n", | ||
4789 | pmbox->vport ? pmbox->vport->vpi : 0, | ||
4790 | pmbox->u.mb.mbxCommand, | ||
4791 | psli->sli_flag, flag); | ||
3417 | goto out_not_finished; | 4792 | goto out_not_finished; |
3418 | } | 4793 | } |
3419 | 4794 | ||
3420 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { | 4795 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) { |
3421 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 4796 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3422 | /* Mbox command <mbxCommand> cannot issue */ | 4797 | /* Mbox command <mbxCommand> cannot issue */ |
3423 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 4798 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4799 | "(%d):2530 Mailbox command x%x " | ||
4800 | "cannot issue Data: x%x x%x\n", | ||
4801 | pmbox->vport ? pmbox->vport->vpi : 0, | ||
4802 | pmbox->u.mb.mbxCommand, | ||
4803 | psli->sli_flag, flag); | ||
3424 | goto out_not_finished; | 4804 | goto out_not_finished; |
3425 | } | 4805 | } |
3426 | 4806 | ||
@@ -3462,12 +4842,17 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3462 | 4842 | ||
3463 | /* If we are not polling, we MUST be in SLI2 mode */ | 4843 | /* If we are not polling, we MUST be in SLI2 mode */ |
3464 | if (flag != MBX_POLL) { | 4844 | if (flag != MBX_POLL) { |
3465 | if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && | 4845 | if (!(psli->sli_flag & LPFC_SLI_ACTIVE) && |
3466 | (mb->mbxCommand != MBX_KILL_BOARD)) { | 4846 | (mb->mbxCommand != MBX_KILL_BOARD)) { |
3467 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 4847 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
3468 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | 4848 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
3469 | /* Mbox command <mbxCommand> cannot issue */ | 4849 | /* Mbox command <mbxCommand> cannot issue */ |
3470 | LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag); | 4850 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
4851 | "(%d):2531 Mailbox command x%x " | ||
4852 | "cannot issue Data: x%x x%x\n", | ||
4853 | pmbox->vport ? pmbox->vport->vpi : 0, | ||
4854 | pmbox->u.mb.mbxCommand, | ||
4855 | psli->sli_flag, flag); | ||
3471 | goto out_not_finished; | 4856 | goto out_not_finished; |
3472 | } | 4857 | } |
3473 | /* timeout active mbox command */ | 4858 | /* timeout active mbox command */ |
@@ -3506,7 +4891,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3506 | /* next set own bit for the adapter and copy over command word */ | 4891 | /* next set own bit for the adapter and copy over command word */ |
3507 | mb->mbxOwner = OWN_CHIP; | 4892 | mb->mbxOwner = OWN_CHIP; |
3508 | 4893 | ||
3509 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 4894 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3510 | /* First copy command data to host SLIM area */ | 4895 | /* First copy command data to host SLIM area */ |
3511 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); | 4896 | lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE); |
3512 | } else { | 4897 | } else { |
@@ -3529,7 +4914,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3529 | 4914 | ||
3530 | if (mb->mbxCommand == MBX_CONFIG_PORT) { | 4915 | if (mb->mbxCommand == MBX_CONFIG_PORT) { |
3531 | /* switch over to host mailbox */ | 4916 | /* switch over to host mailbox */ |
3532 | psli->sli_flag |= LPFC_SLI2_ACTIVE; | 4917 | psli->sli_flag |= LPFC_SLI_ACTIVE; |
3533 | } | 4918 | } |
3534 | } | 4919 | } |
3535 | 4920 | ||
@@ -3552,7 +4937,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3552 | writel(CA_MBATT, phba->CAregaddr); | 4937 | writel(CA_MBATT, phba->CAregaddr); |
3553 | readl(phba->CAregaddr); /* flush */ | 4938 | readl(phba->CAregaddr); /* flush */ |
3554 | 4939 | ||
3555 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 4940 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3556 | /* First read mbox status word */ | 4941 | /* First read mbox status word */ |
3557 | word0 = *((uint32_t *)phba->mbox); | 4942 | word0 = *((uint32_t *)phba->mbox); |
3558 | word0 = le32_to_cpu(word0); | 4943 | word0 = le32_to_cpu(word0); |
@@ -3591,7 +4976,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3591 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | 4976 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
3592 | } | 4977 | } |
3593 | 4978 | ||
3594 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 4979 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3595 | /* First copy command data */ | 4980 | /* First copy command data */ |
3596 | word0 = *((uint32_t *)phba->mbox); | 4981 | word0 = *((uint32_t *)phba->mbox); |
3597 | word0 = le32_to_cpu(word0); | 4982 | word0 = le32_to_cpu(word0); |
@@ -3604,7 +4989,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3604 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) | 4989 | if (((slimword0 & OWN_CHIP) != OWN_CHIP) |
3605 | && slimmb->mbxStatus) { | 4990 | && slimmb->mbxStatus) { |
3606 | psli->sli_flag &= | 4991 | psli->sli_flag &= |
3607 | ~LPFC_SLI2_ACTIVE; | 4992 | ~LPFC_SLI_ACTIVE; |
3608 | word0 = slimword0; | 4993 | word0 = slimword0; |
3609 | } | 4994 | } |
3610 | } | 4995 | } |
@@ -3616,7 +5001,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3616 | ha_copy = readl(phba->HAregaddr); | 5001 | ha_copy = readl(phba->HAregaddr); |
3617 | } | 5002 | } |
3618 | 5003 | ||
3619 | if (psli->sli_flag & LPFC_SLI2_ACTIVE) { | 5004 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
3620 | /* copy results back to user */ | 5005 | /* copy results back to user */ |
3621 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); | 5006 | lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE); |
3622 | } else { | 5007 | } else { |
@@ -3643,13 +5028,527 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | |||
3643 | 5028 | ||
3644 | out_not_finished: | 5029 | out_not_finished: |
3645 | if (processing_queue) { | 5030 | if (processing_queue) { |
3646 | pmbox->mb.mbxStatus = MBX_NOT_FINISHED; | 5031 | pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED; |
3647 | lpfc_mbox_cmpl_put(phba, pmbox); | 5032 | lpfc_mbox_cmpl_put(phba, pmbox); |
3648 | } | 5033 | } |
3649 | return MBX_NOT_FINISHED; | 5034 | return MBX_NOT_FINISHED; |
3650 | } | 5035 | } |
3651 | 5036 | ||
3652 | /** | 5037 | /** |
5038 | * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command | ||
5039 | * @phba: Pointer to HBA context object. | ||
5040 | * | ||
5041 | * The function blocks the posting of SLI4 asynchronous mailbox commands from | ||
5042 | * the driver internal pending mailbox queue. It will then try to wait out the | ||
5043 | * possible outstanding mailbox command before return. | ||
5044 | * | ||
5045 | * Returns: | ||
5046 | * 0 - the outstanding mailbox command completed; otherwise, the wait for | ||
5047 | * the outstanding mailbox command timed out. | ||
5048 | **/ | ||
5049 | static int | ||
5050 | lpfc_sli4_async_mbox_block(struct lpfc_hba *phba) | ||
5051 | { | ||
5052 | struct lpfc_sli *psli = &phba->sli; | ||
5053 | uint8_t actcmd = MBX_HEARTBEAT; | ||
5054 | int rc = 0; | ||
5055 | unsigned long timeout; | ||
5056 | |||
5057 | /* Mark the asynchronous mailbox command posting as blocked */ | ||
5058 | spin_lock_irq(&phba->hbalock); | ||
5059 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | ||
5060 | if (phba->sli.mbox_active) | ||
5061 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | ||
5062 | spin_unlock_irq(&phba->hbalock); | ||
5063 | /* Determine how long we might wait for the active mailbox | ||
5064 | * command to be gracefully completed by firmware. | ||
5065 | */ | ||
5066 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | ||
5067 | jiffies; | ||
5068 | /* Wait for the outstnading mailbox command to complete */ | ||
5069 | while (phba->sli.mbox_active) { | ||
5070 | /* Check active mailbox complete status every 2ms */ | ||
5071 | msleep(2); | ||
5072 | if (time_after(jiffies, timeout)) { | ||
5073 | /* Timeout, marked the outstanding cmd not complete */ | ||
5074 | rc = 1; | ||
5075 | break; | ||
5076 | } | ||
5077 | } | ||
5078 | |||
5079 | /* Can not cleanly block async mailbox command, fails it */ | ||
5080 | if (rc) { | ||
5081 | spin_lock_irq(&phba->hbalock); | ||
5082 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | ||
5083 | spin_unlock_irq(&phba->hbalock); | ||
5084 | } | ||
5085 | return rc; | ||
5086 | } | ||
5087 | |||
5088 | /** | ||
5089 | * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command | ||
5090 | * @phba: Pointer to HBA context object. | ||
5091 | * | ||
5092 | * The function unblocks and resume posting of SLI4 asynchronous mailbox | ||
5093 | * commands from the driver internal pending mailbox queue. It makes sure | ||
5094 | * that there is no outstanding mailbox command before resuming posting | ||
5095 | * asynchronous mailbox commands. If, for any reason, there is outstanding | ||
5096 | * mailbox command, it will try to wait it out before resuming asynchronous | ||
5097 | * mailbox command posting. | ||
5098 | **/ | ||
5099 | static void | ||
5100 | lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba) | ||
5101 | { | ||
5102 | struct lpfc_sli *psli = &phba->sli; | ||
5103 | |||
5104 | spin_lock_irq(&phba->hbalock); | ||
5105 | if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | ||
5106 | /* Asynchronous mailbox posting is not blocked, do nothing */ | ||
5107 | spin_unlock_irq(&phba->hbalock); | ||
5108 | return; | ||
5109 | } | ||
5110 | |||
5111 | /* Outstanding synchronous mailbox command is guaranteed to be done, | ||
5112 | * successful or timeout, after timing-out the outstanding mailbox | ||
5113 | * command shall always be removed, so just unblock posting async | ||
5114 | * mailbox command and resume | ||
5115 | */ | ||
5116 | psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK; | ||
5117 | spin_unlock_irq(&phba->hbalock); | ||
5118 | |||
5119 | /* wake up worker thread to post asynchronlous mailbox command */ | ||
5120 | lpfc_worker_wake_up(phba); | ||
5121 | } | ||
5122 | |||
5123 | /** | ||
5124 | * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox | ||
5125 | * @phba: Pointer to HBA context object. | ||
5126 | * @mboxq: Pointer to mailbox object. | ||
5127 | * | ||
5128 | * The function posts a mailbox to the port. The mailbox is expected | ||
5129 | * to be comletely filled in and ready for the port to operate on it. | ||
5130 | * This routine executes a synchronous completion operation on the | ||
5131 | * mailbox by polling for its completion. | ||
5132 | * | ||
5133 | * The caller must not be holding any locks when calling this routine. | ||
5134 | * | ||
5135 | * Returns: | ||
5136 | * MBX_SUCCESS - mailbox posted successfully | ||
5137 | * Any of the MBX error values. | ||
5138 | **/ | ||
5139 | static int | ||
5140 | lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | ||
5141 | { | ||
5142 | int rc = MBX_SUCCESS; | ||
5143 | unsigned long iflag; | ||
5144 | uint32_t db_ready; | ||
5145 | uint32_t mcqe_status; | ||
5146 | uint32_t mbx_cmnd; | ||
5147 | unsigned long timeout; | ||
5148 | struct lpfc_sli *psli = &phba->sli; | ||
5149 | struct lpfc_mqe *mb = &mboxq->u.mqe; | ||
5150 | struct lpfc_bmbx_create *mbox_rgn; | ||
5151 | struct dma_address *dma_address; | ||
5152 | struct lpfc_register bmbx_reg; | ||
5153 | |||
5154 | /* | ||
5155 | * Only one mailbox can be active to the bootstrap mailbox region | ||
5156 | * at a time and there is no queueing provided. | ||
5157 | */ | ||
5158 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
5159 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | ||
5160 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
5161 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
5162 | "(%d):2532 Mailbox command x%x (x%x) " | ||
5163 | "cannot issue Data: x%x x%x\n", | ||
5164 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
5165 | mboxq->u.mb.mbxCommand, | ||
5166 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5167 | psli->sli_flag, MBX_POLL); | ||
5168 | return MBXERR_ERROR; | ||
5169 | } | ||
5170 | /* The server grabs the token and owns it until release */ | ||
5171 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | ||
5172 | phba->sli.mbox_active = mboxq; | ||
5173 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
5174 | |||
5175 | /* | ||
5176 | * Initialize the bootstrap memory region to avoid stale data areas | ||
5177 | * in the mailbox post. Then copy the caller's mailbox contents to | ||
5178 | * the bmbx mailbox region. | ||
5179 | */ | ||
5180 | mbx_cmnd = bf_get(lpfc_mqe_command, mb); | ||
5181 | memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create)); | ||
5182 | lpfc_sli_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt, | ||
5183 | sizeof(struct lpfc_mqe)); | ||
5184 | |||
5185 | /* Post the high mailbox dma address to the port and wait for ready. */ | ||
5186 | dma_address = &phba->sli4_hba.bmbx.dma_address; | ||
5187 | writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr); | ||
5188 | |||
5189 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | ||
5190 | * 1000) + jiffies; | ||
5191 | do { | ||
5192 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | ||
5193 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | ||
5194 | if (!db_ready) | ||
5195 | msleep(2); | ||
5196 | |||
5197 | if (time_after(jiffies, timeout)) { | ||
5198 | rc = MBXERR_ERROR; | ||
5199 | goto exit; | ||
5200 | } | ||
5201 | } while (!db_ready); | ||
5202 | |||
5203 | /* Post the low mailbox dma address to the port. */ | ||
5204 | writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr); | ||
5205 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mbx_cmnd) | ||
5206 | * 1000) + jiffies; | ||
5207 | do { | ||
5208 | bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr); | ||
5209 | db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg); | ||
5210 | if (!db_ready) | ||
5211 | msleep(2); | ||
5212 | |||
5213 | if (time_after(jiffies, timeout)) { | ||
5214 | rc = MBXERR_ERROR; | ||
5215 | goto exit; | ||
5216 | } | ||
5217 | } while (!db_ready); | ||
5218 | |||
5219 | /* | ||
5220 | * Read the CQ to ensure the mailbox has completed. | ||
5221 | * If so, update the mailbox status so that the upper layers | ||
5222 | * can complete the request normally. | ||
5223 | */ | ||
5224 | lpfc_sli_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb, | ||
5225 | sizeof(struct lpfc_mqe)); | ||
5226 | mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt; | ||
5227 | lpfc_sli_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe, | ||
5228 | sizeof(struct lpfc_mcqe)); | ||
5229 | mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe); | ||
5230 | |||
5231 | /* Prefix the mailbox status with range x4000 to note SLI4 status. */ | ||
5232 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) { | ||
5233 | bf_set(lpfc_mqe_status, mb, LPFC_MBX_ERROR_RANGE | mcqe_status); | ||
5234 | rc = MBXERR_ERROR; | ||
5235 | } | ||
5236 | |||
5237 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | ||
5238 | "(%d):0356 Mailbox cmd x%x (x%x) Status x%x " | ||
5239 | "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x" | ||
5240 | " x%x x%x CQ: x%x x%x x%x x%x\n", | ||
5241 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
5242 | mbx_cmnd, lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5243 | bf_get(lpfc_mqe_status, mb), | ||
5244 | mb->un.mb_words[0], mb->un.mb_words[1], | ||
5245 | mb->un.mb_words[2], mb->un.mb_words[3], | ||
5246 | mb->un.mb_words[4], mb->un.mb_words[5], | ||
5247 | mb->un.mb_words[6], mb->un.mb_words[7], | ||
5248 | mb->un.mb_words[8], mb->un.mb_words[9], | ||
5249 | mb->un.mb_words[10], mb->un.mb_words[11], | ||
5250 | mb->un.mb_words[12], mboxq->mcqe.word0, | ||
5251 | mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1, | ||
5252 | mboxq->mcqe.trailer); | ||
5253 | exit: | ||
5254 | /* We are holding the token, no needed for lock when release */ | ||
5255 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
5256 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
5257 | phba->sli.mbox_active = NULL; | ||
5258 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
5259 | return rc; | ||
5260 | } | ||
5261 | |||
5262 | /** | ||
5263 | * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware | ||
5264 | * @phba: Pointer to HBA context object. | ||
5265 | * @pmbox: Pointer to mailbox object. | ||
5266 | * @flag: Flag indicating how the mailbox need to be processed. | ||
5267 | * | ||
5268 | * This function is called by discovery code and HBA management code to submit | ||
5269 | * a mailbox command to firmware with SLI-4 interface spec. | ||
5270 | * | ||
5271 | * Return codes the caller owns the mailbox command after the return of the | ||
5272 | * function. | ||
5273 | **/ | ||
5274 | static int | ||
5275 | lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq, | ||
5276 | uint32_t flag) | ||
5277 | { | ||
5278 | struct lpfc_sli *psli = &phba->sli; | ||
5279 | unsigned long iflags; | ||
5280 | int rc; | ||
5281 | |||
5282 | /* Detect polling mode and jump to a handler */ | ||
5283 | if (!phba->sli4_hba.intr_enable) { | ||
5284 | if (flag == MBX_POLL) | ||
5285 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | ||
5286 | else | ||
5287 | rc = -EIO; | ||
5288 | if (rc != MBX_SUCCESS) | ||
5289 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
5290 | "(%d):2541 Mailbox command x%x " | ||
5291 | "(x%x) cannot issue Data: x%x x%x\n", | ||
5292 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
5293 | mboxq->u.mb.mbxCommand, | ||
5294 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5295 | psli->sli_flag, flag); | ||
5296 | return rc; | ||
5297 | } else if (flag == MBX_POLL) { | ||
5298 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI, | ||
5299 | "(%d):2542 Try to issue mailbox command " | ||
5300 | "x%x (x%x) synchronously ahead of async" | ||
5301 | "mailbox command queue: x%x x%x\n", | ||
5302 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
5303 | mboxq->u.mb.mbxCommand, | ||
5304 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5305 | psli->sli_flag, flag); | ||
5306 | /* Try to block the asynchronous mailbox posting */ | ||
5307 | rc = lpfc_sli4_async_mbox_block(phba); | ||
5308 | if (!rc) { | ||
5309 | /* Successfully blocked, now issue sync mbox cmd */ | ||
5310 | rc = lpfc_sli4_post_sync_mbox(phba, mboxq); | ||
5311 | if (rc != MBX_SUCCESS) | ||
5312 | lpfc_printf_log(phba, KERN_ERR, | ||
5313 | LOG_MBOX | LOG_SLI, | ||
5314 | "(%d):2597 Mailbox command " | ||
5315 | "x%x (x%x) cannot issue " | ||
5316 | "Data: x%x x%x\n", | ||
5317 | mboxq->vport ? | ||
5318 | mboxq->vport->vpi : 0, | ||
5319 | mboxq->u.mb.mbxCommand, | ||
5320 | lpfc_sli4_mbox_opcode_get(phba, | ||
5321 | mboxq), | ||
5322 | psli->sli_flag, flag); | ||
5323 | /* Unblock the async mailbox posting afterward */ | ||
5324 | lpfc_sli4_async_mbox_unblock(phba); | ||
5325 | } | ||
5326 | return rc; | ||
5327 | } | ||
5328 | |||
5329 | /* Now, interrupt mode asynchrous mailbox command */ | ||
5330 | rc = lpfc_mbox_cmd_check(phba, mboxq); | ||
5331 | if (rc) { | ||
5332 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
5333 | "(%d):2543 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 | rc = lpfc_mbox_dev_check(phba); | ||
5342 | if (unlikely(rc)) { | ||
5343 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
5344 | "(%d):2544 Mailbox command x%x (x%x) " | ||
5345 | "cannot issue Data: x%x x%x\n", | ||
5346 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
5347 | mboxq->u.mb.mbxCommand, | ||
5348 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5349 | psli->sli_flag, flag); | ||
5350 | goto out_not_finished; | ||
5351 | } | ||
5352 | |||
5353 | /* Put the mailbox command to the driver internal FIFO */ | ||
5354 | psli->slistat.mbox_busy++; | ||
5355 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
5356 | lpfc_mbox_put(phba, mboxq); | ||
5357 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5358 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | ||
5359 | "(%d):0354 Mbox cmd issue - Enqueue Data: " | ||
5360 | "x%x (x%x) x%x x%x x%x\n", | ||
5361 | mboxq->vport ? mboxq->vport->vpi : 0xffffff, | ||
5362 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | ||
5363 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5364 | phba->pport->port_state, | ||
5365 | psli->sli_flag, MBX_NOWAIT); | ||
5366 | /* Wake up worker thread to transport mailbox command from head */ | ||
5367 | lpfc_worker_wake_up(phba); | ||
5368 | |||
5369 | return MBX_BUSY; | ||
5370 | |||
5371 | out_not_finished: | ||
5372 | return MBX_NOT_FINISHED; | ||
5373 | } | ||
5374 | |||
5375 | /** | ||
5376 | * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device | ||
5377 | * @phba: Pointer to HBA context object. | ||
5378 | * | ||
5379 | * This function is called by worker thread to send a mailbox command to | ||
5380 | * SLI4 HBA firmware. | ||
5381 | * | ||
5382 | **/ | ||
5383 | int | ||
5384 | lpfc_sli4_post_async_mbox(struct lpfc_hba *phba) | ||
5385 | { | ||
5386 | struct lpfc_sli *psli = &phba->sli; | ||
5387 | LPFC_MBOXQ_t *mboxq; | ||
5388 | int rc = MBX_SUCCESS; | ||
5389 | unsigned long iflags; | ||
5390 | struct lpfc_mqe *mqe; | ||
5391 | uint32_t mbx_cmnd; | ||
5392 | |||
5393 | /* Check interrupt mode before post async mailbox command */ | ||
5394 | if (unlikely(!phba->sli4_hba.intr_enable)) | ||
5395 | return MBX_NOT_FINISHED; | ||
5396 | |||
5397 | /* Check for mailbox command service token */ | ||
5398 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
5399 | if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) { | ||
5400 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5401 | return MBX_NOT_FINISHED; | ||
5402 | } | ||
5403 | if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { | ||
5404 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5405 | return MBX_NOT_FINISHED; | ||
5406 | } | ||
5407 | if (unlikely(phba->sli.mbox_active)) { | ||
5408 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5409 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
5410 | "0384 There is pending active mailbox cmd\n"); | ||
5411 | return MBX_NOT_FINISHED; | ||
5412 | } | ||
5413 | /* Take the mailbox command service token */ | ||
5414 | psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE; | ||
5415 | |||
5416 | /* Get the next mailbox command from head of queue */ | ||
5417 | mboxq = lpfc_mbox_get(phba); | ||
5418 | |||
5419 | /* If no more mailbox command waiting for post, we're done */ | ||
5420 | if (!mboxq) { | ||
5421 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
5422 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5423 | return MBX_SUCCESS; | ||
5424 | } | ||
5425 | phba->sli.mbox_active = mboxq; | ||
5426 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5427 | |||
5428 | /* Check device readiness for posting mailbox command */ | ||
5429 | rc = lpfc_mbox_dev_check(phba); | ||
5430 | if (unlikely(rc)) | ||
5431 | /* Driver clean routine will clean up pending mailbox */ | ||
5432 | goto out_not_finished; | ||
5433 | |||
5434 | /* Prepare the mbox command to be posted */ | ||
5435 | mqe = &mboxq->u.mqe; | ||
5436 | mbx_cmnd = bf_get(lpfc_mqe_command, mqe); | ||
5437 | |||
5438 | /* Start timer for the mbox_tmo and log some mailbox post messages */ | ||
5439 | mod_timer(&psli->mbox_tmo, (jiffies + | ||
5440 | (HZ * lpfc_mbox_tmo_val(phba, mbx_cmnd)))); | ||
5441 | |||
5442 | lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI, | ||
5443 | "(%d):0355 Mailbox cmd x%x (x%x) issue Data: " | ||
5444 | "x%x x%x\n", | ||
5445 | mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd, | ||
5446 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5447 | phba->pport->port_state, psli->sli_flag); | ||
5448 | |||
5449 | if (mbx_cmnd != MBX_HEARTBEAT) { | ||
5450 | if (mboxq->vport) { | ||
5451 | lpfc_debugfs_disc_trc(mboxq->vport, | ||
5452 | LPFC_DISC_TRC_MBOX_VPORT, | ||
5453 | "MBOX Send vport: cmd:x%x mb:x%x x%x", | ||
5454 | mbx_cmnd, mqe->un.mb_words[0], | ||
5455 | mqe->un.mb_words[1]); | ||
5456 | } else { | ||
5457 | lpfc_debugfs_disc_trc(phba->pport, | ||
5458 | LPFC_DISC_TRC_MBOX, | ||
5459 | "MBOX Send: cmd:x%x mb:x%x x%x", | ||
5460 | mbx_cmnd, mqe->un.mb_words[0], | ||
5461 | mqe->un.mb_words[1]); | ||
5462 | } | ||
5463 | } | ||
5464 | psli->slistat.mbox_cmd++; | ||
5465 | |||
5466 | /* Post the mailbox command to the port */ | ||
5467 | rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe); | ||
5468 | if (rc != MBX_SUCCESS) { | ||
5469 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
5470 | "(%d):2533 Mailbox command x%x (x%x) " | ||
5471 | "cannot issue Data: x%x x%x\n", | ||
5472 | mboxq->vport ? mboxq->vport->vpi : 0, | ||
5473 | mboxq->u.mb.mbxCommand, | ||
5474 | lpfc_sli4_mbox_opcode_get(phba, mboxq), | ||
5475 | psli->sli_flag, MBX_NOWAIT); | ||
5476 | goto out_not_finished; | ||
5477 | } | ||
5478 | |||
5479 | return rc; | ||
5480 | |||
5481 | out_not_finished: | ||
5482 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
5483 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | ||
5484 | __lpfc_mbox_cmpl_put(phba, mboxq); | ||
5485 | /* Release the token */ | ||
5486 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
5487 | phba->sli.mbox_active = NULL; | ||
5488 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5489 | |||
5490 | return MBX_NOT_FINISHED; | ||
5491 | } | ||
5492 | |||
5493 | /** | ||
5494 | * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command | ||
5495 | * @phba: Pointer to HBA context object. | ||
5496 | * @pmbox: Pointer to mailbox object. | ||
5497 | * @flag: Flag indicating how the mailbox need to be processed. | ||
5498 | * | ||
5499 | * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from | ||
5500 | * the API jump table function pointer from the lpfc_hba struct. | ||
5501 | * | ||
5502 | * Return codes the caller owns the mailbox command after the return of the | ||
5503 | * function. | ||
5504 | **/ | ||
5505 | int | ||
5506 | lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) | ||
5507 | { | ||
5508 | return phba->lpfc_sli_issue_mbox(phba, pmbox, flag); | ||
5509 | } | ||
5510 | |||
5511 | /** | ||
5512 | * lpfc_mbox_api_table_setup - Set up mbox api fucntion jump table | ||
5513 | * @phba: The hba struct for which this call is being executed. | ||
5514 | * @dev_grp: The HBA PCI-Device group number. | ||
5515 | * | ||
5516 | * This routine sets up the mbox interface API function jump table in @phba | ||
5517 | * struct. | ||
5518 | * Returns: 0 - success, -ENODEV - failure. | ||
5519 | **/ | ||
5520 | int | ||
5521 | lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | ||
5522 | { | ||
5523 | |||
5524 | switch (dev_grp) { | ||
5525 | case LPFC_PCI_DEV_LP: | ||
5526 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3; | ||
5527 | phba->lpfc_sli_handle_slow_ring_event = | ||
5528 | lpfc_sli_handle_slow_ring_event_s3; | ||
5529 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3; | ||
5530 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3; | ||
5531 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s3; | ||
5532 | break; | ||
5533 | case LPFC_PCI_DEV_OC: | ||
5534 | phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4; | ||
5535 | phba->lpfc_sli_handle_slow_ring_event = | ||
5536 | lpfc_sli_handle_slow_ring_event_s4; | ||
5537 | phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4; | ||
5538 | phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4; | ||
5539 | phba->lpfc_sli_brdready = lpfc_sli_brdready_s4; | ||
5540 | break; | ||
5541 | default: | ||
5542 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5543 | "1420 Invalid HBA PCI-device group: 0x%x\n", | ||
5544 | dev_grp); | ||
5545 | return -ENODEV; | ||
5546 | break; | ||
5547 | } | ||
5548 | return 0; | ||
5549 | } | ||
5550 | |||
5551 | /** | ||
3653 | * __lpfc_sli_ringtx_put - Add an iocb to the txq | 5552 | * __lpfc_sli_ringtx_put - Add an iocb to the txq |
3654 | * @phba: Pointer to HBA context object. | 5553 | * @phba: Pointer to HBA context object. |
3655 | * @pring: Pointer to driver SLI ring object. | 5554 | * @pring: Pointer to driver SLI ring object. |
@@ -3701,35 +5600,34 @@ lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
3701 | } | 5600 | } |
3702 | 5601 | ||
3703 | /** | 5602 | /** |
3704 | * __lpfc_sli_issue_iocb - Lockless version of lpfc_sli_issue_iocb | 5603 | * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb |
3705 | * @phba: Pointer to HBA context object. | 5604 | * @phba: Pointer to HBA context object. |
3706 | * @pring: Pointer to driver SLI ring object. | 5605 | * @ring_number: SLI ring number to issue iocb on. |
3707 | * @piocb: Pointer to command iocb. | 5606 | * @piocb: Pointer to command iocb. |
3708 | * @flag: Flag indicating if this command can be put into txq. | 5607 | * @flag: Flag indicating if this command can be put into txq. |
3709 | * | 5608 | * |
3710 | * __lpfc_sli_issue_iocb is used by other functions in the driver | 5609 | * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue |
3711 | * to issue an iocb command to the HBA. If the PCI slot is recovering | 5610 | * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is |
3712 | * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT | 5611 | * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT |
3713 | * flag is turned on, the function returns IOCB_ERROR. | 5612 | * flag is turned on, the function returns IOCB_ERROR. When the link is down, |
3714 | * When the link is down, this function allows only iocbs for | 5613 | * this function allows only iocbs for posting buffers. This function finds |
3715 | * posting buffers. | 5614 | * next available slot in the command ring and posts the command to the |
3716 | * This function finds next available slot in the command ring and | 5615 | * available slot and writes the port attention register to request HBA start |
3717 | * posts the command to the available slot and writes the port | 5616 | * processing new iocb. If there is no slot available in the ring and |
3718 | * attention register to request HBA start processing new iocb. | 5617 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise |
3719 | * If there is no slot available in the ring and | 5618 | * the function returns IOCB_BUSY. |
3720 | * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the | 5619 | * |
3721 | * txq, otherwise the function returns IOCB_BUSY. | 5620 | * This function is called with hbalock held. The function will return success |
3722 | * | 5621 | * after it successfully submit the iocb to firmware or after adding to the |
3723 | * This function is called with hbalock held. | 5622 | * txq. |
3724 | * The function will return success after it successfully submit the | ||
3725 | * iocb to firmware or after adding to the txq. | ||
3726 | **/ | 5623 | **/ |
3727 | static int | 5624 | static int |
3728 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 5625 | __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number, |
3729 | struct lpfc_iocbq *piocb, uint32_t flag) | 5626 | struct lpfc_iocbq *piocb, uint32_t flag) |
3730 | { | 5627 | { |
3731 | struct lpfc_iocbq *nextiocb; | 5628 | struct lpfc_iocbq *nextiocb; |
3732 | IOCB_t *iocb; | 5629 | IOCB_t *iocb; |
5630 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | ||
3733 | 5631 | ||
3734 | if (piocb->iocb_cmpl && (!piocb->vport) && | 5632 | if (piocb->iocb_cmpl && (!piocb->vport) && |
3735 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && | 5633 | (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && |
@@ -3833,6 +5731,493 @@ __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
3833 | return IOCB_BUSY; | 5731 | return IOCB_BUSY; |
3834 | } | 5732 | } |
3835 | 5733 | ||
5734 | /** | ||
5735 | * lpfc_sli4_bpl2sgl - Convert the bpl/bde to a sgl. | ||
5736 | * @phba: Pointer to HBA context object. | ||
5737 | * @piocb: Pointer to command iocb. | ||
5738 | * @sglq: Pointer to the scatter gather queue object. | ||
5739 | * | ||
5740 | * This routine converts the bpl or bde that is in the IOCB | ||
5741 | * to a sgl list for the sli4 hardware. The physical address | ||
5742 | * of the bpl/bde is converted back to a virtual address. | ||
5743 | * If the IOCB contains a BPL then the list of BDE's is | ||
5744 | * converted to sli4_sge's. If the IOCB contains a single | ||
5745 | * BDE then it is converted to a single sli_sge. | ||
5746 | * The IOCB is still in cpu endianess so the contents of | ||
5747 | * the bpl can be used without byte swapping. | ||
5748 | * | ||
5749 | * Returns valid XRI = Success, NO_XRI = Failure. | ||
5750 | **/ | ||
5751 | static uint16_t | ||
5752 | lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq, | ||
5753 | struct lpfc_sglq *sglq) | ||
5754 | { | ||
5755 | uint16_t xritag = NO_XRI; | ||
5756 | struct ulp_bde64 *bpl = NULL; | ||
5757 | struct ulp_bde64 bde; | ||
5758 | struct sli4_sge *sgl = NULL; | ||
5759 | IOCB_t *icmd; | ||
5760 | int numBdes = 0; | ||
5761 | int i = 0; | ||
5762 | |||
5763 | if (!piocbq || !sglq) | ||
5764 | return xritag; | ||
5765 | |||
5766 | sgl = (struct sli4_sge *)sglq->sgl; | ||
5767 | icmd = &piocbq->iocb; | ||
5768 | if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | ||
5769 | numBdes = icmd->un.genreq64.bdl.bdeSize / | ||
5770 | sizeof(struct ulp_bde64); | ||
5771 | /* The addrHigh and addrLow fields within the IOCB | ||
5772 | * have not been byteswapped yet so there is no | ||
5773 | * need to swap them back. | ||
5774 | */ | ||
5775 | bpl = (struct ulp_bde64 *) | ||
5776 | ((struct lpfc_dmabuf *)piocbq->context3)->virt; | ||
5777 | |||
5778 | if (!bpl) | ||
5779 | return xritag; | ||
5780 | |||
5781 | for (i = 0; i < numBdes; i++) { | ||
5782 | /* Should already be byte swapped. */ | ||
5783 | sgl->addr_hi = bpl->addrHigh; | ||
5784 | sgl->addr_lo = bpl->addrLow; | ||
5785 | /* swap the size field back to the cpu so we | ||
5786 | * can assign it to the sgl. | ||
5787 | */ | ||
5788 | bde.tus.w = le32_to_cpu(bpl->tus.w); | ||
5789 | bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize); | ||
5790 | if ((i+1) == numBdes) | ||
5791 | bf_set(lpfc_sli4_sge_last, sgl, 1); | ||
5792 | else | ||
5793 | bf_set(lpfc_sli4_sge_last, sgl, 0); | ||
5794 | sgl->word2 = cpu_to_le32(sgl->word2); | ||
5795 | sgl->word3 = cpu_to_le32(sgl->word3); | ||
5796 | bpl++; | ||
5797 | sgl++; | ||
5798 | } | ||
5799 | } else if (icmd->un.genreq64.bdl.bdeFlags == BUFF_TYPE_BDE_64) { | ||
5800 | /* The addrHigh and addrLow fields of the BDE have not | ||
5801 | * been byteswapped yet so they need to be swapped | ||
5802 | * before putting them in the sgl. | ||
5803 | */ | ||
5804 | sgl->addr_hi = | ||
5805 | cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); | ||
5806 | sgl->addr_lo = | ||
5807 | cpu_to_le32(icmd->un.genreq64.bdl.addrLow); | ||
5808 | bf_set(lpfc_sli4_sge_len, sgl, | ||
5809 | icmd->un.genreq64.bdl.bdeSize); | ||
5810 | bf_set(lpfc_sli4_sge_last, sgl, 1); | ||
5811 | sgl->word2 = cpu_to_le32(sgl->word2); | ||
5812 | sgl->word3 = cpu_to_le32(sgl->word3); | ||
5813 | } | ||
5814 | return sglq->sli4_xritag; | ||
5815 | } | ||
5816 | |||
5817 | /** | ||
5818 | * lpfc_sli4_scmd_to_wqidx_distr - scsi command to SLI4 WQ index distribution | ||
5819 | * @phba: Pointer to HBA context object. | ||
5820 | * @piocb: Pointer to command iocb. | ||
5821 | * | ||
5822 | * This routine performs a round robin SCSI command to SLI4 FCP WQ index | ||
5823 | * distribution. | ||
5824 | * | ||
5825 | * Return: index into SLI4 fast-path FCP queue index. | ||
5826 | **/ | ||
5827 | static uint32_t | ||
5828 | lpfc_sli4_scmd_to_wqidx_distr(struct lpfc_hba *phba, struct lpfc_iocbq *piocb) | ||
5829 | { | ||
5830 | static uint32_t fcp_qidx; | ||
5831 | |||
5832 | return fcp_qidx++ % phba->cfg_fcp_wq_count; | ||
5833 | } | ||
5834 | |||
5835 | /** | ||
5836 | * lpfc_sli_iocb2wqe - Convert the IOCB to a work queue entry. | ||
5837 | * @phba: Pointer to HBA context object. | ||
5838 | * @piocb: Pointer to command iocb. | ||
5839 | * @wqe: Pointer to the work queue entry. | ||
5840 | * | ||
5841 | * This routine converts the iocb command to its Work Queue Entry | ||
5842 | * equivalent. The wqe pointer should not have any fields set when | ||
5843 | * this routine is called because it will memcpy over them. | ||
5844 | * This routine does not set the CQ_ID or the WQEC bits in the | ||
5845 | * wqe. | ||
5846 | * | ||
5847 | * Returns: 0 = Success, IOCB_ERROR = Failure. | ||
5848 | **/ | ||
5849 | static int | ||
5850 | lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq, | ||
5851 | union lpfc_wqe *wqe) | ||
5852 | { | ||
5853 | uint32_t payload_len = 0; | ||
5854 | uint8_t ct = 0; | ||
5855 | uint32_t fip; | ||
5856 | uint32_t abort_tag; | ||
5857 | uint8_t command_type = ELS_COMMAND_NON_FIP; | ||
5858 | uint8_t cmnd; | ||
5859 | uint16_t xritag; | ||
5860 | struct ulp_bde64 *bpl = NULL; | ||
5861 | |||
5862 | fip = bf_get(lpfc_fip_flag, &phba->sli4_hba.sli4_flags); | ||
5863 | /* The fcp commands will set command type */ | ||
5864 | if (iocbq->iocb_flag & LPFC_IO_FCP) | ||
5865 | command_type = FCP_COMMAND; | ||
5866 | else if (fip && (iocbq->iocb_flag & LPFC_FIP_ELS)) | ||
5867 | command_type = ELS_COMMAND_FIP; | ||
5868 | else | ||
5869 | command_type = ELS_COMMAND_NON_FIP; | ||
5870 | |||
5871 | /* Some of the fields are in the right position already */ | ||
5872 | memcpy(wqe, &iocbq->iocb, sizeof(union lpfc_wqe)); | ||
5873 | abort_tag = (uint32_t) iocbq->iotag; | ||
5874 | xritag = iocbq->sli4_xritag; | ||
5875 | wqe->words[7] = 0; /* The ct field has moved so reset */ | ||
5876 | /* words0-2 bpl convert bde */ | ||
5877 | if (iocbq->iocb.un.genreq64.bdl.bdeFlags == BUFF_TYPE_BLP_64) { | ||
5878 | bpl = (struct ulp_bde64 *) | ||
5879 | ((struct lpfc_dmabuf *)iocbq->context3)->virt; | ||
5880 | if (!bpl) | ||
5881 | return IOCB_ERROR; | ||
5882 | |||
5883 | /* Should already be byte swapped. */ | ||
5884 | wqe->generic.bde.addrHigh = le32_to_cpu(bpl->addrHigh); | ||
5885 | wqe->generic.bde.addrLow = le32_to_cpu(bpl->addrLow); | ||
5886 | /* swap the size field back to the cpu so we | ||
5887 | * can assign it to the sgl. | ||
5888 | */ | ||
5889 | wqe->generic.bde.tus.w = le32_to_cpu(bpl->tus.w); | ||
5890 | payload_len = wqe->generic.bde.tus.f.bdeSize; | ||
5891 | } else | ||
5892 | payload_len = iocbq->iocb.un.fcpi64.bdl.bdeSize; | ||
5893 | |||
5894 | iocbq->iocb.ulpIoTag = iocbq->iotag; | ||
5895 | cmnd = iocbq->iocb.ulpCommand; | ||
5896 | |||
5897 | switch (iocbq->iocb.ulpCommand) { | ||
5898 | case CMD_ELS_REQUEST64_CR: | ||
5899 | if (!iocbq->iocb.ulpLe) { | ||
5900 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
5901 | "2007 Only Limited Edition cmd Format" | ||
5902 | " supported 0x%x\n", | ||
5903 | iocbq->iocb.ulpCommand); | ||
5904 | return IOCB_ERROR; | ||
5905 | } | ||
5906 | wqe->els_req.payload_len = payload_len; | ||
5907 | /* Els_reguest64 has a TMO */ | ||
5908 | bf_set(wqe_tmo, &wqe->els_req.wqe_com, | ||
5909 | iocbq->iocb.ulpTimeout); | ||
5910 | /* Need a VF for word 4 set the vf bit*/ | ||
5911 | bf_set(els_req64_vf, &wqe->els_req, 0); | ||
5912 | /* And a VFID for word 12 */ | ||
5913 | bf_set(els_req64_vfid, &wqe->els_req, 0); | ||
5914 | /* | ||
5915 | * Set ct field to 3, indicates that the context_tag field | ||
5916 | * contains the FCFI and remote N_Port_ID is | ||
5917 | * in word 5. | ||
5918 | */ | ||
5919 | |||
5920 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | ||
5921 | bf_set(lpfc_wqe_gen_context, &wqe->generic, | ||
5922 | iocbq->iocb.ulpContext); | ||
5923 | |||
5924 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, ct); | ||
5925 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); | ||
5926 | /* CCP CCPE PV PRI in word10 were set in the memcpy */ | ||
5927 | break; | ||
5928 | case CMD_XMIT_SEQUENCE64_CR: | ||
5929 | /* word3 iocb=io_tag32 wqe=payload_offset */ | ||
5930 | /* payload offset used for multilpe outstanding | ||
5931 | * sequences on the same exchange | ||
5932 | */ | ||
5933 | wqe->words[3] = 0; | ||
5934 | /* word4 relative_offset memcpy */ | ||
5935 | /* word5 r_ctl/df_ctl memcpy */ | ||
5936 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); | ||
5937 | wqe->xmit_sequence.xmit_len = payload_len; | ||
5938 | break; | ||
5939 | case CMD_XMIT_BCAST64_CN: | ||
5940 | /* word3 iocb=iotag32 wqe=payload_len */ | ||
5941 | wqe->words[3] = 0; /* no definition for this in wqe */ | ||
5942 | /* word4 iocb=rsvd wqe=rsvd */ | ||
5943 | /* word5 iocb=rctl/type/df_ctl wqe=rctl/type/df_ctl memcpy */ | ||
5944 | /* word6 iocb=ctxt_tag/io_tag wqe=ctxt_tag/xri */ | ||
5945 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, | ||
5946 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | ||
5947 | break; | ||
5948 | case CMD_FCP_IWRITE64_CR: | ||
5949 | command_type = FCP_COMMAND_DATA_OUT; | ||
5950 | /* The struct for wqe fcp_iwrite has 3 fields that are somewhat | ||
5951 | * confusing. | ||
5952 | * word3 is payload_len: byte offset to the sgl entry for the | ||
5953 | * fcp_command. | ||
5954 | * word4 is total xfer len, same as the IOCB->ulpParameter. | ||
5955 | * word5 is initial xfer len 0 = wait for xfer-ready | ||
5956 | */ | ||
5957 | |||
5958 | /* Always wait for xfer-ready before sending data */ | ||
5959 | wqe->fcp_iwrite.initial_xfer_len = 0; | ||
5960 | /* word 4 (xfer length) should have been set on the memcpy */ | ||
5961 | |||
5962 | /* allow write to fall through to read */ | ||
5963 | case CMD_FCP_IREAD64_CR: | ||
5964 | /* FCP_CMD is always the 1st sgl entry */ | ||
5965 | wqe->fcp_iread.payload_len = | ||
5966 | payload_len + sizeof(struct fcp_rsp); | ||
5967 | |||
5968 | /* word 4 (xfer length) should have been set on the memcpy */ | ||
5969 | |||
5970 | bf_set(lpfc_wqe_gen_erp, &wqe->generic, | ||
5971 | iocbq->iocb.ulpFCP2Rcvy); | ||
5972 | bf_set(lpfc_wqe_gen_lnk, &wqe->generic, iocbq->iocb.ulpXS); | ||
5973 | /* The XC bit and the XS bit are similar. The driver never | ||
5974 | * tracked whether or not the exchange was previouslly open. | ||
5975 | * XC = Exchange create, 0 is create. 1 is already open. | ||
5976 | * XS = link cmd: 1 do not close the exchange after command. | ||
5977 | * XS = 0 close exchange when command completes. | ||
5978 | * The only time we would not set the XC bit is when the XS bit | ||
5979 | * is set and we are sending our 2nd or greater command on | ||
5980 | * this exchange. | ||
5981 | */ | ||
5982 | /* Always open the exchange */ | ||
5983 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | ||
5984 | |||
5985 | wqe->words[10] &= 0xffff0000; /* zero out ebde count */ | ||
5986 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); | ||
5987 | break; | ||
5988 | case CMD_FCP_ICMND64_CR: | ||
5989 | /* Always open the exchange */ | ||
5990 | bf_set(wqe_xc, &wqe->fcp_iread.wqe_com, 0); | ||
5991 | |||
5992 | wqe->words[4] = 0; | ||
5993 | wqe->words[10] &= 0xffff0000; /* zero out ebde count */ | ||
5994 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, 0); | ||
5995 | break; | ||
5996 | case CMD_GEN_REQUEST64_CR: | ||
5997 | /* word3 command length is described as byte offset to the | ||
5998 | * rsp_data. Would always be 16, sizeof(struct sli4_sge) | ||
5999 | * sgl[0] = cmnd | ||
6000 | * sgl[1] = rsp. | ||
6001 | * | ||
6002 | */ | ||
6003 | wqe->gen_req.command_len = payload_len; | ||
6004 | /* Word4 parameter copied in the memcpy */ | ||
6005 | /* Word5 [rctl, type, df_ctl, la] copied in memcpy */ | ||
6006 | /* word6 context tag copied in memcpy */ | ||
6007 | if (iocbq->iocb.ulpCt_h || iocbq->iocb.ulpCt_l) { | ||
6008 | ct = ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l); | ||
6009 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
6010 | "2015 Invalid CT %x command 0x%x\n", | ||
6011 | ct, iocbq->iocb.ulpCommand); | ||
6012 | return IOCB_ERROR; | ||
6013 | } | ||
6014 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, 0); | ||
6015 | bf_set(wqe_tmo, &wqe->gen_req.wqe_com, | ||
6016 | iocbq->iocb.ulpTimeout); | ||
6017 | |||
6018 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); | ||
6019 | command_type = OTHER_COMMAND; | ||
6020 | break; | ||
6021 | case CMD_XMIT_ELS_RSP64_CX: | ||
6022 | /* words0-2 BDE memcpy */ | ||
6023 | /* word3 iocb=iotag32 wqe=rsvd */ | ||
6024 | wqe->words[3] = 0; | ||
6025 | /* word4 iocb=did wge=rsvd. */ | ||
6026 | wqe->words[4] = 0; | ||
6027 | /* word5 iocb=rsvd wge=did */ | ||
6028 | bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, | ||
6029 | iocbq->iocb.un.elsreq64.remoteID); | ||
6030 | |||
6031 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, | ||
6032 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | ||
6033 | |||
6034 | bf_set(lpfc_wqe_gen_pu, &wqe->generic, iocbq->iocb.ulpPU); | ||
6035 | bf_set(wqe_rcvoxid, &wqe->generic, iocbq->iocb.ulpContext); | ||
6036 | if (!iocbq->iocb.ulpCt_h && iocbq->iocb.ulpCt_l) | ||
6037 | bf_set(lpfc_wqe_gen_context, &wqe->generic, | ||
6038 | iocbq->vport->vpi + phba->vpi_base); | ||
6039 | command_type = OTHER_COMMAND; | ||
6040 | break; | ||
6041 | case CMD_CLOSE_XRI_CN: | ||
6042 | case CMD_ABORT_XRI_CN: | ||
6043 | case CMD_ABORT_XRI_CX: | ||
6044 | /* words 0-2 memcpy should be 0 rserved */ | ||
6045 | /* port will send abts */ | ||
6046 | if (iocbq->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | ||
6047 | /* | ||
6048 | * The link is down so the fw does not need to send abts | ||
6049 | * on the wire. | ||
6050 | */ | ||
6051 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 1); | ||
6052 | else | ||
6053 | bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); | ||
6054 | bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); | ||
6055 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | ||
6056 | wqe->words[5] = 0; | ||
6057 | bf_set(lpfc_wqe_gen_ct, &wqe->generic, | ||
6058 | ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); | ||
6059 | abort_tag = iocbq->iocb.un.acxri.abortIoTag; | ||
6060 | wqe->generic.abort_tag = abort_tag; | ||
6061 | /* | ||
6062 | * The abort handler will send us CMD_ABORT_XRI_CN or | ||
6063 | * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX | ||
6064 | */ | ||
6065 | bf_set(lpfc_wqe_gen_command, &wqe->generic, CMD_ABORT_XRI_CX); | ||
6066 | cmnd = CMD_ABORT_XRI_CX; | ||
6067 | command_type = OTHER_COMMAND; | ||
6068 | xritag = 0; | ||
6069 | break; | ||
6070 | case CMD_XRI_ABORTED_CX: | ||
6071 | case CMD_CREATE_XRI_CR: /* Do we expect to use this? */ | ||
6072 | /* words0-2 are all 0's no bde */ | ||
6073 | /* word3 and word4 are rsvrd */ | ||
6074 | wqe->words[3] = 0; | ||
6075 | wqe->words[4] = 0; | ||
6076 | /* word5 iocb=rsvd wge=did */ | ||
6077 | /* There is no remote port id in the IOCB? */ | ||
6078 | /* Let this fall through and fail */ | ||
6079 | case CMD_IOCB_FCP_IBIDIR64_CR: /* bidirectional xfer */ | ||
6080 | case CMD_FCP_TSEND64_CX: /* Target mode send xfer-ready */ | ||
6081 | case CMD_FCP_TRSP64_CX: /* Target mode rcv */ | ||
6082 | case CMD_FCP_AUTO_TRSP_CX: /* Auto target rsp */ | ||
6083 | default: | ||
6084 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
6085 | "2014 Invalid command 0x%x\n", | ||
6086 | iocbq->iocb.ulpCommand); | ||
6087 | return IOCB_ERROR; | ||
6088 | break; | ||
6089 | |||
6090 | } | ||
6091 | bf_set(lpfc_wqe_gen_xri, &wqe->generic, xritag); | ||
6092 | bf_set(lpfc_wqe_gen_request_tag, &wqe->generic, iocbq->iotag); | ||
6093 | wqe->generic.abort_tag = abort_tag; | ||
6094 | bf_set(lpfc_wqe_gen_cmd_type, &wqe->generic, command_type); | ||
6095 | bf_set(lpfc_wqe_gen_command, &wqe->generic, cmnd); | ||
6096 | bf_set(lpfc_wqe_gen_class, &wqe->generic, iocbq->iocb.ulpClass); | ||
6097 | bf_set(lpfc_wqe_gen_cq_id, &wqe->generic, LPFC_WQE_CQ_ID_DEFAULT); | ||
6098 | |||
6099 | return 0; | ||
6100 | } | ||
6101 | |||
6102 | /** | ||
6103 | * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb | ||
6104 | * @phba: Pointer to HBA context object. | ||
6105 | * @ring_number: SLI ring number to issue iocb on. | ||
6106 | * @piocb: Pointer to command iocb. | ||
6107 | * @flag: Flag indicating if this command can be put into txq. | ||
6108 | * | ||
6109 | * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue | ||
6110 | * an iocb command to an HBA with SLI-4 interface spec. | ||
6111 | * | ||
6112 | * This function is called with hbalock held. The function will return success | ||
6113 | * after it successfully submit the iocb to firmware or after adding to the | ||
6114 | * txq. | ||
6115 | **/ | ||
6116 | static int | ||
6117 | __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number, | ||
6118 | struct lpfc_iocbq *piocb, uint32_t flag) | ||
6119 | { | ||
6120 | struct lpfc_sglq *sglq; | ||
6121 | uint16_t xritag; | ||
6122 | union lpfc_wqe wqe; | ||
6123 | struct lpfc_sli_ring *pring = &phba->sli.ring[ring_number]; | ||
6124 | uint32_t fcp_wqidx; | ||
6125 | |||
6126 | if (piocb->sli4_xritag == NO_XRI) { | ||
6127 | if (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN || | ||
6128 | piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN) | ||
6129 | sglq = NULL; | ||
6130 | else { | ||
6131 | sglq = __lpfc_sli_get_sglq(phba); | ||
6132 | if (!sglq) | ||
6133 | return IOCB_ERROR; | ||
6134 | piocb->sli4_xritag = sglq->sli4_xritag; | ||
6135 | } | ||
6136 | } else if (piocb->iocb_flag & LPFC_IO_FCP) { | ||
6137 | sglq = NULL; /* These IO's already have an XRI and | ||
6138 | * a mapped sgl. | ||
6139 | */ | ||
6140 | } else { | ||
6141 | /* This is a continuation of a commandi,(CX) so this | ||
6142 | * sglq is on the active list | ||
6143 | */ | ||
6144 | sglq = __lpfc_get_active_sglq(phba, piocb->sli4_xritag); | ||
6145 | if (!sglq) | ||
6146 | return IOCB_ERROR; | ||
6147 | } | ||
6148 | |||
6149 | if (sglq) { | ||
6150 | xritag = lpfc_sli4_bpl2sgl(phba, piocb, sglq); | ||
6151 | if (xritag != sglq->sli4_xritag) | ||
6152 | return IOCB_ERROR; | ||
6153 | } | ||
6154 | |||
6155 | if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) | ||
6156 | return IOCB_ERROR; | ||
6157 | |||
6158 | if (piocb->iocb_flag & LPFC_IO_FCP) { | ||
6159 | fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba, piocb); | ||
6160 | if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[fcp_wqidx], &wqe)) | ||
6161 | return IOCB_ERROR; | ||
6162 | } else { | ||
6163 | if (lpfc_sli4_wq_put(phba->sli4_hba.els_wq, &wqe)) | ||
6164 | return IOCB_ERROR; | ||
6165 | } | ||
6166 | lpfc_sli_ringtxcmpl_put(phba, pring, piocb); | ||
6167 | |||
6168 | return 0; | ||
6169 | } | ||
6170 | |||
6171 | /** | ||
6172 | * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb | ||
6173 | * | ||
6174 | * This routine wraps the actual lockless version for issusing IOCB function | ||
6175 | * pointer from the lpfc_hba struct. | ||
6176 | * | ||
6177 | * Return codes: | ||
6178 | * IOCB_ERROR - Error | ||
6179 | * IOCB_SUCCESS - Success | ||
6180 | * IOCB_BUSY - Busy | ||
6181 | **/ | ||
6182 | static inline int | ||
6183 | __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, | ||
6184 | struct lpfc_iocbq *piocb, uint32_t flag) | ||
6185 | { | ||
6186 | return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); | ||
6187 | } | ||
6188 | |||
6189 | /** | ||
6190 | * lpfc_sli_api_table_setup - Set up sli api fucntion jump table | ||
6191 | * @phba: The hba struct for which this call is being executed. | ||
6192 | * @dev_grp: The HBA PCI-Device group number. | ||
6193 | * | ||
6194 | * This routine sets up the SLI interface API function jump table in @phba | ||
6195 | * struct. | ||
6196 | * Returns: 0 - success, -ENODEV - failure. | ||
6197 | **/ | ||
6198 | int | ||
6199 | lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | ||
6200 | { | ||
6201 | |||
6202 | switch (dev_grp) { | ||
6203 | case LPFC_PCI_DEV_LP: | ||
6204 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3; | ||
6205 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3; | ||
6206 | break; | ||
6207 | case LPFC_PCI_DEV_OC: | ||
6208 | phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4; | ||
6209 | phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4; | ||
6210 | break; | ||
6211 | default: | ||
6212 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
6213 | "1419 Invalid HBA PCI-device group: 0x%x\n", | ||
6214 | dev_grp); | ||
6215 | return -ENODEV; | ||
6216 | break; | ||
6217 | } | ||
6218 | phba->lpfc_get_iocb_from_iocbq = lpfc_get_iocb_from_iocbq; | ||
6219 | return 0; | ||
6220 | } | ||
3836 | 6221 | ||
3837 | /** | 6222 | /** |
3838 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb | 6223 | * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb |
@@ -3848,14 +6233,14 @@ __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
3848 | * functions which do not hold hbalock. | 6233 | * functions which do not hold hbalock. |
3849 | **/ | 6234 | **/ |
3850 | int | 6235 | int |
3851 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | 6236 | lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number, |
3852 | struct lpfc_iocbq *piocb, uint32_t flag) | 6237 | struct lpfc_iocbq *piocb, uint32_t flag) |
3853 | { | 6238 | { |
3854 | unsigned long iflags; | 6239 | unsigned long iflags; |
3855 | int rc; | 6240 | int rc; |
3856 | 6241 | ||
3857 | spin_lock_irqsave(&phba->hbalock, iflags); | 6242 | spin_lock_irqsave(&phba->hbalock, iflags); |
3858 | rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag); | 6243 | rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag); |
3859 | spin_unlock_irqrestore(&phba->hbalock, iflags); | 6244 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
3860 | 6245 | ||
3861 | return rc; | 6246 | return rc; |
@@ -4148,6 +6533,52 @@ lpfc_sli_queue_setup(struct lpfc_hba *phba) | |||
4148 | } | 6533 | } |
4149 | 6534 | ||
4150 | /** | 6535 | /** |
6536 | * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system | ||
6537 | * @phba: Pointer to HBA context object. | ||
6538 | * | ||
6539 | * This routine flushes the mailbox command subsystem. It will unconditionally | ||
6540 | * flush all the mailbox commands in the three possible stages in the mailbox | ||
6541 | * command sub-system: pending mailbox command queue; the outstanding mailbox | ||
6542 | * command; and completed mailbox command queue. It is caller's responsibility | ||
6543 | * to make sure that the driver is in the proper state to flush the mailbox | ||
6544 | * command sub-system. Namely, the posting of mailbox commands into the | ||
6545 | * pending mailbox command queue from the various clients must be stopped; | ||
6546 | * either the HBA is in a state that it will never works on the outstanding | ||
6547 | * mailbox command (such as in EEH or ERATT conditions) or the outstanding | ||
6548 | * mailbox command has been completed. | ||
6549 | **/ | ||
6550 | static void | ||
6551 | lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba) | ||
6552 | { | ||
6553 | LIST_HEAD(completions); | ||
6554 | struct lpfc_sli *psli = &phba->sli; | ||
6555 | LPFC_MBOXQ_t *pmb; | ||
6556 | unsigned long iflag; | ||
6557 | |||
6558 | /* Flush all the mailbox commands in the mbox system */ | ||
6559 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
6560 | /* The pending mailbox command queue */ | ||
6561 | list_splice_init(&phba->sli.mboxq, &completions); | ||
6562 | /* The outstanding active mailbox command */ | ||
6563 | if (psli->mbox_active) { | ||
6564 | list_add_tail(&psli->mbox_active->list, &completions); | ||
6565 | psli->mbox_active = NULL; | ||
6566 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
6567 | } | ||
6568 | /* The completed mailbox command queue */ | ||
6569 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | ||
6570 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
6571 | |||
6572 | /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */ | ||
6573 | while (!list_empty(&completions)) { | ||
6574 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | ||
6575 | pmb->u.mb.mbxStatus = MBX_NOT_FINISHED; | ||
6576 | if (pmb->mbox_cmpl) | ||
6577 | pmb->mbox_cmpl(phba, pmb); | ||
6578 | } | ||
6579 | } | ||
6580 | |||
6581 | /** | ||
4151 | * lpfc_sli_host_down - Vport cleanup function | 6582 | * lpfc_sli_host_down - Vport cleanup function |
4152 | * @vport: Pointer to virtual port object. | 6583 | * @vport: Pointer to virtual port object. |
4153 | * | 6584 | * |
@@ -4240,9 +6671,11 @@ lpfc_sli_hba_down(struct lpfc_hba *phba) | |||
4240 | struct lpfc_sli *psli = &phba->sli; | 6671 | struct lpfc_sli *psli = &phba->sli; |
4241 | struct lpfc_sli_ring *pring; | 6672 | struct lpfc_sli_ring *pring; |
4242 | struct lpfc_dmabuf *buf_ptr; | 6673 | struct lpfc_dmabuf *buf_ptr; |
4243 | LPFC_MBOXQ_t *pmb; | ||
4244 | int i; | ||
4245 | unsigned long flags = 0; | 6674 | unsigned long flags = 0; |
6675 | int i; | ||
6676 | |||
6677 | /* Shutdown the mailbox command sub-system */ | ||
6678 | lpfc_sli_mbox_sys_shutdown(phba); | ||
4246 | 6679 | ||
4247 | lpfc_hba_down_prep(phba); | 6680 | lpfc_hba_down_prep(phba); |
4248 | 6681 | ||
@@ -4287,28 +6720,42 @@ lpfc_sli_hba_down(struct lpfc_hba *phba) | |||
4287 | 6720 | ||
4288 | /* Return any active mbox cmds */ | 6721 | /* Return any active mbox cmds */ |
4289 | del_timer_sync(&psli->mbox_tmo); | 6722 | del_timer_sync(&psli->mbox_tmo); |
4290 | spin_lock_irqsave(&phba->hbalock, flags); | ||
4291 | 6723 | ||
4292 | spin_lock(&phba->pport->work_port_lock); | 6724 | spin_lock_irqsave(&phba->pport->work_port_lock, flags); |
4293 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | 6725 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; |
4294 | spin_unlock(&phba->pport->work_port_lock); | 6726 | spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); |
4295 | 6727 | ||
4296 | /* Return any pending or completed mbox cmds */ | 6728 | return 1; |
4297 | list_splice_init(&phba->sli.mboxq, &completions); | 6729 | } |
4298 | if (psli->mbox_active) { | 6730 | |
4299 | list_add_tail(&psli->mbox_active->list, &completions); | 6731 | /** |
4300 | psli->mbox_active = NULL; | 6732 | * lpfc_sli4_hba_down - PCI function resource cleanup for the SLI4 HBA |
4301 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | 6733 | * @phba: Pointer to HBA context object. |
4302 | } | 6734 | * |
4303 | list_splice_init(&phba->sli.mboxq_cmpl, &completions); | 6735 | * This function cleans up all queues, iocb, buffers, mailbox commands while |
4304 | spin_unlock_irqrestore(&phba->hbalock, flags); | 6736 | * shutting down the SLI4 HBA FCoE function. This function is called with no |
6737 | * lock held and always returns 1. | ||
6738 | * | ||
6739 | * This function does the following to cleanup driver FCoE function resources: | ||
6740 | * - Free discovery resources for each virtual port | ||
6741 | * - Cleanup any pending fabric iocbs | ||
6742 | * - Iterate through the iocb txq and free each entry in the list. | ||
6743 | * - Free up any buffer posted to the HBA. | ||
6744 | * - Clean up all the queue entries: WQ, RQ, MQ, EQ, CQ, etc. | ||
6745 | * - Free mailbox commands in the mailbox queue. | ||
6746 | **/ | ||
6747 | int | ||
6748 | lpfc_sli4_hba_down(struct lpfc_hba *phba) | ||
6749 | { | ||
6750 | /* Stop the SLI4 device port */ | ||
6751 | lpfc_stop_port(phba); | ||
6752 | |||
6753 | /* Tear down the queues in the HBA */ | ||
6754 | lpfc_sli4_queue_unset(phba); | ||
6755 | |||
6756 | /* unregister default FCFI from the HBA */ | ||
6757 | lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi); | ||
4305 | 6758 | ||
4306 | while (!list_empty(&completions)) { | ||
4307 | list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list); | ||
4308 | pmb->mb.mbxStatus = MBX_NOT_FINISHED; | ||
4309 | if (pmb->mbox_cmpl) | ||
4310 | pmb->mbox_cmpl(phba,pmb); | ||
4311 | } | ||
4312 | return 1; | 6759 | return 1; |
4313 | } | 6760 | } |
4314 | 6761 | ||
@@ -4639,7 +7086,10 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
4639 | iabt = &abtsiocbp->iocb; | 7086 | iabt = &abtsiocbp->iocb; |
4640 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; | 7087 | iabt->un.acxri.abortType = ABORT_TYPE_ABTS; |
4641 | iabt->un.acxri.abortContextTag = icmd->ulpContext; | 7088 | iabt->un.acxri.abortContextTag = icmd->ulpContext; |
4642 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | 7089 | if (phba->sli_rev == LPFC_SLI_REV4) |
7090 | iabt->un.acxri.abortIoTag = cmdiocb->sli4_xritag; | ||
7091 | else | ||
7092 | iabt->un.acxri.abortIoTag = icmd->ulpIoTag; | ||
4643 | iabt->ulpLe = 1; | 7093 | iabt->ulpLe = 1; |
4644 | iabt->ulpClass = icmd->ulpClass; | 7094 | iabt->ulpClass = icmd->ulpClass; |
4645 | 7095 | ||
@@ -4655,7 +7105,7 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, | |||
4655 | "abort cmd iotag x%x\n", | 7105 | "abort cmd iotag x%x\n", |
4656 | iabt->un.acxri.abortContextTag, | 7106 | iabt->un.acxri.abortContextTag, |
4657 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); | 7107 | iabt->un.acxri.abortIoTag, abtsiocbp->iotag); |
4658 | retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); | 7108 | retval = __lpfc_sli_issue_iocb(phba, pring->ringno, abtsiocbp, 0); |
4659 | 7109 | ||
4660 | if (retval) | 7110 | if (retval) |
4661 | __lpfc_sli_release_iocbq(phba, abtsiocbp); | 7111 | __lpfc_sli_release_iocbq(phba, abtsiocbp); |
@@ -4838,7 +7288,10 @@ lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, | |||
4838 | cmd = &iocbq->iocb; | 7288 | cmd = &iocbq->iocb; |
4839 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; | 7289 | abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS; |
4840 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; | 7290 | abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext; |
4841 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | 7291 | if (phba->sli_rev == LPFC_SLI_REV4) |
7292 | abtsiocb->iocb.un.acxri.abortIoTag = iocbq->sli4_xritag; | ||
7293 | else | ||
7294 | abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; | ||
4842 | abtsiocb->iocb.ulpLe = 1; | 7295 | abtsiocb->iocb.ulpLe = 1; |
4843 | abtsiocb->iocb.ulpClass = cmd->ulpClass; | 7296 | abtsiocb->iocb.ulpClass = cmd->ulpClass; |
4844 | abtsiocb->vport = phba->pport; | 7297 | abtsiocb->vport = phba->pport; |
@@ -4850,7 +7303,8 @@ lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, | |||
4850 | 7303 | ||
4851 | /* Setup callback routine and issue the command. */ | 7304 | /* Setup callback routine and issue the command. */ |
4852 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; | 7305 | abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl; |
4853 | ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0); | 7306 | ret_val = lpfc_sli_issue_iocb(phba, pring->ringno, |
7307 | abtsiocb, 0); | ||
4854 | if (ret_val == IOCB_ERROR) { | 7308 | if (ret_val == IOCB_ERROR) { |
4855 | lpfc_sli_release_iocbq(phba, abtsiocb); | 7309 | lpfc_sli_release_iocbq(phba, abtsiocb); |
4856 | errcnt++; | 7310 | errcnt++; |
@@ -4900,6 +7354,32 @@ lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |||
4900 | } | 7354 | } |
4901 | 7355 | ||
4902 | /** | 7356 | /** |
7357 | * lpfc_chk_iocb_flg - Test IOCB flag with lock held. | ||
7358 | * @phba: Pointer to HBA context object.. | ||
7359 | * @piocbq: Pointer to command iocb. | ||
7360 | * @flag: Flag to test. | ||
7361 | * | ||
7362 | * This routine grabs the hbalock and then test the iocb_flag to | ||
7363 | * see if the passed in flag is set. | ||
7364 | * Returns: | ||
7365 | * 1 if flag is set. | ||
7366 | * 0 if flag is not set. | ||
7367 | **/ | ||
7368 | static int | ||
7369 | lpfc_chk_iocb_flg(struct lpfc_hba *phba, | ||
7370 | struct lpfc_iocbq *piocbq, uint32_t flag) | ||
7371 | { | ||
7372 | unsigned long iflags; | ||
7373 | int ret; | ||
7374 | |||
7375 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
7376 | ret = piocbq->iocb_flag & flag; | ||
7377 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
7378 | return ret; | ||
7379 | |||
7380 | } | ||
7381 | |||
7382 | /** | ||
4903 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands | 7383 | * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands |
4904 | * @phba: Pointer to HBA context object.. | 7384 | * @phba: Pointer to HBA context object.. |
4905 | * @pring: Pointer to sli ring. | 7385 | * @pring: Pointer to sli ring. |
@@ -4931,7 +7411,7 @@ lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, | |||
4931 | **/ | 7411 | **/ |
4932 | int | 7412 | int |
4933 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, | 7413 | lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, |
4934 | struct lpfc_sli_ring *pring, | 7414 | uint32_t ring_number, |
4935 | struct lpfc_iocbq *piocb, | 7415 | struct lpfc_iocbq *piocb, |
4936 | struct lpfc_iocbq *prspiocbq, | 7416 | struct lpfc_iocbq *prspiocbq, |
4937 | uint32_t timeout) | 7417 | uint32_t timeout) |
@@ -4962,11 +7442,11 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, | |||
4962 | readl(phba->HCregaddr); /* flush */ | 7442 | readl(phba->HCregaddr); /* flush */ |
4963 | } | 7443 | } |
4964 | 7444 | ||
4965 | retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); | 7445 | retval = lpfc_sli_issue_iocb(phba, ring_number, piocb, 0); |
4966 | if (retval == IOCB_SUCCESS) { | 7446 | if (retval == IOCB_SUCCESS) { |
4967 | timeout_req = timeout * HZ; | 7447 | timeout_req = timeout * HZ; |
4968 | timeleft = wait_event_timeout(done_q, | 7448 | timeleft = wait_event_timeout(done_q, |
4969 | piocb->iocb_flag & LPFC_IO_WAKE, | 7449 | lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE), |
4970 | timeout_req); | 7450 | timeout_req); |
4971 | 7451 | ||
4972 | if (piocb->iocb_flag & LPFC_IO_WAKE) { | 7452 | if (piocb->iocb_flag & LPFC_IO_WAKE) { |
@@ -5077,53 +7557,150 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, | |||
5077 | } | 7557 | } |
5078 | 7558 | ||
5079 | /** | 7559 | /** |
5080 | * lpfc_sli_flush_mbox_queue - mailbox queue cleanup function | 7560 | * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system |
5081 | * @phba: Pointer to HBA context. | 7561 | * @phba: Pointer to HBA context. |
5082 | * | 7562 | * |
5083 | * This function is called to cleanup any pending mailbox | 7563 | * This function is called to shutdown the driver's mailbox sub-system. |
5084 | * objects in the driver queue before bringing the HBA offline. | 7564 | * It first marks the mailbox sub-system is in a block state to prevent |
5085 | * This function is called while resetting the HBA. | 7565 | * the asynchronous mailbox command from issued off the pending mailbox |
5086 | * The function is called without any lock held. The function | 7566 | * command queue. If the mailbox command sub-system shutdown is due to |
5087 | * takes hbalock to update SLI data structure. | 7567 | * HBA error conditions such as EEH or ERATT, this routine shall invoke |
5088 | * This function returns 1 when there is an active mailbox | 7568 | * the mailbox sub-system flush routine to forcefully bring down the |
5089 | * command pending else returns 0. | 7569 | * mailbox sub-system. Otherwise, if it is due to normal condition (such |
7570 | * as with offline or HBA function reset), this routine will wait for the | ||
7571 | * outstanding mailbox command to complete before invoking the mailbox | ||
7572 | * sub-system flush routine to gracefully bring down mailbox sub-system. | ||
5090 | **/ | 7573 | **/ |
5091 | int | 7574 | void |
5092 | lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) | 7575 | lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba) |
5093 | { | 7576 | { |
5094 | struct lpfc_vport *vport = phba->pport; | 7577 | struct lpfc_sli *psli = &phba->sli; |
5095 | int i = 0; | 7578 | uint8_t actcmd = MBX_HEARTBEAT; |
5096 | uint32_t ha_copy; | 7579 | unsigned long timeout; |
5097 | 7580 | ||
5098 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { | 7581 | spin_lock_irq(&phba->hbalock); |
5099 | if (i++ > LPFC_MBOX_TMO * 1000) | 7582 | psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
5100 | return 1; | 7583 | spin_unlock_irq(&phba->hbalock); |
5101 | 7584 | ||
5102 | /* | 7585 | if (psli->sli_flag & LPFC_SLI_ACTIVE) { |
5103 | * Call lpfc_sli_handle_mb_event only if a mailbox cmd | ||
5104 | * did finish. This way we won't get the misleading | ||
5105 | * "Stray Mailbox Interrupt" message. | ||
5106 | */ | ||
5107 | spin_lock_irq(&phba->hbalock); | 7586 | spin_lock_irq(&phba->hbalock); |
5108 | ha_copy = phba->work_ha; | 7587 | if (phba->sli.mbox_active) |
5109 | phba->work_ha &= ~HA_MBATT; | 7588 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
5110 | spin_unlock_irq(&phba->hbalock); | 7589 | spin_unlock_irq(&phba->hbalock); |
7590 | /* Determine how long we might wait for the active mailbox | ||
7591 | * command to be gracefully completed by firmware. | ||
7592 | */ | ||
7593 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * | ||
7594 | 1000) + jiffies; | ||
7595 | while (phba->sli.mbox_active) { | ||
7596 | /* Check active mailbox complete status every 2ms */ | ||
7597 | msleep(2); | ||
7598 | if (time_after(jiffies, timeout)) | ||
7599 | /* Timeout, let the mailbox flush routine to | ||
7600 | * forcefully release active mailbox command | ||
7601 | */ | ||
7602 | break; | ||
7603 | } | ||
7604 | } | ||
7605 | lpfc_sli_mbox_sys_flush(phba); | ||
7606 | } | ||
5111 | 7607 | ||
5112 | if (ha_copy & HA_MBATT) | 7608 | /** |
5113 | if (lpfc_sli_handle_mb_event(phba) == 0) | 7609 | * lpfc_sli_eratt_read - read sli-3 error attention events |
5114 | i = 0; | 7610 | * @phba: Pointer to HBA context. |
7611 | * | ||
7612 | * This function is called to read the SLI3 device error attention registers | ||
7613 | * for possible error attention events. The caller must hold the hostlock | ||
7614 | * with spin_lock_irq(). | ||
7615 | * | ||
7616 | * This fucntion returns 1 when there is Error Attention in the Host Attention | ||
7617 | * Register and returns 0 otherwise. | ||
7618 | **/ | ||
7619 | static int | ||
7620 | lpfc_sli_eratt_read(struct lpfc_hba *phba) | ||
7621 | { | ||
7622 | uint32_t ha_copy; | ||
7623 | |||
7624 | /* Read chip Host Attention (HA) register */ | ||
7625 | ha_copy = readl(phba->HAregaddr); | ||
7626 | if (ha_copy & HA_ERATT) { | ||
7627 | /* Read host status register to retrieve error event */ | ||
7628 | lpfc_sli_read_hs(phba); | ||
5115 | 7629 | ||
5116 | msleep(1); | 7630 | /* Check if there is a deferred error condition is active */ |
7631 | if ((HS_FFER1 & phba->work_hs) && | ||
7632 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | ||
7633 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { | ||
7634 | phba->hba_flag |= DEFER_ERATT; | ||
7635 | /* Clear all interrupt enable conditions */ | ||
7636 | writel(0, phba->HCregaddr); | ||
7637 | readl(phba->HCregaddr); | ||
7638 | } | ||
7639 | |||
7640 | /* Set the driver HA work bitmap */ | ||
7641 | phba->work_ha |= HA_ERATT; | ||
7642 | /* Indicate polling handles this ERATT */ | ||
7643 | phba->hba_flag |= HBA_ERATT_HANDLED; | ||
7644 | return 1; | ||
5117 | } | 7645 | } |
7646 | return 0; | ||
7647 | } | ||
7648 | |||
7649 | /** | ||
7650 | * lpfc_sli4_eratt_read - read sli-4 error attention events | ||
7651 | * @phba: Pointer to HBA context. | ||
7652 | * | ||
7653 | * This function is called to read the SLI4 device error attention registers | ||
7654 | * for possible error attention events. The caller must hold the hostlock | ||
7655 | * with spin_lock_irq(). | ||
7656 | * | ||
7657 | * This fucntion returns 1 when there is Error Attention in the Host Attention | ||
7658 | * Register and returns 0 otherwise. | ||
7659 | **/ | ||
7660 | static int | ||
7661 | lpfc_sli4_eratt_read(struct lpfc_hba *phba) | ||
7662 | { | ||
7663 | uint32_t uerr_sta_hi, uerr_sta_lo; | ||
7664 | uint32_t onlnreg0, onlnreg1; | ||
5118 | 7665 | ||
5119 | return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; | 7666 | /* For now, use the SLI4 device internal unrecoverable error |
7667 | * registers for error attention. This can be changed later. | ||
7668 | */ | ||
7669 | onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr); | ||
7670 | onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr); | ||
7671 | if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) { | ||
7672 | uerr_sta_lo = readl(phba->sli4_hba.UERRLOregaddr); | ||
7673 | uerr_sta_hi = readl(phba->sli4_hba.UERRHIregaddr); | ||
7674 | if (uerr_sta_lo || uerr_sta_hi) { | ||
7675 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7676 | "1423 HBA Unrecoverable error: " | ||
7677 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | ||
7678 | "online0_reg=0x%x, online1_reg=0x%x\n", | ||
7679 | uerr_sta_lo, uerr_sta_hi, | ||
7680 | onlnreg0, onlnreg1); | ||
7681 | /* TEMP: as the driver error recover logic is not | ||
7682 | * fully developed, we just log the error message | ||
7683 | * and the device error attention action is now | ||
7684 | * temporarily disabled. | ||
7685 | */ | ||
7686 | return 0; | ||
7687 | phba->work_status[0] = uerr_sta_lo; | ||
7688 | phba->work_status[1] = uerr_sta_hi; | ||
7689 | /* Set the driver HA work bitmap */ | ||
7690 | phba->work_ha |= HA_ERATT; | ||
7691 | /* Indicate polling handles this ERATT */ | ||
7692 | phba->hba_flag |= HBA_ERATT_HANDLED; | ||
7693 | return 1; | ||
7694 | } | ||
7695 | } | ||
7696 | return 0; | ||
5120 | } | 7697 | } |
5121 | 7698 | ||
5122 | /** | 7699 | /** |
5123 | * lpfc_sli_check_eratt - check error attention events | 7700 | * lpfc_sli_check_eratt - check error attention events |
5124 | * @phba: Pointer to HBA context. | 7701 | * @phba: Pointer to HBA context. |
5125 | * | 7702 | * |
5126 | * This function is called form timer soft interrupt context to check HBA's | 7703 | * This function is called from timer soft interrupt context to check HBA's |
5127 | * error attention register bit for error attention events. | 7704 | * error attention register bit for error attention events. |
5128 | * | 7705 | * |
5129 | * This fucntion returns 1 when there is Error Attention in the Host Attention | 7706 | * This fucntion returns 1 when there is Error Attention in the Host Attention |
@@ -5134,10 +7711,6 @@ lpfc_sli_check_eratt(struct lpfc_hba *phba) | |||
5134 | { | 7711 | { |
5135 | uint32_t ha_copy; | 7712 | uint32_t ha_copy; |
5136 | 7713 | ||
5137 | /* If PCI channel is offline, don't process it */ | ||
5138 | if (unlikely(pci_channel_offline(phba->pcidev))) | ||
5139 | return 0; | ||
5140 | |||
5141 | /* If somebody is waiting to handle an eratt, don't process it | 7714 | /* If somebody is waiting to handle an eratt, don't process it |
5142 | * here. The brdkill function will do this. | 7715 | * here. The brdkill function will do this. |
5143 | */ | 7716 | */ |
@@ -5161,56 +7734,84 @@ lpfc_sli_check_eratt(struct lpfc_hba *phba) | |||
5161 | return 0; | 7734 | return 0; |
5162 | } | 7735 | } |
5163 | 7736 | ||
5164 | /* Read chip Host Attention (HA) register */ | 7737 | /* If PCI channel is offline, don't process it */ |
5165 | ha_copy = readl(phba->HAregaddr); | 7738 | if (unlikely(pci_channel_offline(phba->pcidev))) { |
5166 | if (ha_copy & HA_ERATT) { | ||
5167 | /* Read host status register to retrieve error event */ | ||
5168 | lpfc_sli_read_hs(phba); | ||
5169 | |||
5170 | /* Check if there is a deferred error condition is active */ | ||
5171 | if ((HS_FFER1 & phba->work_hs) && | ||
5172 | ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 | | ||
5173 | HS_FFER6 | HS_FFER7) & phba->work_hs)) { | ||
5174 | phba->hba_flag |= DEFER_ERATT; | ||
5175 | /* Clear all interrupt enable conditions */ | ||
5176 | writel(0, phba->HCregaddr); | ||
5177 | readl(phba->HCregaddr); | ||
5178 | } | ||
5179 | |||
5180 | /* Set the driver HA work bitmap */ | ||
5181 | phba->work_ha |= HA_ERATT; | ||
5182 | /* Indicate polling handles this ERATT */ | ||
5183 | phba->hba_flag |= HBA_ERATT_HANDLED; | ||
5184 | spin_unlock_irq(&phba->hbalock); | 7739 | spin_unlock_irq(&phba->hbalock); |
5185 | return 1; | 7740 | return 0; |
7741 | } | ||
7742 | |||
7743 | switch (phba->sli_rev) { | ||
7744 | case LPFC_SLI_REV2: | ||
7745 | case LPFC_SLI_REV3: | ||
7746 | /* Read chip Host Attention (HA) register */ | ||
7747 | ha_copy = lpfc_sli_eratt_read(phba); | ||
7748 | break; | ||
7749 | case LPFC_SLI_REV4: | ||
7750 | /* Read devcie Uncoverable Error (UERR) registers */ | ||
7751 | ha_copy = lpfc_sli4_eratt_read(phba); | ||
7752 | break; | ||
7753 | default: | ||
7754 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7755 | "0299 Invalid SLI revision (%d)\n", | ||
7756 | phba->sli_rev); | ||
7757 | ha_copy = 0; | ||
7758 | break; | ||
5186 | } | 7759 | } |
5187 | spin_unlock_irq(&phba->hbalock); | 7760 | spin_unlock_irq(&phba->hbalock); |
7761 | |||
7762 | return ha_copy; | ||
7763 | } | ||
7764 | |||
7765 | /** | ||
7766 | * lpfc_intr_state_check - Check device state for interrupt handling | ||
7767 | * @phba: Pointer to HBA context. | ||
7768 | * | ||
7769 | * This inline routine checks whether a device or its PCI slot is in a state | ||
7770 | * that the interrupt should be handled. | ||
7771 | * | ||
7772 | * This function returns 0 if the device or the PCI slot is in a state that | ||
7773 | * interrupt should be handled, otherwise -EIO. | ||
7774 | */ | ||
7775 | static inline int | ||
7776 | lpfc_intr_state_check(struct lpfc_hba *phba) | ||
7777 | { | ||
7778 | /* If the pci channel is offline, ignore all the interrupts */ | ||
7779 | if (unlikely(pci_channel_offline(phba->pcidev))) | ||
7780 | return -EIO; | ||
7781 | |||
7782 | /* Update device level interrupt statistics */ | ||
7783 | phba->sli.slistat.sli_intr++; | ||
7784 | |||
7785 | /* Ignore all interrupts during initialization. */ | ||
7786 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | ||
7787 | return -EIO; | ||
7788 | |||
5188 | return 0; | 7789 | return 0; |
5189 | } | 7790 | } |
5190 | 7791 | ||
5191 | /** | 7792 | /** |
5192 | * lpfc_sp_intr_handler - The slow-path interrupt handler of lpfc driver | 7793 | * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device |
5193 | * @irq: Interrupt number. | 7794 | * @irq: Interrupt number. |
5194 | * @dev_id: The device context pointer. | 7795 | * @dev_id: The device context pointer. |
5195 | * | 7796 | * |
5196 | * This function is directly called from the PCI layer as an interrupt | 7797 | * This function is directly called from the PCI layer as an interrupt |
5197 | * service routine when the device is enabled with MSI-X multi-message | 7798 | * service routine when device with SLI-3 interface spec is enabled with |
5198 | * interrupt mode and there are slow-path events in the HBA. However, | 7799 | * MSI-X multi-message interrupt mode and there are slow-path events in |
5199 | * when the device is enabled with either MSI or Pin-IRQ interrupt mode, | 7800 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ |
5200 | * this function is called as part of the device-level interrupt handler. | 7801 | * interrupt mode, this function is called as part of the device-level |
5201 | * When the PCI slot is in error recovery or the HBA is undergoing | 7802 | * interrupt handler. When the PCI slot is in error recovery or the HBA |
5202 | * initialization, the interrupt handler will not process the interrupt. | 7803 | * is undergoing initialization, the interrupt handler will not process |
5203 | * The link attention and ELS ring attention events are handled by the | 7804 | * the interrupt. The link attention and ELS ring attention events are |
5204 | * worker thread. The interrupt handler signals the worker thread and | 7805 | * handled by the worker thread. The interrupt handler signals the worker |
5205 | * and returns for these events. This function is called without any | 7806 | * thread and returns for these events. This function is called without |
5206 | * lock held. It gets the hbalock to access and update SLI data | 7807 | * any lock held. It gets the hbalock to access and update SLI data |
5207 | * structures. | 7808 | * structures. |
5208 | * | 7809 | * |
5209 | * This function returns IRQ_HANDLED when interrupt is handled else it | 7810 | * This function returns IRQ_HANDLED when interrupt is handled else it |
5210 | * returns IRQ_NONE. | 7811 | * returns IRQ_NONE. |
5211 | **/ | 7812 | **/ |
5212 | irqreturn_t | 7813 | irqreturn_t |
5213 | lpfc_sp_intr_handler(int irq, void *dev_id) | 7814 | lpfc_sli_sp_intr_handler(int irq, void *dev_id) |
5214 | { | 7815 | { |
5215 | struct lpfc_hba *phba; | 7816 | struct lpfc_hba *phba; |
5216 | uint32_t ha_copy; | 7817 | uint32_t ha_copy; |
@@ -5240,13 +7841,8 @@ lpfc_sp_intr_handler(int irq, void *dev_id) | |||
5240 | * individual interrupt handler in MSI-X multi-message interrupt mode | 7841 | * individual interrupt handler in MSI-X multi-message interrupt mode |
5241 | */ | 7842 | */ |
5242 | if (phba->intr_type == MSIX) { | 7843 | if (phba->intr_type == MSIX) { |
5243 | /* If the pci channel is offline, ignore all the interrupts */ | 7844 | /* Check device state for handling interrupt */ |
5244 | if (unlikely(pci_channel_offline(phba->pcidev))) | 7845 | if (lpfc_intr_state_check(phba)) |
5245 | return IRQ_NONE; | ||
5246 | /* Update device-level interrupt statistics */ | ||
5247 | phba->sli.slistat.sli_intr++; | ||
5248 | /* Ignore all interrupts during initialization. */ | ||
5249 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | ||
5250 | return IRQ_NONE; | 7846 | return IRQ_NONE; |
5251 | /* Need to read HA REG for slow-path events */ | 7847 | /* Need to read HA REG for slow-path events */ |
5252 | spin_lock_irqsave(&phba->hbalock, iflag); | 7848 | spin_lock_irqsave(&phba->hbalock, iflag); |
@@ -5271,7 +7867,7 @@ lpfc_sp_intr_handler(int irq, void *dev_id) | |||
5271 | * interrupt. | 7867 | * interrupt. |
5272 | */ | 7868 | */ |
5273 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | 7869 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
5274 | spin_unlock_irq(&phba->hbalock); | 7870 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5275 | return IRQ_NONE; | 7871 | return IRQ_NONE; |
5276 | } | 7872 | } |
5277 | 7873 | ||
@@ -5364,7 +7960,7 @@ lpfc_sp_intr_handler(int irq, void *dev_id) | |||
5364 | 7960 | ||
5365 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { | 7961 | if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) { |
5366 | pmb = phba->sli.mbox_active; | 7962 | pmb = phba->sli.mbox_active; |
5367 | pmbox = &pmb->mb; | 7963 | pmbox = &pmb->u.mb; |
5368 | mbox = phba->mbox; | 7964 | mbox = phba->mbox; |
5369 | vport = pmb->vport; | 7965 | vport = pmb->vport; |
5370 | 7966 | ||
@@ -5434,7 +8030,8 @@ lpfc_sp_intr_handler(int irq, void *dev_id) | |||
5434 | LOG_MBOX | LOG_SLI, | 8030 | LOG_MBOX | LOG_SLI, |
5435 | "0350 rc should have" | 8031 | "0350 rc should have" |
5436 | "been MBX_BUSY"); | 8032 | "been MBX_BUSY"); |
5437 | goto send_current_mbox; | 8033 | if (rc != MBX_NOT_FINISHED) |
8034 | goto send_current_mbox; | ||
5438 | } | 8035 | } |
5439 | } | 8036 | } |
5440 | spin_lock_irqsave( | 8037 | spin_lock_irqsave( |
@@ -5471,29 +8068,29 @@ send_current_mbox: | |||
5471 | } | 8068 | } |
5472 | return IRQ_HANDLED; | 8069 | return IRQ_HANDLED; |
5473 | 8070 | ||
5474 | } /* lpfc_sp_intr_handler */ | 8071 | } /* lpfc_sli_sp_intr_handler */ |
5475 | 8072 | ||
5476 | /** | 8073 | /** |
5477 | * lpfc_fp_intr_handler - The fast-path interrupt handler of lpfc driver | 8074 | * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device. |
5478 | * @irq: Interrupt number. | 8075 | * @irq: Interrupt number. |
5479 | * @dev_id: The device context pointer. | 8076 | * @dev_id: The device context pointer. |
5480 | * | 8077 | * |
5481 | * This function is directly called from the PCI layer as an interrupt | 8078 | * This function is directly called from the PCI layer as an interrupt |
5482 | * service routine when the device is enabled with MSI-X multi-message | 8079 | * service routine when device with SLI-3 interface spec is enabled with |
5483 | * interrupt mode and there is a fast-path FCP IOCB ring event in the | 8080 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB |
5484 | * HBA. However, when the device is enabled with either MSI or Pin-IRQ | 8081 | * ring event in the HBA. However, when the device is enabled with either |
5485 | * interrupt mode, this function is called as part of the device-level | 8082 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the |
5486 | * interrupt handler. When the PCI slot is in error recovery or the HBA | 8083 | * device-level interrupt handler. When the PCI slot is in error recovery |
5487 | * is undergoing initialization, the interrupt handler will not process | 8084 | * or the HBA is undergoing initialization, the interrupt handler will not |
5488 | * the interrupt. The SCSI FCP fast-path ring event are handled in the | 8085 | * process the interrupt. The SCSI FCP fast-path ring event are handled in |
5489 | * intrrupt context. This function is called without any lock held. It | 8086 | * the intrrupt context. This function is called without any lock held. |
5490 | * gets the hbalock to access and update SLI data structures. | 8087 | * It gets the hbalock to access and update SLI data structures. |
5491 | * | 8088 | * |
5492 | * This function returns IRQ_HANDLED when interrupt is handled else it | 8089 | * This function returns IRQ_HANDLED when interrupt is handled else it |
5493 | * returns IRQ_NONE. | 8090 | * returns IRQ_NONE. |
5494 | **/ | 8091 | **/ |
5495 | irqreturn_t | 8092 | irqreturn_t |
5496 | lpfc_fp_intr_handler(int irq, void *dev_id) | 8093 | lpfc_sli_fp_intr_handler(int irq, void *dev_id) |
5497 | { | 8094 | { |
5498 | struct lpfc_hba *phba; | 8095 | struct lpfc_hba *phba; |
5499 | uint32_t ha_copy; | 8096 | uint32_t ha_copy; |
@@ -5513,13 +8110,8 @@ lpfc_fp_intr_handler(int irq, void *dev_id) | |||
5513 | * individual interrupt handler in MSI-X multi-message interrupt mode | 8110 | * individual interrupt handler in MSI-X multi-message interrupt mode |
5514 | */ | 8111 | */ |
5515 | if (phba->intr_type == MSIX) { | 8112 | if (phba->intr_type == MSIX) { |
5516 | /* If pci channel is offline, ignore all the interrupts */ | 8113 | /* Check device state for handling interrupt */ |
5517 | if (unlikely(pci_channel_offline(phba->pcidev))) | 8114 | if (lpfc_intr_state_check(phba)) |
5518 | return IRQ_NONE; | ||
5519 | /* Update device-level interrupt statistics */ | ||
5520 | phba->sli.slistat.sli_intr++; | ||
5521 | /* Ignore all interrupts during initialization. */ | ||
5522 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | ||
5523 | return IRQ_NONE; | 8115 | return IRQ_NONE; |
5524 | /* Need to read HA REG for FCP ring and other ring events */ | 8116 | /* Need to read HA REG for FCP ring and other ring events */ |
5525 | ha_copy = readl(phba->HAregaddr); | 8117 | ha_copy = readl(phba->HAregaddr); |
@@ -5530,7 +8122,7 @@ lpfc_fp_intr_handler(int irq, void *dev_id) | |||
5530 | * any interrupt. | 8122 | * any interrupt. |
5531 | */ | 8123 | */ |
5532 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { | 8124 | if (unlikely(phba->hba_flag & DEFER_ERATT)) { |
5533 | spin_unlock_irq(&phba->hbalock); | 8125 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
5534 | return IRQ_NONE; | 8126 | return IRQ_NONE; |
5535 | } | 8127 | } |
5536 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), | 8128 | writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)), |
@@ -5566,26 +8158,27 @@ lpfc_fp_intr_handler(int irq, void *dev_id) | |||
5566 | } | 8158 | } |
5567 | } | 8159 | } |
5568 | return IRQ_HANDLED; | 8160 | return IRQ_HANDLED; |
5569 | } /* lpfc_fp_intr_handler */ | 8161 | } /* lpfc_sli_fp_intr_handler */ |
5570 | 8162 | ||
5571 | /** | 8163 | /** |
5572 | * lpfc_intr_handler - The device-level interrupt handler of lpfc driver | 8164 | * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device |
5573 | * @irq: Interrupt number. | 8165 | * @irq: Interrupt number. |
5574 | * @dev_id: The device context pointer. | 8166 | * @dev_id: The device context pointer. |
5575 | * | 8167 | * |
5576 | * This function is the device-level interrupt handler called from the PCI | 8168 | * This function is the HBA device-level interrupt handler to device with |
5577 | * layer when either MSI or Pin-IRQ interrupt mode is enabled and there is | 8169 | * SLI-3 interface spec, called from the PCI layer when either MSI or |
5578 | * an event in the HBA which requires driver attention. This function | 8170 | * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which |
5579 | * invokes the slow-path interrupt attention handling function and fast-path | 8171 | * requires driver attention. This function invokes the slow-path interrupt |
5580 | * interrupt attention handling function in turn to process the relevant | 8172 | * attention handling function and fast-path interrupt attention handling |
5581 | * HBA attention events. This function is called without any lock held. It | 8173 | * function in turn to process the relevant HBA attention events. This |
5582 | * gets the hbalock to access and update SLI data structures. | 8174 | * function is called without any lock held. It gets the hbalock to access |
8175 | * and update SLI data structures. | ||
5583 | * | 8176 | * |
5584 | * This function returns IRQ_HANDLED when interrupt is handled, else it | 8177 | * This function returns IRQ_HANDLED when interrupt is handled, else it |
5585 | * returns IRQ_NONE. | 8178 | * returns IRQ_NONE. |
5586 | **/ | 8179 | **/ |
5587 | irqreturn_t | 8180 | irqreturn_t |
5588 | lpfc_intr_handler(int irq, void *dev_id) | 8181 | lpfc_sli_intr_handler(int irq, void *dev_id) |
5589 | { | 8182 | { |
5590 | struct lpfc_hba *phba; | 8183 | struct lpfc_hba *phba; |
5591 | irqreturn_t sp_irq_rc, fp_irq_rc; | 8184 | irqreturn_t sp_irq_rc, fp_irq_rc; |
@@ -5600,15 +8193,8 @@ lpfc_intr_handler(int irq, void *dev_id) | |||
5600 | if (unlikely(!phba)) | 8193 | if (unlikely(!phba)) |
5601 | return IRQ_NONE; | 8194 | return IRQ_NONE; |
5602 | 8195 | ||
5603 | /* If the pci channel is offline, ignore all the interrupts. */ | 8196 | /* Check device state for handling interrupt */ |
5604 | if (unlikely(pci_channel_offline(phba->pcidev))) | 8197 | if (lpfc_intr_state_check(phba)) |
5605 | return IRQ_NONE; | ||
5606 | |||
5607 | /* Update device level interrupt statistics */ | ||
5608 | phba->sli.slistat.sli_intr++; | ||
5609 | |||
5610 | /* Ignore all interrupts during initialization. */ | ||
5611 | if (unlikely(phba->link_state < LPFC_LINK_DOWN)) | ||
5612 | return IRQ_NONE; | 8198 | return IRQ_NONE; |
5613 | 8199 | ||
5614 | spin_lock(&phba->hbalock); | 8200 | spin_lock(&phba->hbalock); |
@@ -5650,7 +8236,7 @@ lpfc_intr_handler(int irq, void *dev_id) | |||
5650 | status2 >>= (4*LPFC_ELS_RING); | 8236 | status2 >>= (4*LPFC_ELS_RING); |
5651 | 8237 | ||
5652 | if (status1 || (status2 & HA_RXMASK)) | 8238 | if (status1 || (status2 & HA_RXMASK)) |
5653 | sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id); | 8239 | sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id); |
5654 | else | 8240 | else |
5655 | sp_irq_rc = IRQ_NONE; | 8241 | sp_irq_rc = IRQ_NONE; |
5656 | 8242 | ||
@@ -5670,10 +8256,3321 @@ lpfc_intr_handler(int irq, void *dev_id) | |||
5670 | status2 = 0; | 8256 | status2 = 0; |
5671 | 8257 | ||
5672 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) | 8258 | if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK)) |
5673 | fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id); | 8259 | fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id); |
5674 | else | 8260 | else |
5675 | fp_irq_rc = IRQ_NONE; | 8261 | fp_irq_rc = IRQ_NONE; |
5676 | 8262 | ||
5677 | /* Return device-level interrupt handling status */ | 8263 | /* Return device-level interrupt handling status */ |
5678 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; | 8264 | return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc; |
5679 | } /* lpfc_intr_handler */ | 8265 | } /* lpfc_sli_intr_handler */ |
8266 | |||
8267 | /** | ||
8268 | * lpfc_sli4_fcp_xri_abort_event_proc - Process fcp xri abort event | ||
8269 | * @phba: pointer to lpfc hba data structure. | ||
8270 | * | ||
8271 | * This routine is invoked by the worker thread to process all the pending | ||
8272 | * SLI4 FCP abort XRI events. | ||
8273 | **/ | ||
8274 | void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *phba) | ||
8275 | { | ||
8276 | struct lpfc_cq_event *cq_event; | ||
8277 | |||
8278 | /* First, declare the fcp xri abort event has been handled */ | ||
8279 | spin_lock_irq(&phba->hbalock); | ||
8280 | phba->hba_flag &= ~FCP_XRI_ABORT_EVENT; | ||
8281 | spin_unlock_irq(&phba->hbalock); | ||
8282 | /* Now, handle all the fcp xri abort events */ | ||
8283 | while (!list_empty(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue)) { | ||
8284 | /* Get the first event from the head of the event queue */ | ||
8285 | spin_lock_irq(&phba->hbalock); | ||
8286 | list_remove_head(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | ||
8287 | cq_event, struct lpfc_cq_event, list); | ||
8288 | spin_unlock_irq(&phba->hbalock); | ||
8289 | /* Notify aborted XRI for FCP work queue */ | ||
8290 | lpfc_sli4_fcp_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | ||
8291 | /* Free the event processed back to the free pool */ | ||
8292 | lpfc_sli4_cq_event_release(phba, cq_event); | ||
8293 | } | ||
8294 | } | ||
8295 | |||
8296 | /** | ||
8297 | * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event | ||
8298 | * @phba: pointer to lpfc hba data structure. | ||
8299 | * | ||
8300 | * This routine is invoked by the worker thread to process all the pending | ||
8301 | * SLI4 els abort xri events. | ||
8302 | **/ | ||
8303 | void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba) | ||
8304 | { | ||
8305 | struct lpfc_cq_event *cq_event; | ||
8306 | |||
8307 | /* First, declare the els xri abort event has been handled */ | ||
8308 | spin_lock_irq(&phba->hbalock); | ||
8309 | phba->hba_flag &= ~ELS_XRI_ABORT_EVENT; | ||
8310 | spin_unlock_irq(&phba->hbalock); | ||
8311 | /* Now, handle all the els xri abort events */ | ||
8312 | while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) { | ||
8313 | /* Get the first event from the head of the event queue */ | ||
8314 | spin_lock_irq(&phba->hbalock); | ||
8315 | list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | ||
8316 | cq_event, struct lpfc_cq_event, list); | ||
8317 | spin_unlock_irq(&phba->hbalock); | ||
8318 | /* Notify aborted XRI for ELS work queue */ | ||
8319 | lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri); | ||
8320 | /* Free the event processed back to the free pool */ | ||
8321 | lpfc_sli4_cq_event_release(phba, cq_event); | ||
8322 | } | ||
8323 | } | ||
8324 | |||
8325 | static void | ||
8326 | lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn, | ||
8327 | struct lpfc_iocbq *pIocbOut, | ||
8328 | struct lpfc_wcqe_complete *wcqe) | ||
8329 | { | ||
8330 | size_t offset = offsetof(struct lpfc_iocbq, iocb); | ||
8331 | |||
8332 | memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, | ||
8333 | sizeof(struct lpfc_iocbq) - offset); | ||
8334 | memset(&pIocbIn->sli4_info, 0, | ||
8335 | sizeof(struct lpfc_sli4_rspiocb_info)); | ||
8336 | /* Map WCQE parameters into irspiocb parameters */ | ||
8337 | pIocbIn->iocb.ulpStatus = bf_get(lpfc_wcqe_c_status, wcqe); | ||
8338 | if (pIocbOut->iocb_flag & LPFC_IO_FCP) | ||
8339 | if (pIocbIn->iocb.ulpStatus == IOSTAT_FCP_RSP_ERROR) | ||
8340 | pIocbIn->iocb.un.fcpi.fcpi_parm = | ||
8341 | pIocbOut->iocb.un.fcpi.fcpi_parm - | ||
8342 | wcqe->total_data_placed; | ||
8343 | else | ||
8344 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | ||
8345 | else | ||
8346 | pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; | ||
8347 | /* Load in additional WCQE parameters */ | ||
8348 | pIocbIn->sli4_info.hw_status = bf_get(lpfc_wcqe_c_hw_status, wcqe); | ||
8349 | pIocbIn->sli4_info.bfield = 0; | ||
8350 | if (bf_get(lpfc_wcqe_c_xb, wcqe)) | ||
8351 | pIocbIn->sli4_info.bfield |= LPFC_XB; | ||
8352 | if (bf_get(lpfc_wcqe_c_pv, wcqe)) { | ||
8353 | pIocbIn->sli4_info.bfield |= LPFC_PV; | ||
8354 | pIocbIn->sli4_info.priority = | ||
8355 | bf_get(lpfc_wcqe_c_priority, wcqe); | ||
8356 | } | ||
8357 | } | ||
8358 | |||
8359 | /** | ||
8360 | * lpfc_sli4_sp_handle_async_event - Handle an asynchroous event | ||
8361 | * @phba: Pointer to HBA context object. | ||
8362 | * @cqe: Pointer to mailbox completion queue entry. | ||
8363 | * | ||
8364 | * This routine process a mailbox completion queue entry with asynchrous | ||
8365 | * event. | ||
8366 | * | ||
8367 | * Return: true if work posted to worker thread, otherwise false. | ||
8368 | **/ | ||
8369 | static bool | ||
8370 | lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | ||
8371 | { | ||
8372 | struct lpfc_cq_event *cq_event; | ||
8373 | unsigned long iflags; | ||
8374 | |||
8375 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | ||
8376 | "0392 Async Event: word0:x%x, word1:x%x, " | ||
8377 | "word2:x%x, word3:x%x\n", mcqe->word0, | ||
8378 | mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer); | ||
8379 | |||
8380 | /* Allocate a new internal CQ_EVENT entry */ | ||
8381 | cq_event = lpfc_sli4_cq_event_alloc(phba); | ||
8382 | if (!cq_event) { | ||
8383 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8384 | "0394 Failed to allocate CQ_EVENT entry\n"); | ||
8385 | return false; | ||
8386 | } | ||
8387 | |||
8388 | /* Move the CQE into an asynchronous event entry */ | ||
8389 | memcpy(&cq_event->cqe, mcqe, sizeof(struct lpfc_mcqe)); | ||
8390 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8391 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue); | ||
8392 | /* Set the async event flag */ | ||
8393 | phba->hba_flag |= ASYNC_EVENT; | ||
8394 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8395 | |||
8396 | return true; | ||
8397 | } | ||
8398 | |||
8399 | /** | ||
8400 | * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event | ||
8401 | * @phba: Pointer to HBA context object. | ||
8402 | * @cqe: Pointer to mailbox completion queue entry. | ||
8403 | * | ||
8404 | * This routine process a mailbox completion queue entry with mailbox | ||
8405 | * completion event. | ||
8406 | * | ||
8407 | * Return: true if work posted to worker thread, otherwise false. | ||
8408 | **/ | ||
8409 | static bool | ||
8410 | lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe) | ||
8411 | { | ||
8412 | uint32_t mcqe_status; | ||
8413 | MAILBOX_t *mbox, *pmbox; | ||
8414 | struct lpfc_mqe *mqe; | ||
8415 | struct lpfc_vport *vport; | ||
8416 | struct lpfc_nodelist *ndlp; | ||
8417 | struct lpfc_dmabuf *mp; | ||
8418 | unsigned long iflags; | ||
8419 | LPFC_MBOXQ_t *pmb; | ||
8420 | bool workposted = false; | ||
8421 | int rc; | ||
8422 | |||
8423 | /* If not a mailbox complete MCQE, out by checking mailbox consume */ | ||
8424 | if (!bf_get(lpfc_trailer_completed, mcqe)) | ||
8425 | goto out_no_mqe_complete; | ||
8426 | |||
8427 | /* Get the reference to the active mbox command */ | ||
8428 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8429 | pmb = phba->sli.mbox_active; | ||
8430 | if (unlikely(!pmb)) { | ||
8431 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | ||
8432 | "1832 No pending MBOX command to handle\n"); | ||
8433 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8434 | goto out_no_mqe_complete; | ||
8435 | } | ||
8436 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8437 | mqe = &pmb->u.mqe; | ||
8438 | pmbox = (MAILBOX_t *)&pmb->u.mqe; | ||
8439 | mbox = phba->mbox; | ||
8440 | vport = pmb->vport; | ||
8441 | |||
8442 | /* Reset heartbeat timer */ | ||
8443 | phba->last_completion_time = jiffies; | ||
8444 | del_timer(&phba->sli.mbox_tmo); | ||
8445 | |||
8446 | /* Move mbox data to caller's mailbox region, do endian swapping */ | ||
8447 | if (pmb->mbox_cmpl && mbox) | ||
8448 | lpfc_sli_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe)); | ||
8449 | /* Set the mailbox status with SLI4 range 0x4000 */ | ||
8450 | mcqe_status = bf_get(lpfc_mcqe_status, mcqe); | ||
8451 | if (mcqe_status != MB_CQE_STATUS_SUCCESS) | ||
8452 | bf_set(lpfc_mqe_status, mqe, | ||
8453 | (LPFC_MBX_ERROR_RANGE | mcqe_status)); | ||
8454 | |||
8455 | if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) { | ||
8456 | pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG; | ||
8457 | lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT, | ||
8458 | "MBOX dflt rpi: status:x%x rpi:x%x", | ||
8459 | mcqe_status, | ||
8460 | pmbox->un.varWords[0], 0); | ||
8461 | if (mcqe_status == MB_CQE_STATUS_SUCCESS) { | ||
8462 | mp = (struct lpfc_dmabuf *)(pmb->context1); | ||
8463 | ndlp = (struct lpfc_nodelist *)pmb->context2; | ||
8464 | /* Reg_LOGIN of dflt RPI was successful. Now lets get | ||
8465 | * RID of the PPI using the same mbox buffer. | ||
8466 | */ | ||
8467 | lpfc_unreg_login(phba, vport->vpi, | ||
8468 | pmbox->un.varWords[0], pmb); | ||
8469 | pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi; | ||
8470 | pmb->context1 = mp; | ||
8471 | pmb->context2 = ndlp; | ||
8472 | pmb->vport = vport; | ||
8473 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | ||
8474 | if (rc != MBX_BUSY) | ||
8475 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | | ||
8476 | LOG_SLI, "0385 rc should " | ||
8477 | "have been MBX_BUSY\n"); | ||
8478 | if (rc != MBX_NOT_FINISHED) | ||
8479 | goto send_current_mbox; | ||
8480 | } | ||
8481 | } | ||
8482 | spin_lock_irqsave(&phba->pport->work_port_lock, iflags); | ||
8483 | phba->pport->work_port_events &= ~WORKER_MBOX_TMO; | ||
8484 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags); | ||
8485 | |||
8486 | /* There is mailbox completion work to do */ | ||
8487 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8488 | __lpfc_mbox_cmpl_put(phba, pmb); | ||
8489 | phba->work_ha |= HA_MBATT; | ||
8490 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8491 | workposted = true; | ||
8492 | |||
8493 | send_current_mbox: | ||
8494 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8495 | /* Release the mailbox command posting token */ | ||
8496 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
8497 | /* Setting active mailbox pointer need to be in sync to flag clear */ | ||
8498 | phba->sli.mbox_active = NULL; | ||
8499 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8500 | /* Wake up worker thread to post the next pending mailbox command */ | ||
8501 | lpfc_worker_wake_up(phba); | ||
8502 | out_no_mqe_complete: | ||
8503 | if (bf_get(lpfc_trailer_consumed, mcqe)) | ||
8504 | lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq); | ||
8505 | return workposted; | ||
8506 | } | ||
8507 | |||
8508 | /** | ||
8509 | * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry | ||
8510 | * @phba: Pointer to HBA context object. | ||
8511 | * @cqe: Pointer to mailbox completion queue entry. | ||
8512 | * | ||
8513 | * This routine process a mailbox completion queue entry, it invokes the | ||
8514 | * proper mailbox complete handling or asynchrous event handling routine | ||
8515 | * according to the MCQE's async bit. | ||
8516 | * | ||
8517 | * Return: true if work posted to worker thread, otherwise false. | ||
8518 | **/ | ||
8519 | static bool | ||
8520 | lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | ||
8521 | { | ||
8522 | struct lpfc_mcqe mcqe; | ||
8523 | bool workposted; | ||
8524 | |||
8525 | /* Copy the mailbox MCQE and convert endian order as needed */ | ||
8526 | lpfc_sli_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe)); | ||
8527 | |||
8528 | /* Invoke the proper event handling routine */ | ||
8529 | if (!bf_get(lpfc_trailer_async, &mcqe)) | ||
8530 | workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe); | ||
8531 | else | ||
8532 | workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe); | ||
8533 | return workposted; | ||
8534 | } | ||
8535 | |||
8536 | /** | ||
8537 | * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event | ||
8538 | * @phba: Pointer to HBA context object. | ||
8539 | * @wcqe: Pointer to work-queue completion queue entry. | ||
8540 | * | ||
8541 | * This routine handles an ELS work-queue completion event. | ||
8542 | * | ||
8543 | * Return: true if work posted to worker thread, otherwise false. | ||
8544 | **/ | ||
8545 | static bool | ||
8546 | lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, | ||
8547 | struct lpfc_wcqe_complete *wcqe) | ||
8548 | { | ||
8549 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; | ||
8550 | struct lpfc_iocbq *cmdiocbq; | ||
8551 | struct lpfc_iocbq *irspiocbq; | ||
8552 | unsigned long iflags; | ||
8553 | bool workposted = false; | ||
8554 | |||
8555 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8556 | pring->stats.iocb_event++; | ||
8557 | /* Look up the ELS command IOCB and create pseudo response IOCB */ | ||
8558 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | ||
8559 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | ||
8560 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8561 | |||
8562 | if (unlikely(!cmdiocbq)) { | ||
8563 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
8564 | "0386 ELS complete with no corresponding " | ||
8565 | "cmdiocb: iotag (%d)\n", | ||
8566 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | ||
8567 | return workposted; | ||
8568 | } | ||
8569 | |||
8570 | /* Fake the irspiocbq and copy necessary response information */ | ||
8571 | irspiocbq = lpfc_sli_get_iocbq(phba); | ||
8572 | if (!irspiocbq) { | ||
8573 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8574 | "0387 Failed to allocate an iocbq\n"); | ||
8575 | return workposted; | ||
8576 | } | ||
8577 | lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe); | ||
8578 | |||
8579 | /* Add the irspiocb to the response IOCB work list */ | ||
8580 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8581 | list_add_tail(&irspiocbq->list, &phba->sli4_hba.sp_rspiocb_work_queue); | ||
8582 | /* Indicate ELS ring attention */ | ||
8583 | phba->work_ha |= (HA_R0ATT << (4*LPFC_ELS_RING)); | ||
8584 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8585 | workposted = true; | ||
8586 | |||
8587 | return workposted; | ||
8588 | } | ||
8589 | |||
8590 | /** | ||
8591 | * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event | ||
8592 | * @phba: Pointer to HBA context object. | ||
8593 | * @wcqe: Pointer to work-queue completion queue entry. | ||
8594 | * | ||
8595 | * This routine handles slow-path WQ entry comsumed event by invoking the | ||
8596 | * proper WQ release routine to the slow-path WQ. | ||
8597 | **/ | ||
8598 | static void | ||
8599 | lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba, | ||
8600 | struct lpfc_wcqe_release *wcqe) | ||
8601 | { | ||
8602 | /* Check for the slow-path ELS work queue */ | ||
8603 | if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id) | ||
8604 | lpfc_sli4_wq_release(phba->sli4_hba.els_wq, | ||
8605 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | ||
8606 | else | ||
8607 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
8608 | "2579 Slow-path wqe consume event carries " | ||
8609 | "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n", | ||
8610 | bf_get(lpfc_wcqe_r_wqe_index, wcqe), | ||
8611 | phba->sli4_hba.els_wq->queue_id); | ||
8612 | } | ||
8613 | |||
8614 | /** | ||
8615 | * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event | ||
8616 | * @phba: Pointer to HBA context object. | ||
8617 | * @cq: Pointer to a WQ completion queue. | ||
8618 | * @wcqe: Pointer to work-queue completion queue entry. | ||
8619 | * | ||
8620 | * This routine handles an XRI abort event. | ||
8621 | * | ||
8622 | * Return: true if work posted to worker thread, otherwise false. | ||
8623 | **/ | ||
8624 | static bool | ||
8625 | lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba, | ||
8626 | struct lpfc_queue *cq, | ||
8627 | struct sli4_wcqe_xri_aborted *wcqe) | ||
8628 | { | ||
8629 | bool workposted = false; | ||
8630 | struct lpfc_cq_event *cq_event; | ||
8631 | unsigned long iflags; | ||
8632 | |||
8633 | /* Allocate a new internal CQ_EVENT entry */ | ||
8634 | cq_event = lpfc_sli4_cq_event_alloc(phba); | ||
8635 | if (!cq_event) { | ||
8636 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8637 | "0602 Failed to allocate CQ_EVENT entry\n"); | ||
8638 | return false; | ||
8639 | } | ||
8640 | |||
8641 | /* Move the CQE into the proper xri abort event list */ | ||
8642 | memcpy(&cq_event->cqe, wcqe, sizeof(struct sli4_wcqe_xri_aborted)); | ||
8643 | switch (cq->subtype) { | ||
8644 | case LPFC_FCP: | ||
8645 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8646 | list_add_tail(&cq_event->list, | ||
8647 | &phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | ||
8648 | /* Set the fcp xri abort event flag */ | ||
8649 | phba->hba_flag |= FCP_XRI_ABORT_EVENT; | ||
8650 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8651 | workposted = true; | ||
8652 | break; | ||
8653 | case LPFC_ELS: | ||
8654 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8655 | list_add_tail(&cq_event->list, | ||
8656 | &phba->sli4_hba.sp_els_xri_aborted_work_queue); | ||
8657 | /* Set the els xri abort event flag */ | ||
8658 | phba->hba_flag |= ELS_XRI_ABORT_EVENT; | ||
8659 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8660 | workposted = true; | ||
8661 | break; | ||
8662 | default: | ||
8663 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8664 | "0603 Invalid work queue CQE subtype (x%x)\n", | ||
8665 | cq->subtype); | ||
8666 | workposted = false; | ||
8667 | break; | ||
8668 | } | ||
8669 | return workposted; | ||
8670 | } | ||
8671 | |||
8672 | /** | ||
8673 | * lpfc_sli4_sp_handle_wcqe - Process a work-queue completion queue entry | ||
8674 | * @phba: Pointer to HBA context object. | ||
8675 | * @cq: Pointer to the completion queue. | ||
8676 | * @wcqe: Pointer to a completion queue entry. | ||
8677 | * | ||
8678 | * This routine process a slow-path work-queue completion queue entry. | ||
8679 | * | ||
8680 | * Return: true if work posted to worker thread, otherwise false. | ||
8681 | **/ | ||
8682 | static bool | ||
8683 | lpfc_sli4_sp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | ||
8684 | struct lpfc_cqe *cqe) | ||
8685 | { | ||
8686 | struct lpfc_wcqe_complete wcqe; | ||
8687 | bool workposted = false; | ||
8688 | |||
8689 | /* Copy the work queue CQE and convert endian order if needed */ | ||
8690 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | ||
8691 | |||
8692 | /* Check and process for different type of WCQE and dispatch */ | ||
8693 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | ||
8694 | case CQE_CODE_COMPL_WQE: | ||
8695 | /* Process the WQ complete event */ | ||
8696 | workposted = lpfc_sli4_sp_handle_els_wcqe(phba, | ||
8697 | (struct lpfc_wcqe_complete *)&wcqe); | ||
8698 | break; | ||
8699 | case CQE_CODE_RELEASE_WQE: | ||
8700 | /* Process the WQ release event */ | ||
8701 | lpfc_sli4_sp_handle_rel_wcqe(phba, | ||
8702 | (struct lpfc_wcqe_release *)&wcqe); | ||
8703 | break; | ||
8704 | case CQE_CODE_XRI_ABORTED: | ||
8705 | /* Process the WQ XRI abort event */ | ||
8706 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, | ||
8707 | (struct sli4_wcqe_xri_aborted *)&wcqe); | ||
8708 | break; | ||
8709 | default: | ||
8710 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8711 | "0388 Not a valid WCQE code: x%x\n", | ||
8712 | bf_get(lpfc_wcqe_c_code, &wcqe)); | ||
8713 | break; | ||
8714 | } | ||
8715 | return workposted; | ||
8716 | } | ||
8717 | |||
8718 | /** | ||
8719 | * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry | ||
8720 | * @phba: Pointer to HBA context object. | ||
8721 | * @rcqe: Pointer to receive-queue completion queue entry. | ||
8722 | * | ||
8723 | * This routine process a receive-queue completion queue entry. | ||
8724 | * | ||
8725 | * Return: true if work posted to worker thread, otherwise false. | ||
8726 | **/ | ||
8727 | static bool | ||
8728 | lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_cqe *cqe) | ||
8729 | { | ||
8730 | struct lpfc_rcqe rcqe; | ||
8731 | bool workposted = false; | ||
8732 | struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq; | ||
8733 | struct lpfc_queue *drq = phba->sli4_hba.dat_rq; | ||
8734 | struct hbq_dmabuf *dma_buf; | ||
8735 | uint32_t status; | ||
8736 | unsigned long iflags; | ||
8737 | |||
8738 | /* Copy the receive queue CQE and convert endian order if needed */ | ||
8739 | lpfc_sli_pcimem_bcopy(cqe, &rcqe, sizeof(struct lpfc_rcqe)); | ||
8740 | lpfc_sli4_rq_release(hrq, drq); | ||
8741 | if (bf_get(lpfc_rcqe_code, &rcqe) != CQE_CODE_RECEIVE) | ||
8742 | goto out; | ||
8743 | if (bf_get(lpfc_rcqe_rq_id, &rcqe) != hrq->queue_id) | ||
8744 | goto out; | ||
8745 | |||
8746 | status = bf_get(lpfc_rcqe_status, &rcqe); | ||
8747 | switch (status) { | ||
8748 | case FC_STATUS_RQ_BUF_LEN_EXCEEDED: | ||
8749 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8750 | "2537 Receive Frame Truncated!!\n"); | ||
8751 | case FC_STATUS_RQ_SUCCESS: | ||
8752 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8753 | dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list); | ||
8754 | if (!dma_buf) { | ||
8755 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8756 | goto out; | ||
8757 | } | ||
8758 | memcpy(&dma_buf->rcqe, &rcqe, sizeof(rcqe)); | ||
8759 | /* save off the frame for the word thread to process */ | ||
8760 | list_add_tail(&dma_buf->dbuf.list, &phba->rb_pend_list); | ||
8761 | /* Frame received */ | ||
8762 | phba->hba_flag |= HBA_RECEIVE_BUFFER; | ||
8763 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8764 | workposted = true; | ||
8765 | break; | ||
8766 | case FC_STATUS_INSUFF_BUF_NEED_BUF: | ||
8767 | case FC_STATUS_INSUFF_BUF_FRM_DISC: | ||
8768 | /* Post more buffers if possible */ | ||
8769 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8770 | phba->hba_flag |= HBA_POST_RECEIVE_BUFFER; | ||
8771 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8772 | workposted = true; | ||
8773 | break; | ||
8774 | } | ||
8775 | out: | ||
8776 | return workposted; | ||
8777 | |||
8778 | } | ||
8779 | |||
8780 | /** | ||
8781 | * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry | ||
8782 | * @phba: Pointer to HBA context object. | ||
8783 | * @eqe: Pointer to fast-path event queue entry. | ||
8784 | * | ||
8785 | * This routine process a event queue entry from the slow-path event queue. | ||
8786 | * It will check the MajorCode and MinorCode to determine this is for a | ||
8787 | * completion event on a completion queue, if not, an error shall be logged | ||
8788 | * and just return. Otherwise, it will get to the corresponding completion | ||
8789 | * queue and process all the entries on that completion queue, rearm the | ||
8790 | * completion queue, and then return. | ||
8791 | * | ||
8792 | **/ | ||
8793 | static void | ||
8794 | lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe) | ||
8795 | { | ||
8796 | struct lpfc_queue *cq = NULL, *childq, *speq; | ||
8797 | struct lpfc_cqe *cqe; | ||
8798 | bool workposted = false; | ||
8799 | int ecount = 0; | ||
8800 | uint16_t cqid; | ||
8801 | |||
8802 | if (bf_get(lpfc_eqe_major_code, eqe) != 0 || | ||
8803 | bf_get(lpfc_eqe_minor_code, eqe) != 0) { | ||
8804 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8805 | "0359 Not a valid slow-path completion " | ||
8806 | "event: majorcode=x%x, minorcode=x%x\n", | ||
8807 | bf_get(lpfc_eqe_major_code, eqe), | ||
8808 | bf_get(lpfc_eqe_minor_code, eqe)); | ||
8809 | return; | ||
8810 | } | ||
8811 | |||
8812 | /* Get the reference to the corresponding CQ */ | ||
8813 | cqid = bf_get(lpfc_eqe_resource_id, eqe); | ||
8814 | |||
8815 | /* Search for completion queue pointer matching this cqid */ | ||
8816 | speq = phba->sli4_hba.sp_eq; | ||
8817 | list_for_each_entry(childq, &speq->child_list, list) { | ||
8818 | if (childq->queue_id == cqid) { | ||
8819 | cq = childq; | ||
8820 | break; | ||
8821 | } | ||
8822 | } | ||
8823 | if (unlikely(!cq)) { | ||
8824 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8825 | "0365 Slow-path CQ identifier (%d) does " | ||
8826 | "not exist\n", cqid); | ||
8827 | return; | ||
8828 | } | ||
8829 | |||
8830 | /* Process all the entries to the CQ */ | ||
8831 | switch (cq->type) { | ||
8832 | case LPFC_MCQ: | ||
8833 | while ((cqe = lpfc_sli4_cq_get(cq))) { | ||
8834 | workposted |= lpfc_sli4_sp_handle_mcqe(phba, cqe); | ||
8835 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | ||
8836 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | ||
8837 | } | ||
8838 | break; | ||
8839 | case LPFC_WCQ: | ||
8840 | while ((cqe = lpfc_sli4_cq_get(cq))) { | ||
8841 | workposted |= lpfc_sli4_sp_handle_wcqe(phba, cq, cqe); | ||
8842 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | ||
8843 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | ||
8844 | } | ||
8845 | break; | ||
8846 | case LPFC_RCQ: | ||
8847 | while ((cqe = lpfc_sli4_cq_get(cq))) { | ||
8848 | workposted |= lpfc_sli4_sp_handle_rcqe(phba, cqe); | ||
8849 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | ||
8850 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | ||
8851 | } | ||
8852 | break; | ||
8853 | default: | ||
8854 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8855 | "0370 Invalid completion queue type (%d)\n", | ||
8856 | cq->type); | ||
8857 | return; | ||
8858 | } | ||
8859 | |||
8860 | /* Catch the no cq entry condition, log an error */ | ||
8861 | if (unlikely(ecount == 0)) | ||
8862 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
8863 | "0371 No entry from the CQ: identifier " | ||
8864 | "(x%x), type (%d)\n", cq->queue_id, cq->type); | ||
8865 | |||
8866 | /* In any case, flash and re-arm the RCQ */ | ||
8867 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | ||
8868 | |||
8869 | /* wake up worker thread if there are works to be done */ | ||
8870 | if (workposted) | ||
8871 | lpfc_worker_wake_up(phba); | ||
8872 | } | ||
8873 | |||
8874 | /** | ||
8875 | * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry | ||
8876 | * @eqe: Pointer to fast-path completion queue entry. | ||
8877 | * | ||
8878 | * This routine process a fast-path work queue completion entry from fast-path | ||
8879 | * event queue for FCP command response completion. | ||
8880 | **/ | ||
8881 | static void | ||
8882 | lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, | ||
8883 | struct lpfc_wcqe_complete *wcqe) | ||
8884 | { | ||
8885 | struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_FCP_RING]; | ||
8886 | struct lpfc_iocbq *cmdiocbq; | ||
8887 | struct lpfc_iocbq irspiocbq; | ||
8888 | unsigned long iflags; | ||
8889 | |||
8890 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8891 | pring->stats.iocb_event++; | ||
8892 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8893 | |||
8894 | /* Check for response status */ | ||
8895 | if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) { | ||
8896 | /* If resource errors reported from HBA, reduce queue | ||
8897 | * depth of the SCSI device. | ||
8898 | */ | ||
8899 | if ((bf_get(lpfc_wcqe_c_status, wcqe) == | ||
8900 | IOSTAT_LOCAL_REJECT) && | ||
8901 | (wcqe->parameter == IOERR_NO_RESOURCES)) { | ||
8902 | phba->lpfc_rampdown_queue_depth(phba); | ||
8903 | } | ||
8904 | /* Log the error status */ | ||
8905 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
8906 | "0373 FCP complete error: status=x%x, " | ||
8907 | "hw_status=x%x, total_data_specified=%d, " | ||
8908 | "parameter=x%x, word3=x%x\n", | ||
8909 | bf_get(lpfc_wcqe_c_status, wcqe), | ||
8910 | bf_get(lpfc_wcqe_c_hw_status, wcqe), | ||
8911 | wcqe->total_data_placed, wcqe->parameter, | ||
8912 | wcqe->word3); | ||
8913 | } | ||
8914 | |||
8915 | /* Look up the FCP command IOCB and create pseudo response IOCB */ | ||
8916 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
8917 | cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring, | ||
8918 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | ||
8919 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
8920 | if (unlikely(!cmdiocbq)) { | ||
8921 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
8922 | "0374 FCP complete with no corresponding " | ||
8923 | "cmdiocb: iotag (%d)\n", | ||
8924 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | ||
8925 | return; | ||
8926 | } | ||
8927 | if (unlikely(!cmdiocbq->iocb_cmpl)) { | ||
8928 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
8929 | "0375 FCP cmdiocb not callback function " | ||
8930 | "iotag: (%d)\n", | ||
8931 | bf_get(lpfc_wcqe_c_request_tag, wcqe)); | ||
8932 | return; | ||
8933 | } | ||
8934 | |||
8935 | /* Fake the irspiocb and copy necessary response information */ | ||
8936 | lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe); | ||
8937 | |||
8938 | /* Pass the cmd_iocb and the rsp state to the upper layer */ | ||
8939 | (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); | ||
8940 | } | ||
8941 | |||
8942 | /** | ||
8943 | * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event | ||
8944 | * @phba: Pointer to HBA context object. | ||
8945 | * @cq: Pointer to completion queue. | ||
8946 | * @wcqe: Pointer to work-queue completion queue entry. | ||
8947 | * | ||
8948 | * This routine handles an fast-path WQ entry comsumed event by invoking the | ||
8949 | * proper WQ release routine to the slow-path WQ. | ||
8950 | **/ | ||
8951 | static void | ||
8952 | lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | ||
8953 | struct lpfc_wcqe_release *wcqe) | ||
8954 | { | ||
8955 | struct lpfc_queue *childwq; | ||
8956 | bool wqid_matched = false; | ||
8957 | uint16_t fcp_wqid; | ||
8958 | |||
8959 | /* Check for fast-path FCP work queue release */ | ||
8960 | fcp_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe); | ||
8961 | list_for_each_entry(childwq, &cq->child_list, list) { | ||
8962 | if (childwq->queue_id == fcp_wqid) { | ||
8963 | lpfc_sli4_wq_release(childwq, | ||
8964 | bf_get(lpfc_wcqe_r_wqe_index, wcqe)); | ||
8965 | wqid_matched = true; | ||
8966 | break; | ||
8967 | } | ||
8968 | } | ||
8969 | /* Report warning log message if no match found */ | ||
8970 | if (wqid_matched != true) | ||
8971 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
8972 | "2580 Fast-path wqe consume event carries " | ||
8973 | "miss-matched qid: wcqe-qid=x%x\n", fcp_wqid); | ||
8974 | } | ||
8975 | |||
8976 | /** | ||
8977 | * lpfc_sli4_fp_handle_wcqe - Process fast-path work queue completion entry | ||
8978 | * @cq: Pointer to the completion queue. | ||
8979 | * @eqe: Pointer to fast-path completion queue entry. | ||
8980 | * | ||
8981 | * This routine process a fast-path work queue completion entry from fast-path | ||
8982 | * event queue for FCP command response completion. | ||
8983 | **/ | ||
8984 | static int | ||
8985 | lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq, | ||
8986 | struct lpfc_cqe *cqe) | ||
8987 | { | ||
8988 | struct lpfc_wcqe_release wcqe; | ||
8989 | bool workposted = false; | ||
8990 | |||
8991 | /* Copy the work queue CQE and convert endian order if needed */ | ||
8992 | lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); | ||
8993 | |||
8994 | /* Check and process for different type of WCQE and dispatch */ | ||
8995 | switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { | ||
8996 | case CQE_CODE_COMPL_WQE: | ||
8997 | /* Process the WQ complete event */ | ||
8998 | lpfc_sli4_fp_handle_fcp_wcqe(phba, | ||
8999 | (struct lpfc_wcqe_complete *)&wcqe); | ||
9000 | break; | ||
9001 | case CQE_CODE_RELEASE_WQE: | ||
9002 | /* Process the WQ release event */ | ||
9003 | lpfc_sli4_fp_handle_rel_wcqe(phba, cq, | ||
9004 | (struct lpfc_wcqe_release *)&wcqe); | ||
9005 | break; | ||
9006 | case CQE_CODE_XRI_ABORTED: | ||
9007 | /* Process the WQ XRI abort event */ | ||
9008 | workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, | ||
9009 | (struct sli4_wcqe_xri_aborted *)&wcqe); | ||
9010 | break; | ||
9011 | default: | ||
9012 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9013 | "0144 Not a valid WCQE code: x%x\n", | ||
9014 | bf_get(lpfc_wcqe_c_code, &wcqe)); | ||
9015 | break; | ||
9016 | } | ||
9017 | return workposted; | ||
9018 | } | ||
9019 | |||
9020 | /** | ||
9021 | * lpfc_sli4_fp_handle_eqe - Process a fast-path event queue entry | ||
9022 | * @phba: Pointer to HBA context object. | ||
9023 | * @eqe: Pointer to fast-path event queue entry. | ||
9024 | * | ||
9025 | * This routine process a event queue entry from the fast-path event queue. | ||
9026 | * It will check the MajorCode and MinorCode to determine this is for a | ||
9027 | * completion event on a completion queue, if not, an error shall be logged | ||
9028 | * and just return. Otherwise, it will get to the corresponding completion | ||
9029 | * queue and process all the entries on the completion queue, rearm the | ||
9030 | * completion queue, and then return. | ||
9031 | **/ | ||
9032 | static void | ||
9033 | lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe, | ||
9034 | uint32_t fcp_cqidx) | ||
9035 | { | ||
9036 | struct lpfc_queue *cq; | ||
9037 | struct lpfc_cqe *cqe; | ||
9038 | bool workposted = false; | ||
9039 | uint16_t cqid; | ||
9040 | int ecount = 0; | ||
9041 | |||
9042 | if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) || | ||
9043 | unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) { | ||
9044 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9045 | "0366 Not a valid fast-path completion " | ||
9046 | "event: majorcode=x%x, minorcode=x%x\n", | ||
9047 | bf_get(lpfc_eqe_major_code, eqe), | ||
9048 | bf_get(lpfc_eqe_minor_code, eqe)); | ||
9049 | return; | ||
9050 | } | ||
9051 | |||
9052 | cq = phba->sli4_hba.fcp_cq[fcp_cqidx]; | ||
9053 | if (unlikely(!cq)) { | ||
9054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9055 | "0367 Fast-path completion queue does not " | ||
9056 | "exist\n"); | ||
9057 | return; | ||
9058 | } | ||
9059 | |||
9060 | /* Get the reference to the corresponding CQ */ | ||
9061 | cqid = bf_get(lpfc_eqe_resource_id, eqe); | ||
9062 | if (unlikely(cqid != cq->queue_id)) { | ||
9063 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9064 | "0368 Miss-matched fast-path completion " | ||
9065 | "queue identifier: eqcqid=%d, fcpcqid=%d\n", | ||
9066 | cqid, cq->queue_id); | ||
9067 | return; | ||
9068 | } | ||
9069 | |||
9070 | /* Process all the entries to the CQ */ | ||
9071 | while ((cqe = lpfc_sli4_cq_get(cq))) { | ||
9072 | workposted |= lpfc_sli4_fp_handle_wcqe(phba, cq, cqe); | ||
9073 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | ||
9074 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_NOARM); | ||
9075 | } | ||
9076 | |||
9077 | /* Catch the no cq entry condition */ | ||
9078 | if (unlikely(ecount == 0)) | ||
9079 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9080 | "0369 No entry from fast-path completion " | ||
9081 | "queue fcpcqid=%d\n", cq->queue_id); | ||
9082 | |||
9083 | /* In any case, flash and re-arm the CQ */ | ||
9084 | lpfc_sli4_cq_release(cq, LPFC_QUEUE_REARM); | ||
9085 | |||
9086 | /* wake up worker thread if there are works to be done */ | ||
9087 | if (workposted) | ||
9088 | lpfc_worker_wake_up(phba); | ||
9089 | } | ||
9090 | |||
9091 | static void | ||
9092 | lpfc_sli4_eq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq) | ||
9093 | { | ||
9094 | struct lpfc_eqe *eqe; | ||
9095 | |||
9096 | /* walk all the EQ entries and drop on the floor */ | ||
9097 | while ((eqe = lpfc_sli4_eq_get(eq))) | ||
9098 | ; | ||
9099 | |||
9100 | /* Clear and re-arm the EQ */ | ||
9101 | lpfc_sli4_eq_release(eq, LPFC_QUEUE_REARM); | ||
9102 | } | ||
9103 | |||
9104 | /** | ||
9105 | * lpfc_sli4_sp_intr_handler - Slow-path interrupt handler to SLI-4 device | ||
9106 | * @irq: Interrupt number. | ||
9107 | * @dev_id: The device context pointer. | ||
9108 | * | ||
9109 | * This function is directly called from the PCI layer as an interrupt | ||
9110 | * service routine when device with SLI-4 interface spec is enabled with | ||
9111 | * MSI-X multi-message interrupt mode and there are slow-path events in | ||
9112 | * the HBA. However, when the device is enabled with either MSI or Pin-IRQ | ||
9113 | * interrupt mode, this function is called as part of the device-level | ||
9114 | * interrupt handler. When the PCI slot is in error recovery or the HBA is | ||
9115 | * undergoing initialization, the interrupt handler will not process the | ||
9116 | * interrupt. The link attention and ELS ring attention events are handled | ||
9117 | * by the worker thread. The interrupt handler signals the worker thread | ||
9118 | * and returns for these events. This function is called without any lock | ||
9119 | * held. It gets the hbalock to access and update SLI data structures. | ||
9120 | * | ||
9121 | * This function returns IRQ_HANDLED when interrupt is handled else it | ||
9122 | * returns IRQ_NONE. | ||
9123 | **/ | ||
9124 | irqreturn_t | ||
9125 | lpfc_sli4_sp_intr_handler(int irq, void *dev_id) | ||
9126 | { | ||
9127 | struct lpfc_hba *phba; | ||
9128 | struct lpfc_queue *speq; | ||
9129 | struct lpfc_eqe *eqe; | ||
9130 | unsigned long iflag; | ||
9131 | int ecount = 0; | ||
9132 | |||
9133 | /* | ||
9134 | * Get the driver's phba structure from the dev_id | ||
9135 | */ | ||
9136 | phba = (struct lpfc_hba *)dev_id; | ||
9137 | |||
9138 | if (unlikely(!phba)) | ||
9139 | return IRQ_NONE; | ||
9140 | |||
9141 | /* Get to the EQ struct associated with this vector */ | ||
9142 | speq = phba->sli4_hba.sp_eq; | ||
9143 | |||
9144 | /* Check device state for handling interrupt */ | ||
9145 | if (unlikely(lpfc_intr_state_check(phba))) { | ||
9146 | /* Check again for link_state with lock held */ | ||
9147 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
9148 | if (phba->link_state < LPFC_LINK_DOWN) | ||
9149 | /* Flush, clear interrupt, and rearm the EQ */ | ||
9150 | lpfc_sli4_eq_flush(phba, speq); | ||
9151 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
9152 | return IRQ_NONE; | ||
9153 | } | ||
9154 | |||
9155 | /* | ||
9156 | * Process all the event on FCP slow-path EQ | ||
9157 | */ | ||
9158 | while ((eqe = lpfc_sli4_eq_get(speq))) { | ||
9159 | lpfc_sli4_sp_handle_eqe(phba, eqe); | ||
9160 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | ||
9161 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_NOARM); | ||
9162 | } | ||
9163 | |||
9164 | /* Always clear and re-arm the slow-path EQ */ | ||
9165 | lpfc_sli4_eq_release(speq, LPFC_QUEUE_REARM); | ||
9166 | |||
9167 | /* Catch the no cq entry condition */ | ||
9168 | if (unlikely(ecount == 0)) { | ||
9169 | if (phba->intr_type == MSIX) | ||
9170 | /* MSI-X treated interrupt served as no EQ share INT */ | ||
9171 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
9172 | "0357 MSI-X interrupt with no EQE\n"); | ||
9173 | else | ||
9174 | /* Non MSI-X treated on interrupt as EQ share INT */ | ||
9175 | return IRQ_NONE; | ||
9176 | } | ||
9177 | |||
9178 | return IRQ_HANDLED; | ||
9179 | } /* lpfc_sli4_sp_intr_handler */ | ||
9180 | |||
9181 | /** | ||
9182 | * lpfc_sli4_fp_intr_handler - Fast-path interrupt handler to SLI-4 device | ||
9183 | * @irq: Interrupt number. | ||
9184 | * @dev_id: The device context pointer. | ||
9185 | * | ||
9186 | * This function is directly called from the PCI layer as an interrupt | ||
9187 | * service routine when device with SLI-4 interface spec is enabled with | ||
9188 | * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB | ||
9189 | * ring event in the HBA. However, when the device is enabled with either | ||
9190 | * MSI or Pin-IRQ interrupt mode, this function is called as part of the | ||
9191 | * device-level interrupt handler. When the PCI slot is in error recovery | ||
9192 | * or the HBA is undergoing initialization, the interrupt handler will not | ||
9193 | * process the interrupt. The SCSI FCP fast-path ring event are handled in | ||
9194 | * the intrrupt context. This function is called without any lock held. | ||
9195 | * It gets the hbalock to access and update SLI data structures. Note that, | ||
9196 | * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is | ||
9197 | * equal to that of FCP CQ index. | ||
9198 | * | ||
9199 | * This function returns IRQ_HANDLED when interrupt is handled else it | ||
9200 | * returns IRQ_NONE. | ||
9201 | **/ | ||
9202 | irqreturn_t | ||
9203 | lpfc_sli4_fp_intr_handler(int irq, void *dev_id) | ||
9204 | { | ||
9205 | struct lpfc_hba *phba; | ||
9206 | struct lpfc_fcp_eq_hdl *fcp_eq_hdl; | ||
9207 | struct lpfc_queue *fpeq; | ||
9208 | struct lpfc_eqe *eqe; | ||
9209 | unsigned long iflag; | ||
9210 | int ecount = 0; | ||
9211 | uint32_t fcp_eqidx; | ||
9212 | |||
9213 | /* Get the driver's phba structure from the dev_id */ | ||
9214 | fcp_eq_hdl = (struct lpfc_fcp_eq_hdl *)dev_id; | ||
9215 | phba = fcp_eq_hdl->phba; | ||
9216 | fcp_eqidx = fcp_eq_hdl->idx; | ||
9217 | |||
9218 | if (unlikely(!phba)) | ||
9219 | return IRQ_NONE; | ||
9220 | |||
9221 | /* Get to the EQ struct associated with this vector */ | ||
9222 | fpeq = phba->sli4_hba.fp_eq[fcp_eqidx]; | ||
9223 | |||
9224 | /* Check device state for handling interrupt */ | ||
9225 | if (unlikely(lpfc_intr_state_check(phba))) { | ||
9226 | /* Check again for link_state with lock held */ | ||
9227 | spin_lock_irqsave(&phba->hbalock, iflag); | ||
9228 | if (phba->link_state < LPFC_LINK_DOWN) | ||
9229 | /* Flush, clear interrupt, and rearm the EQ */ | ||
9230 | lpfc_sli4_eq_flush(phba, fpeq); | ||
9231 | spin_unlock_irqrestore(&phba->hbalock, iflag); | ||
9232 | return IRQ_NONE; | ||
9233 | } | ||
9234 | |||
9235 | /* | ||
9236 | * Process all the event on FCP fast-path EQ | ||
9237 | */ | ||
9238 | while ((eqe = lpfc_sli4_eq_get(fpeq))) { | ||
9239 | lpfc_sli4_fp_handle_eqe(phba, eqe, fcp_eqidx); | ||
9240 | if (!(++ecount % LPFC_GET_QE_REL_INT)) | ||
9241 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_NOARM); | ||
9242 | } | ||
9243 | |||
9244 | /* Always clear and re-arm the fast-path EQ */ | ||
9245 | lpfc_sli4_eq_release(fpeq, LPFC_QUEUE_REARM); | ||
9246 | |||
9247 | if (unlikely(ecount == 0)) { | ||
9248 | if (phba->intr_type == MSIX) | ||
9249 | /* MSI-X treated interrupt served as no EQ share INT */ | ||
9250 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
9251 | "0358 MSI-X interrupt with no EQE\n"); | ||
9252 | else | ||
9253 | /* Non MSI-X treated on interrupt as EQ share INT */ | ||
9254 | return IRQ_NONE; | ||
9255 | } | ||
9256 | |||
9257 | return IRQ_HANDLED; | ||
9258 | } /* lpfc_sli4_fp_intr_handler */ | ||
9259 | |||
9260 | /** | ||
9261 | * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device | ||
9262 | * @irq: Interrupt number. | ||
9263 | * @dev_id: The device context pointer. | ||
9264 | * | ||
9265 | * This function is the device-level interrupt handler to device with SLI-4 | ||
9266 | * interface spec, called from the PCI layer when either MSI or Pin-IRQ | ||
9267 | * interrupt mode is enabled and there is an event in the HBA which requires | ||
9268 | * driver attention. This function invokes the slow-path interrupt attention | ||
9269 | * handling function and fast-path interrupt attention handling function in | ||
9270 | * turn to process the relevant HBA attention events. This function is called | ||
9271 | * without any lock held. It gets the hbalock to access and update SLI data | ||
9272 | * structures. | ||
9273 | * | ||
9274 | * This function returns IRQ_HANDLED when interrupt is handled, else it | ||
9275 | * returns IRQ_NONE. | ||
9276 | **/ | ||
9277 | irqreturn_t | ||
9278 | lpfc_sli4_intr_handler(int irq, void *dev_id) | ||
9279 | { | ||
9280 | struct lpfc_hba *phba; | ||
9281 | irqreturn_t sp_irq_rc, fp_irq_rc; | ||
9282 | bool fp_handled = false; | ||
9283 | uint32_t fcp_eqidx; | ||
9284 | |||
9285 | /* Get the driver's phba structure from the dev_id */ | ||
9286 | phba = (struct lpfc_hba *)dev_id; | ||
9287 | |||
9288 | if (unlikely(!phba)) | ||
9289 | return IRQ_NONE; | ||
9290 | |||
9291 | /* | ||
9292 | * Invokes slow-path host attention interrupt handling as appropriate. | ||
9293 | */ | ||
9294 | sp_irq_rc = lpfc_sli4_sp_intr_handler(irq, dev_id); | ||
9295 | |||
9296 | /* | ||
9297 | * Invoke fast-path host attention interrupt handling as appropriate. | ||
9298 | */ | ||
9299 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | ||
9300 | fp_irq_rc = lpfc_sli4_fp_intr_handler(irq, | ||
9301 | &phba->sli4_hba.fcp_eq_hdl[fcp_eqidx]); | ||
9302 | if (fp_irq_rc == IRQ_HANDLED) | ||
9303 | fp_handled |= true; | ||
9304 | } | ||
9305 | |||
9306 | return (fp_handled == true) ? IRQ_HANDLED : sp_irq_rc; | ||
9307 | } /* lpfc_sli4_intr_handler */ | ||
9308 | |||
9309 | /** | ||
9310 | * lpfc_sli4_queue_free - free a queue structure and associated memory | ||
9311 | * @queue: The queue structure to free. | ||
9312 | * | ||
9313 | * This function frees a queue structure and the DMAable memeory used for | ||
9314 | * the host resident queue. This function must be called after destroying the | ||
9315 | * queue on the HBA. | ||
9316 | **/ | ||
9317 | void | ||
9318 | lpfc_sli4_queue_free(struct lpfc_queue *queue) | ||
9319 | { | ||
9320 | struct lpfc_dmabuf *dmabuf; | ||
9321 | |||
9322 | if (!queue) | ||
9323 | return; | ||
9324 | |||
9325 | while (!list_empty(&queue->page_list)) { | ||
9326 | list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf, | ||
9327 | list); | ||
9328 | dma_free_coherent(&queue->phba->pcidev->dev, PAGE_SIZE, | ||
9329 | dmabuf->virt, dmabuf->phys); | ||
9330 | kfree(dmabuf); | ||
9331 | } | ||
9332 | kfree(queue); | ||
9333 | return; | ||
9334 | } | ||
9335 | |||
9336 | /** | ||
9337 | * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure | ||
9338 | * @phba: The HBA that this queue is being created on. | ||
9339 | * @entry_size: The size of each queue entry for this queue. | ||
9340 | * @entry count: The number of entries that this queue will handle. | ||
9341 | * | ||
9342 | * This function allocates a queue structure and the DMAable memory used for | ||
9343 | * the host resident queue. This function must be called before creating the | ||
9344 | * queue on the HBA. | ||
9345 | **/ | ||
9346 | struct lpfc_queue * | ||
9347 | lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t entry_size, | ||
9348 | uint32_t entry_count) | ||
9349 | { | ||
9350 | struct lpfc_queue *queue; | ||
9351 | struct lpfc_dmabuf *dmabuf; | ||
9352 | int x, total_qe_count; | ||
9353 | void *dma_pointer; | ||
9354 | |||
9355 | |||
9356 | queue = kzalloc(sizeof(struct lpfc_queue) + | ||
9357 | (sizeof(union sli4_qe) * entry_count), GFP_KERNEL); | ||
9358 | if (!queue) | ||
9359 | return NULL; | ||
9360 | queue->page_count = (PAGE_ALIGN(entry_size * entry_count))/PAGE_SIZE; | ||
9361 | INIT_LIST_HEAD(&queue->list); | ||
9362 | INIT_LIST_HEAD(&queue->page_list); | ||
9363 | INIT_LIST_HEAD(&queue->child_list); | ||
9364 | for (x = 0, total_qe_count = 0; x < queue->page_count; x++) { | ||
9365 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | ||
9366 | if (!dmabuf) | ||
9367 | goto out_fail; | ||
9368 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | ||
9369 | PAGE_SIZE, &dmabuf->phys, | ||
9370 | GFP_KERNEL); | ||
9371 | if (!dmabuf->virt) { | ||
9372 | kfree(dmabuf); | ||
9373 | goto out_fail; | ||
9374 | } | ||
9375 | memset(dmabuf->virt, 0, PAGE_SIZE); | ||
9376 | dmabuf->buffer_tag = x; | ||
9377 | list_add_tail(&dmabuf->list, &queue->page_list); | ||
9378 | /* initialize queue's entry array */ | ||
9379 | dma_pointer = dmabuf->virt; | ||
9380 | for (; total_qe_count < entry_count && | ||
9381 | dma_pointer < (PAGE_SIZE + dmabuf->virt); | ||
9382 | total_qe_count++, dma_pointer += entry_size) { | ||
9383 | queue->qe[total_qe_count].address = dma_pointer; | ||
9384 | } | ||
9385 | } | ||
9386 | queue->entry_size = entry_size; | ||
9387 | queue->entry_count = entry_count; | ||
9388 | queue->phba = phba; | ||
9389 | |||
9390 | return queue; | ||
9391 | out_fail: | ||
9392 | lpfc_sli4_queue_free(queue); | ||
9393 | return NULL; | ||
9394 | } | ||
9395 | |||
9396 | /** | ||
9397 | * lpfc_eq_create - Create an Event Queue on the HBA | ||
9398 | * @phba: HBA structure that indicates port to create a queue on. | ||
9399 | * @eq: The queue structure to use to create the event queue. | ||
9400 | * @imax: The maximum interrupt per second limit. | ||
9401 | * | ||
9402 | * This function creates an event queue, as detailed in @eq, on a port, | ||
9403 | * described by @phba by sending an EQ_CREATE mailbox command to the HBA. | ||
9404 | * | ||
9405 | * The @phba struct is used to send mailbox command to HBA. The @eq struct | ||
9406 | * is used to get the entry count and entry size that are necessary to | ||
9407 | * determine the number of pages to allocate and use for this queue. This | ||
9408 | * function will send the EQ_CREATE mailbox command to the HBA to setup the | ||
9409 | * event queue. This function is asynchronous and will wait for the mailbox | ||
9410 | * command to finish before continuing. | ||
9411 | * | ||
9412 | * On success this function will return a zero. If unable to allocate enough | ||
9413 | * memory this function will return ENOMEM. If the queue create mailbox command | ||
9414 | * fails this function will return ENXIO. | ||
9415 | **/ | ||
9416 | uint32_t | ||
9417 | lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint16_t imax) | ||
9418 | { | ||
9419 | struct lpfc_mbx_eq_create *eq_create; | ||
9420 | LPFC_MBOXQ_t *mbox; | ||
9421 | int rc, length, status = 0; | ||
9422 | struct lpfc_dmabuf *dmabuf; | ||
9423 | uint32_t shdr_status, shdr_add_status; | ||
9424 | union lpfc_sli4_cfg_shdr *shdr; | ||
9425 | uint16_t dmult; | ||
9426 | |||
9427 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
9428 | if (!mbox) | ||
9429 | return -ENOMEM; | ||
9430 | length = (sizeof(struct lpfc_mbx_eq_create) - | ||
9431 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
9432 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
9433 | LPFC_MBOX_OPCODE_EQ_CREATE, | ||
9434 | length, LPFC_SLI4_MBX_EMBED); | ||
9435 | eq_create = &mbox->u.mqe.un.eq_create; | ||
9436 | bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request, | ||
9437 | eq->page_count); | ||
9438 | bf_set(lpfc_eq_context_size, &eq_create->u.request.context, | ||
9439 | LPFC_EQE_SIZE); | ||
9440 | bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1); | ||
9441 | /* Calculate delay multiper from maximum interrupt per second */ | ||
9442 | dmult = LPFC_DMULT_CONST/imax - 1; | ||
9443 | bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context, | ||
9444 | dmult); | ||
9445 | switch (eq->entry_count) { | ||
9446 | default: | ||
9447 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9448 | "0360 Unsupported EQ count. (%d)\n", | ||
9449 | eq->entry_count); | ||
9450 | if (eq->entry_count < 256) | ||
9451 | return -EINVAL; | ||
9452 | /* otherwise default to smallest count (drop through) */ | ||
9453 | case 256: | ||
9454 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | ||
9455 | LPFC_EQ_CNT_256); | ||
9456 | break; | ||
9457 | case 512: | ||
9458 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | ||
9459 | LPFC_EQ_CNT_512); | ||
9460 | break; | ||
9461 | case 1024: | ||
9462 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | ||
9463 | LPFC_EQ_CNT_1024); | ||
9464 | break; | ||
9465 | case 2048: | ||
9466 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | ||
9467 | LPFC_EQ_CNT_2048); | ||
9468 | break; | ||
9469 | case 4096: | ||
9470 | bf_set(lpfc_eq_context_count, &eq_create->u.request.context, | ||
9471 | LPFC_EQ_CNT_4096); | ||
9472 | break; | ||
9473 | } | ||
9474 | list_for_each_entry(dmabuf, &eq->page_list, list) { | ||
9475 | eq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | ||
9476 | putPaddrLow(dmabuf->phys); | ||
9477 | eq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | ||
9478 | putPaddrHigh(dmabuf->phys); | ||
9479 | } | ||
9480 | mbox->vport = phba->pport; | ||
9481 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
9482 | mbox->context1 = NULL; | ||
9483 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
9484 | shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr; | ||
9485 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
9486 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
9487 | if (shdr_status || shdr_add_status || rc) { | ||
9488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
9489 | "2500 EQ_CREATE mailbox failed with " | ||
9490 | "status x%x add_status x%x, mbx status x%x\n", | ||
9491 | shdr_status, shdr_add_status, rc); | ||
9492 | status = -ENXIO; | ||
9493 | } | ||
9494 | eq->type = LPFC_EQ; | ||
9495 | eq->subtype = LPFC_NONE; | ||
9496 | eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response); | ||
9497 | if (eq->queue_id == 0xFFFF) | ||
9498 | status = -ENXIO; | ||
9499 | eq->host_index = 0; | ||
9500 | eq->hba_index = 0; | ||
9501 | |||
9502 | if (rc != MBX_TIMEOUT) | ||
9503 | mempool_free(mbox, phba->mbox_mem_pool); | ||
9504 | return status; | ||
9505 | } | ||
9506 | |||
9507 | /** | ||
9508 | * lpfc_cq_create - Create a Completion Queue on the HBA | ||
9509 | * @phba: HBA structure that indicates port to create a queue on. | ||
9510 | * @cq: The queue structure to use to create the completion queue. | ||
9511 | * @eq: The event queue to bind this completion queue to. | ||
9512 | * | ||
9513 | * This function creates a completion queue, as detailed in @wq, on a port, | ||
9514 | * described by @phba by sending a CQ_CREATE mailbox command to the HBA. | ||
9515 | * | ||
9516 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | ||
9517 | * is used to get the entry count and entry size that are necessary to | ||
9518 | * determine the number of pages to allocate and use for this queue. The @eq | ||
9519 | * is used to indicate which event queue to bind this completion queue to. This | ||
9520 | * function will send the CQ_CREATE mailbox command to the HBA to setup the | ||
9521 | * completion queue. This function is asynchronous and will wait for the mailbox | ||
9522 | * command to finish before continuing. | ||
9523 | * | ||
9524 | * On success this function will return a zero. If unable to allocate enough | ||
9525 | * memory this function will return ENOMEM. If the queue create mailbox command | ||
9526 | * fails this function will return ENXIO. | ||
9527 | **/ | ||
9528 | uint32_t | ||
9529 | lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq, | ||
9530 | struct lpfc_queue *eq, uint32_t type, uint32_t subtype) | ||
9531 | { | ||
9532 | struct lpfc_mbx_cq_create *cq_create; | ||
9533 | struct lpfc_dmabuf *dmabuf; | ||
9534 | LPFC_MBOXQ_t *mbox; | ||
9535 | int rc, length, status = 0; | ||
9536 | uint32_t shdr_status, shdr_add_status; | ||
9537 | union lpfc_sli4_cfg_shdr *shdr; | ||
9538 | |||
9539 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
9540 | if (!mbox) | ||
9541 | return -ENOMEM; | ||
9542 | length = (sizeof(struct lpfc_mbx_cq_create) - | ||
9543 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
9544 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
9545 | LPFC_MBOX_OPCODE_CQ_CREATE, | ||
9546 | length, LPFC_SLI4_MBX_EMBED); | ||
9547 | cq_create = &mbox->u.mqe.un.cq_create; | ||
9548 | bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request, | ||
9549 | cq->page_count); | ||
9550 | bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1); | ||
9551 | bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1); | ||
9552 | bf_set(lpfc_cq_eq_id, &cq_create->u.request.context, eq->queue_id); | ||
9553 | switch (cq->entry_count) { | ||
9554 | default: | ||
9555 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9556 | "0361 Unsupported CQ count. (%d)\n", | ||
9557 | cq->entry_count); | ||
9558 | if (cq->entry_count < 256) | ||
9559 | return -EINVAL; | ||
9560 | /* otherwise default to smallest count (drop through) */ | ||
9561 | case 256: | ||
9562 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | ||
9563 | LPFC_CQ_CNT_256); | ||
9564 | break; | ||
9565 | case 512: | ||
9566 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | ||
9567 | LPFC_CQ_CNT_512); | ||
9568 | break; | ||
9569 | case 1024: | ||
9570 | bf_set(lpfc_cq_context_count, &cq_create->u.request.context, | ||
9571 | LPFC_CQ_CNT_1024); | ||
9572 | break; | ||
9573 | } | ||
9574 | list_for_each_entry(dmabuf, &cq->page_list, list) { | ||
9575 | cq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | ||
9576 | putPaddrLow(dmabuf->phys); | ||
9577 | cq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | ||
9578 | putPaddrHigh(dmabuf->phys); | ||
9579 | } | ||
9580 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
9581 | |||
9582 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
9583 | shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr; | ||
9584 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
9585 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
9586 | if (shdr_status || shdr_add_status || rc) { | ||
9587 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
9588 | "2501 CQ_CREATE mailbox failed with " | ||
9589 | "status x%x add_status x%x, mbx status x%x\n", | ||
9590 | shdr_status, shdr_add_status, rc); | ||
9591 | status = -ENXIO; | ||
9592 | goto out; | ||
9593 | } | ||
9594 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | ||
9595 | if (cq->queue_id == 0xFFFF) { | ||
9596 | status = -ENXIO; | ||
9597 | goto out; | ||
9598 | } | ||
9599 | /* link the cq onto the parent eq child list */ | ||
9600 | list_add_tail(&cq->list, &eq->child_list); | ||
9601 | /* Set up completion queue's type and subtype */ | ||
9602 | cq->type = type; | ||
9603 | cq->subtype = subtype; | ||
9604 | cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response); | ||
9605 | cq->host_index = 0; | ||
9606 | cq->hba_index = 0; | ||
9607 | out: | ||
9608 | |||
9609 | if (rc != MBX_TIMEOUT) | ||
9610 | mempool_free(mbox, phba->mbox_mem_pool); | ||
9611 | return status; | ||
9612 | } | ||
9613 | |||
9614 | /** | ||
9615 | * lpfc_mq_create - Create a mailbox Queue on the HBA | ||
9616 | * @phba: HBA structure that indicates port to create a queue on. | ||
9617 | * @mq: The queue structure to use to create the mailbox queue. | ||
9618 | * | ||
9619 | * This function creates a mailbox queue, as detailed in @mq, on a port, | ||
9620 | * described by @phba by sending a MQ_CREATE mailbox command to the HBA. | ||
9621 | * | ||
9622 | * The @phba struct is used to send mailbox command to HBA. The @cq struct | ||
9623 | * is used to get the entry count and entry size that are necessary to | ||
9624 | * determine the number of pages to allocate and use for this queue. This | ||
9625 | * function will send the MQ_CREATE mailbox command to the HBA to setup the | ||
9626 | * mailbox queue. This function is asynchronous and will wait for the mailbox | ||
9627 | * command to finish before continuing. | ||
9628 | * | ||
9629 | * On success this function will return a zero. If unable to allocate enough | ||
9630 | * memory this function will return ENOMEM. If the queue create mailbox command | ||
9631 | * fails this function will return ENXIO. | ||
9632 | **/ | ||
9633 | uint32_t | ||
9634 | lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq, | ||
9635 | struct lpfc_queue *cq, uint32_t subtype) | ||
9636 | { | ||
9637 | struct lpfc_mbx_mq_create *mq_create; | ||
9638 | struct lpfc_dmabuf *dmabuf; | ||
9639 | LPFC_MBOXQ_t *mbox; | ||
9640 | int rc, length, status = 0; | ||
9641 | uint32_t shdr_status, shdr_add_status; | ||
9642 | union lpfc_sli4_cfg_shdr *shdr; | ||
9643 | |||
9644 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
9645 | if (!mbox) | ||
9646 | return -ENOMEM; | ||
9647 | length = (sizeof(struct lpfc_mbx_mq_create) - | ||
9648 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
9649 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
9650 | LPFC_MBOX_OPCODE_MQ_CREATE, | ||
9651 | length, LPFC_SLI4_MBX_EMBED); | ||
9652 | mq_create = &mbox->u.mqe.un.mq_create; | ||
9653 | bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request, | ||
9654 | mq->page_count); | ||
9655 | bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context, | ||
9656 | cq->queue_id); | ||
9657 | bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1); | ||
9658 | switch (mq->entry_count) { | ||
9659 | default: | ||
9660 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9661 | "0362 Unsupported MQ count. (%d)\n", | ||
9662 | mq->entry_count); | ||
9663 | if (mq->entry_count < 16) | ||
9664 | return -EINVAL; | ||
9665 | /* otherwise default to smallest count (drop through) */ | ||
9666 | case 16: | ||
9667 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | ||
9668 | LPFC_MQ_CNT_16); | ||
9669 | break; | ||
9670 | case 32: | ||
9671 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | ||
9672 | LPFC_MQ_CNT_32); | ||
9673 | break; | ||
9674 | case 64: | ||
9675 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | ||
9676 | LPFC_MQ_CNT_64); | ||
9677 | break; | ||
9678 | case 128: | ||
9679 | bf_set(lpfc_mq_context_count, &mq_create->u.request.context, | ||
9680 | LPFC_MQ_CNT_128); | ||
9681 | break; | ||
9682 | } | ||
9683 | list_for_each_entry(dmabuf, &mq->page_list, list) { | ||
9684 | mq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | ||
9685 | putPaddrLow(dmabuf->phys); | ||
9686 | mq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | ||
9687 | putPaddrHigh(dmabuf->phys); | ||
9688 | } | ||
9689 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
9690 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
9691 | shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr; | ||
9692 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
9693 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
9694 | if (shdr_status || shdr_add_status || rc) { | ||
9695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
9696 | "2502 MQ_CREATE mailbox failed with " | ||
9697 | "status x%x add_status x%x, mbx status x%x\n", | ||
9698 | shdr_status, shdr_add_status, rc); | ||
9699 | status = -ENXIO; | ||
9700 | goto out; | ||
9701 | } | ||
9702 | mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id, &mq_create->u.response); | ||
9703 | if (mq->queue_id == 0xFFFF) { | ||
9704 | status = -ENXIO; | ||
9705 | goto out; | ||
9706 | } | ||
9707 | mq->type = LPFC_MQ; | ||
9708 | mq->subtype = subtype; | ||
9709 | mq->host_index = 0; | ||
9710 | mq->hba_index = 0; | ||
9711 | |||
9712 | /* link the mq onto the parent cq child list */ | ||
9713 | list_add_tail(&mq->list, &cq->child_list); | ||
9714 | out: | ||
9715 | if (rc != MBX_TIMEOUT) | ||
9716 | mempool_free(mbox, phba->mbox_mem_pool); | ||
9717 | return status; | ||
9718 | } | ||
9719 | |||
9720 | /** | ||
9721 | * lpfc_wq_create - Create a Work Queue on the HBA | ||
9722 | * @phba: HBA structure that indicates port to create a queue on. | ||
9723 | * @wq: The queue structure to use to create the work queue. | ||
9724 | * @cq: The completion queue to bind this work queue to. | ||
9725 | * @subtype: The subtype of the work queue indicating its functionality. | ||
9726 | * | ||
9727 | * This function creates a work queue, as detailed in @wq, on a port, described | ||
9728 | * by @phba by sending a WQ_CREATE mailbox command to the HBA. | ||
9729 | * | ||
9730 | * The @phba struct is used to send mailbox command to HBA. The @wq struct | ||
9731 | * is used to get the entry count and entry size that are necessary to | ||
9732 | * determine the number of pages to allocate and use for this queue. The @cq | ||
9733 | * is used to indicate which completion queue to bind this work queue to. This | ||
9734 | * function will send the WQ_CREATE mailbox command to the HBA to setup the | ||
9735 | * work queue. This function is asynchronous and will wait for the mailbox | ||
9736 | * command to finish before continuing. | ||
9737 | * | ||
9738 | * On success this function will return a zero. If unable to allocate enough | ||
9739 | * memory this function will return ENOMEM. If the queue create mailbox command | ||
9740 | * fails this function will return ENXIO. | ||
9741 | **/ | ||
9742 | uint32_t | ||
9743 | lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq, | ||
9744 | struct lpfc_queue *cq, uint32_t subtype) | ||
9745 | { | ||
9746 | struct lpfc_mbx_wq_create *wq_create; | ||
9747 | struct lpfc_dmabuf *dmabuf; | ||
9748 | LPFC_MBOXQ_t *mbox; | ||
9749 | int rc, length, status = 0; | ||
9750 | uint32_t shdr_status, shdr_add_status; | ||
9751 | union lpfc_sli4_cfg_shdr *shdr; | ||
9752 | |||
9753 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
9754 | if (!mbox) | ||
9755 | return -ENOMEM; | ||
9756 | length = (sizeof(struct lpfc_mbx_wq_create) - | ||
9757 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
9758 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
9759 | LPFC_MBOX_OPCODE_FCOE_WQ_CREATE, | ||
9760 | length, LPFC_SLI4_MBX_EMBED); | ||
9761 | wq_create = &mbox->u.mqe.un.wq_create; | ||
9762 | bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request, | ||
9763 | wq->page_count); | ||
9764 | bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request, | ||
9765 | cq->queue_id); | ||
9766 | list_for_each_entry(dmabuf, &wq->page_list, list) { | ||
9767 | wq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | ||
9768 | putPaddrLow(dmabuf->phys); | ||
9769 | wq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | ||
9770 | putPaddrHigh(dmabuf->phys); | ||
9771 | } | ||
9772 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
9773 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
9774 | shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr; | ||
9775 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
9776 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
9777 | if (shdr_status || shdr_add_status || rc) { | ||
9778 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
9779 | "2503 WQ_CREATE mailbox failed with " | ||
9780 | "status x%x add_status x%x, mbx status x%x\n", | ||
9781 | shdr_status, shdr_add_status, rc); | ||
9782 | status = -ENXIO; | ||
9783 | goto out; | ||
9784 | } | ||
9785 | wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id, &wq_create->u.response); | ||
9786 | if (wq->queue_id == 0xFFFF) { | ||
9787 | status = -ENXIO; | ||
9788 | goto out; | ||
9789 | } | ||
9790 | wq->type = LPFC_WQ; | ||
9791 | wq->subtype = subtype; | ||
9792 | wq->host_index = 0; | ||
9793 | wq->hba_index = 0; | ||
9794 | |||
9795 | /* link the wq onto the parent cq child list */ | ||
9796 | list_add_tail(&wq->list, &cq->child_list); | ||
9797 | out: | ||
9798 | if (rc != MBX_TIMEOUT) | ||
9799 | mempool_free(mbox, phba->mbox_mem_pool); | ||
9800 | return status; | ||
9801 | } | ||
9802 | |||
9803 | /** | ||
9804 | * lpfc_rq_create - Create a Receive Queue on the HBA | ||
9805 | * @phba: HBA structure that indicates port to create a queue on. | ||
9806 | * @hrq: The queue structure to use to create the header receive queue. | ||
9807 | * @drq: The queue structure to use to create the data receive queue. | ||
9808 | * @cq: The completion queue to bind this work queue to. | ||
9809 | * | ||
9810 | * This function creates a receive buffer queue pair , as detailed in @hrq and | ||
9811 | * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command | ||
9812 | * to the HBA. | ||
9813 | * | ||
9814 | * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq | ||
9815 | * struct is used to get the entry count that is necessary to determine the | ||
9816 | * number of pages to use for this queue. The @cq is used to indicate which | ||
9817 | * completion queue to bind received buffers that are posted to these queues to. | ||
9818 | * This function will send the RQ_CREATE mailbox command to the HBA to setup the | ||
9819 | * receive queue pair. This function is asynchronous and will wait for the | ||
9820 | * mailbox command to finish before continuing. | ||
9821 | * | ||
9822 | * On success this function will return a zero. If unable to allocate enough | ||
9823 | * memory this function will return ENOMEM. If the queue create mailbox command | ||
9824 | * fails this function will return ENXIO. | ||
9825 | **/ | ||
9826 | uint32_t | ||
9827 | lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq, | ||
9828 | struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype) | ||
9829 | { | ||
9830 | struct lpfc_mbx_rq_create *rq_create; | ||
9831 | struct lpfc_dmabuf *dmabuf; | ||
9832 | LPFC_MBOXQ_t *mbox; | ||
9833 | int rc, length, status = 0; | ||
9834 | uint32_t shdr_status, shdr_add_status; | ||
9835 | union lpfc_sli4_cfg_shdr *shdr; | ||
9836 | |||
9837 | if (hrq->entry_count != drq->entry_count) | ||
9838 | return -EINVAL; | ||
9839 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
9840 | if (!mbox) | ||
9841 | return -ENOMEM; | ||
9842 | length = (sizeof(struct lpfc_mbx_rq_create) - | ||
9843 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
9844 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
9845 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | ||
9846 | length, LPFC_SLI4_MBX_EMBED); | ||
9847 | rq_create = &mbox->u.mqe.un.rq_create; | ||
9848 | switch (hrq->entry_count) { | ||
9849 | default: | ||
9850 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9851 | "2535 Unsupported RQ count. (%d)\n", | ||
9852 | hrq->entry_count); | ||
9853 | if (hrq->entry_count < 512) | ||
9854 | return -EINVAL; | ||
9855 | /* otherwise default to smallest count (drop through) */ | ||
9856 | case 512: | ||
9857 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9858 | LPFC_RQ_RING_SIZE_512); | ||
9859 | break; | ||
9860 | case 1024: | ||
9861 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9862 | LPFC_RQ_RING_SIZE_1024); | ||
9863 | break; | ||
9864 | case 2048: | ||
9865 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9866 | LPFC_RQ_RING_SIZE_2048); | ||
9867 | break; | ||
9868 | case 4096: | ||
9869 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9870 | LPFC_RQ_RING_SIZE_4096); | ||
9871 | break; | ||
9872 | } | ||
9873 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | ||
9874 | cq->queue_id); | ||
9875 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | ||
9876 | hrq->page_count); | ||
9877 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | ||
9878 | LPFC_HDR_BUF_SIZE); | ||
9879 | list_for_each_entry(dmabuf, &hrq->page_list, list) { | ||
9880 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | ||
9881 | putPaddrLow(dmabuf->phys); | ||
9882 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | ||
9883 | putPaddrHigh(dmabuf->phys); | ||
9884 | } | ||
9885 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
9886 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
9887 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | ||
9888 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
9889 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
9890 | if (shdr_status || shdr_add_status || rc) { | ||
9891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
9892 | "2504 RQ_CREATE mailbox failed with " | ||
9893 | "status x%x add_status x%x, mbx status x%x\n", | ||
9894 | shdr_status, shdr_add_status, rc); | ||
9895 | status = -ENXIO; | ||
9896 | goto out; | ||
9897 | } | ||
9898 | hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | ||
9899 | if (hrq->queue_id == 0xFFFF) { | ||
9900 | status = -ENXIO; | ||
9901 | goto out; | ||
9902 | } | ||
9903 | hrq->type = LPFC_HRQ; | ||
9904 | hrq->subtype = subtype; | ||
9905 | hrq->host_index = 0; | ||
9906 | hrq->hba_index = 0; | ||
9907 | |||
9908 | /* now create the data queue */ | ||
9909 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
9910 | LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, | ||
9911 | length, LPFC_SLI4_MBX_EMBED); | ||
9912 | switch (drq->entry_count) { | ||
9913 | default: | ||
9914 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
9915 | "2536 Unsupported RQ count. (%d)\n", | ||
9916 | drq->entry_count); | ||
9917 | if (drq->entry_count < 512) | ||
9918 | return -EINVAL; | ||
9919 | /* otherwise default to smallest count (drop through) */ | ||
9920 | case 512: | ||
9921 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9922 | LPFC_RQ_RING_SIZE_512); | ||
9923 | break; | ||
9924 | case 1024: | ||
9925 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9926 | LPFC_RQ_RING_SIZE_1024); | ||
9927 | break; | ||
9928 | case 2048: | ||
9929 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9930 | LPFC_RQ_RING_SIZE_2048); | ||
9931 | break; | ||
9932 | case 4096: | ||
9933 | bf_set(lpfc_rq_context_rq_size, &rq_create->u.request.context, | ||
9934 | LPFC_RQ_RING_SIZE_4096); | ||
9935 | break; | ||
9936 | } | ||
9937 | bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context, | ||
9938 | cq->queue_id); | ||
9939 | bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request, | ||
9940 | drq->page_count); | ||
9941 | bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context, | ||
9942 | LPFC_DATA_BUF_SIZE); | ||
9943 | list_for_each_entry(dmabuf, &drq->page_list, list) { | ||
9944 | rq_create->u.request.page[dmabuf->buffer_tag].addr_lo = | ||
9945 | putPaddrLow(dmabuf->phys); | ||
9946 | rq_create->u.request.page[dmabuf->buffer_tag].addr_hi = | ||
9947 | putPaddrHigh(dmabuf->phys); | ||
9948 | } | ||
9949 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
9950 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
9951 | shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr; | ||
9952 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
9953 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
9954 | if (shdr_status || shdr_add_status || rc) { | ||
9955 | status = -ENXIO; | ||
9956 | goto out; | ||
9957 | } | ||
9958 | drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response); | ||
9959 | if (drq->queue_id == 0xFFFF) { | ||
9960 | status = -ENXIO; | ||
9961 | goto out; | ||
9962 | } | ||
9963 | drq->type = LPFC_DRQ; | ||
9964 | drq->subtype = subtype; | ||
9965 | drq->host_index = 0; | ||
9966 | drq->hba_index = 0; | ||
9967 | |||
9968 | /* link the header and data RQs onto the parent cq child list */ | ||
9969 | list_add_tail(&hrq->list, &cq->child_list); | ||
9970 | list_add_tail(&drq->list, &cq->child_list); | ||
9971 | |||
9972 | out: | ||
9973 | if (rc != MBX_TIMEOUT) | ||
9974 | mempool_free(mbox, phba->mbox_mem_pool); | ||
9975 | return status; | ||
9976 | } | ||
9977 | |||
9978 | /** | ||
9979 | * lpfc_eq_destroy - Destroy an event Queue on the HBA | ||
9980 | * @eq: The queue structure associated with the queue to destroy. | ||
9981 | * | ||
9982 | * This function destroys a queue, as detailed in @eq by sending an mailbox | ||
9983 | * command, specific to the type of queue, to the HBA. | ||
9984 | * | ||
9985 | * The @eq struct is used to get the queue ID of the queue to destroy. | ||
9986 | * | ||
9987 | * On success this function will return a zero. If the queue destroy mailbox | ||
9988 | * command fails this function will return ENXIO. | ||
9989 | **/ | ||
9990 | uint32_t | ||
9991 | lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq) | ||
9992 | { | ||
9993 | LPFC_MBOXQ_t *mbox; | ||
9994 | int rc, length, status = 0; | ||
9995 | uint32_t shdr_status, shdr_add_status; | ||
9996 | union lpfc_sli4_cfg_shdr *shdr; | ||
9997 | |||
9998 | if (!eq) | ||
9999 | return -ENODEV; | ||
10000 | mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL); | ||
10001 | if (!mbox) | ||
10002 | return -ENOMEM; | ||
10003 | length = (sizeof(struct lpfc_mbx_eq_destroy) - | ||
10004 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
10005 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
10006 | LPFC_MBOX_OPCODE_EQ_DESTROY, | ||
10007 | length, LPFC_SLI4_MBX_EMBED); | ||
10008 | bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request, | ||
10009 | eq->queue_id); | ||
10010 | mbox->vport = eq->phba->pport; | ||
10011 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
10012 | |||
10013 | rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL); | ||
10014 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
10015 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10016 | &mbox->u.mqe.un.eq_destroy.header.cfg_shdr; | ||
10017 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10018 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10019 | if (shdr_status || shdr_add_status || rc) { | ||
10020 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10021 | "2505 EQ_DESTROY mailbox failed with " | ||
10022 | "status x%x add_status x%x, mbx status x%x\n", | ||
10023 | shdr_status, shdr_add_status, rc); | ||
10024 | status = -ENXIO; | ||
10025 | } | ||
10026 | |||
10027 | /* Remove eq from any list */ | ||
10028 | list_del_init(&eq->list); | ||
10029 | if (rc != MBX_TIMEOUT) | ||
10030 | mempool_free(mbox, eq->phba->mbox_mem_pool); | ||
10031 | return status; | ||
10032 | } | ||
10033 | |||
10034 | /** | ||
10035 | * lpfc_cq_destroy - Destroy a Completion Queue on the HBA | ||
10036 | * @cq: The queue structure associated with the queue to destroy. | ||
10037 | * | ||
10038 | * This function destroys a queue, as detailed in @cq by sending an mailbox | ||
10039 | * command, specific to the type of queue, to the HBA. | ||
10040 | * | ||
10041 | * The @cq struct is used to get the queue ID of the queue to destroy. | ||
10042 | * | ||
10043 | * On success this function will return a zero. If the queue destroy mailbox | ||
10044 | * command fails this function will return ENXIO. | ||
10045 | **/ | ||
10046 | uint32_t | ||
10047 | lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq) | ||
10048 | { | ||
10049 | LPFC_MBOXQ_t *mbox; | ||
10050 | int rc, length, status = 0; | ||
10051 | uint32_t shdr_status, shdr_add_status; | ||
10052 | union lpfc_sli4_cfg_shdr *shdr; | ||
10053 | |||
10054 | if (!cq) | ||
10055 | return -ENODEV; | ||
10056 | mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL); | ||
10057 | if (!mbox) | ||
10058 | return -ENOMEM; | ||
10059 | length = (sizeof(struct lpfc_mbx_cq_destroy) - | ||
10060 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
10061 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
10062 | LPFC_MBOX_OPCODE_CQ_DESTROY, | ||
10063 | length, LPFC_SLI4_MBX_EMBED); | ||
10064 | bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request, | ||
10065 | cq->queue_id); | ||
10066 | mbox->vport = cq->phba->pport; | ||
10067 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
10068 | rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL); | ||
10069 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
10070 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10071 | &mbox->u.mqe.un.wq_create.header.cfg_shdr; | ||
10072 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10073 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10074 | if (shdr_status || shdr_add_status || rc) { | ||
10075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10076 | "2506 CQ_DESTROY mailbox failed with " | ||
10077 | "status x%x add_status x%x, mbx status x%x\n", | ||
10078 | shdr_status, shdr_add_status, rc); | ||
10079 | status = -ENXIO; | ||
10080 | } | ||
10081 | /* Remove cq from any list */ | ||
10082 | list_del_init(&cq->list); | ||
10083 | if (rc != MBX_TIMEOUT) | ||
10084 | mempool_free(mbox, cq->phba->mbox_mem_pool); | ||
10085 | return status; | ||
10086 | } | ||
10087 | |||
10088 | /** | ||
10089 | * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA | ||
10090 | * @qm: The queue structure associated with the queue to destroy. | ||
10091 | * | ||
10092 | * This function destroys a queue, as detailed in @mq by sending an mailbox | ||
10093 | * command, specific to the type of queue, to the HBA. | ||
10094 | * | ||
10095 | * The @mq struct is used to get the queue ID of the queue to destroy. | ||
10096 | * | ||
10097 | * On success this function will return a zero. If the queue destroy mailbox | ||
10098 | * command fails this function will return ENXIO. | ||
10099 | **/ | ||
10100 | uint32_t | ||
10101 | lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq) | ||
10102 | { | ||
10103 | LPFC_MBOXQ_t *mbox; | ||
10104 | int rc, length, status = 0; | ||
10105 | uint32_t shdr_status, shdr_add_status; | ||
10106 | union lpfc_sli4_cfg_shdr *shdr; | ||
10107 | |||
10108 | if (!mq) | ||
10109 | return -ENODEV; | ||
10110 | mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL); | ||
10111 | if (!mbox) | ||
10112 | return -ENOMEM; | ||
10113 | length = (sizeof(struct lpfc_mbx_mq_destroy) - | ||
10114 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
10115 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
10116 | LPFC_MBOX_OPCODE_MQ_DESTROY, | ||
10117 | length, LPFC_SLI4_MBX_EMBED); | ||
10118 | bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request, | ||
10119 | mq->queue_id); | ||
10120 | mbox->vport = mq->phba->pport; | ||
10121 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
10122 | rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL); | ||
10123 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
10124 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10125 | &mbox->u.mqe.un.mq_destroy.header.cfg_shdr; | ||
10126 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10127 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10128 | if (shdr_status || shdr_add_status || rc) { | ||
10129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10130 | "2507 MQ_DESTROY mailbox failed with " | ||
10131 | "status x%x add_status x%x, mbx status x%x\n", | ||
10132 | shdr_status, shdr_add_status, rc); | ||
10133 | status = -ENXIO; | ||
10134 | } | ||
10135 | /* Remove mq from any list */ | ||
10136 | list_del_init(&mq->list); | ||
10137 | if (rc != MBX_TIMEOUT) | ||
10138 | mempool_free(mbox, mq->phba->mbox_mem_pool); | ||
10139 | return status; | ||
10140 | } | ||
10141 | |||
10142 | /** | ||
10143 | * lpfc_wq_destroy - Destroy a Work Queue on the HBA | ||
10144 | * @wq: The queue structure associated with the queue to destroy. | ||
10145 | * | ||
10146 | * This function destroys a queue, as detailed in @wq by sending an mailbox | ||
10147 | * command, specific to the type of queue, to the HBA. | ||
10148 | * | ||
10149 | * The @wq struct is used to get the queue ID of the queue to destroy. | ||
10150 | * | ||
10151 | * On success this function will return a zero. If the queue destroy mailbox | ||
10152 | * command fails this function will return ENXIO. | ||
10153 | **/ | ||
10154 | uint32_t | ||
10155 | lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq) | ||
10156 | { | ||
10157 | LPFC_MBOXQ_t *mbox; | ||
10158 | int rc, length, status = 0; | ||
10159 | uint32_t shdr_status, shdr_add_status; | ||
10160 | union lpfc_sli4_cfg_shdr *shdr; | ||
10161 | |||
10162 | if (!wq) | ||
10163 | return -ENODEV; | ||
10164 | mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL); | ||
10165 | if (!mbox) | ||
10166 | return -ENOMEM; | ||
10167 | length = (sizeof(struct lpfc_mbx_wq_destroy) - | ||
10168 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
10169 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
10170 | LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY, | ||
10171 | length, LPFC_SLI4_MBX_EMBED); | ||
10172 | bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request, | ||
10173 | wq->queue_id); | ||
10174 | mbox->vport = wq->phba->pport; | ||
10175 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
10176 | rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL); | ||
10177 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10178 | &mbox->u.mqe.un.wq_destroy.header.cfg_shdr; | ||
10179 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10180 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10181 | if (shdr_status || shdr_add_status || rc) { | ||
10182 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10183 | "2508 WQ_DESTROY mailbox failed with " | ||
10184 | "status x%x add_status x%x, mbx status x%x\n", | ||
10185 | shdr_status, shdr_add_status, rc); | ||
10186 | status = -ENXIO; | ||
10187 | } | ||
10188 | /* Remove wq from any list */ | ||
10189 | list_del_init(&wq->list); | ||
10190 | if (rc != MBX_TIMEOUT) | ||
10191 | mempool_free(mbox, wq->phba->mbox_mem_pool); | ||
10192 | return status; | ||
10193 | } | ||
10194 | |||
10195 | /** | ||
10196 | * lpfc_rq_destroy - Destroy a Receive Queue on the HBA | ||
10197 | * @rq: The queue structure associated with the queue to destroy. | ||
10198 | * | ||
10199 | * This function destroys a queue, as detailed in @rq by sending an mailbox | ||
10200 | * command, specific to the type of queue, to the HBA. | ||
10201 | * | ||
10202 | * The @rq struct is used to get the queue ID of the queue to destroy. | ||
10203 | * | ||
10204 | * On success this function will return a zero. If the queue destroy mailbox | ||
10205 | * command fails this function will return ENXIO. | ||
10206 | **/ | ||
10207 | uint32_t | ||
10208 | lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq, | ||
10209 | struct lpfc_queue *drq) | ||
10210 | { | ||
10211 | LPFC_MBOXQ_t *mbox; | ||
10212 | int rc, length, status = 0; | ||
10213 | uint32_t shdr_status, shdr_add_status; | ||
10214 | union lpfc_sli4_cfg_shdr *shdr; | ||
10215 | |||
10216 | if (!hrq || !drq) | ||
10217 | return -ENODEV; | ||
10218 | mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL); | ||
10219 | if (!mbox) | ||
10220 | return -ENOMEM; | ||
10221 | length = (sizeof(struct lpfc_mbx_rq_destroy) - | ||
10222 | sizeof(struct mbox_header)); | ||
10223 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
10224 | LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY, | ||
10225 | length, LPFC_SLI4_MBX_EMBED); | ||
10226 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | ||
10227 | hrq->queue_id); | ||
10228 | mbox->vport = hrq->phba->pport; | ||
10229 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | ||
10230 | rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL); | ||
10231 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
10232 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10233 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | ||
10234 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10235 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10236 | if (shdr_status || shdr_add_status || rc) { | ||
10237 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10238 | "2509 RQ_DESTROY mailbox failed with " | ||
10239 | "status x%x add_status x%x, mbx status x%x\n", | ||
10240 | shdr_status, shdr_add_status, rc); | ||
10241 | if (rc != MBX_TIMEOUT) | ||
10242 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | ||
10243 | return -ENXIO; | ||
10244 | } | ||
10245 | bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request, | ||
10246 | drq->queue_id); | ||
10247 | rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL); | ||
10248 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10249 | &mbox->u.mqe.un.rq_destroy.header.cfg_shdr; | ||
10250 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10251 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10252 | if (shdr_status || shdr_add_status || rc) { | ||
10253 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10254 | "2510 RQ_DESTROY mailbox failed with " | ||
10255 | "status x%x add_status x%x, mbx status x%x\n", | ||
10256 | shdr_status, shdr_add_status, rc); | ||
10257 | status = -ENXIO; | ||
10258 | } | ||
10259 | list_del_init(&hrq->list); | ||
10260 | list_del_init(&drq->list); | ||
10261 | if (rc != MBX_TIMEOUT) | ||
10262 | mempool_free(mbox, hrq->phba->mbox_mem_pool); | ||
10263 | return status; | ||
10264 | } | ||
10265 | |||
10266 | /** | ||
10267 | * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA | ||
10268 | * @phba: The virtual port for which this call being executed. | ||
10269 | * @pdma_phys_addr0: Physical address of the 1st SGL page. | ||
10270 | * @pdma_phys_addr1: Physical address of the 2nd SGL page. | ||
10271 | * @xritag: the xritag that ties this io to the SGL pages. | ||
10272 | * | ||
10273 | * This routine will post the sgl pages for the IO that has the xritag | ||
10274 | * that is in the iocbq structure. The xritag is assigned during iocbq | ||
10275 | * creation and persists for as long as the driver is loaded. | ||
10276 | * if the caller has fewer than 256 scatter gather segments to map then | ||
10277 | * pdma_phys_addr1 should be 0. | ||
10278 | * If the caller needs to map more than 256 scatter gather segment then | ||
10279 | * pdma_phys_addr1 should be a valid physical address. | ||
10280 | * physical address for SGLs must be 64 byte aligned. | ||
10281 | * If you are going to map 2 SGL's then the first one must have 256 entries | ||
10282 | * the second sgl can have between 1 and 256 entries. | ||
10283 | * | ||
10284 | * Return codes: | ||
10285 | * 0 - Success | ||
10286 | * -ENXIO, -ENOMEM - Failure | ||
10287 | **/ | ||
10288 | int | ||
10289 | lpfc_sli4_post_sgl(struct lpfc_hba *phba, | ||
10290 | dma_addr_t pdma_phys_addr0, | ||
10291 | dma_addr_t pdma_phys_addr1, | ||
10292 | uint16_t xritag) | ||
10293 | { | ||
10294 | struct lpfc_mbx_post_sgl_pages *post_sgl_pages; | ||
10295 | LPFC_MBOXQ_t *mbox; | ||
10296 | int rc; | ||
10297 | uint32_t shdr_status, shdr_add_status; | ||
10298 | union lpfc_sli4_cfg_shdr *shdr; | ||
10299 | |||
10300 | if (xritag == NO_XRI) { | ||
10301 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
10302 | "0364 Invalid param:\n"); | ||
10303 | return -EINVAL; | ||
10304 | } | ||
10305 | |||
10306 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
10307 | if (!mbox) | ||
10308 | return -ENOMEM; | ||
10309 | |||
10310 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
10311 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, | ||
10312 | sizeof(struct lpfc_mbx_post_sgl_pages) - | ||
10313 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | ||
10314 | |||
10315 | post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *) | ||
10316 | &mbox->u.mqe.un.post_sgl_pages; | ||
10317 | bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag); | ||
10318 | bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1); | ||
10319 | |||
10320 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo = | ||
10321 | cpu_to_le32(putPaddrLow(pdma_phys_addr0)); | ||
10322 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi = | ||
10323 | cpu_to_le32(putPaddrHigh(pdma_phys_addr0)); | ||
10324 | |||
10325 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo = | ||
10326 | cpu_to_le32(putPaddrLow(pdma_phys_addr1)); | ||
10327 | post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi = | ||
10328 | cpu_to_le32(putPaddrHigh(pdma_phys_addr1)); | ||
10329 | if (!phba->sli4_hba.intr_enable) | ||
10330 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
10331 | else | ||
10332 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | ||
10333 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
10334 | shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr; | ||
10335 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10336 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10337 | if (rc != MBX_TIMEOUT) | ||
10338 | mempool_free(mbox, phba->mbox_mem_pool); | ||
10339 | if (shdr_status || shdr_add_status || rc) { | ||
10340 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10341 | "2511 POST_SGL mailbox failed with " | ||
10342 | "status x%x add_status x%x, mbx status x%x\n", | ||
10343 | shdr_status, shdr_add_status, rc); | ||
10344 | rc = -ENXIO; | ||
10345 | } | ||
10346 | return 0; | ||
10347 | } | ||
10348 | /** | ||
10349 | * lpfc_sli4_remove_all_sgl_pages - Post scatter gather list for an XRI to HBA | ||
10350 | * @phba: The virtual port for which this call being executed. | ||
10351 | * | ||
10352 | * This routine will remove all of the sgl pages registered with the hba. | ||
10353 | * | ||
10354 | * Return codes: | ||
10355 | * 0 - Success | ||
10356 | * -ENXIO, -ENOMEM - Failure | ||
10357 | **/ | ||
10358 | int | ||
10359 | lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *phba) | ||
10360 | { | ||
10361 | LPFC_MBOXQ_t *mbox; | ||
10362 | int rc; | ||
10363 | uint32_t shdr_status, shdr_add_status; | ||
10364 | union lpfc_sli4_cfg_shdr *shdr; | ||
10365 | |||
10366 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
10367 | if (!mbox) | ||
10368 | return -ENOMEM; | ||
10369 | |||
10370 | lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
10371 | LPFC_MBOX_OPCODE_FCOE_REMOVE_SGL_PAGES, 0, | ||
10372 | LPFC_SLI4_MBX_EMBED); | ||
10373 | if (!phba->sli4_hba.intr_enable) | ||
10374 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
10375 | else | ||
10376 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO); | ||
10377 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
10378 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
10379 | &mbox->u.mqe.un.sli4_config.header.cfg_shdr; | ||
10380 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10381 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10382 | if (rc != MBX_TIMEOUT) | ||
10383 | mempool_free(mbox, phba->mbox_mem_pool); | ||
10384 | if (shdr_status || shdr_add_status || rc) { | ||
10385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10386 | "2512 REMOVE_ALL_SGL_PAGES mailbox failed with " | ||
10387 | "status x%x add_status x%x, mbx status x%x\n", | ||
10388 | shdr_status, shdr_add_status, rc); | ||
10389 | rc = -ENXIO; | ||
10390 | } | ||
10391 | return rc; | ||
10392 | } | ||
10393 | |||
10394 | /** | ||
10395 | * lpfc_sli4_next_xritag - Get an xritag for the io | ||
10396 | * @phba: Pointer to HBA context object. | ||
10397 | * | ||
10398 | * This function gets an xritag for the iocb. If there is no unused xritag | ||
10399 | * it will return 0xffff. | ||
10400 | * The function returns the allocated xritag if successful, else returns zero. | ||
10401 | * Zero is not a valid xritag. | ||
10402 | * The caller is not required to hold any lock. | ||
10403 | **/ | ||
10404 | uint16_t | ||
10405 | lpfc_sli4_next_xritag(struct lpfc_hba *phba) | ||
10406 | { | ||
10407 | uint16_t xritag; | ||
10408 | |||
10409 | spin_lock_irq(&phba->hbalock); | ||
10410 | xritag = phba->sli4_hba.next_xri; | ||
10411 | if ((xritag != (uint16_t) -1) && xritag < | ||
10412 | (phba->sli4_hba.max_cfg_param.max_xri | ||
10413 | + phba->sli4_hba.max_cfg_param.xri_base)) { | ||
10414 | phba->sli4_hba.next_xri++; | ||
10415 | phba->sli4_hba.max_cfg_param.xri_used++; | ||
10416 | spin_unlock_irq(&phba->hbalock); | ||
10417 | return xritag; | ||
10418 | } | ||
10419 | spin_unlock_irq(&phba->hbalock); | ||
10420 | |||
10421 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
10422 | "2004 Failed to allocate XRI.last XRITAG is %d" | ||
10423 | " Max XRI is %d, Used XRI is %d\n", | ||
10424 | phba->sli4_hba.next_xri, | ||
10425 | phba->sli4_hba.max_cfg_param.max_xri, | ||
10426 | phba->sli4_hba.max_cfg_param.xri_used); | ||
10427 | return -1; | ||
10428 | } | ||
10429 | |||
10430 | /** | ||
10431 | * lpfc_sli4_post_sgl_list - post a block of sgl list to the firmware. | ||
10432 | * @phba: pointer to lpfc hba data structure. | ||
10433 | * | ||
10434 | * This routine is invoked to post a block of driver's sgl pages to the | ||
10435 | * HBA using non-embedded mailbox command. No Lock is held. This routine | ||
10436 | * is only called when the driver is loading and after all IO has been | ||
10437 | * stopped. | ||
10438 | **/ | ||
10439 | int | ||
10440 | lpfc_sli4_post_sgl_list(struct lpfc_hba *phba) | ||
10441 | { | ||
10442 | struct lpfc_sglq *sglq_entry; | ||
10443 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | ||
10444 | struct sgl_page_pairs *sgl_pg_pairs; | ||
10445 | void *viraddr; | ||
10446 | LPFC_MBOXQ_t *mbox; | ||
10447 | uint32_t reqlen, alloclen, pg_pairs; | ||
10448 | uint32_t mbox_tmo; | ||
10449 | uint16_t xritag_start = 0; | ||
10450 | int els_xri_cnt, rc = 0; | ||
10451 | uint32_t shdr_status, shdr_add_status; | ||
10452 | union lpfc_sli4_cfg_shdr *shdr; | ||
10453 | |||
10454 | /* The number of sgls to be posted */ | ||
10455 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | ||
10456 | |||
10457 | reqlen = els_xri_cnt * sizeof(struct sgl_page_pairs) + | ||
10458 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | ||
10459 | if (reqlen > PAGE_SIZE) { | ||
10460 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
10461 | "2559 Block sgl registration required DMA " | ||
10462 | "size (%d) great than a page\n", reqlen); | ||
10463 | return -ENOMEM; | ||
10464 | } | ||
10465 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
10466 | if (!mbox) { | ||
10467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10468 | "2560 Failed to allocate mbox cmd memory\n"); | ||
10469 | return -ENOMEM; | ||
10470 | } | ||
10471 | |||
10472 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | ||
10473 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
10474 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | ||
10475 | LPFC_SLI4_MBX_NEMBED); | ||
10476 | |||
10477 | if (alloclen < reqlen) { | ||
10478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10479 | "0285 Allocated DMA memory size (%d) is " | ||
10480 | "less than the requested DMA memory " | ||
10481 | "size (%d)\n", alloclen, reqlen); | ||
10482 | lpfc_sli4_mbox_cmd_free(phba, mbox); | ||
10483 | return -ENOMEM; | ||
10484 | } | ||
10485 | |||
10486 | /* Get the first SGE entry from the non-embedded DMA memory */ | ||
10487 | if (unlikely(!mbox->sge_array)) { | ||
10488 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | ||
10489 | "2525 Failed to get the non-embedded SGE " | ||
10490 | "virtual address\n"); | ||
10491 | lpfc_sli4_mbox_cmd_free(phba, mbox); | ||
10492 | return -ENOMEM; | ||
10493 | } | ||
10494 | viraddr = mbox->sge_array->addr[0]; | ||
10495 | |||
10496 | /* Set up the SGL pages in the non-embedded DMA pages */ | ||
10497 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | ||
10498 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | ||
10499 | |||
10500 | for (pg_pairs = 0; pg_pairs < els_xri_cnt; pg_pairs++) { | ||
10501 | sglq_entry = phba->sli4_hba.lpfc_els_sgl_array[pg_pairs]; | ||
10502 | /* Set up the sge entry */ | ||
10503 | sgl_pg_pairs->sgl_pg0_addr_lo = | ||
10504 | cpu_to_le32(putPaddrLow(sglq_entry->phys)); | ||
10505 | sgl_pg_pairs->sgl_pg0_addr_hi = | ||
10506 | cpu_to_le32(putPaddrHigh(sglq_entry->phys)); | ||
10507 | sgl_pg_pairs->sgl_pg1_addr_lo = | ||
10508 | cpu_to_le32(putPaddrLow(0)); | ||
10509 | sgl_pg_pairs->sgl_pg1_addr_hi = | ||
10510 | cpu_to_le32(putPaddrHigh(0)); | ||
10511 | /* Keep the first xritag on the list */ | ||
10512 | if (pg_pairs == 0) | ||
10513 | xritag_start = sglq_entry->sli4_xritag; | ||
10514 | sgl_pg_pairs++; | ||
10515 | } | ||
10516 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | ||
10517 | pg_pairs = (pg_pairs > 0) ? (pg_pairs - 1) : pg_pairs; | ||
10518 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | ||
10519 | /* Perform endian conversion if necessary */ | ||
10520 | sgl->word0 = cpu_to_le32(sgl->word0); | ||
10521 | |||
10522 | if (!phba->sli4_hba.intr_enable) | ||
10523 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
10524 | else { | ||
10525 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | ||
10526 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | ||
10527 | } | ||
10528 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | ||
10529 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10530 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10531 | if (rc != MBX_TIMEOUT) | ||
10532 | lpfc_sli4_mbox_cmd_free(phba, mbox); | ||
10533 | if (shdr_status || shdr_add_status || rc) { | ||
10534 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
10535 | "2513 POST_SGL_BLOCK mailbox command failed " | ||
10536 | "status x%x add_status x%x mbx status x%x\n", | ||
10537 | shdr_status, shdr_add_status, rc); | ||
10538 | rc = -ENXIO; | ||
10539 | } | ||
10540 | return rc; | ||
10541 | } | ||
10542 | |||
10543 | /** | ||
10544 | * lpfc_sli4_post_scsi_sgl_block - post a block of scsi sgl list to firmware | ||
10545 | * @phba: pointer to lpfc hba data structure. | ||
10546 | * @sblist: pointer to scsi buffer list. | ||
10547 | * @count: number of scsi buffers on the list. | ||
10548 | * | ||
10549 | * This routine is invoked to post a block of @count scsi sgl pages from a | ||
10550 | * SCSI buffer list @sblist to the HBA using non-embedded mailbox command. | ||
10551 | * No Lock is held. | ||
10552 | * | ||
10553 | **/ | ||
10554 | int | ||
10555 | lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *phba, struct list_head *sblist, | ||
10556 | int cnt) | ||
10557 | { | ||
10558 | struct lpfc_scsi_buf *psb; | ||
10559 | struct lpfc_mbx_post_uembed_sgl_page1 *sgl; | ||
10560 | struct sgl_page_pairs *sgl_pg_pairs; | ||
10561 | void *viraddr; | ||
10562 | LPFC_MBOXQ_t *mbox; | ||
10563 | uint32_t reqlen, alloclen, pg_pairs; | ||
10564 | uint32_t mbox_tmo; | ||
10565 | uint16_t xritag_start = 0; | ||
10566 | int rc = 0; | ||
10567 | uint32_t shdr_status, shdr_add_status; | ||
10568 | dma_addr_t pdma_phys_bpl1; | ||
10569 | union lpfc_sli4_cfg_shdr *shdr; | ||
10570 | |||
10571 | /* Calculate the requested length of the dma memory */ | ||
10572 | reqlen = cnt * sizeof(struct sgl_page_pairs) + | ||
10573 | sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t); | ||
10574 | if (reqlen > PAGE_SIZE) { | ||
10575 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
10576 | "0217 Block sgl registration required DMA " | ||
10577 | "size (%d) great than a page\n", reqlen); | ||
10578 | return -ENOMEM; | ||
10579 | } | ||
10580 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
10581 | if (!mbox) { | ||
10582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10583 | "0283 Failed to allocate mbox cmd memory\n"); | ||
10584 | return -ENOMEM; | ||
10585 | } | ||
10586 | |||
10587 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | ||
10588 | alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
10589 | LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen, | ||
10590 | LPFC_SLI4_MBX_NEMBED); | ||
10591 | |||
10592 | if (alloclen < reqlen) { | ||
10593 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
10594 | "2561 Allocated DMA memory size (%d) is " | ||
10595 | "less than the requested DMA memory " | ||
10596 | "size (%d)\n", alloclen, reqlen); | ||
10597 | lpfc_sli4_mbox_cmd_free(phba, mbox); | ||
10598 | return -ENOMEM; | ||
10599 | } | ||
10600 | |||
10601 | /* Get the first SGE entry from the non-embedded DMA memory */ | ||
10602 | if (unlikely(!mbox->sge_array)) { | ||
10603 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | ||
10604 | "2565 Failed to get the non-embedded SGE " | ||
10605 | "virtual address\n"); | ||
10606 | lpfc_sli4_mbox_cmd_free(phba, mbox); | ||
10607 | return -ENOMEM; | ||
10608 | } | ||
10609 | viraddr = mbox->sge_array->addr[0]; | ||
10610 | |||
10611 | /* Set up the SGL pages in the non-embedded DMA pages */ | ||
10612 | sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr; | ||
10613 | sgl_pg_pairs = &sgl->sgl_pg_pairs; | ||
10614 | |||
10615 | pg_pairs = 0; | ||
10616 | list_for_each_entry(psb, sblist, list) { | ||
10617 | /* Set up the sge entry */ | ||
10618 | sgl_pg_pairs->sgl_pg0_addr_lo = | ||
10619 | cpu_to_le32(putPaddrLow(psb->dma_phys_bpl)); | ||
10620 | sgl_pg_pairs->sgl_pg0_addr_hi = | ||
10621 | cpu_to_le32(putPaddrHigh(psb->dma_phys_bpl)); | ||
10622 | if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE) | ||
10623 | pdma_phys_bpl1 = psb->dma_phys_bpl + SGL_PAGE_SIZE; | ||
10624 | else | ||
10625 | pdma_phys_bpl1 = 0; | ||
10626 | sgl_pg_pairs->sgl_pg1_addr_lo = | ||
10627 | cpu_to_le32(putPaddrLow(pdma_phys_bpl1)); | ||
10628 | sgl_pg_pairs->sgl_pg1_addr_hi = | ||
10629 | cpu_to_le32(putPaddrHigh(pdma_phys_bpl1)); | ||
10630 | /* Keep the first xritag on the list */ | ||
10631 | if (pg_pairs == 0) | ||
10632 | xritag_start = psb->cur_iocbq.sli4_xritag; | ||
10633 | sgl_pg_pairs++; | ||
10634 | pg_pairs++; | ||
10635 | } | ||
10636 | bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start); | ||
10637 | bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs); | ||
10638 | /* Perform endian conversion if necessary */ | ||
10639 | sgl->word0 = cpu_to_le32(sgl->word0); | ||
10640 | |||
10641 | if (!phba->sli4_hba.intr_enable) | ||
10642 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
10643 | else { | ||
10644 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | ||
10645 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | ||
10646 | } | ||
10647 | shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr; | ||
10648 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
10649 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
10650 | if (rc != MBX_TIMEOUT) | ||
10651 | lpfc_sli4_mbox_cmd_free(phba, mbox); | ||
10652 | if (shdr_status || shdr_add_status || rc) { | ||
10653 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
10654 | "2564 POST_SGL_BLOCK mailbox command failed " | ||
10655 | "status x%x add_status x%x mbx status x%x\n", | ||
10656 | shdr_status, shdr_add_status, rc); | ||
10657 | rc = -ENXIO; | ||
10658 | } | ||
10659 | return rc; | ||
10660 | } | ||
10661 | |||
10662 | /** | ||
10663 | * lpfc_fc_frame_check - Check that this frame is a valid frame to handle | ||
10664 | * @phba: pointer to lpfc_hba struct that the frame was received on | ||
10665 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | ||
10666 | * | ||
10667 | * This function checks the fields in the @fc_hdr to see if the FC frame is a | ||
10668 | * valid type of frame that the LPFC driver will handle. This function will | ||
10669 | * return a zero if the frame is a valid frame or a non zero value when the | ||
10670 | * frame does not pass the check. | ||
10671 | **/ | ||
10672 | static int | ||
10673 | lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr) | ||
10674 | { | ||
10675 | char *rctl_names[] = FC_RCTL_NAMES_INIT; | ||
10676 | char *type_names[] = FC_TYPE_NAMES_INIT; | ||
10677 | struct fc_vft_header *fc_vft_hdr; | ||
10678 | |||
10679 | switch (fc_hdr->fh_r_ctl) { | ||
10680 | case FC_RCTL_DD_UNCAT: /* uncategorized information */ | ||
10681 | case FC_RCTL_DD_SOL_DATA: /* solicited data */ | ||
10682 | case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */ | ||
10683 | case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */ | ||
10684 | case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */ | ||
10685 | case FC_RCTL_DD_DATA_DESC: /* data descriptor */ | ||
10686 | case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */ | ||
10687 | case FC_RCTL_DD_CMD_STATUS: /* command status */ | ||
10688 | case FC_RCTL_ELS_REQ: /* extended link services request */ | ||
10689 | case FC_RCTL_ELS_REP: /* extended link services reply */ | ||
10690 | case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */ | ||
10691 | case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */ | ||
10692 | case FC_RCTL_BA_NOP: /* basic link service NOP */ | ||
10693 | case FC_RCTL_BA_ABTS: /* basic link service abort */ | ||
10694 | case FC_RCTL_BA_RMC: /* remove connection */ | ||
10695 | case FC_RCTL_BA_ACC: /* basic accept */ | ||
10696 | case FC_RCTL_BA_RJT: /* basic reject */ | ||
10697 | case FC_RCTL_BA_PRMT: | ||
10698 | case FC_RCTL_ACK_1: /* acknowledge_1 */ | ||
10699 | case FC_RCTL_ACK_0: /* acknowledge_0 */ | ||
10700 | case FC_RCTL_P_RJT: /* port reject */ | ||
10701 | case FC_RCTL_F_RJT: /* fabric reject */ | ||
10702 | case FC_RCTL_P_BSY: /* port busy */ | ||
10703 | case FC_RCTL_F_BSY: /* fabric busy to data frame */ | ||
10704 | case FC_RCTL_F_BSYL: /* fabric busy to link control frame */ | ||
10705 | case FC_RCTL_LCR: /* link credit reset */ | ||
10706 | case FC_RCTL_END: /* end */ | ||
10707 | break; | ||
10708 | case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */ | ||
10709 | fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | ||
10710 | fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1]; | ||
10711 | return lpfc_fc_frame_check(phba, fc_hdr); | ||
10712 | default: | ||
10713 | goto drop; | ||
10714 | } | ||
10715 | switch (fc_hdr->fh_type) { | ||
10716 | case FC_TYPE_BLS: | ||
10717 | case FC_TYPE_ELS: | ||
10718 | case FC_TYPE_FCP: | ||
10719 | case FC_TYPE_CT: | ||
10720 | break; | ||
10721 | case FC_TYPE_IP: | ||
10722 | case FC_TYPE_ILS: | ||
10723 | default: | ||
10724 | goto drop; | ||
10725 | } | ||
10726 | lpfc_printf_log(phba, KERN_INFO, LOG_ELS, | ||
10727 | "2538 Received frame rctl:%s type:%s\n", | ||
10728 | rctl_names[fc_hdr->fh_r_ctl], | ||
10729 | type_names[fc_hdr->fh_type]); | ||
10730 | return 0; | ||
10731 | drop: | ||
10732 | lpfc_printf_log(phba, KERN_WARNING, LOG_ELS, | ||
10733 | "2539 Dropped frame rctl:%s type:%s\n", | ||
10734 | rctl_names[fc_hdr->fh_r_ctl], | ||
10735 | type_names[fc_hdr->fh_type]); | ||
10736 | return 1; | ||
10737 | } | ||
10738 | |||
10739 | /** | ||
10740 | * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame | ||
10741 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | ||
10742 | * | ||
10743 | * This function processes the FC header to retrieve the VFI from the VF | ||
10744 | * header, if one exists. This function will return the VFI if one exists | ||
10745 | * or 0 if no VSAN Header exists. | ||
10746 | **/ | ||
10747 | static uint32_t | ||
10748 | lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr) | ||
10749 | { | ||
10750 | struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr; | ||
10751 | |||
10752 | if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH) | ||
10753 | return 0; | ||
10754 | return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr); | ||
10755 | } | ||
10756 | |||
10757 | /** | ||
10758 | * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to | ||
10759 | * @phba: Pointer to the HBA structure to search for the vport on | ||
10760 | * @fc_hdr: A pointer to the FC Header data (In Big Endian Format) | ||
10761 | * @fcfi: The FC Fabric ID that the frame came from | ||
10762 | * | ||
10763 | * This function searches the @phba for a vport that matches the content of the | ||
10764 | * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the | ||
10765 | * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function | ||
10766 | * returns the matching vport pointer or NULL if unable to match frame to a | ||
10767 | * vport. | ||
10768 | **/ | ||
10769 | static struct lpfc_vport * | ||
10770 | lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr, | ||
10771 | uint16_t fcfi) | ||
10772 | { | ||
10773 | struct lpfc_vport **vports; | ||
10774 | struct lpfc_vport *vport = NULL; | ||
10775 | int i; | ||
10776 | uint32_t did = (fc_hdr->fh_d_id[0] << 16 | | ||
10777 | fc_hdr->fh_d_id[1] << 8 | | ||
10778 | fc_hdr->fh_d_id[2]); | ||
10779 | |||
10780 | vports = lpfc_create_vport_work_array(phba); | ||
10781 | if (vports != NULL) | ||
10782 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | ||
10783 | if (phba->fcf.fcfi == fcfi && | ||
10784 | vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) && | ||
10785 | vports[i]->fc_myDID == did) { | ||
10786 | vport = vports[i]; | ||
10787 | break; | ||
10788 | } | ||
10789 | } | ||
10790 | lpfc_destroy_vport_work_array(phba, vports); | ||
10791 | return vport; | ||
10792 | } | ||
10793 | |||
10794 | /** | ||
10795 | * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences | ||
10796 | * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame | ||
10797 | * | ||
10798 | * This function searches through the existing incomplete sequences that have | ||
10799 | * been sent to this @vport. If the frame matches one of the incomplete | ||
10800 | * sequences then the dbuf in the @dmabuf is added to the list of frames that | ||
10801 | * make up that sequence. If no sequence is found that matches this frame then | ||
10802 | * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list | ||
10803 | * This function returns a pointer to the first dmabuf in the sequence list that | ||
10804 | * the frame was linked to. | ||
10805 | **/ | ||
10806 | static struct hbq_dmabuf * | ||
10807 | lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf) | ||
10808 | { | ||
10809 | struct fc_frame_header *new_hdr; | ||
10810 | struct fc_frame_header *temp_hdr; | ||
10811 | struct lpfc_dmabuf *d_buf; | ||
10812 | struct lpfc_dmabuf *h_buf; | ||
10813 | struct hbq_dmabuf *seq_dmabuf = NULL; | ||
10814 | struct hbq_dmabuf *temp_dmabuf = NULL; | ||
10815 | |||
10816 | new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | ||
10817 | /* Use the hdr_buf to find the sequence that this frame belongs to */ | ||
10818 | list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) { | ||
10819 | temp_hdr = (struct fc_frame_header *)h_buf->virt; | ||
10820 | if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) || | ||
10821 | (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) || | ||
10822 | (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3))) | ||
10823 | continue; | ||
10824 | /* found a pending sequence that matches this frame */ | ||
10825 | seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf); | ||
10826 | break; | ||
10827 | } | ||
10828 | if (!seq_dmabuf) { | ||
10829 | /* | ||
10830 | * This indicates first frame received for this sequence. | ||
10831 | * Queue the buffer on the vport's rcv_buffer_list. | ||
10832 | */ | ||
10833 | list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list); | ||
10834 | return dmabuf; | ||
10835 | } | ||
10836 | temp_hdr = seq_dmabuf->hbuf.virt; | ||
10837 | if (new_hdr->fh_seq_cnt < temp_hdr->fh_seq_cnt) { | ||
10838 | list_add(&seq_dmabuf->dbuf.list, &dmabuf->dbuf.list); | ||
10839 | return dmabuf; | ||
10840 | } | ||
10841 | /* find the correct place in the sequence to insert this frame */ | ||
10842 | list_for_each_entry_reverse(d_buf, &seq_dmabuf->dbuf.list, list) { | ||
10843 | temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | ||
10844 | temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt; | ||
10845 | /* | ||
10846 | * If the frame's sequence count is greater than the frame on | ||
10847 | * the list then insert the frame right after this frame | ||
10848 | */ | ||
10849 | if (new_hdr->fh_seq_cnt > temp_hdr->fh_seq_cnt) { | ||
10850 | list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list); | ||
10851 | return seq_dmabuf; | ||
10852 | } | ||
10853 | } | ||
10854 | return NULL; | ||
10855 | } | ||
10856 | |||
10857 | /** | ||
10858 | * lpfc_seq_complete - Indicates if a sequence is complete | ||
10859 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | ||
10860 | * | ||
10861 | * This function checks the sequence, starting with the frame described by | ||
10862 | * @dmabuf, to see if all the frames associated with this sequence are present. | ||
10863 | * the frames associated with this sequence are linked to the @dmabuf using the | ||
10864 | * dbuf list. This function looks for two major things. 1) That the first frame | ||
10865 | * has a sequence count of zero. 2) There is a frame with last frame of sequence | ||
10866 | * set. 3) That there are no holes in the sequence count. The function will | ||
10867 | * return 1 when the sequence is complete, otherwise it will return 0. | ||
10868 | **/ | ||
10869 | static int | ||
10870 | lpfc_seq_complete(struct hbq_dmabuf *dmabuf) | ||
10871 | { | ||
10872 | struct fc_frame_header *hdr; | ||
10873 | struct lpfc_dmabuf *d_buf; | ||
10874 | struct hbq_dmabuf *seq_dmabuf; | ||
10875 | uint32_t fctl; | ||
10876 | int seq_count = 0; | ||
10877 | |||
10878 | hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | ||
10879 | /* make sure first fame of sequence has a sequence count of zero */ | ||
10880 | if (hdr->fh_seq_cnt != seq_count) | ||
10881 | return 0; | ||
10882 | fctl = (hdr->fh_f_ctl[0] << 16 | | ||
10883 | hdr->fh_f_ctl[1] << 8 | | ||
10884 | hdr->fh_f_ctl[2]); | ||
10885 | /* If last frame of sequence we can return success. */ | ||
10886 | if (fctl & FC_FC_END_SEQ) | ||
10887 | return 1; | ||
10888 | list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) { | ||
10889 | seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf); | ||
10890 | hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | ||
10891 | /* If there is a hole in the sequence count then fail. */ | ||
10892 | if (++seq_count != hdr->fh_seq_cnt) | ||
10893 | return 0; | ||
10894 | fctl = (hdr->fh_f_ctl[0] << 16 | | ||
10895 | hdr->fh_f_ctl[1] << 8 | | ||
10896 | hdr->fh_f_ctl[2]); | ||
10897 | /* If last frame of sequence we can return success. */ | ||
10898 | if (fctl & FC_FC_END_SEQ) | ||
10899 | return 1; | ||
10900 | } | ||
10901 | return 0; | ||
10902 | } | ||
10903 | |||
10904 | /** | ||
10905 | * lpfc_prep_seq - Prep sequence for ULP processing | ||
10906 | * @vport: Pointer to the vport on which this sequence was received | ||
10907 | * @dmabuf: pointer to a dmabuf that describes the FC sequence | ||
10908 | * | ||
10909 | * This function takes a sequence, described by a list of frames, and creates | ||
10910 | * a list of iocbq structures to describe the sequence. This iocbq list will be | ||
10911 | * used to issue to the generic unsolicited sequence handler. This routine | ||
10912 | * returns a pointer to the first iocbq in the list. If the function is unable | ||
10913 | * to allocate an iocbq then it throw out the received frames that were not | ||
10914 | * able to be described and return a pointer to the first iocbq. If unable to | ||
10915 | * allocate any iocbqs (including the first) this function will return NULL. | ||
10916 | **/ | ||
10917 | static struct lpfc_iocbq * | ||
10918 | lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf) | ||
10919 | { | ||
10920 | struct lpfc_dmabuf *d_buf, *n_buf; | ||
10921 | struct lpfc_iocbq *first_iocbq, *iocbq; | ||
10922 | struct fc_frame_header *fc_hdr; | ||
10923 | uint32_t sid; | ||
10924 | |||
10925 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | ||
10926 | /* remove from receive buffer list */ | ||
10927 | list_del_init(&seq_dmabuf->hbuf.list); | ||
10928 | /* get the Remote Port's SID */ | ||
10929 | sid = (fc_hdr->fh_s_id[0] << 16 | | ||
10930 | fc_hdr->fh_s_id[1] << 8 | | ||
10931 | fc_hdr->fh_s_id[2]); | ||
10932 | /* Get an iocbq struct to fill in. */ | ||
10933 | first_iocbq = lpfc_sli_get_iocbq(vport->phba); | ||
10934 | if (first_iocbq) { | ||
10935 | /* Initialize the first IOCB. */ | ||
10936 | first_iocbq->iocb.ulpStatus = IOSTAT_SUCCESS; | ||
10937 | first_iocbq->iocb.ulpCommand = CMD_IOCB_RCV_SEQ64_CX; | ||
10938 | first_iocbq->iocb.ulpContext = be16_to_cpu(fc_hdr->fh_ox_id); | ||
10939 | first_iocbq->iocb.unsli3.rcvsli3.vpi = | ||
10940 | vport->vpi + vport->phba->vpi_base; | ||
10941 | /* put the first buffer into the first IOCBq */ | ||
10942 | first_iocbq->context2 = &seq_dmabuf->dbuf; | ||
10943 | first_iocbq->context3 = NULL; | ||
10944 | first_iocbq->iocb.ulpBdeCount = 1; | ||
10945 | first_iocbq->iocb.un.cont64[0].tus.f.bdeSize = | ||
10946 | LPFC_DATA_BUF_SIZE; | ||
10947 | first_iocbq->iocb.un.rcvels.remoteID = sid; | ||
10948 | } | ||
10949 | iocbq = first_iocbq; | ||
10950 | /* | ||
10951 | * Each IOCBq can have two Buffers assigned, so go through the list | ||
10952 | * of buffers for this sequence and save two buffers in each IOCBq | ||
10953 | */ | ||
10954 | list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) { | ||
10955 | if (!iocbq) { | ||
10956 | lpfc_in_buf_free(vport->phba, d_buf); | ||
10957 | continue; | ||
10958 | } | ||
10959 | if (!iocbq->context3) { | ||
10960 | iocbq->context3 = d_buf; | ||
10961 | iocbq->iocb.ulpBdeCount++; | ||
10962 | iocbq->iocb.unsli3.rcvsli3.bde2.tus.f.bdeSize = | ||
10963 | LPFC_DATA_BUF_SIZE; | ||
10964 | } else { | ||
10965 | iocbq = lpfc_sli_get_iocbq(vport->phba); | ||
10966 | if (!iocbq) { | ||
10967 | if (first_iocbq) { | ||
10968 | first_iocbq->iocb.ulpStatus = | ||
10969 | IOSTAT_FCP_RSP_ERROR; | ||
10970 | first_iocbq->iocb.un.ulpWord[4] = | ||
10971 | IOERR_NO_RESOURCES; | ||
10972 | } | ||
10973 | lpfc_in_buf_free(vport->phba, d_buf); | ||
10974 | continue; | ||
10975 | } | ||
10976 | iocbq->context2 = d_buf; | ||
10977 | iocbq->context3 = NULL; | ||
10978 | iocbq->iocb.ulpBdeCount = 1; | ||
10979 | iocbq->iocb.un.cont64[0].tus.f.bdeSize = | ||
10980 | LPFC_DATA_BUF_SIZE; | ||
10981 | iocbq->iocb.un.rcvels.remoteID = sid; | ||
10982 | list_add_tail(&iocbq->list, &first_iocbq->list); | ||
10983 | } | ||
10984 | } | ||
10985 | return first_iocbq; | ||
10986 | } | ||
10987 | |||
10988 | /** | ||
10989 | * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware | ||
10990 | * @phba: Pointer to HBA context object. | ||
10991 | * | ||
10992 | * This function is called with no lock held. This function processes all | ||
10993 | * the received buffers and gives it to upper layers when a received buffer | ||
10994 | * indicates that it is the final frame in the sequence. The interrupt | ||
10995 | * service routine processes received buffers at interrupt contexts and adds | ||
10996 | * received dma buffers to the rb_pend_list queue and signals the worker thread. | ||
10997 | * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the | ||
10998 | * appropriate receive function when the final frame in a sequence is received. | ||
10999 | **/ | ||
11000 | int | ||
11001 | lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba) | ||
11002 | { | ||
11003 | LIST_HEAD(cmplq); | ||
11004 | struct hbq_dmabuf *dmabuf, *seq_dmabuf; | ||
11005 | struct fc_frame_header *fc_hdr; | ||
11006 | struct lpfc_vport *vport; | ||
11007 | uint32_t fcfi; | ||
11008 | struct lpfc_iocbq *iocbq; | ||
11009 | |||
11010 | /* Clear hba flag and get all received buffers into the cmplq */ | ||
11011 | spin_lock_irq(&phba->hbalock); | ||
11012 | phba->hba_flag &= ~HBA_RECEIVE_BUFFER; | ||
11013 | list_splice_init(&phba->rb_pend_list, &cmplq); | ||
11014 | spin_unlock_irq(&phba->hbalock); | ||
11015 | |||
11016 | /* Process each received buffer */ | ||
11017 | while ((dmabuf = lpfc_sli_hbqbuf_get(&cmplq)) != NULL) { | ||
11018 | fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt; | ||
11019 | /* check to see if this a valid type of frame */ | ||
11020 | if (lpfc_fc_frame_check(phba, fc_hdr)) { | ||
11021 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | ||
11022 | continue; | ||
11023 | } | ||
11024 | fcfi = bf_get(lpfc_rcqe_fcf_id, &dmabuf->rcqe); | ||
11025 | vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi); | ||
11026 | if (!vport) { | ||
11027 | /* throw out the frame */ | ||
11028 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | ||
11029 | continue; | ||
11030 | } | ||
11031 | /* Link this frame */ | ||
11032 | seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf); | ||
11033 | if (!seq_dmabuf) { | ||
11034 | /* unable to add frame to vport - throw it out */ | ||
11035 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | ||
11036 | continue; | ||
11037 | } | ||
11038 | /* If not last frame in sequence continue processing frames. */ | ||
11039 | if (!lpfc_seq_complete(seq_dmabuf)) { | ||
11040 | /* | ||
11041 | * When saving off frames post a new one and mark this | ||
11042 | * frame to be freed when it is finished. | ||
11043 | **/ | ||
11044 | lpfc_sli_hbqbuf_fill_hbqs(phba, LPFC_ELS_HBQ, 1); | ||
11045 | dmabuf->tag = -1; | ||
11046 | continue; | ||
11047 | } | ||
11048 | fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt; | ||
11049 | iocbq = lpfc_prep_seq(vport, seq_dmabuf); | ||
11050 | if (!lpfc_complete_unsol_iocb(phba, | ||
11051 | &phba->sli.ring[LPFC_ELS_RING], | ||
11052 | iocbq, fc_hdr->fh_r_ctl, | ||
11053 | fc_hdr->fh_type)) | ||
11054 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | ||
11055 | "2540 Ring %d handler: unexpected Rctl " | ||
11056 | "x%x Type x%x received\n", | ||
11057 | LPFC_ELS_RING, | ||
11058 | fc_hdr->fh_r_ctl, fc_hdr->fh_type); | ||
11059 | }; | ||
11060 | return 0; | ||
11061 | } | ||
11062 | |||
11063 | /** | ||
11064 | * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port | ||
11065 | * @phba: pointer to lpfc hba data structure. | ||
11066 | * | ||
11067 | * This routine is invoked to post rpi header templates to the | ||
11068 | * HBA consistent with the SLI-4 interface spec. This routine | ||
11069 | * posts a PAGE_SIZE memory region to the port to hold up to | ||
11070 | * PAGE_SIZE modulo 64 rpi context headers. | ||
11071 | * | ||
11072 | * This routine does not require any locks. It's usage is expected | ||
11073 | * to be driver load or reset recovery when the driver is | ||
11074 | * sequential. | ||
11075 | * | ||
11076 | * Return codes | ||
11077 | * 0 - sucessful | ||
11078 | * EIO - The mailbox failed to complete successfully. | ||
11079 | * When this error occurs, the driver is not guaranteed | ||
11080 | * to have any rpi regions posted to the device and | ||
11081 | * must either attempt to repost the regions or take a | ||
11082 | * fatal error. | ||
11083 | **/ | ||
11084 | int | ||
11085 | lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba) | ||
11086 | { | ||
11087 | struct lpfc_rpi_hdr *rpi_page; | ||
11088 | uint32_t rc = 0; | ||
11089 | |||
11090 | /* Post all rpi memory regions to the port. */ | ||
11091 | list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | ||
11092 | rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page); | ||
11093 | if (rc != MBX_SUCCESS) { | ||
11094 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
11095 | "2008 Error %d posting all rpi " | ||
11096 | "headers\n", rc); | ||
11097 | rc = -EIO; | ||
11098 | break; | ||
11099 | } | ||
11100 | } | ||
11101 | |||
11102 | return rc; | ||
11103 | } | ||
11104 | |||
11105 | /** | ||
11106 | * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port | ||
11107 | * @phba: pointer to lpfc hba data structure. | ||
11108 | * @rpi_page: pointer to the rpi memory region. | ||
11109 | * | ||
11110 | * This routine is invoked to post a single rpi header to the | ||
11111 | * HBA consistent with the SLI-4 interface spec. This memory region | ||
11112 | * maps up to 64 rpi context regions. | ||
11113 | * | ||
11114 | * Return codes | ||
11115 | * 0 - sucessful | ||
11116 | * ENOMEM - No available memory | ||
11117 | * EIO - The mailbox failed to complete successfully. | ||
11118 | **/ | ||
11119 | int | ||
11120 | lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page) | ||
11121 | { | ||
11122 | LPFC_MBOXQ_t *mboxq; | ||
11123 | struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl; | ||
11124 | uint32_t rc = 0; | ||
11125 | uint32_t mbox_tmo; | ||
11126 | uint32_t shdr_status, shdr_add_status; | ||
11127 | union lpfc_sli4_cfg_shdr *shdr; | ||
11128 | |||
11129 | /* The port is notified of the header region via a mailbox command. */ | ||
11130 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
11131 | if (!mboxq) { | ||
11132 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
11133 | "2001 Unable to allocate memory for issuing " | ||
11134 | "SLI_CONFIG_SPECIAL mailbox command\n"); | ||
11135 | return -ENOMEM; | ||
11136 | } | ||
11137 | |||
11138 | /* Post all rpi memory regions to the port. */ | ||
11139 | hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl; | ||
11140 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | ||
11141 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
11142 | LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE, | ||
11143 | sizeof(struct lpfc_mbx_post_hdr_tmpl) - | ||
11144 | sizeof(struct mbox_header), LPFC_SLI4_MBX_EMBED); | ||
11145 | bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt, | ||
11146 | hdr_tmpl, rpi_page->page_count); | ||
11147 | bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl, | ||
11148 | rpi_page->start_rpi); | ||
11149 | hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys); | ||
11150 | hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys); | ||
11151 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
11152 | shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr; | ||
11153 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
11154 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
11155 | if (rc != MBX_TIMEOUT) | ||
11156 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
11157 | if (shdr_status || shdr_add_status || rc) { | ||
11158 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11159 | "2514 POST_RPI_HDR mailbox failed with " | ||
11160 | "status x%x add_status x%x, mbx status x%x\n", | ||
11161 | shdr_status, shdr_add_status, rc); | ||
11162 | rc = -ENXIO; | ||
11163 | } | ||
11164 | return rc; | ||
11165 | } | ||
11166 | |||
11167 | /** | ||
11168 | * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range | ||
11169 | * @phba: pointer to lpfc hba data structure. | ||
11170 | * | ||
11171 | * This routine is invoked to post rpi header templates to the | ||
11172 | * HBA consistent with the SLI-4 interface spec. This routine | ||
11173 | * posts a PAGE_SIZE memory region to the port to hold up to | ||
11174 | * PAGE_SIZE modulo 64 rpi context headers. | ||
11175 | * | ||
11176 | * Returns | ||
11177 | * A nonzero rpi defined as rpi_base <= rpi < max_rpi if sucessful | ||
11178 | * LPFC_RPI_ALLOC_ERROR if no rpis are available. | ||
11179 | **/ | ||
11180 | int | ||
11181 | lpfc_sli4_alloc_rpi(struct lpfc_hba *phba) | ||
11182 | { | ||
11183 | int rpi; | ||
11184 | uint16_t max_rpi, rpi_base, rpi_limit; | ||
11185 | uint16_t rpi_remaining; | ||
11186 | struct lpfc_rpi_hdr *rpi_hdr; | ||
11187 | |||
11188 | max_rpi = phba->sli4_hba.max_cfg_param.max_rpi; | ||
11189 | rpi_base = phba->sli4_hba.max_cfg_param.rpi_base; | ||
11190 | rpi_limit = phba->sli4_hba.next_rpi; | ||
11191 | |||
11192 | /* | ||
11193 | * The valid rpi range is not guaranteed to be zero-based. Start | ||
11194 | * the search at the rpi_base as reported by the port. | ||
11195 | */ | ||
11196 | spin_lock_irq(&phba->hbalock); | ||
11197 | rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, rpi_base); | ||
11198 | if (rpi >= rpi_limit || rpi < rpi_base) | ||
11199 | rpi = LPFC_RPI_ALLOC_ERROR; | ||
11200 | else { | ||
11201 | set_bit(rpi, phba->sli4_hba.rpi_bmask); | ||
11202 | phba->sli4_hba.max_cfg_param.rpi_used++; | ||
11203 | phba->sli4_hba.rpi_count++; | ||
11204 | } | ||
11205 | |||
11206 | /* | ||
11207 | * Don't try to allocate more rpi header regions if the device limit | ||
11208 | * on available rpis max has been exhausted. | ||
11209 | */ | ||
11210 | if ((rpi == LPFC_RPI_ALLOC_ERROR) && | ||
11211 | (phba->sli4_hba.rpi_count >= max_rpi)) { | ||
11212 | spin_unlock_irq(&phba->hbalock); | ||
11213 | return rpi; | ||
11214 | } | ||
11215 | |||
11216 | /* | ||
11217 | * If the driver is running low on rpi resources, allocate another | ||
11218 | * page now. Note that the next_rpi value is used because | ||
11219 | * it represents how many are actually in use whereas max_rpi notes | ||
11220 | * how many are supported max by the device. | ||
11221 | */ | ||
11222 | rpi_remaining = phba->sli4_hba.next_rpi - rpi_base - | ||
11223 | phba->sli4_hba.rpi_count; | ||
11224 | spin_unlock_irq(&phba->hbalock); | ||
11225 | if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) { | ||
11226 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | ||
11227 | if (!rpi_hdr) { | ||
11228 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
11229 | "2002 Error Could not grow rpi " | ||
11230 | "count\n"); | ||
11231 | } else { | ||
11232 | lpfc_sli4_post_rpi_hdr(phba, rpi_hdr); | ||
11233 | } | ||
11234 | } | ||
11235 | |||
11236 | return rpi; | ||
11237 | } | ||
11238 | |||
11239 | /** | ||
11240 | * lpfc_sli4_free_rpi - Release an rpi for reuse. | ||
11241 | * @phba: pointer to lpfc hba data structure. | ||
11242 | * | ||
11243 | * This routine is invoked to release an rpi to the pool of | ||
11244 | * available rpis maintained by the driver. | ||
11245 | **/ | ||
11246 | void | ||
11247 | lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi) | ||
11248 | { | ||
11249 | spin_lock_irq(&phba->hbalock); | ||
11250 | clear_bit(rpi, phba->sli4_hba.rpi_bmask); | ||
11251 | phba->sli4_hba.rpi_count--; | ||
11252 | phba->sli4_hba.max_cfg_param.rpi_used--; | ||
11253 | spin_unlock_irq(&phba->hbalock); | ||
11254 | } | ||
11255 | |||
11256 | /** | ||
11257 | * lpfc_sli4_remove_rpis - Remove the rpi bitmask region | ||
11258 | * @phba: pointer to lpfc hba data structure. | ||
11259 | * | ||
11260 | * This routine is invoked to remove the memory region that | ||
11261 | * provided rpi via a bitmask. | ||
11262 | **/ | ||
11263 | void | ||
11264 | lpfc_sli4_remove_rpis(struct lpfc_hba *phba) | ||
11265 | { | ||
11266 | kfree(phba->sli4_hba.rpi_bmask); | ||
11267 | } | ||
11268 | |||
11269 | /** | ||
11270 | * lpfc_sli4_resume_rpi - Remove the rpi bitmask region | ||
11271 | * @phba: pointer to lpfc hba data structure. | ||
11272 | * | ||
11273 | * This routine is invoked to remove the memory region that | ||
11274 | * provided rpi via a bitmask. | ||
11275 | **/ | ||
11276 | int | ||
11277 | lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp) | ||
11278 | { | ||
11279 | LPFC_MBOXQ_t *mboxq; | ||
11280 | struct lpfc_hba *phba = ndlp->phba; | ||
11281 | int rc; | ||
11282 | |||
11283 | /* The port is notified of the header region via a mailbox command. */ | ||
11284 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
11285 | if (!mboxq) | ||
11286 | return -ENOMEM; | ||
11287 | |||
11288 | /* Post all rpi memory regions to the port. */ | ||
11289 | lpfc_resume_rpi(mboxq, ndlp); | ||
11290 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | ||
11291 | if (rc == MBX_NOT_FINISHED) { | ||
11292 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
11293 | "2010 Resume RPI Mailbox failed " | ||
11294 | "status %d, mbxStatus x%x\n", rc, | ||
11295 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | ||
11296 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
11297 | return -EIO; | ||
11298 | } | ||
11299 | return 0; | ||
11300 | } | ||
11301 | |||
11302 | /** | ||
11303 | * lpfc_sli4_init_vpi - Initialize a vpi with the port | ||
11304 | * @phba: pointer to lpfc hba data structure. | ||
11305 | * @vpi: vpi value to activate with the port. | ||
11306 | * | ||
11307 | * This routine is invoked to activate a vpi with the | ||
11308 | * port when the host intends to use vports with a | ||
11309 | * nonzero vpi. | ||
11310 | * | ||
11311 | * Returns: | ||
11312 | * 0 success | ||
11313 | * -Evalue otherwise | ||
11314 | **/ | ||
11315 | int | ||
11316 | lpfc_sli4_init_vpi(struct lpfc_hba *phba, uint16_t vpi) | ||
11317 | { | ||
11318 | LPFC_MBOXQ_t *mboxq; | ||
11319 | int rc = 0; | ||
11320 | uint32_t mbox_tmo; | ||
11321 | |||
11322 | if (vpi == 0) | ||
11323 | return -EINVAL; | ||
11324 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
11325 | if (!mboxq) | ||
11326 | return -ENOMEM; | ||
11327 | lpfc_init_vpi(mboxq, vpi); | ||
11328 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_INIT_VPI); | ||
11329 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | ||
11330 | if (rc != MBX_TIMEOUT) | ||
11331 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
11332 | if (rc != MBX_SUCCESS) { | ||
11333 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
11334 | "2022 INIT VPI Mailbox failed " | ||
11335 | "status %d, mbxStatus x%x\n", rc, | ||
11336 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | ||
11337 | rc = -EIO; | ||
11338 | } | ||
11339 | return rc; | ||
11340 | } | ||
11341 | |||
11342 | /** | ||
11343 | * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler. | ||
11344 | * @phba: pointer to lpfc hba data structure. | ||
11345 | * @mboxq: Pointer to mailbox object. | ||
11346 | * | ||
11347 | * This routine is invoked to manually add a single FCF record. The caller | ||
11348 | * must pass a completely initialized FCF_Record. This routine takes | ||
11349 | * care of the nonembedded mailbox operations. | ||
11350 | **/ | ||
11351 | static void | ||
11352 | lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | ||
11353 | { | ||
11354 | void *virt_addr; | ||
11355 | union lpfc_sli4_cfg_shdr *shdr; | ||
11356 | uint32_t shdr_status, shdr_add_status; | ||
11357 | |||
11358 | virt_addr = mboxq->sge_array->addr[0]; | ||
11359 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
11360 | shdr = (union lpfc_sli4_cfg_shdr *) virt_addr; | ||
11361 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
11362 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
11363 | |||
11364 | if ((shdr_status || shdr_add_status) && | ||
11365 | (shdr_status != STATUS_FCF_IN_USE)) | ||
11366 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11367 | "2558 ADD_FCF_RECORD mailbox failed with " | ||
11368 | "status x%x add_status x%x\n", | ||
11369 | shdr_status, shdr_add_status); | ||
11370 | |||
11371 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11372 | } | ||
11373 | |||
11374 | /** | ||
11375 | * lpfc_sli4_add_fcf_record - Manually add an FCF Record. | ||
11376 | * @phba: pointer to lpfc hba data structure. | ||
11377 | * @fcf_record: pointer to the initialized fcf record to add. | ||
11378 | * | ||
11379 | * This routine is invoked to manually add a single FCF record. The caller | ||
11380 | * must pass a completely initialized FCF_Record. This routine takes | ||
11381 | * care of the nonembedded mailbox operations. | ||
11382 | **/ | ||
11383 | int | ||
11384 | lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record) | ||
11385 | { | ||
11386 | int rc = 0; | ||
11387 | LPFC_MBOXQ_t *mboxq; | ||
11388 | uint8_t *bytep; | ||
11389 | void *virt_addr; | ||
11390 | dma_addr_t phys_addr; | ||
11391 | struct lpfc_mbx_sge sge; | ||
11392 | uint32_t alloc_len, req_len; | ||
11393 | uint32_t fcfindex; | ||
11394 | |||
11395 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
11396 | if (!mboxq) { | ||
11397 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11398 | "2009 Failed to allocate mbox for ADD_FCF cmd\n"); | ||
11399 | return -ENOMEM; | ||
11400 | } | ||
11401 | |||
11402 | req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) + | ||
11403 | sizeof(uint32_t); | ||
11404 | |||
11405 | /* Allocate DMA memory and set up the non-embedded mailbox command */ | ||
11406 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
11407 | LPFC_MBOX_OPCODE_FCOE_ADD_FCF, | ||
11408 | req_len, LPFC_SLI4_MBX_NEMBED); | ||
11409 | if (alloc_len < req_len) { | ||
11410 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11411 | "2523 Allocated DMA memory size (x%x) is " | ||
11412 | "less than the requested DMA memory " | ||
11413 | "size (x%x)\n", alloc_len, req_len); | ||
11414 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11415 | return -ENOMEM; | ||
11416 | } | ||
11417 | |||
11418 | /* | ||
11419 | * Get the first SGE entry from the non-embedded DMA memory. This | ||
11420 | * routine only uses a single SGE. | ||
11421 | */ | ||
11422 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | ||
11423 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | ||
11424 | if (unlikely(!mboxq->sge_array)) { | ||
11425 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | ||
11426 | "2526 Failed to get the non-embedded SGE " | ||
11427 | "virtual address\n"); | ||
11428 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11429 | return -ENOMEM; | ||
11430 | } | ||
11431 | virt_addr = mboxq->sge_array->addr[0]; | ||
11432 | /* | ||
11433 | * Configure the FCF record for FCFI 0. This is the driver's | ||
11434 | * hardcoded default and gets used in nonFIP mode. | ||
11435 | */ | ||
11436 | fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record); | ||
11437 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | ||
11438 | lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t)); | ||
11439 | |||
11440 | /* | ||
11441 | * Copy the fcf_index and the FCF Record Data. The data starts after | ||
11442 | * the FCoE header plus word10. The data copy needs to be endian | ||
11443 | * correct. | ||
11444 | */ | ||
11445 | bytep += sizeof(uint32_t); | ||
11446 | lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record)); | ||
11447 | mboxq->vport = phba->pport; | ||
11448 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record; | ||
11449 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | ||
11450 | if (rc == MBX_NOT_FINISHED) { | ||
11451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11452 | "2515 ADD_FCF_RECORD mailbox failed with " | ||
11453 | "status 0x%x\n", rc); | ||
11454 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11455 | rc = -EIO; | ||
11456 | } else | ||
11457 | rc = 0; | ||
11458 | |||
11459 | return rc; | ||
11460 | } | ||
11461 | |||
11462 | /** | ||
11463 | * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record. | ||
11464 | * @phba: pointer to lpfc hba data structure. | ||
11465 | * @fcf_record: pointer to the fcf record to write the default data. | ||
11466 | * @fcf_index: FCF table entry index. | ||
11467 | * | ||
11468 | * This routine is invoked to build the driver's default FCF record. The | ||
11469 | * values used are hardcoded. This routine handles memory initialization. | ||
11470 | * | ||
11471 | **/ | ||
11472 | void | ||
11473 | lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba, | ||
11474 | struct fcf_record *fcf_record, | ||
11475 | uint16_t fcf_index) | ||
11476 | { | ||
11477 | memset(fcf_record, 0, sizeof(struct fcf_record)); | ||
11478 | fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE; | ||
11479 | fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER; | ||
11480 | fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY; | ||
11481 | bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]); | ||
11482 | bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]); | ||
11483 | bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]); | ||
11484 | bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3); | ||
11485 | bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4); | ||
11486 | bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5); | ||
11487 | bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]); | ||
11488 | bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]); | ||
11489 | bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]); | ||
11490 | bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1); | ||
11491 | bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1); | ||
11492 | bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index); | ||
11493 | bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record, | ||
11494 | LPFC_FCF_FPMA | LPFC_FCF_SPMA); | ||
11495 | /* Set the VLAN bit map */ | ||
11496 | if (phba->valid_vlan) { | ||
11497 | fcf_record->vlan_bitmap[phba->vlan_id / 8] | ||
11498 | = 1 << (phba->vlan_id % 8); | ||
11499 | } | ||
11500 | } | ||
11501 | |||
11502 | /** | ||
11503 | * lpfc_sli4_read_fcf_record - Read the driver's default FCF Record. | ||
11504 | * @phba: pointer to lpfc hba data structure. | ||
11505 | * @fcf_index: FCF table entry offset. | ||
11506 | * | ||
11507 | * This routine is invoked to read up to @fcf_num of FCF record from the | ||
11508 | * device starting with the given @fcf_index. | ||
11509 | **/ | ||
11510 | int | ||
11511 | lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index) | ||
11512 | { | ||
11513 | int rc = 0, error; | ||
11514 | LPFC_MBOXQ_t *mboxq; | ||
11515 | void *virt_addr; | ||
11516 | dma_addr_t phys_addr; | ||
11517 | uint8_t *bytep; | ||
11518 | struct lpfc_mbx_sge sge; | ||
11519 | uint32_t alloc_len, req_len; | ||
11520 | struct lpfc_mbx_read_fcf_tbl *read_fcf; | ||
11521 | |||
11522 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
11523 | if (!mboxq) { | ||
11524 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11525 | "2000 Failed to allocate mbox for " | ||
11526 | "READ_FCF cmd\n"); | ||
11527 | return -ENOMEM; | ||
11528 | } | ||
11529 | |||
11530 | req_len = sizeof(struct fcf_record) + | ||
11531 | sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); | ||
11532 | |||
11533 | /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */ | ||
11534 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
11535 | LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len, | ||
11536 | LPFC_SLI4_MBX_NEMBED); | ||
11537 | |||
11538 | if (alloc_len < req_len) { | ||
11539 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
11540 | "0291 Allocated DMA memory size (x%x) is " | ||
11541 | "less than the requested DMA memory " | ||
11542 | "size (x%x)\n", alloc_len, req_len); | ||
11543 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11544 | return -ENOMEM; | ||
11545 | } | ||
11546 | |||
11547 | /* Get the first SGE entry from the non-embedded DMA memory. This | ||
11548 | * routine only uses a single SGE. | ||
11549 | */ | ||
11550 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); | ||
11551 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); | ||
11552 | if (unlikely(!mboxq->sge_array)) { | ||
11553 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | ||
11554 | "2527 Failed to get the non-embedded SGE " | ||
11555 | "virtual address\n"); | ||
11556 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11557 | return -ENOMEM; | ||
11558 | } | ||
11559 | virt_addr = mboxq->sge_array->addr[0]; | ||
11560 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; | ||
11561 | |||
11562 | /* Set up command fields */ | ||
11563 | bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index); | ||
11564 | /* Perform necessary endian conversion */ | ||
11565 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); | ||
11566 | lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t)); | ||
11567 | mboxq->vport = phba->pport; | ||
11568 | mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record; | ||
11569 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); | ||
11570 | if (rc == MBX_NOT_FINISHED) { | ||
11571 | lpfc_sli4_mbox_cmd_free(phba, mboxq); | ||
11572 | error = -EIO; | ||
11573 | } else | ||
11574 | error = 0; | ||
11575 | return error; | ||
11576 | } | ||